本文整理匯總了Python中xdg.BaseDirectory.xdg_config_home方法的典型用法代碼示例。如果您正苦於以下問題:Python BaseDirectory.xdg_config_home方法的具體用法?Python BaseDirectory.xdg_config_home怎麽用?Python BaseDirectory.xdg_config_home使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xdg.BaseDirectory
的用法示例。
在下文中一共展示了BaseDirectory.xdg_config_home方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_user_dir
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def get_user_dir(key):
"""
http://www.freedesktop.org/wiki/Software/xdg-user-dirs
- XDG_DESKTOP_DIR
- XDG_DOWNLOAD_DIR
- XDG_TEMPLATES_DIR
- XDG_PUBLICSHARE_DIR
- XDG_DOCUMENTS_DIR
- XDG_MUSIC_DIR
- XDG_PICTURES_DIR
- XDG_VIDEOS_DIR
Taken from FrontBringer
(distributed under the GNU GPL v3 license),
courtesy of Jean-François Fortin Tam.
"""
user_dirs_dirs = os.path.join(xdg_config_home, "user-dirs.dirs")
user_dirs_dirs = os.path.expanduser(user_dirs_dirs)
if not os.path.exists(user_dirs_dirs):
return
for line in open(user_dirs_dirs, "r"):
if line.startswith(key):
return os.path.expandvars(line[len(key) + 2:-2])
示例2: get_config_dir
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def get_config_dir(app_name):
if 'XDG_CONFIG_HOME' in os.environ:
confighome = os.environ['XDG_CONFIG_HOME']
elif 'APPDATA' in os.environ: # On Windows
confighome = os.environ['APPDATA']
else:
try:
from xdg import BaseDirectory
confighome = BaseDirectory.xdg_config_home
except ImportError: # Most likely a Linux/Unix system anyway
confighome = os.path.join(os.path.expanduser('~'), '.config')
configdir = os.path.join(confighome, app_name)
return configdir
示例3: __init__
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def __init__(self):
"""
Manages book files and provides metadata
"""
self.config = configparser.ConfigParser()
# Loads configuration from $XDG_CONFIG_HOME/easy-ebook-viewer.conf
self.__config_path = os.path.expanduser(os.path.join(xdg_config_home, "easy-ebook-viewer.conf"))
if os.access(self.__config_path, os.W_OK): # Checks if a config file exists
# Config file exists, loads it.
self.config.read(self.__config_path)
else:
# Config file doesn't exist, creates new
self.__create_new_configuration()
# Validates configuration
self.__validate_configuration()
示例4: __init__
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def __init__(self):
# The home dir
self.HOME_DIR = os.path.expanduser('~')
# The default song dir
self.SONG_DIR = self._get_music_dir()
# The temp dir
self.SONG_TEMP_DIR = os.path.join(self.SONG_DIR, 'ytmdl')
# The default song quality
self.SONG_QUALITY = '320'
# The config path
self.CONFIG_PATH = os.path.join(xdg_config_home, 'ytmdl')
示例5: test_confdir_xdg
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def test_confdir_xdg(self):
direct = helpers.get_confdir()
self.assertEqual(direct, os.path.join(BaseDirectory.xdg_config_home, 'fades'))
示例6: test_confdir_xdg_nonexistant
# 需要導入模塊: from xdg import BaseDirectory [as 別名]
# 或者: from xdg.BaseDirectory import xdg_config_home [as 別名]
def test_confdir_xdg_nonexistant(self):
with patch("xdg.BaseDirectory") as mock:
with tempfile.TemporaryDirectory() as dirname:
mock.xdg_config_home = dirname
direct = helpers.get_confdir()
self.assertTrue(os.path.exists(direct))