o )Xw@sdZddlZddlZejdZejdpejeddZ e gejdp'd d Z ejd p8ejed Z e gejd pBd d Z ejdpSejedZdde DZ dde DZ ddZddZddZddZddZddZd"d d!ZdS)#a  This module is based on a rox module (LGPL): http://cvs.sourceforge.net/viewcvs.py/rox/ROX-Lib2/python/rox/basedir.py?rev=1.9&view=log The freedesktop.org Base Directory specification provides a way for applications to locate shared data and configuration: http://standards.freedesktop.org/basedir-spec/ (based on version 0.6) This module can be used to load and save from and to these directories. Typical usage: from rox import basedir for dir in basedir.load_config_paths('mydomain.org', 'MyProg', 'Options'): print "Load settings from", dir dir = basedir.save_config_path('mydomain.org', 'MyProg') print >>file(os.path.join(dir, 'Options'), 'w'), "foo=2" Note: see the rox.Options module for a higher-level API for managing options. N~ XDG_DATA_HOMEz.localshare XDG_DATA_DIRSz/usr/local/share:/usr/share:XDG_CONFIG_HOMEz.configXDG_CONFIG_DIRSz/etc/xdgXDG_CACHE_HOMEz.cachecCg|]}|r|qSr .0xr r 3/usr/lib/python3/dist-packages/xdg/BaseDirectory.py .rcCr r r r r r rr/rcGsDtjj|}|dr Jtjt|}tj|s t|d|S)zEnsure ``$XDG_CONFIG_HOME//`` exists, and return its path. 'resource' should normally be the name of your application. Use this when saving configuration settings. /)ospathjoin startswithxdg_config_homeisdirmakedirsresourcerr r rsave_config_path1s   rcGBtjj|}|dr Jtjt|}tj|st||S)zEnsure ``$XDG_DATA_HOME//`` exists, and return its path. 'resource' should normally be the name of your application or a shared resource. Use this when saving or updating application data. r)rrrr xdg_data_homerrrr r rsave_data_path=s   r cGr)zEnsure ``$XDG_CACHE_HOME//`` exists, and return its path. 'resource' should normally be the name of your application or a shared resource.r)rrrrxdg_cache_homerrrr r rsave_cache_pathIs   r"cg<tjj|}tD]}tj||}tj|r|Vq dS)zReturns an iterator which gives each directory named 'resource' in the configuration search path. Information provided by earlier directories should take precedence over later ones, and the user-specific config dir comes first.N)rrrxdg_config_dirsexists)r config_dirrr r rload_config_pathsTs r'cGst|D]}|SdS)zYReturns the first result from load_config_paths, or None if there is nothing to load.N)r')rrr r rload_first_config^s r(cgr#)zReturns an iterator which gives each directory named 'resource' in the application data search path. Information provided by earlier directories should take precedence over later ones.N)rrr xdg_data_dirsr%)rdata_dirrr r rload_data_pathses r+Tc CsztjdWStyu|rddl}d|}d}zt|}Wn tyC}zddl}|j|jkr8d}nWYd}~n*d}~wwt |j sRt |d}n|j tksb|j t jt jB@rit|d}|rqt|d|YSw)aReturns the value of $XDG_RUNTIME_DIR, a directory path. This directory is intended for 'user-specific non-essential runtime files and other file objects (such as sockets, named pipes, ...)', and 'communication and synchronization purposes'. As of late 2012, only quite new systems set $XDG_RUNTIME_DIR. If it is not set, with ``strict=True`` (the default), a KeyError is raised. With ``strict=False``, PyXDG will create a fallback under /tmp for the current user. This fallback does *not* provide the same guarantees as the specification requires for the runtime directory. The strict default is deliberately conservative, so that application developers can make a conscious decision to allow the fallback. XDG_RUNTIME_DIRrNz /tmp/pyxdg-runtime-dir-fallback-FTr)renvironKeyErrorgetpassgetuserlstatOSErrorerrnoENOENTstatS_ISDIRst_modeunlinkst_uidgetuidS_IRWXGS_IRWXOrmdirmkdir)strictr/fallbackcreatester3r r rget_runtime_dirns<         rD)T)__doc__rr5r expanduser_homer-getrrsplitr)rr$r!rr r"r'r(r+rDr r r rs6