本文整理汇总了Python中zeroinstall.logger.info函数的典型用法代码示例。如果您正苦于以下问题:Python info函数的具体用法?Python info怎么用?Python info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_exec_binding
def do_exec_binding(self, binding, iface):
assert iface is not None
name = binding.name
if '/' in name or name.startswith('.') or "'" in name:
raise SafeException("Invalid <executable> name '%s'" % name)
exec_dir = basedir.save_cache_path(namespaces.config_site, namespaces.config_prog, 'executables', name)
exec_path = os.path.join(exec_dir, name + ".exe" if os.name == "nt" else name)
if not self._checked_runenv:
self._check_runenv()
if not os.path.exists(exec_path):
if os.name == "nt":
# Copy runenv.cli.template to ~/.cache/0install.net/injector/executables/$name/$name
import shutil
shutil.copyfile(os.environ['ZEROINSTALL_CLI_TEMPLATE'], exec_path)
else:
# Symlink ~/.cache/0install.net/injector/executables/$name/$name to runenv.py
os.symlink('../../runenv.py', exec_path)
os.chmod(exec_dir, 0o500)
if binding.in_path:
path = os.environ["PATH"] = exec_dir + os.pathsep + os.environ["PATH"]
logger.info("PATH=%s", path)
else:
os.environ[name] = exec_path
logger.info("%s=%s", name, exec_path)
args = self.build_command(iface, binding.command)
if os.name == "nt":
os.environ["0install-runenv-file-" + name + ".exe"] = args[0]
os.environ["0install-runenv-args-" + name + ".exe"] = support.windows_args_escape(args[1:])
else:
import json
os.environ["0install-runenv-" + name] = json.dumps(args)
示例2: installed_fixup
def installed_fixup(self, impl):
# OpenSUSE uses _, Fedora uses .
"""@type impl: L{zeroinstall.injector.model.DistributionImplementation}"""
impl_id = impl.id.replace('_', '.')
# Hack: If we added any Java implementations, find the corresponding JAVA_HOME...
if impl_id.startswith('package:rpm:java-1.6.0-openjdk:'):
java_version = '1.6.0-openjdk'
elif impl_id.startswith('package:rpm:java-1.7.0-openjdk:'):
java_version = '1.7.0-openjdk'
else:
return Distribution.installed_fixup(self, impl) # super
# On Fedora, unlike Debian, the arch is x86_64, not amd64
java_bin = '/usr/lib/jvm/jre-%s.%s/bin/java' % (java_version, impl.machine)
if not os.path.exists(java_bin):
# Try without the arch...
java_bin = '/usr/lib/jvm/jre-%s/bin/java' % java_version
if not os.path.exists(java_bin):
logger.info("Java binary not found (%s)", java_bin)
if impl.main is None:
java_bin = '/usr/bin/java'
else:
return
impl.main = java_bin
示例3: get_selections
def get_selections(self, snapshot_date = None, may_update = False, use_gui = None):
"""Load the selections.
If may_update is True then the returned selections will be cached and available.
@param snapshot_date: get a historical snapshot
@type snapshot_date: (as returned by L{get_history}) | None
@param may_update: whether to check for updates
@type may_update: bool
@param use_gui: whether to use the GUI for foreground updates
@type use_gui: bool | None (never/always/if possible)
@return: the selections
@rtype: L{selections.Selections}"""
if snapshot_date:
assert may_update is False, "Can't update a snapshot!"
sels_file = os.path.join(self.path, 'selections-' + snapshot_date + '.xml')
else:
sels_file = os.path.join(self.path, 'selections.xml')
try:
with open(sels_file, 'rb') as stream:
sels = selections.Selections(qdom.parse(stream))
except IOError as ex:
if may_update and ex.errno == errno.ENOENT:
logger.info("App selections missing: %s", ex)
sels = None
else:
raise
if may_update:
sels = self._check_for_updates(sels, use_gui)
return sels
示例4: _0install_man
def _0install_man(config, command):
"""@type command: str"""
from zeroinstall import apps, alias, helpers
path = support.find_in_path(command)
if not path:
return None
try:
with open(path, "rt") as stream:
app_info = apps.parse_script_header(stream)
if app_info:
app = config.app_mgr.lookup_app(app_info.name)
sels = app.get_selections()
main = None
else:
alias_info = alias.parse_script_header(stream)
if alias_info is None:
return None
sels = helpers.ensure_cached(alias_info.uri, alias_info.command, config=config)
if not sels:
# Cancelled by user
sys.exit(1)
main = alias_info.main
except IOError as ex:
logger.info("%s: falling back to `man %s`", ex, command)
os.execlp("man", "man", command)
sys.exit(1)
helpers.exec_man(config.stores, sels, main, fallback_name=command)
assert 0
示例5: handle
def handle(config, options, args):
if not args:
raise UsageError()
for x in args:
if not os.path.isfile(x):
raise SafeException(_("File '%s' does not exist") % x)
logger.info(_("Importing from file '%s'"), x)
with open(x, 'rb') as signed_data:
data, sigs = gpg.check_stream(signed_data)
doc = minidom.parseString(data.read())
uri = doc.documentElement.getAttribute('uri')
if not uri:
raise SafeException(_("Missing 'uri' attribute on root element in '%s'") % x)
logger.info(_("Importing information about interface %s"), uri)
signed_data.seek(0)
pending = PendingFeed(uri, signed_data)
def run():
keys_downloaded = tasks.Task(pending.download_keys(config.fetcher), "download keys")
yield keys_downloaded.finished
tasks.check(keys_downloaded.finished)
if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml):
blocker = config.trust_mgr.confirm_keys(pending)
if blocker:
yield blocker
tasks.check(blocker)
if not config.iface_cache.update_feed_if_trusted(uri, pending.sigs, pending.new_xml):
raise SafeException(_("No signing keys trusted; not importing"))
task = tasks.Task(run(), "import feed")
tasks.wait_for_blocker(task.finished)
示例6: get_inputs
def get_inputs():
for sel in sels.selections.values():
logger.info("Checking %s", sel.feed)
if sel.feed.startswith('distribution:'):
# If the package has changed version, we'll detect that below
# with get_unavailable_selections.
pass
elif os.path.isabs(sel.feed):
# Local feed
yield sel.feed
else:
# Cached feed
cached = basedir.load_first_cache(namespaces.config_site, 'interfaces', model.escape(sel.feed))
if cached:
yield cached
else:
raise IOError("Input %s missing; update" % sel.feed)
# Per-feed configuration
yield basedir.load_first_config(namespaces.config_site, namespaces.config_prog,
'interfaces', model._pretty_escape(sel.interface))
# Global configuration
yield basedir.load_first_config(namespaces.config_site, namespaces.config_prog, 'global')
示例7: get_selections
def get_selections(config, options, iface_uri, select_only, download_only, test_callback):
"""Get selections for iface_uri, according to the options passed.
Will switch to GUI mode if necessary.
@param options: options from OptionParser
@param iface_uri: canonical URI of the interface
@param select_only: return immediately even if the selected versions aren't cached
@param download_only: wait for stale feeds, and display GUI button as Download, not Run
@return: the selected versions, or None if the user cancels
@rtype: L{selections.Selections} | None
"""
if options.offline:
config.network_use = model.network_offline
iface_cache = config.iface_cache
# Try to load it as a feed. If it is a feed, it'll get cached. If not, it's a
# selections document and we return immediately.
maybe_selections = iface_cache.get_feed(iface_uri, selections_ok = True)
if isinstance(maybe_selections, selections.Selections):
if not select_only:
blocker = maybe_selections.download_missing(config)
if blocker:
logger.info(_("Waiting for selected implementations to be downloaded..."))
tasks.wait_for_blocker(blocker)
return maybe_selections
r = requirements.Requirements(iface_uri)
r.parse_options(options)
return get_selections_for(r, config, options, select_only, download_only, test_callback)
示例8: installed_fixup
def installed_fixup(self, impl):
# Hack: If we added any Java implementations, find the corresponding JAVA_HOME...
if impl.id.startswith('package:deb:openjdk-6-jre:'):
java_version = '6-openjdk'
elif impl.id.startswith('package:deb:openjdk-7-jre:'):
java_version = '7-openjdk'
else:
return
if impl.machine == 'x86_64':
java_arch = 'amd64'
else:
java_arch = impl.machine
java_bin = '/usr/lib/jvm/java-%s-%s/jre/bin/java' % (java_version, java_arch)
if not os.path.exists(java_bin):
# Try without the arch...
java_bin = '/usr/lib/jvm/java-%s/jre/bin/java' % java_version
if not os.path.exists(java_bin):
logger.info("Java binary not found (%s)", java_bin)
if impl.main is None:
java_bin = '/usr/bin/java'
else:
return
impl.commands["run"] = model.Command(qdom.Element(namespaces.XMLNS_IFACE, 'command',
{'path': java_bin, 'name': 'run'}), None)
示例9: handle
def handle(config, options, args):
if len(args) == 0:
raise UsageError()
url = config.mirror + '/search/?q=' + quote(' '.join(args))
logger.info("Fetching %s...", url)
root = qdom.parse(urllib2.urlopen(url))
assert root.name == 'results'
first = True
for child in root.childNodes:
if child.name != 'result': continue
if first:
first = False
else:
print()
print(child.attrs['uri'])
score = child.attrs['score']
details = {}
for detail in child.childNodes:
details[detail.name] = detail.content
print(" {name} - {summary} [{score}%]".format(
name = child.attrs['name'],
summary = details.get('summary', ''),
score = score))
示例10: parse_script_header
def parse_script_header(stream):
"""If stream is a shell script for an application, return the app details.
@param stream: the executable file's stream (will seek)
@type stream: file-like object
@return: the app details, if any
@rtype: L{AppScriptInfo} | None
@since: 1.12"""
try:
stream.seek(0)
template_header = _command_template[:_command_template.index("{app}")]
actual_header = stream.read(len(template_header))
stream.seek(0)
if template_header == actual_header:
# If it's a launcher script, it should be quite short!
rest = stream.read()
line = rest.split('\n')[1]
else:
return None
except UnicodeDecodeError as ex:
logger.info("Not an app script '%s': %s", stream, ex)
return None
info = AppScriptInfo()
info.name = line.split()[3]
return info
示例11: update_feed_from_network
def update_feed_from_network(self, feed_url, new_xml, modified_time, dry_run = False):
"""Update a cached feed.
Called by L{update_feed_if_trusted} if we trust this data.
After a successful update, L{writer} is used to update the feed's
last_checked time.
@param feed_url: the feed being updated
@type feed_url: L{model.Interface}
@param new_xml: the downloaded replacement feed document
@type new_xml: str
@param modified_time: the timestamp of the oldest trusted signature (used as an approximation to the feed's modification time)
@type modified_time: long
@type dry_run: bool
@raises ReplayAttack: if modified_time is older than the currently cached time
@since: 0.48"""
logger.debug(_("Updating '%(interface)s' from network; modified at %(time)s") %
{'interface': feed_url, 'time': _pretty_time(modified_time)})
self._import_new_feed(feed_url, new_xml, modified_time, dry_run)
if dry_run: return
feed = self.get_feed(feed_url)
from . import writer
feed.last_checked = int(time.time())
writer.save_feed(feed)
logger.info(_("Updated feed cache entry for %(interface)s (modified %(time)s)"),
{'interface': feed.get_name(), 'time': _pretty_time(modified_time)})
示例12: notify
def notify(self, title, message, timeout = 0, actions = []):
"""Send a D-BUS notification message if possible. If there is no notification
service available, log the message instead.
@type title: str
@type message: str
@type timeout: int"""
if not self.notification_service:
logger.info('%s: %s', title, message)
return None
LOW = 0
NORMAL = 1
#CRITICAL = 2
import dbus.types
hints = {}
if actions:
hints['urgency'] = dbus.types.Byte(NORMAL)
else:
hints['urgency'] = dbus.types.Byte(LOW)
return self.notification_service.Notify('Zero Install',
0, # replaces_id,
'', # icon
_escape_xml(title),
_escape_xml(message),
actions,
hints,
timeout * 1000)
示例13: add_archive_to_cache
def add_archive_to_cache(self, required_digest, data, url, extract = None, type = None, start_offset = 0, try_helper = False, dry_run = False):
"""@type required_digest: str
@type data: file
@type url: str
@type extract: str | None
@type type: str | None
@type start_offset: int
@type try_helper: bool
@type dry_run: bool"""
from . import unpack
if self.lookup(required_digest):
logger.info(_("Not adding %s as it already exists!"), required_digest)
return
tmp = self.get_tmp_dir_for(required_digest)
try:
unpack.unpack_archive(url, data, tmp, extract, type = type, start_offset = start_offset)
except:
import shutil
shutil.rmtree(tmp)
raise
try:
self.check_manifest_and_rename(required_digest, tmp, extract, try_helper = try_helper, dry_run = dry_run)
except Exception:
#warn(_("Leaving extracted directory as %s"), tmp)
support.ro_rmtree(tmp)
raise
示例14: discover_existing_apps
def discover_existing_apps():
"""Search through the configured XDG datadirs looking for .desktop files created by L{add_to_menu}.
@return: a map from application URIs to .desktop filenames"""
already_installed = {}
for d in basedir.load_data_paths('applications'):
for desktop_file in os.listdir(d):
if desktop_file.startswith('zeroinstall-') and desktop_file.endswith('.desktop'):
full = os.path.join(d, desktop_file)
try:
with open(full, 'rt') as stream:
for line in stream:
line = line.strip()
if line.startswith('Exec=0launch '):
bits = line.split(' -- ', 1)
if ' ' in bits[0]:
uri = bits[0].split(' ', 1)[1] # 0launch URI -- %u
else:
uri = bits[1].split(' ', 1)[0].strip() # 0launch -- URI %u
already_installed[uri] = full
break
else:
logger.info(_("Failed to find Exec line in %s"), full)
except Exception as ex:
logger.warn(_("Failed to load .desktop file %(filename)s: %(exceptions"), {'filename': full, 'exception': ex})
return already_installed
示例15: load_config
def load_config(handler = None):
"""@type handler: L{zeroinstall.injector.handler.Handler} | None
@rtype: L{Config}"""
config = Config(handler)
parser = ConfigParser.RawConfigParser()
parser.add_section('global')
parser.set('global', 'help_with_testing', 'False')
parser.set('global', 'freshness', str(60 * 60 * 24 * 30)) # One month
parser.set('global', 'network_use', 'full')
parser.set('global', 'auto_approve_keys', 'True')
path = basedir.load_first_config(config_site, config_prog, 'global')
if path:
logger.info("Loading configuration from %s", path)
try:
parser.read(path)
except Exception as ex:
logger.warning(_("Error loading config: %s"), str(ex) or repr(ex))
config.help_with_testing = parser.getboolean('global', 'help_with_testing')
config.network_use = parser.get('global', 'network_use')
config.freshness = int(parser.get('global', 'freshness'))
config.auto_approve_keys = parser.getboolean('global', 'auto_approve_keys')
assert config.network_use in network_levels, config.network_use
return config