summaryrefslogtreecommitdiff
path: root/lib/python/qmk/path.py
diff options
context:
space:
mode:
authorWilliam Chang <william@factual.com>2019-11-20 22:17:07 -0800
committerWilliam Chang <william@factual.com>2019-11-20 22:17:07 -0800
commite7f4d56592b3975c38af329e77b4efd9108495e8 (patch)
tree0a416bccbf70bfdbdb9ffcdb3bf136b47378c014 /lib/python/qmk/path.py
parent71493b2f9bbd5f3d18373c518fa14ccafcbf48fc (diff)
parent8416a94ad27b3ff058576f09f35f0704a8b39ff3 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'lib/python/qmk/path.py')
-rw-r--r--lib/python/qmk/path.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/python/qmk/path.py b/lib/python/qmk/path.py
new file mode 100644
index 0000000000..cf087265fb
--- /dev/null
+++ b/lib/python/qmk/path.py
@@ -0,0 +1,35 @@
+"""Functions that help us work with files and folders.
+"""
+import logging
+import os
+
+from qmk.errors import NoSuchKeyboardError
+
+
+def keymap(keyboard):
+ """Locate the correct directory for storing a keymap.
+
+ Args:
+ keyboard
+ The name of the keyboard. Example: clueboard/66/rev3
+ """
+ for directory in ['.', '..', '../..', '../../..', '../../../..', '../../../../..']:
+ basepath = os.path.normpath(os.path.join('keyboards', keyboard, directory, 'keymaps'))
+
+ if os.path.exists(basepath):
+ return basepath
+
+ logging.error('Could not find keymaps directory!')
+ raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
+
+
+def normpath(path):
+ """Returns the fully resolved absolute path to a file.
+
+ This function will return the absolute path to a file as seen from the
+ directory the script was called from.
+ """
+ if path and path[0] == '/':
+ return os.path.normpath(path)
+
+ return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))