def get_home_folder(): """ Return the home directory of the user running the Odemis GUI """ # fall-back to HOME if sys.platform.startswith('linux'): folder = os.path.expanduser(u"~") elif sys.platform.startswith('win32'): # expanduser(u) fails with non-ASCII usernames in Python2, # see https://bugs.python.org/issue13207 # Import functions here because wintypes in ctypes library cannot be opened in linux from odemis.gui.util.winknownpaths import get_path, FOLDERID folder = get_path(FOLDERID.Profile) if os.path.isdir(folder): return folder # last resort: current working directory should always be existing return os.getcwd()
def get_picture_folder(): """ return (unicode): a full path to the "Picture" user folder. It tries to always return an existing folder. """ if sys.platform.startswith('linux'): # First try to find the XDG picture folder folder = None try: folder = subprocess.check_output(["xdg-user-dir", "PICTURES"]) folder = folder.strip().decode(sys.getfilesystemencoding()) except subprocess.CalledProcessError: # XDG not supported pass if os.path.isdir(folder): return folder # drop to default elif sys.platform.startswith('win32'): # expanduser(u) fails with non-ASCII usernames in Python2, # see https://bugs.python.org/issue13207 # Import functions here because wintypes in ctypes library cannot be opened in linux from odemis.gui.util.winknownpaths import get_path, FOLDERID try: folder = get_path(FOLDERID.Pictures) return folder except: logging.warning("Cannot find picture folder") else: logging.warning("Platform not supported for picture folder") # fall-back to HOME folder = os.path.expanduser(u"~") if os.path.isdir(folder): return folder # last resort: current working directory should always be existing return os.getcwd()