本文整理汇总了Python中xdg.BaseDirectory.save_cache_path方法的典型用法代码示例。如果您正苦于以下问题:Python BaseDirectory.save_cache_path方法的具体用法?Python BaseDirectory.save_cache_path怎么用?Python BaseDirectory.save_cache_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xdg.BaseDirectory
的用法示例。
在下文中一共展示了BaseDirectory.save_cache_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_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")
示例2: main
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def main():
cache_directory = BaseDirectory.save_cache_path('ob_xdg_apps')
xml_file = os.path.join(cache_directory, 'menu.xml')
appdirs = (os.path.join(datadir, 'applications') for datadir in
BaseDirectory.xdg_data_dirs)
if os.path.isfile(xml_file):
updated = False
for appdir in appdirs:
if os.path.isdir(appdir):
if os.stat(appdir).st_ctime > os.stat(xml_file).st_ctime:
updated = True
break
if not updated:
with open(xml_file) as f:
print f.read()
return
icon_theme = gtk.icon_theme_get_default()
menu = etree.Element('openbox_pipe_menu')
menu_accumulator = MenuAccumulator()
for desktop_entry in get_desktop_entries():
menu_accumulator.add_entry(desktop_entry)
menu_accumulator.finalize()
categories = sorted(menu_accumulator.structure.keys())
for category in categories:
submenu_id = '{}-submenu'.format(category)
submenu = etree.SubElement(menu, 'menu',
{'id': submenu_id, 'label': category})
for desktop_entry in menu_accumulator.structure[category]:
name = desktop_entry.getName()
item_attributes = {'label': name.decode('utf-8')}
entry_icon = desktop_entry.getIcon()
if os.path.isfile(entry_icon):
item_attributes['icon'] = entry_icon
else:
icon_name = os.path.splitext(entry_icon)[0]
icon_info = icon_theme.lookup_icon(icon_name, 48, 0)
if icon_info is not None:
item_attributes['icon'] = icon_info.get_filename()
item = etree.SubElement(submenu, 'item', item_attributes)
action = etree.SubElement(item, 'action', {'name': 'Execute'})
command = etree.SubElement(action, 'command')
command.text = desktop_entry.getExec()
if desktop_entry.getStartupNotify():
startup_notify = etree.SubElement(action, 'startupnotify')
enabled = etree.SubElement(startup_notify, 'enabled')
enabled.text = 'yes'
xml = etree.tostring(menu, pretty_print=True)
with open(xml_file, 'w') as f:
f.write(xml)
print xml
示例3: run
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def run(self, lines):
""" Match and store Fenced Code Blocks in the HtmlStash. """
print("text reading")
text = "\n".join(lines)
print("text read")
while 1:
m = FENCED_BLOCK_RE.search(text)
if m:
out_file = m.group('out')
code = m.group('code')
show = True
if out_file[0] == '!':
show = False
out_file = out_file[1:]
ext = os.path.splitext(out_file)[1][1:].strip()
h_path = md5.new(out_file.encode('utf8')).hexdigest()
h_code = md5.new(code.encode('utf8')).hexdigest()
cache = BaseDirectory.save_cache_path('markdown-dot') + h_path
if self.should_generate(out_file, cache, h_code):
self.ensure_dir_exists(out_file)
print("generate " + out_file)
dot = subprocess.Popen(['dot', '-T', ext, '-o', out_file], bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("".join(dot.communicate(input=code.encode('utf8'))))
else:
print("pass " + out_file)
if show:
img = "![%s](%s)" % (os.path.basename(out_file), out_file)
text = '%s\n%s\n%s' % (text[:m.start()], img, text[m.end():])
else:
text = '%s\n%s' % (text[:m.start()], text[m.end():])
else:
break
return text.split("\n")
示例4: test_save_cache_path
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def test_save_cache_path(self):
tmpdir = tempfile.mkdtemp()
try:
environ['XDG_CACHE_HOME'] = tmpdir
reload(BaseDirectory)
datapath = BaseDirectory.save_cache_path("foo")
self.assertEqual(datapath, os.path.join(tmpdir, "foo"))
finally:
shutil.rmtree(tmpdir)
示例5: getCache
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def getCache(self):
try:
from xdg import BaseDirectory
path = BaseDirectory.save_cache_path('morituri')
self.info('Using XDG, cache directory is %s' % path)
except ImportError:
path = os.path.expanduser('~/.morituri/cache')
if not os.path.exists(path):
os.makedirs(path)
self.info('Not using XDG, cache directory is %s' % path)
return path
示例6: _get_cache_path
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def _get_cache_path(self):
"Get the cache file path"
# Some versions of pyxdg don't have save_cache_path (0.20 and older)
# See: https://bugs.freedesktop.org/show_bug.cgi?id=26458
if _xdg_basedirectory and "save_cache_path" in dir(_xdg_basedirectory):
path = _xdg_basedirectory.save_cache_path("")
else:
self._log_xdg_import_error()
path = _os_path.expanduser(_os_path.join("~", ".cache"))
if not _os_path.isdir(path):
_os.makedirs(path)
return _os_path.join(path, "mutt-ldap.json")
示例7: getCache
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def getCache(self, name=None):
try:
from xdg import BaseDirectory
path = BaseDirectory.save_cache_path('morituri')
self.info('Using XDG, cache directory is %s' % path)
except (ImportError, AttributeError):
# save_cache_path was added in pyxdg 0.25
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
if not os.path.exists(path):
os.makedirs(path)
self.info('Not using XDG, cache directory is %s' % path)
if name:
path = os.path.join(path, name)
if not os.path.exists(path):
os.makedirs(path)
return path
示例8: getReadCaches
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def getReadCaches(self, name=None):
paths = []
try:
from xdg import BaseDirectory
path = BaseDirectory.save_cache_path('morituri')
self.info('For XDG, read cache directory is %s' % path)
paths.append(path)
except ImportError:
pass
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache')
if os.path.exists(path):
self.info('From before XDG, read cache directory is %s' % path)
paths.append(path)
if name:
paths = [os.path.join(p, name) for p in paths]
return paths
示例9: Gmail
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
from xdg import BaseDirectory
from logger import StreamToLogger
# Check https://developers.google.com/gmail/api/auth/scopes
# for all available scopes
OAUTH_SCOPE = 'https://mail.google.com/'
# Path to the client_secret.json, file comes from the Google Developer Console
CLIENT_SECRET_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)),
'client_secret.json')
# Directory where the credentials storage files are placed
STORAGE_DIR = BaseDirectory.save_cache_path(os.path.join('goopg', 'storage'))
class Gmail():
def __init__(self, username):
# the main username
self.username = username
self.http = httplib2.Http()
self.logger = logging.getLogger('Gmail')
# Start the OAuth flow to retrieve credentials
flow = flow_from_clientsecrets(CLIENT_SECRET_FILE,
scope=OAUTH_SCOPE)
# The storage for current user
示例10: VersionRestriction
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
import urllib2
from debian import debian_support
import subprocess
import re
import gzip
import hashlib
import shutil
import contextlib
import itertools
import tempfile
import logging
import make_overlay
LOGGER = logging.getLogger(__name__)
from xdg import BaseDirectory
CACHE_DIR = BaseDirectory.save_cache_path('rundeb')
if not os.path.exists(CACHE_DIR):
os.makedirs(CACHE_DIR)
class VersionRestriction(object):
LT = "<<"
LTE = "<="
EQ = "="
GTE = ">="
GT = ">>"
OPS = (LT, LTE, EQ, GTE, GT, None)
def __init__(self, op, version):
assert op in self.OPS, "Invalid operator: %s" % (op,)
self.op = op
self.version = version
def zi_xml(self):
示例11: closing
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
url = full_repo_url
param = {
'path': path,
'per_page': '100'
}
while url:
r = session.get(
url,
params=param
)
yield r.json()
url = r.links.get("next", {"url": False})["url"]
param = {}
with closing(percache.Cache(
os.path.join(BaseDirectory.save_cache_path("malucrawl_reportificate"), "cache")
)) as cache:
@cache
def get_commit_details(commit_url):
return session.get(commit_url).json()
@cache
def count_words_in_tree(tree_url):
return sum(
map(
lambda tree: blob_lacount(tree["url"]),
itertools.ifilter(
lambda tree: tree["type"] == "blob" and fnmatchcase(tree["path"], valid_files),
session.get(tree_url, params={"recursive": 1}).json()["tree"]
)
示例12: put
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import os
from xdg import BaseDirectory
cache_dir = BaseDirectory.save_cache_path('zapys')
def put(server, id, text):
if not os.path.exists(os.path.join(cache_dir, server)):
os.makedirs(os.path.join(cache_dir, server))
f = open(os.path.join(cache_dir, server, str(id) + '.text'), 'w')
f.write(text)
f.close()
def get(server, id):
return open(os.path.join(cache_dir, server, str(id) + '.text')).read()
def get_temp():
return open(os.path.join(cache_dir, 'entry.html'), 'w')
示例13: cache_path
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
def cache_path():
"""Return the path of the cache file."""
return os.path.join(BaseDirectory.save_cache_path(__appname__),
'menu-cache')
示例14: open
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
import pytoml
import ctypes
import platform
import sys
app_name = 'fatbot'
# define filesystem paths
from xdg import BaseDirectory
package_dir = os.path.dirname(os.path.realpath(__file__))
config_dir = BaseDirectory.save_config_path(app_name)
data_dir = BaseDirectory.save_data_path(app_name)
cache_dir = BaseDirectory.save_cache_path(app_name)
#runtime_dir = BaseDirectory.get_runtime_dir(app_name) # XDG_RUNTIME_DIR undefined in systemd?
runtime_dir = cache_dir
config_file = os.path.join(config_dir, 'config.toml')
# load config file
if not os.path.isfile(config_file):
shutil.copyfile(os.path.join(package_dir, 'examples', 'config.toml'), config_file)
with open(config_file) as config_file_object:
settings = pytoml.load(config_file_object)
示例15:
# 需要导入模块: from xdg import BaseDirectory [as 别名]
# 或者: from xdg.BaseDirectory import save_cache_path [as 别名]
import os.path
from xdg import BaseDirectory
import redis
from icecrate.utils import keygen
from icecrate._version import __version__, __version_info__
__db_version__ = "1"
# TEMP CONFIG
HOST = "localhost"
PORT = 6379
DB = 0
INDEXDIR = BaseDirectory.save_cache_path("icecrate")
database = redis.StrictRedis(host=HOST, port=PORT, db=DB, decode_responses=True)
database.set(keygen("icecrate", meta="version"), __version__)
database.set(keygen("icecrate", meta="dbversion"), __db_version__)
import icecrate.items
import icecrate.tags
import icecrate.search