本文整理汇总了Python中zeroinstall._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: canonical_iface_uri
def canonical_iface_uri(uri):
"""If uri is a relative path, convert to an absolute one.
A "file:///foo" URI is converted to "/foo".
An "alias:prog" URI expands to the URI in the 0alias script
Otherwise, return it unmodified.
@rtype: str
@raise SafeException: if uri isn't valid
"""
if uri.startswith('http://') or uri.startswith('https://'):
if uri.count("/") < 3:
raise SafeException(_("Missing / after hostname in URI '%s'") % uri)
return uri
elif uri.startswith('file:///'):
return uri[7:]
elif uri.startswith('alias:'):
from zeroinstall import alias, support
alias_prog = uri[6:]
if not os.path.isabs(alias_prog):
full_path = support.find_in_path(alias_prog)
if not full_path:
raise alias.NotAnAliasScript("Not found in $PATH: " + alias_prog)
else:
full_path = alias_prog
interface_uri, main = alias.parse_script(full_path)
return interface_uri
else:
iface_uri = os.path.realpath(uri)
if os.path.isfile(iface_uri):
return iface_uri
raise SafeException(_("Bad interface name '%(uri)s'.\n"
"(doesn't start with 'http:', and "
"doesn't exist as a local file '%(interface_uri)s' either)") %
{'uri': uri, 'interface_uri': iface_uri})
示例2: populate_model
def populate_model(self):
m = self.model
m.clear()
for uri in self.app_list.get_apps():
itr = m.append()
m[itr][AppListBox.URI] = uri
try:
iface = self.iface_cache.get_interface(uri)
feed = self.iface_cache.get_feed(uri)
if feed:
name = feed.get_name()
summary = feed.summary or _('No information available')
summary = summary[:1].capitalize() + summary[1:]
else:
name = iface.get_name()
summary = _('No information available')
# (GTK3 returns an extra boolean at the start)
icon_width, icon_height = gtk.icon_size_lookup(gtk.ICON_SIZE_DIALOG)[-2:]
pixbuf = icon.load_icon(self.iface_cache.get_icon_path(iface), icon_width, icon_height)
except model.InvalidInterface as ex:
name = uri
summary = unicode(ex)
pixbuf = None
m[itr][AppListBox.NAME] = name
if pixbuf is None:
pixbuf = self.window.render_icon(gtk.STOCK_EXECUTE, gtk.ICON_SIZE_DIALOG)
m[itr][AppListBox.ICON] = pixbuf
m[itr][AppListBox.MARKUP] = '<b>%s</b>\n<i>%s</i>' % (_pango_escape(name), _pango_escape(summary))
示例3: import_key
def import_key(stream):
"""Run C{gpg --import} with this stream as stdin."""
errors = tempfile.TemporaryFile()
child = _run_gpg(['--quiet', '--import', '--batch'],
stdin = stream, stderr = errors)
status = child.wait()
errors.seek(0)
error_messages = errors.read().strip()
errors.close()
if error_messages:
import codecs
decoder = codecs.lookup('utf-8')
error_messages = decoder.decode(error_messages, errors = 'replace')[0]
if status != 0:
if error_messages:
raise SafeException(_("Errors from 'gpg --import':\n%s") % error_messages)
else:
raise SafeException(_("Non-zero exit code %d from 'gpg --import'") % status)
elif error_messages:
warn(_("Warnings from 'gpg --import':\n%s") % error_messages)
示例4: __init__
def __init__(self, config, requirements):
"""
@param config: The configuration settings to use
@type config: L{config.Config}
@param requirements: Details about the program we want to run
@type requirements: L{requirements.Requirements}
@since: 0.53
"""
self.watchers = []
assert config
self.config = config
assert requirements
self.requirements = requirements
self.target_arch = arch.get_architecture(requirements.os, requirements.cpu)
from zeroinstall.injector.solver import DefaultSolver
self.solver = DefaultSolver(self.config)
logger.debug(_("Supported systems: '%s'"), arch.os_ranks)
logger.debug(_("Supported processors: '%s'"), arch.machine_ranks)
if requirements.before or requirements.not_before:
self.solver.extra_restrictions[config.iface_cache.get_interface(requirements.interface_uri)] = [
model.VersionRangeRestriction(
model.parse_version(requirements.before), model.parse_version(requirements.not_before)
)
]
示例5: 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)})
示例6: process_binding
def process_binding(e):
"""Internal"""
if e.name == 'environment':
mode = {
None: EnvironmentBinding.PREPEND,
'prepend': EnvironmentBinding.PREPEND,
'append': EnvironmentBinding.APPEND,
'replace': EnvironmentBinding.REPLACE,
}[e.getAttribute('mode')]
binding = EnvironmentBinding(e.getAttribute('name'),
insert = e.getAttribute('insert'),
default = e.getAttribute('default'),
value = e.getAttribute('value'),
mode = mode,
separator = e.getAttribute('separator'))
if not binding.name: raise InvalidInterface(_("Missing 'name' in binding"))
if binding.insert is None and binding.value is None:
raise InvalidInterface(_("Missing 'insert' or 'value' in binding"))
if binding.insert is not None and binding.value is not None:
raise InvalidInterface(_("Binding contains both 'insert' and 'value'"))
return binding
elif e.name == 'executable-in-path':
return ExecutableBinding(e, in_path = True)
elif e.name == 'executable-in-var':
return ExecutableBinding(e, in_path = False)
elif e.name == 'overlay':
return OverlayBinding(e.getAttribute('src'), e.getAttribute('mount-point'))
else:
raise Exception(_("Unknown binding type '%s'") % e.name)
示例7: extract_deb
def extract_deb(stream, destdir, extract = None, start_offset = 0):
if extract:
raise SafeException(_('Sorry, but the "extract" attribute is not yet supported for Debs'))
stream.seek(start_offset)
# ar can't read from stdin, so make a copy...
deb_copy_name = os.path.join(destdir, 'archive.deb')
with open(deb_copy_name, 'wb') as deb_copy:
shutil.copyfileobj(stream, deb_copy)
data_tar = None
p = subprocess.Popen(('ar', 't', 'archive.deb'), stdout=subprocess.PIPE, cwd=destdir, universal_newlines=True)
o = p.communicate()[0]
for line in o.split('\n'):
if line == 'data.tar':
data_compression = None
elif line == 'data.tar.gz':
data_compression = 'gzip'
elif line == 'data.tar.bz2':
data_compression = 'bzip2'
elif line == 'data.tar.lzma':
data_compression = 'lzma'
else:
continue
data_tar = line
break
else:
raise SafeException(_("File is not a Debian package."))
_extract(stream, destdir, ('ar', 'x', 'archive.deb', data_tar))
os.unlink(deb_copy_name)
data_name = os.path.join(destdir, data_tar)
with open(data_name, 'rb') as data_stream:
os.unlink(data_name)
extract_tar(data_stream, destdir, None, data_compression)
示例8: confirm_install
def confirm_install(self, message):
yield self._switch_to_main_window(_('Need to confirm installation of distribution packages'))
from zeroinstall.injector.download import DownloadAborted
import dialog
import gtk
box = gtk.MessageDialog(self.mainwindow.window,
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_CANCEL,
str(message))
box.set_position(gtk.WIN_POS_CENTER)
install = dialog.MixedButton(_('Install'), gtk.STOCK_OK)
install.set_can_default(True)
box.add_action_widget(install, gtk.RESPONSE_OK)
install.show_all()
box.set_default_response(gtk.RESPONSE_OK)
box.show()
response = dialog.DialogResponse(box)
yield response
box.destroy()
if response.response != gtk.RESPONSE_OK:
raise DownloadAborted()
示例9: load_feed
def load_feed(source, local=False):
"""Load a feed from a local file.
@param source: the name of the file to read
@type source: str
@param local: this is a local feed
@type local: bool
@return: the new feed
@rtype: L{ZeroInstallFeed}
@raise InvalidInterface: if the source's syntax is incorrect
@since: 0.48
@see: L{iface_cache.iface_cache}, which uses this to load the feeds"""
try:
with open(source, "rb") as stream:
root = qdom.parse(stream, filter_for_version=True)
except IOError as ex:
if ex.errno == errno.ENOENT and local:
raise MissingLocalFeed(
_(
"Feed not found. Perhaps this is a local feed that no longer exists? You can remove it from the list of feeds in that case."
)
)
raise InvalidInterface(_("Can't read file"), ex)
except Exception as ex:
raise InvalidInterface(_("Invalid XML"), ex)
if local:
assert os.path.isabs(source), source
local_path = source
else:
local_path = None
feed = ZeroInstallFeed(root, local_path)
feed.last_modified = int(os.stat(source).st_mtime)
return feed
示例10: fetch_feed
def fetch_feed():
yield dl.downloaded
tasks.check(dl.downloaded)
pending = PendingFeed(feed_url, stream)
if use_mirror:
# If we got the feed from a mirror, get the key from there too
key_mirror = self.feed_mirror + "/keys/"
else:
key_mirror = None
keys_downloaded = tasks.Task(
pending.download_keys(self.handler, feed_hint=feed_url, key_mirror=key_mirror),
_("download keys for %s") % feed_url,
)
yield keys_downloaded.finished
tasks.check(keys_downloaded.finished)
if not iface_cache.update_feed_if_trusted(pending.url, pending.sigs, pending.new_xml):
blocker = self.handler.confirm_keys(pending, self.fetch_key_info)
if blocker:
yield blocker
tasks.check(blocker)
if not iface_cache.update_feed_if_trusted(pending.url, pending.sigs, pending.new_xml):
raise NoTrustedKeys(_("No signing keys trusted; not importing"))
示例11: _confirm_unknown_keys
def _confirm_unknown_keys(self, to_trust, valid_sigs):
"""Check the key-info server's results for these keys. If we don't know any of them,
ask for extra confirmation from the user.
@param to_trust: the signatures the user wants to trust
@return: True to continue"""
def is_unknown(sig):
for note in valid_sigs[sig].info:
if note.getAttribute("vote") == "good":
return False
return True
unknown = [sig for sig in to_trust if is_unknown(sig)]
if unknown:
if len(unknown) == 1:
msg = _('WARNING: you are confirming a key which was not known to the key server. Are you sure?')
else:
msg = _('WARNING: you are confirming keys which were not known to the key server. Are you sure?')
box = gtk.MessageDialog(self,
gtk.DIALOG_DESTROY_WITH_PARENT,
gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL,
msg)
box.set_position(gtk.WIN_POS_CENTER)
response = box.run()
box.destroy()
return response == gtk.RESPONSE_OK
return True
示例12: is_stale
def is_stale(self, feed, freshness_threshold):
"""Check whether feed needs updating, based on the configured L{freshness}.
None is considered to be stale.
If we already tried to update the feed within FAILED_CHECK_DELAY, returns false.
@return: True if feed should be updated
@since: 0.53"""
if feed is None:
return True
if os.path.isabs(feed.url):
return False # Local feeds are never stale
if feed.last_modified is None:
return True # Don't even have it yet
now = time.time()
staleness = now - (feed.last_checked or 0)
debug(_("Staleness for %(feed)s is %(staleness).2f hours"), {'feed': feed, 'staleness': staleness / 3600.0})
if freshness_threshold <= 0 or staleness < freshness_threshold:
return False # Fresh enough for us
last_check_attempt = self.get_last_check_attempt(feed.url)
if last_check_attempt and last_check_attempt > now - FAILED_CHECK_DELAY:
debug(_("Stale, but tried to check recently (%s) so not rechecking now."), time.ctime(last_check_attempt))
return False
return True
示例13: parse_version
def parse_version(version_string):
"""Convert a version string to an internal representation.
The parsed format can be compared quickly using the standard Python functions.
- Version := DottedList ("-" Mod DottedList?)*
- DottedList := (Integer ("." Integer)*)
@rtype: tuple (opaque)
@raise SafeException: if the string isn't a valid version
@since: 0.24 (moved from L{reader}, from where it is still available):"""
if version_string is None: return None
parts = _version_re.split(version_string)
if parts[-1] == '':
del parts[-1] # Ends with a modifier
else:
parts.append('')
if not parts:
raise SafeException(_("Empty version string!"))
l = len(parts)
try:
for x in range(0, l, 2):
part = parts[x]
if part:
parts[x] = list(map(int, parts[x].split('.')))
else:
parts[x] = [] # (because ''.split('.') == [''], not [])
for x in range(1, l, 2):
parts[x] = _version_mod_to_value[parts[x]]
return parts
except ValueError as ex:
raise SafeException(_("Invalid version format in '%(version_string)s': %(exception)s") % {'version_string': version_string, 'exception': ex})
except KeyError as ex:
raise SafeException(_("Invalid version modifier in '%(version_string)s': %(exception)s") % {'version_string': version_string, 'exception': str(ex).strip("u")})
示例14: process_depends
def process_depends(item, local_feed_dir):
"""Internal"""
# Note: also called from selections
attrs = item.attrs
dep_iface = item.getAttribute('interface')
if not dep_iface:
raise InvalidInterface(_("Missing 'interface' on <%s>") % item.name)
if dep_iface.startswith('./'):
if local_feed_dir:
dep_iface = os.path.abspath(os.path.join(local_feed_dir, dep_iface))
# (updates the element too, in case we write it out again)
attrs['interface'] = dep_iface
else:
raise InvalidInterface(_('Relative interface URI "%s" in non-local feed') % dep_iface)
dependency = InterfaceDependency(dep_iface, element = item)
for e in item.childNodes:
if e.uri != XMLNS_IFACE: continue
if e.name in binding_names:
dependency.bindings.append(process_binding(e))
elif e.name == 'version':
dependency.restrictions.append(
VersionRangeRestriction(not_before = parse_version(e.getAttribute('not-before')),
before = parse_version(e.getAttribute('before'))))
return dependency
示例15: __init__
def __init__(self):
user_store = os.path.join(basedir.xdg_cache_home, '0install.net', 'implementations')
self.stores = [Store(user_store)]
impl_dirs = basedir.load_first_config('0install.net', 'injector',
'implementation-dirs')
debug(_("Location of 'implementation-dirs' config file being used: '%s'"), impl_dirs)
if impl_dirs:
dirs = open(impl_dirs)
else:
if os.name == "nt":
from win32com.shell import shell, shellcon
localAppData = shell.SHGetFolderPath(0, shellcon.CSIDL_LOCAL_APPDATA, 0, 0)
commonAppData = shell.SHGetFolderPath(0, shellcon.CSIDL_COMMON_APPDATA, 0, 0)
userCache = os.path.join(localAppData, "0install.net", "implementations")
sharedCache = os.path.join(commonAppData, "0install.net", "implementations")
dirs = [userCache, sharedCache]
else:
dirs = ['/var/cache/0install.net/implementations']
for directory in dirs:
directory = directory.strip()
if directory and not directory.startswith('#'):
debug(_("Added system store '%s'"), directory)
self.stores.append(Store(directory))