本文整理汇总了Python中qutebrowser.utils.standarddir.data函数的典型用法代码示例。如果您正苦于以下问题:Python data函数的具体用法?Python data怎么用?Python data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _init_misc
def _init_misc():
"""Initialize misc. config-related files."""
save_manager = objreg.get('save-manager')
state_config = ini.ReadWriteConfigParser(standarddir.data(), 'state')
for sect in ['general', 'geometry']:
try:
state_config.add_section(sect)
except configparser.DuplicateSectionError:
pass
# See commit a98060e020a4ba83b663813a4b9404edb47f28ad.
state_config['general'].pop('fooled', None)
objreg.register('state-config', state_config)
save_manager.add_saveable('state-config', state_config.save)
# We need to import this here because lineparser needs config.
from qutebrowser.misc import lineparser
command_history = lineparser.LimitLineParser(
standarddir.data(), 'cmd-history',
limit=('completion', 'cmd-history-max-items'),
parent=objreg.get('config'))
objreg.register('command-history', command_history)
save_manager.add_saveable('command-history', command_history.save,
command_history.changed)
# Set the QSettings path to something like
# ~/.config/qutebrowser/qsettings/qutebrowser/qutebrowser.conf so it
# doesn't overwrite our config.
#
# This fixes one of the corruption issues here:
# https://github.com/qutebrowser/qutebrowser/issues/515
path = os.path.join(standarddir.config(), 'qsettings')
for fmt in [QSettings.NativeFormat, QSettings.IniFormat]:
QSettings.setPath(fmt, QSettings.UserScope, path)
开发者ID:phansch,项目名称:qutebrowser,代码行数:34,代码来源:config.py
示例2: test_system_datadir_not_exist_linux
def test_system_datadir_not_exist_linux(self, monkeypatch, tmpdir,
fake_args):
"""Test that system-wide path isn't used on linux if path not exist."""
fake_args.basedir = str(tmpdir)
monkeypatch.setattr(os.path, 'exists', lambda path: False)
standarddir._init_dirs(fake_args)
assert standarddir.data(system=True) == standarddir.data()
开发者ID:swalladge,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py
示例3: test_system_datadir_unsupportedos
def test_system_datadir_unsupportedos(self, monkeypatch, tmpdir,
fake_args):
"""Test that system-wide path is not used on non-Linux OS."""
fake_args.basedir = str(tmpdir)
monkeypatch.setattr('sys.platform', "potato")
standarddir._init_dirs(fake_args)
assert standarddir.data(system=True) == standarddir.data()
开发者ID:swalladge,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py
示例4: run_async
def run_async(tab, cmd, *args, win_id, env, verbose=False):
"""Run a userscript after dumping page html/source.
Raises:
UnsupportedError if userscripts are not supported on the current
platform.
Args:
tab: The WebKitTab/WebEngineTab to get the source from.
cmd: The userscript binary to run.
*args: The arguments to pass to the userscript.
win_id: The window id the userscript is executed in.
env: A dictionary of variables to add to the process environment.
verbose: Show notifications when the command started/exited.
"""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
commandrunner = runners.CommandRunner(win_id, parent=tabbed_browser)
if os.name == 'posix':
runner = _POSIXUserscriptRunner(win_id, tabbed_browser)
elif os.name == 'nt': # pragma: no cover
runner = _WindowsUserscriptRunner(win_id, tabbed_browser)
else: # pragma: no cover
raise UnsupportedError
runner.got_cmd.connect(
lambda cmd:
log.commands.debug("Got userscript command: {}".format(cmd)))
runner.got_cmd.connect(commandrunner.run_safely)
user_agent = config.get('network', 'user-agent')
if user_agent is not None:
env['QUTE_USER_AGENT'] = user_agent
config_dir = standarddir.config()
if config_dir is not None:
env['QUTE_CONFIG_DIR'] = config_dir
data_dir = standarddir.data()
if data_dir is not None:
env['QUTE_DATA_DIR'] = data_dir
download_dir = downloads.download_dir()
if download_dir is not None:
env['QUTE_DOWNLOAD_DIR'] = download_dir
cmd_path = os.path.expanduser(cmd)
# if cmd is not given as an absolute path, look it up
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
if not os.path.isabs(cmd_path):
log.misc.debug("{} is no absolute path".format(cmd_path))
cmd_path = os.path.join(standarddir.data(), "userscripts", cmd)
if not os.path.exists(cmd_path):
cmd_path = os.path.join(standarddir.system_data(),
"userscripts", cmd)
log.misc.debug("Userscript to run: {}".format(cmd_path))
runner.finished.connect(commandrunner.deleteLater)
runner.finished.connect(runner.deleteLater)
runner.prepare_run(cmd_path, *args, env=env, verbose=verbose)
tab.dump_async(runner.store_html)
tab.dump_async(runner.store_text, plain=True)
开发者ID:DoITCreative,项目名称:qutebrowser,代码行数:60,代码来源:userscripts.py
示例5: __init__
def __init__(self, parent=None):
super().__init__(parent)
self._current = None
data_dir = standarddir.data()
if data_dir is None:
self._base_path = None
else:
self._base_path = os.path.join(standarddir.data(), 'sessions')
self._last_window_session = None
self.did_load = False
if self._base_path is not None and not os.path.exists(self._base_path):
os.mkdir(self._base_path)
开发者ID:jagajaga,项目名称:qutebrowser,代码行数:12,代码来源:sessions.py
示例6: init
def init():
"""Initialize the global QWebSettings."""
cache_path = standarddir.cache()
data_path = standarddir.data()
if config.get('general', 'private-browsing') or cache_path is None:
QWebSettings.setIconDatabasePath('')
else:
QWebSettings.setIconDatabasePath(cache_path)
if cache_path is not None:
QWebSettings.setOfflineWebApplicationCachePath(
os.path.join(cache_path, 'application-cache'))
if data_path is not None:
QWebSettings.globalSettings().setLocalStoragePath(
os.path.join(data_path, 'local-storage'))
QWebSettings.setOfflineStoragePath(
os.path.join(data_path, 'offline-storage'))
for sectname, section in MAPPINGS.items():
for optname, mapping in section.items():
default = mapping.save_default()
log.config.vdebug("Saved default for {} -> {}: {!r}".format(
sectname, optname, default))
value = config.get(sectname, optname)
log.config.vdebug("Setting {} -> {} to {!r}".format(
sectname, optname, value))
mapping.set(value)
objreg.get('config').changed.connect(update_settings)
开发者ID:AdaJass,项目名称:qutebrowser,代码行数:27,代码来源:websettings.py
示例7: handle_segfault
def handle_segfault(self):
"""Handle a segfault from a previous run."""
data_dir = standarddir.data()
if data_dir is None:
return
logname = os.path.join(data_dir, 'crash.log')
try:
# First check if an old logfile exists.
if os.path.exists(logname):
with open(logname, 'r', encoding='ascii') as f:
data = f.read()
os.remove(logname)
self._init_crashlogfile()
if data:
# Crashlog exists and has data in it, so something crashed
# previously.
self._crash_dialog = crashdialog.get_fatal_crash_dialog(
self._args.debug, data)
self._crash_dialog.show()
else:
# There's no log file, so we can use this to display crashes to
# the user on the next start.
self._init_crashlogfile()
except OSError:
log.init.exception("Error while handling crash log file!")
self._init_crashlogfile()
开发者ID:Dietr1ch,项目名称:qutebrowser,代码行数:26,代码来源:crashsignal.py
示例8: __init__
def __init__(self, parent=None):
super().__init__(parent)
self._lineparser = lineparser.AppendLineParser(
standarddir.data(), 'history', parent=self)
self._history_dict = collections.OrderedDict()
with self._lineparser.open():
for line in self._lineparser:
data = line.rstrip().split(maxsplit=1)
if not data:
# empty line
continue
elif len(data) != 2:
# other malformed line
log.init.warning("Invalid history entry {!r}!".format(
line))
continue
atime, url = data
# This de-duplicates history entries; only the latest
# entry for each URL is kept. If you want to keep
# information about previous hits change the items in
# old_urls to be lists or change HistoryEntry to have a
# list of atimes.
self._history_dict[url] = HistoryEntry(atime, url)
self._history_dict.move_to_end(url)
self._new_history = []
self._saved_count = 0
objreg.get('save-manager').add_saveable(
'history', self.save, self.item_added)
开发者ID:andor44,项目名称:qutebrowser,代码行数:28,代码来源:history.py
示例9: test_data
def test_data(self, monkeypatch, tmpdir):
"""Test data dir with XDG_DATA_HOME not set."""
monkeypatch.setenv('HOME', str(tmpdir))
monkeypatch.delenv('XDG_DATA_HOME', raising=False)
standarddir.init(None)
expected = tmpdir / '.local' / 'share' / 'qutebrowser_test'
assert standarddir.data() == str(expected)
开发者ID:tharugrim,项目名称:qutebrowser,代码行数:7,代码来源:test_standarddir.py
示例10: dictionary_dir
def dictionary_dir(old=False):
"""Return the path (str) to the QtWebEngine's dictionaries directory."""
if qtutils.version_check('5.10', compiled=False) and not old:
datapath = standarddir.data()
else:
datapath = QLibraryInfo.location(QLibraryInfo.DataPath)
return os.path.join(datapath, 'qtwebengine_dictionaries')
开发者ID:mehak,项目名称:qutebrowser,代码行数:7,代码来源:spell.py
示例11: __init__
def __init__(self, parent=None):
super().__init__(parent)
self._base_path = os.path.join(standarddir.data(), 'sessions')
self._last_window_session = None
self.did_load = False
if not os.path.exists(self._base_path):
os.mkdir(self._base_path)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:7,代码来源:sessions.py
示例12: import_txt
def import_txt(self):
"""Import a history text file into sqlite if it exists.
In older versions of qutebrowser, history was stored in a text format.
This converts that file into the new sqlite format and moves it to a
backup location.
"""
path = os.path.join(standarddir.data(), 'history')
if not os.path.isfile(path):
return
def action():
with debug.log_time(log.init, 'Import old history file to sqlite'):
try:
self._read(path)
except ValueError as ex:
message.error('Failed to import history: {}'.format(ex))
else:
bakpath = path + '.bak'
message.info('History import complete. Moving {} to {}'
.format(path, bakpath))
os.rename(path, bakpath)
# delay to give message time to appear before locking down for import
message.info('Converting {} to sqlite...'.format(path))
QTimer.singleShot(100, action)
开发者ID:swalladge,项目名称:qutebrowser,代码行数:26,代码来源:history.py
示例13: generate_pdfjs_page
def generate_pdfjs_page(filename, url):
"""Return the html content of a page that displays a file with pdfjs.
Returns a string.
Args:
filename: The filename of the PDF to open.
url: The URL being opened.
"""
if not is_available():
pdfjs_dir = os.path.join(standarddir.data(), 'pdfjs')
return jinja.render('no_pdfjs.html',
url=url.toDisplayString(),
title="PDF.js not found",
pdfjs_dir=pdfjs_dir)
html = get_pdfjs_res('web/viewer.html').decode('utf-8')
script = _generate_pdfjs_script(filename)
html = html.replace('</body>',
'</body><script>{}</script>'.format(script))
# WORKAROUND for the fact that PDF.js tries to use the Fetch API even with
# qute:// URLs.
pdfjs_script = '<script src="../build/pdf.js"></script>'
html = html.replace(pdfjs_script,
'<script>window.Response = undefined;</script>\n' +
pdfjs_script)
return html
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:27,代码来源:pdfjs.py
示例14: _read_history
def _read_history(self):
"""Read the initial history."""
if standarddir.data() is None:
return
with self._lineparser.open():
for line in self._lineparser:
data = line.rstrip().split(maxsplit=1)
if not data:
# empty line
continue
elif len(data) != 2:
# other malformed line
log.init.warning("Invalid history entry {!r}!".format(
line))
continue
atime, url = data
if atime.startswith('\0'):
log.init.warning(
"Removing NUL bytes from entry {!r} - see "
"https://github.com/The-Compiler/qutebrowser/issues/"
"670".format(data))
atime = atime.lstrip('\0')
# This de-duplicates history entries; only the latest
# entry for each URL is kept. If you want to keep
# information about previous hits change the items in
# old_urls to be lists or change HistoryEntry to have a
# list of atimes.
self._history_dict[url] = HistoryEntry(atime, url)
self._history_dict.move_to_end(url)
开发者ID:tharugrim,项目名称:qutebrowser,代码行数:29,代码来源:history.py
示例15: run
def run(cmd, *args, win_id, env, verbose=False):
"""Convenience method to run a userscript.
Args:
cmd: The userscript binary to run.
*args: The arguments to pass to the userscript.
win_id: The window id the userscript is executed in.
env: A dictionary of variables to add to the process environment.
verbose: Show notifications when the command started/exited.
"""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
commandrunner = runners.CommandRunner(win_id, tabbed_browser)
runner = UserscriptRunner(win_id, tabbed_browser)
runner.got_cmd.connect(
lambda cmd: log.commands.debug("Got userscript command: {}".format(
cmd)))
runner.got_cmd.connect(commandrunner.run_safely)
user_agent = config.get('network', 'user-agent')
if user_agent is not None:
env['QUTE_USER_AGENT'] = user_agent
cmd = os.path.expanduser(cmd)
# if cmd is not given as an absolute path, look it up
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_DIR)
if not os.path.isabs(cmd):
log.misc.debug("{} is no absolute path".format(cmd))
cmd = os.path.join(standarddir.data(), "userscripts", cmd)
runner.run(cmd, *args, env=env, verbose=verbose)
runner.finished.connect(commandrunner.deleteLater)
runner.finished.connect(runner.deleteLater)
开发者ID:shawa,项目名称:qutebrowser,代码行数:32,代码来源:userscripts.py
示例16: run_async
def run_async(tab, cmd, *args, win_id, env, verbose=False):
"""Run a userscript after dumping page html/source.
Raises:
UnsupportedError if userscripts are not supported on the current
platform.
NotFoundError if the command could not be found.
Args:
tab: The WebKitTab/WebEngineTab to get the source from.
cmd: The userscript binary to run.
*args: The arguments to pass to the userscript.
win_id: The window id the userscript is executed in.
env: A dictionary of variables to add to the process environment.
verbose: Show notifications when the command started/exited.
"""
tabbed_browser = objreg.get('tabbed-browser', scope='window',
window=win_id)
commandrunner = runners.CommandRunner(win_id, parent=tabbed_browser)
if utils.is_posix:
runner = _POSIXUserscriptRunner(tabbed_browser)
elif utils.is_windows: # pragma: no cover
runner = _WindowsUserscriptRunner(tabbed_browser)
else: # pragma: no cover
raise UnsupportedError
runner.got_cmd.connect(
lambda cmd:
log.commands.debug("Got userscript command: {}".format(cmd)))
runner.got_cmd.connect(commandrunner.run_safely)
user_agent = config.val.content.headers.user_agent
if user_agent is not None:
env['QUTE_USER_AGENT'] = user_agent
env['QUTE_CONFIG_DIR'] = standarddir.config()
env['QUTE_DATA_DIR'] = standarddir.data()
env['QUTE_DOWNLOAD_DIR'] = downloads.download_dir()
env['QUTE_COMMANDLINE_TEXT'] = objreg.get('status-command', scope='window',
window=win_id).text()
cmd_path = os.path.expanduser(cmd)
# if cmd is not given as an absolute path, look it up
# ~/.local/share/qutebrowser/userscripts (or $XDG_DATA_HOME)
if not os.path.isabs(cmd_path):
log.misc.debug("{} is no absolute path".format(cmd_path))
cmd_path = _lookup_path(cmd)
elif not os.path.exists(cmd_path):
raise NotFoundError(cmd_path)
log.misc.debug("Userscript to run: {}".format(cmd_path))
runner.finished.connect(commandrunner.deleteLater)
runner.finished.connect(runner.deleteLater)
runner.prepare_run(cmd_path, *args, env=env, verbose=verbose)
tab.dump_async(runner.store_html)
tab.dump_async(runner.store_text, plain=True)
return runner
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:59,代码来源:userscripts.py
示例17: _path_info
def _path_info():
"""Get info about important path names.
Return:
A dictionary of descriptive to actual path names.
"""
info = {
'config': standarddir.config(),
'data': standarddir.data(),
'cache': standarddir.cache(),
'runtime': standarddir.runtime(),
}
if standarddir.config() != standarddir.config(auto=True):
info['auto config'] = standarddir.config(auto=True)
if standarddir.data() != standarddir.data(system=True):
info['system data'] = standarddir.data(system=True)
return info
开发者ID:nanjekyejoannah,项目名称:qutebrowser,代码行数:17,代码来源:version.py
示例18: test_data
def test_data(self):
"""Test data dir with XDG_DATA_HOME not set."""
env = {'HOME': self.temp_dir, 'XDG_DATA_HOME': None}
with helpers.environ_set_temp(env):
standarddir.init(None)
expected = os.path.join(self.temp_dir, '.local', 'share',
'qutebrowser')
self.assertEqual(standarddir.data(), expected)
开发者ID:JIVS,项目名称:qutebrowser,代码行数:8,代码来源:test_standarddir.py
示例19: init
def init():
"""Initialize the LimitLineParser storing the history."""
save_manager = objreg.get('save-manager')
command_history = lineparser.LimitLineParser(
standarddir.data(), 'cmd-history',
limit='completion.cmd_history_max_items')
objreg.register('command-history', command_history)
save_manager.add_saveable('command-history', command_history.save,
command_history.changed)
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:9,代码来源:cmdhistory.py
示例20: init
def init(parent=None):
"""Initialize sessions.
Args:
parent: The parent to use for the SessionManager.
"""
data_dir = standarddir.data()
if data_dir is None:
base_path = None
else:
base_path = os.path.join(standarddir.data(), 'sessions')
try:
os.mkdir(base_path)
except FileExistsError:
pass
session_manager = SessionManager(base_path, parent)
objreg.register('session-manager', session_manager)
开发者ID:a2batic,项目名称:qutebrowser,代码行数:18,代码来源:sessions.py
注:本文中的qutebrowser.utils.standarddir.data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论