diff options
author | Benjamin Drung <benjamin.drung@profitbricks.com> | 2014-03-26 12:09:28 +0100 |
---|---|---|
committer | Benjamin Drung <benjamin.drung@profitbricks.com> | 2014-03-26 12:09:28 +0100 |
commit | ebd443e78d3df99d98d001707786e561fa827b68 (patch) | |
tree | 30a3f4a5ce9a0056dcd8f8a17df15ec281c5084b | |
parent | d86a78f7fe72eed37835417ec50f9249a3bc111d (diff) | |
download | appdirs-ebd443e78d3df99d98d001707786e561fa827b68.tar.gz |
Some PEP 8 fixes.
-rw-r--r-- | appdirs.py | 57 | ||||
-rw-r--r-- | setup.py | 3 |
2 files changed, 35 insertions, 25 deletions
@@ -26,7 +26,6 @@ if PY3: unicode = str - def user_data_dir(appname=None, appauthor=None, version=None, roaming=False): r"""Return full path to the user-specific data dir for this application. @@ -122,12 +121,12 @@ def site_data_dir(appname=None, appauthor=None, version=None, multipath=False): # XDG default for $XDG_DATA_DIRS # only first, if multipath is False path = os.getenv('XDG_DATA_DIRS', - os.pathsep.join(['/usr/local/share', '/usr/share'])) - pathlist = [ os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) ] + os.pathsep.join(['/usr/local/share', '/usr/share'])) + pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] if appname: if version: appname = os.path.join(appname, version) - pathlist = [ os.sep.join([x, appname]) for x in pathlist ] + pathlist = [os.sep.join([x, appname]) for x in pathlist] if multipath: path = os.pathsep.join(pathlist) @@ -168,7 +167,7 @@ def user_config_dir(appname=None, appauthor=None, version=None, roaming=False): For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME. That means, by deafult "~/.config/<AppName>". """ - if sys.platform in [ "win32", "darwin" ]: + if sys.platform in ["win32", "darwin"]: path = user_data_dir(appname, appauthor, None, roaming) else: path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser("~/.config")) @@ -208,7 +207,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) WARNING: Do not use this on Windows. See the Vista-Fail note above for why. """ - if sys.platform in [ "win32", "darwin" ]: + if sys.platform in ["win32", "darwin"]: path = site_data_dir(appname, appauthor) if appname and version: path = os.path.join(path, version) @@ -216,11 +215,11 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) # XDG default for $XDG_CONFIG_DIRS # only first, if multipath is False path = os.getenv('XDG_CONFIG_DIRS', '/etc/xdg') - pathlist = [ os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) ] + pathlist = [os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep)] if appname: if version: appname = os.path.join(appname, version) - pathlist = [ os.sep.join([x, appname]) for x in pathlist ] + pathlist = [os.sep.join([x, appname]) for x in pathlist] if multipath: path = os.pathsep.join(pathlist) @@ -228,6 +227,7 @@ def site_config_dir(appname=None, appauthor=None, version=None, multipath=False) path = pathlist[0] return path + def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True): r"""Return full path to the user-specific cache dir for this application. @@ -280,6 +280,7 @@ def user_cache_dir(appname=None, appauthor=None, version=None, opinion=True): path = os.path.join(path, version) return path + def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): r"""Return full path to the user-specific log dir for this application. @@ -316,11 +317,13 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): os.path.expanduser('~/Library/Logs'), appname) elif sys.platform == "win32": - path = user_data_dir(appname, appauthor, version); version=False + path = user_data_dir(appname, appauthor, version) + version = False if opinion: path = os.path.join(path, "Logs") else: - path = user_cache_dir(appname, appauthor, version); version=False + path = user_cache_dir(appname, appauthor, version) + version = False if opinion: path = os.path.join(path, "log") if appname and version: @@ -330,39 +333,43 @@ def user_log_dir(appname=None, appauthor=None, version=None, opinion=True): class AppDirs(object): """Convenience wrapper for getting application dirs.""" - def __init__(self, appname, appauthor=None, version=None, - roaming=False, multipath=False): + def __init__(self, appname, appauthor=None, version=None, roaming=False, + multipath=False): self.appname = appname self.appauthor = appauthor self.version = version self.roaming = roaming self.multipath = multipath + @property def user_data_dir(self): return user_data_dir(self.appname, self.appauthor, - version=self.version, roaming=self.roaming) + version=self.version, roaming=self.roaming) + @property def site_data_dir(self): return site_data_dir(self.appname, self.appauthor, - version=self.version, multipath=self.multipath) + version=self.version, multipath=self.multipath) + @property def user_config_dir(self): return user_config_dir(self.appname, self.appauthor, - version=self.version, roaming=self.roaming) + version=self.version, roaming=self.roaming) + @property def site_config_dir(self): return site_data_dir(self.appname, self.appauthor, - version=self.version, multipath=self.multipath) + version=self.version, multipath=self.multipath) + @property def user_cache_dir(self): return user_cache_dir(self.appname, self.appauthor, - version=self.version) + version=self.version) + @property def user_log_dir(self): return user_log_dir(self.appname, self.appauthor, - version=self.version) - - + version=self.version) #---- internal support stuff @@ -380,11 +387,14 @@ def _get_win_folder_from_registry(csidl_name): "CSIDL_LOCAL_APPDATA": "Local AppData", }[csidl_name] - key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, - r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") + key = _winreg.OpenKey( + _winreg.HKEY_CURRENT_USER, + r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" + ) dir, type = _winreg.QueryValueEx(key, shell_folder_name) return dir + def _get_win_folder_with_pywin32(csidl_name): from win32com.shell import shellcon, shell dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0) @@ -411,6 +421,7 @@ def _get_win_folder_with_pywin32(csidl_name): pass return dir + def _get_win_folder_with_ctypes(csidl_name): import ctypes @@ -449,7 +460,6 @@ if sys.platform == "win32": _get_win_folder = _get_win_folder_from_registry - #---- self test code if __name__ == "__main__": @@ -474,4 +484,3 @@ if __name__ == "__main__": dirs = AppDirs(appname) for prop in props: print("%s: %s" % (prop, getattr(dirs, prop))) - @@ -17,7 +17,8 @@ def read(fname): return out -setup(name='appdirs', +setup( + name='appdirs', version=appdirs.__version__, description='A small Python module for determining appropriate " + \ "platform-specific dirs, e.g. a "user data dir".', |