本文整理汇总了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))