def _site_data_path( app_name: str = None, app_author: str = None, version: str = None, multi_path: bool = False, ) -> Path: r"""Return full path to the user-shared data dir for this application. "app_name" is the name of application. If None, just the system directory is returned. "app_author" (only used on Windows) is the name of the app_author or distributing body for this application. Typically it is the owning company name. This falls back to app_name. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be "<major>.<minor>". Only applied when app_name is present. "multi_path" is an optional parameter only applicable to *nix which indicates that the entire list of data dirs should be returned. By default, the first item from XDG_DATA_DIRS is returned, or '/usr/local/share/<AppName>', if XDG_DATA_DIRS is not set Typical site data directories are: Mac OS X: /Library/Application Support/<AppName> Unix: /usr/local/share/<AppName> or /usr/share/<AppName> Win XP: C:\Documents and Settings\All Users\Application Data\<AppAuthor>\<AppName> Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.) Win 7: C:\ProgramData\<AppAuthor>\<AppName> # Hidden, but writeable on Win 7. For Unix, this is using the $XDG_DATA_DIRS[0] default. WARNING: Do not use this on Windows. See the Vista-Fail note above for why.""" if SYSTEM == "win32": if app_author is None: app_author = app_name path = Path( os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))) if app_name: if app_author is not False: path = path / app_author / app_name else: path /= app_name elif SYSTEM == "darwin": path = Path.home() / "Library" / "Application Support" if app_name: path /= app_name else: # 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"])) path_list = [ os.path.expanduser(x.rstrip(os.sep)) for x in path.split(os.pathsep) ] if app_name: if version: app_name = Path(app_name) / version path_list = [Path(x) / app_name for x in path_list] if multi_path: path = os.pathsep.join([str(a) for a in path_list]) else: path_list = [Path(a) for a in path_list] path = path_list[0] return path if app_name and version: path /= version return path
def _user_cache_path( app_name: str = None, app_author: str = None, version: str = None, opinionated: bool = True, ) -> Path: r"""Return full path to the user-specific cache dir for this application. "appname" is the name of application. If None, just the system directory is returned. "appauthor" (only used on Windows) is the name of the appauthor or distributing body for this application. Typically it is the owning company name. This falls back to appname. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be "<major>.<minor>". Only applied when appname is present. "opinionated" (boolean) can be False to disable the appending of "Cache" to the base app data dir for Windows. See discussion below. Typical user cache directories are: Mac OS X: ~/Library/Caches/<AppName> Unix: ~/.cache/<AppName> (XDG default) Win XP: C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName>\Cache Vista: C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName>\Cache On Windows the only suggestion in the MSDN docs is that local settings go in the `CSIDL_LOCAL_APPDATA` directory. This is identical to the non-roaming app data dir (the default returned by `user_data_dir` above). Apps typically put cache data somewhere *under* the given dir here. Some examples: ...\Mozilla\Firefox\Profiles\<ProfileName>\Cache ...\Acme\SuperApp\Cache\1.0 OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value. This can be disabled with the `opinionated=False` option.""" if SYSTEM == "win32": if app_author is None: app_author = app_name path = Path(os.path.normpath( get_win_folder("CSIDL_LOCAL_APPDATA"))) if app_name: if app_author is not False: path = path / app_author / app_name else: path /= app_name if opinionated: path /= "Cache" elif SYSTEM == "darwin": path = Path.home() / "Library" / "Caches" if app_name: path /= app_name else: path = Path(os.getenv("XDG_CACHE_HOME", Path.home() / ".cache")) if app_name: path /= app_name if app_name and version: path /= version return path
def _user_data_path( app_name: str = None, app_author: str = None, version: str = None, roaming: bool = False, ) -> Path: r"""Return full path to the user-specific data dir for this application. "app_name" is the name of application. If None, just the system directory is returned. "app_author" (only used on Windows) is the name of the app_author or distributing body for this application. Typically it is the owning company name. This falls back to app_name. You may pass False to disable it. "version" is an optional version path element to append to the path. You might want to use this if you want multiple versions of your app to be able to run independently. If used, this would typically be "<major>.<minor>". Only applied when app_name is present. "roaming" (boolean, default False) can be set True to use the Windows roaming appdata directory. That means that for users on a Windows network setup for roaming profiles, this user data will be sync'd on login. See <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx> for a discussion of issues. Notes: - MSDN on where to store app data files: http://support.microsoft.com/default.aspx?scid=kb;en-us;310294#XSLTH3194121123120121120120 - Mac OS X: http://developer.apple.com/documentation/MacOSX/Conceptual/BPFileSystem/index.html - XDG spec for Un*x: https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html Typical user data directories are: Mac OS X: ~/Library/Application Support/<AppName> Unix: ~/.local/share/<AppName> # or in $XDG_DATA_HOME, if defined Win XP (not roaming): C:\Documents and Settings\<username>\Application Data\<AppAuthor>\<AppName> Win XP (roaming): C:\Documents and Settings\<username>\Local Settings\Application Data\<AppAuthor>\<AppName> Win 7 (not roaming): C:\Users\<username>\AppData\Local\<AppAuthor>\<AppName> Win 7 (roaming): C:\Users\<username>\AppData\Roaming\<AppAuthor>\<AppName> For Unix, we follow the XDG spec and support $XDG_DATA_HOME. That means, by default "~/.local/share/<AppName>".""" if SYSTEM == "win32": if app_author is None: app_author = app_name const = roaming and "CSIDL_APPDATA" or "CSIDL_LOCAL_APPDATA" path_ = Path(os.path.normpath(get_win_folder(const))) if app_name: if app_author is not False: path_ = path_ / app_author / app_name else: path_ /= app_name elif SYSTEM == "darwin": path_ = Path.home() / "Library" / "Application Support" if app_name: path_ /= app_name else: path_ = Path( os.getenv("XDG_DATA_HOME", Path.home() / ".local" / "share")) if app_name: path_ /= app_name if app_name and version: path_ /= version return path_