本文整理汇总了Python中xdg.BaseDirectory.save_config_path方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDirectory.save_config_path方法的具体用法?Python BaseDirectory.save_config_path怎么用?Python BaseDirectory.save_config_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdg.BaseDirectory
的用法示例。
在下文中一共展示了BaseDirectory.save_config_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def write(self, filename=None):
"""
Writes a configuration file.
Write a configuration file at <pre>filename</pre>. If no filename
is supplied, the default path is <pre>~/.config/pydof/pydof.rc</pre>
or the <pre>pydof/pydof.rc</pre> file in your configured XDG
configuration directory.
"""
if filename is None:
basedir.save_config_path("pydof")
self.write(Config.DEFAULTPATH)
else:
with open(filename, "w") as configfile:
self.__parser.write(configfile)
示例2: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self):
self.key_sequence = KeySequence()
self.nag_interval = 300
self.nag_header = '\nReminders:'
self.use_git = True
os.environ.pop('GIT_DIR', None)
# for path in xdgbase.load_config_paths(APP_NAME, 'config.py'):
# with file(path) as stream:
# exec stream in self.__dict__
self.nag_home = xdgbase.save_config_path(APP_NAME)
self.nag_file_dir = xdgbase.save_config_path(APP_NAME, 'files')
self.runtime = os.path.join(xdgbase.get_runtime_dir(), APP_NAME)
self.timestamp = os.path.join(self.runtime, 'timestamp')
示例3: on_checkautostart_toggled
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def on_checkautostart_toggled(self, widget):
KUPFER_DESKTOP = "kupfer.desktop"
AUTOSTART_KEY = "X-GNOME-Autostart-enabled"
autostart_dir = base.save_config_path("autostart")
autostart_file = os.path.join(autostart_dir, KUPFER_DESKTOP)
if not os.path.exists(autostart_file):
desktop_files = list(base.load_data_paths("applications",
KUPFER_DESKTOP))
if not desktop_files:
self.output_error("Installed kupfer desktop file not found!")
return
desktop_file_path = desktop_files[0]
# Read installed file and modify it
dfile = desktop.DesktopEntry(desktop_file_path)
executable = dfile.getExec()
## append no-splash
if "--no-splash" not in executable:
executable += " --no-splash"
dfile.set("Exec", executable)
else:
dfile = desktop.DesktopEntry(autostart_file)
activestr = str(bool(widget.get_active())).lower()
self.output_debug("Setting autostart to", activestr)
dfile.set(AUTOSTART_KEY, activestr)
## remove the format specifiers
executable = dfile.getExec().replace("%F", "")
dfile.set("Exec", executable)
dfile.write(filename=autostart_file)
示例4: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self, release):
self.release = release
self.name = 'apt-venv'
self.config = _loadJSON(open('/etc/apt-venv.conf'))
self.distro = None
for distro in self.config['distributions']:
if self.release in self.config['distributions'][distro]['releases']:
self.distro = distro
if not self.distro:
base = "Release \"{}\" not valid. ".format(self.release)
if not self.release:
base = "No release declared. "
all_releases = []
for distro in sorted(self.config['distributions'].keys()):
releases = self.config['distributions'][distro]['releases']
all_releases.append(" [%s] %s" % (distro, ' - '.join(releases)))
raise ValueError(base +
"Please specify one of:\n%s" %
'\n'.join(all_releases))
self.config_path = _BaseDirectory.save_config_path(self.name)
self.cache_path = _BaseDirectory.save_cache_path(self.name)
self.data_path = _BaseDirectory.save_data_path(self.name)
self.config_path = _os.path.join(self.config_path, self.release)
self.cache_path = _os.path.join(self.cache_path, self.release)
self.data_path = _os.path.join(self.data_path, self.release)
self.bashrc = _os.path.join(self.config_path, "bash.rc")
self.sourceslist = _os.path.join(self.config_path, "sources.list")
self.aptconf = _os.path.join(self.config_path, "apt.conf")
示例5: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self):
config_dir = xdg.save_config_path('hobo')
data_dir = xdg.save_data_path('hobo')
self.images_dir = os.path.join(data_dir, 'images')
if not os.path.isdir(self.images_dir):
os.mkdir(self.images_dir)
self.template_file = os.path.join(self.images_dir, 'hobo.templates')
touch(self.template_file)
self.db = Db(os.path.join(data_dir, 'hobo.db'))
config_file = os.path.join(config_dir, 'hobo.ini')
self._cfg = ConfigParser()
self._cfg.read(config_file)
self.bridge_device = self.get('config', 'bridge_device') or 'hob0'
self.base_mem = self.get('config', 'base_mem') or '1024'
self.base_cpu = self.get('config', 'base_cpu') or '1'
# compression analysis:
# -1 256M
# -9 213M
# --best 223M
# might as well use -1
# libvirt docs recommend:
# --best --block-size=16777216
# but it's sloooow
self.compress_flags = self.get('config', 'compress_flags') or '-1 -T0 --block-size=16777216'
示例6: _load_config
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def _load_config(self):
config = ConfigParser.SafeConfigParser()
self.VERBOSE = False
self._read_configs_into(config)
DEFAULT_WORDPRESS_URL = 'http://wordpress.example.com/wordpress/xmlrpc.php'
if not config.has_section('account'):
config.add_section('account')
# Fill in some default values
config.set('account', 'url', DEFAULT_WORDPRESS_URL)
config.set('account', 'username', 'joe_user')
config.set('account', 'password', 'trustNo1')
config.add_section('config')
config.set('config', 'data_storage', 'file')
config.set('config', 'publish_default', 'no')
config.set('config', 'save_uploads', 'no')
config.set('config', 'scale_images', 'no')
path = os.path.join(BaseDirectory.save_config_path('rst2wp'), 'wordpressrc')
print 'Need configuration! Edit %s'%(path,)
with file(path, 'wb') as fp:
config.write(fp)
sys.exit()
if config.get('account', 'url') == DEFAULT_WORDPRESS_URL:
# Don't wipe out what they might have configured
print 'Still needs configuration! Edit %s'%(path,)
sys.exit()
self._config = config
return config
示例7: load_config
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def load_config():
resource_name = 'yt-bulk-py'
if not bd.load_first_config(resource_name):
sys.stderr.write('Creating config directory: ' + bd.save_config_path(resource_name))
conf_dir = bd.load_first_config(resource_name)
conf_file = os.path.join(conf_dir, 'config')
conf_skel = """# Configuration file for yt-bulk-py
# Account information for the user doing the uploading.
[user]
email = [email protected]
password = secret
"""
if not os.path.isfile(conf_file):
with open(conf_file, 'w+b') as f:
f.write(conf_skel)
config = ConfigParser.ConfigParser()
config.read(conf_file)
if not 'user' in config.sections():
sys.stderr.write('Error: No [user] section in config file.')
exit(1)
if not 'email' in config.options('user') and 'password' in config.options('user'):
sys.stderr.write('Error: Missing "email" or "password" options in config file.')
exit(1)
return (config.get('user', 'email'), config.get('user', 'password'))
示例8: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self):
self.palette = None
self.color = Color()
self.h_ids = {}
self.color.connect("changed", self.color_changed)
self.init_config()
self.build_gui()
self.palette_dir = os.path.join(base.save_config_path(appinfo.pkgname), "palettes")
Palette.PaletteDir = self.palette_dir
self.palette_list = PaletteList()
self.palette_list.load(self.palette_dir)
self.palette_combo.set_model(self.palette_list)
# no palettes, so create default
if len(self.palette_list) == 0:
palette = Palette()
palette.name = "Default Palette"
palette.filename = os.path.join(self.palette_dir, "default.gpl")
self.palette_list.append(palette)
self.palette_combo.select(0)
self.colorpicker.set_color(self.color)
self.load_config()
示例9: write_empty_config
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def write_empty_config(self, config, conffile):
rootdir = BaseDirectory.save_config_path('tuyau')
with file(conffile, 'wb') as fp:
config.write(fp)
g = GPG(gnupghome=os.path.join(rootdir, 'gnupg'))
g.list_keys()
示例10: read_config
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def read_config(args):
config = os.path.join(xdg.save_config_path(myname), "%s.conf" % myname)
username = ""
password = ""
hostnames = []
# Read
log.debug("Reading settings from '%s'", config)
try:
with open(config, 'r') as fd:
username, password = fd.readline().strip().split('\t')
for line in fd:
hostnames.append(line.strip())
except IOError as e:
log.warn(e)
except ValueError as e:
log.error("Error in config file, check credentials at '%s'", config)
# Save
if args.username or args.password or args.hostnames:
log.info("Saving settings to '%s'", config)
try:
with open(config, 'w') as fd:
fd.write("%s\t%s\n" % (args.username or username,
args.password or password,))
for hostname in (args.hostnames or hostnames):
fd.write("%s\n" % hostname)
os.chmod(config, 0600)
except IOError as e:
log.error(e)
return dict(username=username,
password=password,
hostnames=hostnames)
示例11: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self):
self.palette = None
self.color = Color()
self.color.connect('changed', self.color_changed)
self.icon_path = os.path.join(os.path.dirname(__file__), 'data', 'icons')
self.init_config()
self.build_gui()
self.palette_dir = os.path.join(base.save_config_path(appinfo.pkgname), 'palettes')
Palette.PaletteDir = self.palette_dir
self.palette_list = PaletteList()
self.palette_list.load(self.palette_dir)
self.palette_combo.set_model(self.palette_list)
# no palettes, so create default
if len(self.palette_list) == 0:
palette = Palette()
palette.name = "Default Palette"
palette.filename = os.path.join(self.palette_dir, 'default.gpl')
self.palette_list.append(palette)
self.palette_combo.select(0)
self.colorpicker.set_color(self.color)
self.load_config()
示例12: get_auth
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def get_auth():
def check_auth(auth):
return requests.head(full_repo_url, auth=auth).status_code != httplib.UNAUTHORIZED
# config file init
config_file = os.path.join(BaseDirectory.save_config_path("malucrawl_reportificate"), "settings.ini")
config = configparser.SafeConfigParser()
config.read(config_file)
if not config.has_section('auth'):
config.add_section('auth')
try:
username = config.get('auth', 'username')
except configparser.NoOptionError:
username = raw_input("Username: ")
password = keyring.get_password(github_url, username)
if password is None:
password = getpass.getpass()
while not check_auth((username, password)):
print "Authorization Failed"
username = raw_input("Username: ")
password = getpass.getpass()
keyring.set_password(github_url, username, password)
config.set('auth', 'username', username)
config.write(open(config_file, 'w'))
return (username, password)
示例13: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def __init__(self, sender=None, addresses=[], *args, **kwargs):
super().__init__(*args, **kwargs)
if not isinstance(addresses, list):
addresses = [addresses]
elif not addresses:
import xdg.BaseDirectory as xdgb
p = xdgb.load_first_config('notifier', 'addresses')
if p is not None:
with open(p, 'r') as f:
addresses = f.read().split()
if not addresses:
raise ValueError('No email addresses (defaults are read from {}/addresses, one address per line)'
.format(xdgb.save_config_path('notifier')))
for addr in addresses:
if not isinstance(addr, str) or not '@' in addr:
raise TypeError('`addresses` must be an email address or a list of email addresses')
self._addresses = addresses
if sender is None:
sender = 'Notifier'
self._sender = sender
self._addr = '[email protected]{}'.format(platform.node())
示例14: load_credentials
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def load_credentials():
p = xdgb.load_first_config('prisma', 'credentials')
if p is None:
exit('Please save your card number and password (each on its own line) in {}/credentials'
.format(xdgb.save_config_path('prisma')))
with open(p, 'r') as f:
t = f.read().split()
return (t[0], t[1])
示例15: test_save_config_path
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_config_path [as 别名]
def test_save_config_path(self):
tmpdir = tempfile.mkdtemp()
try:
environ['XDG_CONFIG_HOME'] = tmpdir
reload(BaseDirectory)
configpath = BaseDirectory.save_config_path("foo")
self.assertEqual(configpath, os.path.join(tmpdir, "foo"))
finally:
shutil.rmtree(tmpdir)