You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
992 B

  1. """Functions that help us work with files and folders.
  2. """
  3. import os
  4. def keymap(keyboard):
  5. """Locate the correct directory for storing a keymap.
  6. Args:
  7. keyboard
  8. The name of the keyboard. Example: clueboard/66/rev3
  9. """
  10. for directory in ['.', '..', '../..', '../../..', '../../../..', '../../../../..']:
  11. basepath = os.path.normpath(os.path.join('keyboards', keyboard, directory, 'keymaps'))
  12. if os.path.exists(basepath):
  13. return basepath
  14. logging.error('Could not find keymaps directory!')
  15. raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
  16. def normpath(path):
  17. """Returns the fully resolved absolute path to a file.
  18. This function will return the absolute path to a file as seen from the
  19. directory the script was called from.
  20. """
  21. if path and path[0] == '/':
  22. return os.path.normpath(path)
  23. return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))