方便地访问xdg基本目录规范变量
xdgspec的Python项目详细描述
xdgspec python包
xdgspec
是一个简单的python包,提供方便的访问
在XDG Base Directory
Specification中定义的变量。
xdgspec
能做什么?
使用xdgspec
您可以:
使用适当的回退
访问XDG Base Directory variablesfromxdgspecimportXDGDirectoryprint(XDGDirectory("XDG_CONFIG_HOME").path)print(XDGDirectory("XDG_CACHE_HOME").path)print(XDGDirectory("XDG_DATA_HOME").path)# ...
如果不存在,则使用上下文管理器自动创建XDG Base Directories中的一个。
fromxdgspecimportXDGDirectorywithXDGDirectory("XDG_CONFIG_HOME")aspath:print("{} is now definitely existing".format(path))
访问和创建包目录
fromxdgspecimportXDGPackageDirectorywithXDGPackageDirectory("XDG_CONFIG_HOME","mypackage")aspath:# path = ~/.config/mypackageprint("{} is now definitely existing".format(path))
循环现有的XDG系统目录< EH3>fromxdgspecimportXDGDirectories# variable contentprint(XDGDirectories("XDG_CONFIG_DIRS").paths)# generator of actually existing, unique directoriesprint(list(XDGDirectories("XDG_CONFIG_DIRS").existing_paths))
安装
fromxdgspecimportXDGDirectories# variable contentprint(XDGDirectories("XDG_CONFIG_DIRS").paths)# generator of actually existing, unique directoriesprint(list(XDGDirectories("XDG_CONFIG_DIRS").existing_paths))
安装
最好通过pip
安装xdgspec
包。从任何地方运行:
python3 -m pip install --user xdgspec
这将从Python Package Index下载并安装包。
您还可以从存储库根目录安装xdgspec
:
python3 -m pip install --user .
文档
可以找到xdgspec
包的文档here on
GitLab。