3 Pf`W@sdZd1ZdjeeeZddlZddlZejddkZ e r>eZ ej j drddl Z e j ddZej drrd Zqej d rd Zqd Znej Zd2ddZd3ddZd4ddZd5ddZd6ddZd7ddZGdddeZddZdd Zd!d"Zd#d$Zed kryddlZeZWnnek rydd%l m!Z!eZWnBek r|yddl"Z#eZWnek rveZYnXYnXYnXe$d&kr~d'Z%d(Z&d8Z'e(d)ee%e&d*d+Z)x$e'D]Z*e(d,e*e+e)e*fqWe(d-ee%e&Z)x$e'D]Z*e(d,e*e+e)e*fqWe(d.ee%Z)x$e'D]Z*e(d,e*e+e)e*fq$We(d/ee%d d0Z)x$e'D]Z*e(d,e*e+e)e*fq^WdS)9zyUtilities for determining application-specific dirs. See for details and usage. .NjavaZWindowswin32ZMacdarwinZlinux2FcCstdkr^|dkr|}|rdpd}tjjt|}|r|dk rNtjj|||}qtjj||}nNtdkrtjjd}|rtjj||}n&tjdtjjd }|rtjj||}|r|rtjj||}|S) aJReturn full path to the user-specific data 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 ".". Only applied when appname 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 for a discussion of issues. Typical user data directories are: macOS: ~/Library/Application Support/ Unix: ~/.local/share/ # or in $XDG_DATA_HOME, if defined Win XP (not roaming): C:\Documents and Settings\\Application Data\\ Win XP (roaming): C:\Documents and Settings\\Local Settings\Application Data\\ Win 7 (not roaming): C:\Users\\AppData\Local\\ Win 7 (roaming): C:\Users\\AppData\Roaming\\ For Unix, we follow the XDG spec and support $XDG_DATA_HOME. That means, by default "~/.local/share/". rN CSIDL_APPDATACSIDL_LOCAL_APPDATAFrz~/Library/Application Support/Z XDG_DATA_HOMEz~/.local/share)systemospathnormpath_get_win_folderjoin expandusergetenv)appname appauthorversionroamingconstr r/usr/lib/python3.6/appdirs.py user_data_dir-s&   rcs tdkrR|dkr}tjjtd}r|dk rBtjj||}qtjj|}ntdkrztjjd}rtjj|}nttjdtjjdd g}d d |j tjD}r|rtjj|fd d |D}|rtjj|}n|d }|So|rtjj||}|S)aiReturn full path to the user-shared data 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 ".". Only applied when appname is present. "multipath" 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/', if XDG_DATA_DIRS is not set Typical user data directories are: macOS: /Library/Application Support/ Unix: /usr/local/share/ or /usr/share/ Win XP: C:\Documents and Settings\All Users\Application Data\\ Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.) Win 7: C:\ProgramData\\ # 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. rNCSIDL_COMMON_APPDATAFrz/Library/Application SupportZ XDG_DATA_DIRSz/usr/local/sharez /usr/sharecSs g|]}tjj|jtjqSr)r r rrstripsep).0xrrr sz!site_data_dir..csg|]}tjj|gqSr)r rr)rr)rrrr sr) r r r rrrrrpathsepsplit)rrr multipathr pathlistr)rr site_data_dirds4  r%cCsXtdkrt||d|}n&tjdtjjd}|r>tjj||}|rT|rTtjj||}|S)aReturn full path to the user-specific config 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 ".". Only applied when appname 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 for a discussion of issues. Typical user data directories are: macOS: same as user_data_dir Unix: ~/.config/ # or in $XDG_CONFIG_HOME, if defined Win *: same as user_data_dir For Unix, we follow the XDG spec and support $XDG_CONFIG_HOME. That means, by deafult "~/.config/". rrNZXDG_CONFIG_HOMEz ~/.config)rr)r rr rr rr)rrrrr rrruser_config_dirsr&cstd kr*t|}r|rtjj||}ndtjdd}dd|jtjD}rt|rbtjj|fdd|D}|rtjj|}n|d}|S) aReturn full path to the user-shared data 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 ".". Only applied when appname is present. "multipath" is an optional parameter only applicable to *nix which indicates that the entire list of config dirs should be returned. By default, the first item from XDG_CONFIG_DIRS is returned, or '/etc/xdg/', if XDG_CONFIG_DIRS is not set Typical user data directories are: macOS: same as site_data_dir Unix: /etc/xdg/ or $XDG_CONFIG_DIRS[i]/ for each value in $XDG_CONFIG_DIRS Win *: same as site_data_dir Vista: (Fail! "C:\ProgramData" is a hidden *system* directory on Vista.) For Unix, this is using the $XDG_CONFIG_DIRS[0] default, if multipath=False WARNING: Do not use this on Windows. See the Vista-Fail note above for why. rrZXDG_CONFIG_DIRSz/etc/xdgcSs g|]}tjj|jtjqSr)r r rrr)rrrrrr sz#site_config_dir..csg|]}tjj|gqSr)r rr)rr)rrrr sr)rr)r r%r r rrr"r!)rrrr#r r$r)rrsite_config_dirs  r'TcCstdkrd|dkr|}tjjtd}|r|dk rBtjj|||}ntjj||}|rtjj|d}nNtdkrtjjd}|rtjj||}n&tjdtjjd }|rtjj||}|r|rtjj||}|S) aReturn 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 ".". Only applied when appname is present. "opinion" (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: macOS: ~/Library/Caches/ Unix: ~/.cache/ (XDG default) Win XP: C:\Documents and Settings\\Local Settings\Application Data\\\Cache Vista: C:\Users\\AppData\Local\\\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\\Cache ...\Acme\SuperApp\Cache\1.0 OPINION: This function appends "Cache" to the `CSIDL_LOCAL_APPDATA` value. This can be disabled with the `opinion=False` option. rNr FZCacherz~/Library/CachesZXDG_CACHE_HOMEz~/.cache)r r r rrrrr)rrropinionr rrruser_cache_dirs(! r)cCstdkr tjjtjjd|}nNtdkrLt|||}d}|rntjj|d}n"t|||}d}|rntjj|d}|r|rtjj||}|S)aReturn full path to the user-specific log 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 ".". Only applied when appname is present. "opinion" (boolean) can be False to disable the appending of "Logs" to the base app data dir for Windows, and "log" to the base cache dir for Unix. See discussion below. Typical user cache directories are: macOS: ~/Library/Logs/ Unix: ~/.cache//log # or under $XDG_CACHE_HOME if defined Win XP: C:\Documents and Settings\\Local Settings\Application Data\\\Logs Vista: C:\Users\\AppData\Local\\\Logs On Windows the only suggestion in the MSDN docs is that local settings go in the `CSIDL_LOCAL_APPDATA` directory. (Note: I'm interested in examples of what some windows apps use for a logs dir.) OPINION: This function appends "Logs" to the `CSIDL_LOCAL_APPDATA` value for Windows and appends "log" to the user cache dir for Unix. This can be disabled with the `opinion=False` option. rz~/Library/LogsrFZLogslog)r r r rrrr))rrrr(r rrr user_log_dir:s    r+c@sbeZdZdZdddZeddZedd Zed d Zed d Z eddZ eddZ dS)AppDirsz1Convenience wrapper for getting application dirs.NFcCs"||_||_||_||_||_dS)N)rrrrr#)selfrrrrr#rrr__init__os zAppDirs.__init__cCst|j|j|j|jdS)N)rr)rrrrr)r-rrrrws zAppDirs.user_data_dircCst|j|j|j|jdS)N)rr#)r%rrrr#)r-rrrr%|s zAppDirs.site_data_dircCst|j|j|j|jdS)N)rr)r&rrrr)r-rrrr&s zAppDirs.user_config_dircCst|j|j|j|jdS)N)rr#)r'rrrr#)r-rrrr's zAppDirs.site_config_dircCst|j|j|jdS)N)r)r)rrr)r-rrrr)s zAppDirs.user_cache_dircCst|j|j|jdS)N)r)r+rrr)r-rrrr+s zAppDirs.user_log_dir)NNFF) __name__ __module__ __qualname____doc__r.propertyrr%r&r'r)r+rrrrr,ms      r,cCs:ddl}dddd|}|j|jd}|j||\}}|S)zThis is a fallback technique at best. I'm not sure if using the registry for this guarantees us the correct answer for all CSIDL_* names. rNZAppDatazCommon AppDataz Local AppData)r rr z@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)_winregOpenKeyHKEY_CURRENT_USERZ QueryValueEx) csidl_namer4Zshell_folder_namekeydirtyperrr_get_win_folder_from_registrysr;cCsddlm}m}|jdt||dd}y`t|}d}x|D]}t|dkr:d}Pq:W|ryddl}|j|}Wnt k rYnXWnt k rYnX|S)Nr)shellconshellFT) win32com.shellr<r=SHGetFolderPathgetattrunicodeordwin32apiGetShortPathName ImportError UnicodeError)r7r<r=r9 has_high_charcrDrrr_get_win_folder_with_pywin32s$   rJcCsddl}dddd|}|jd}|jjjd|dd|d}x|D]}t|dkrBd }PqBW|r|jd}|jjj|j|dr|}|jS) Nr#)r rr iFr>T) ctypesZcreate_unicode_bufferwindllZshell32ZSHGetFolderPathWrCZkernel32ZGetShortPathNameWvalue)r7rNZ csidl_constbufrHrIZbuf2rrr_get_win_folder_with_ctypess"    rRc Csddl}ddlm}ddlm}|jjd}|jd|}|jj }|j dt |j |d|j j ||jj|jjd}d}x|D]} t| dkr~d }Pq~W|r|jd|}|jj } tj|||r|jj|jjd}|S) Nr)jna)rrIFr>T)arrayZcom.sunrSZcom.sun.jna.platformrZWinDefZMAX_PATHZzerosZShell32ZINSTANCEr@rAZShlObjZSHGFP_TYPE_CURRENTZNativeZtoStringZtostringrrCZKernel32ZkernalrE) r7rVrSrZbuf_sizerQr=r9rHrIZkernelrrr_get_win_folder_with_jnas&       rW)rO__main__ZMyAppZ MyCompanyz%-- app dirs (with optional 'version')z1.0)rz%s: %sz) -- app dirs (without optional 'version')z+ -- app dirs (without optional 'appauthor')z( -- app dirs (with disabled 'appauthor'))r)rrr)NNNF)NNNF)NNNF)NNNF)NNNT)NNNT)rr%r&r'r)r+),r2Z__version_info__rmapstr __version__sysr version_infoZPY3rBplatform startswithZjava_verZos_namer rr%r&r'r)r+objectr,r;rJrRrWr?Zwin32comrrFrNrOZ com.sun.jnaZcomr/rrZpropsprintdirsZproprArrrr s~    7 B ( 3 9 3+