path.py 899 B

12345678910111213141516171819202122232425262728
  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. """
  7. for directory in ['.', '..', '../..', '../../..', '../../../..', '../../../../..']:
  8. basepath = os.path.normpath(os.path.join('keyboards', keyboard, directory, 'keymaps'))
  9. if os.path.exists(basepath):
  10. return basepath
  11. logging.error('Could not find keymaps directory!')
  12. raise NoSuchKeyboardError('Could not find keymaps directory for: %s' % keyboard)
  13. def normpath(path):
  14. """Returns the fully resolved absolute path to a file.
  15. This function will return the absolute path to a file as seen from the
  16. directory the script was called from.
  17. """
  18. if path and path[0] == '/':
  19. return os.path.normpath(path)
  20. return os.path.normpath(os.path.join(os.environ['ORIG_CWD'], path))