本文整理汇总了Python中zeroinstall.logger.warn函数的典型用法代码示例。如果您正苦于以下问题:Python warn函数的具体用法?Python warn怎么用?Python warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_candidates
def fetch_candidates(self, master_feed):
package_names = [item.getAttribute("package") for item, item_attrs, depends in master_feed.get_package_impls(self)]
if self.packagekit.available:
return self.packagekit.fetch_candidates(package_names)
# No PackageKit. Use apt-cache directly.
for package in package_names:
# Check to see whether we could get a newer version using apt-get
try:
null = os.open(os.devnull, os.O_WRONLY)
child = subprocess.Popen(['apt-cache', 'show', '--no-all-versions', '--', package], stdout = subprocess.PIPE, stderr = null, universal_newlines = True)
os.close(null)
arch = version = size = None
for line in child.stdout:
line = line.strip()
if line.startswith('Version: '):
version = line[9:]
version = try_cleanup_distro_version(version)
elif line.startswith('Architecture: '):
arch = canonical_machine(line[14:].strip())
elif line.startswith('Size: '):
size = int(line[6:].strip())
if version and arch:
cached = {'version': version, 'arch': arch, 'size': size}
else:
cached = None
child.stdout.close()
child.wait()
except Exception as ex:
logger.warn("'apt-cache show %s' failed: %s", package, ex)
cached = None
# (multi-arch support? can there be multiple candidates?)
self.apt_cache[package] = cached
示例2: get_package_info
def get_package_info(self, package, factory):
_name_version_regexp = '^(.+)-([^-]+)$'
nameversion = re.compile(_name_version_regexp)
for pkgname in os.listdir(self._pkgdir):
pkgdir = os.path.join(self._pkgdir, pkgname)
if not os.path.isdir(pkgdir): continue
#contents = open(os.path.join(pkgdir, '+CONTENTS')).readline().strip()
match = nameversion.search(pkgname)
if match is None:
logger.warn(_('Cannot parse version from Ports package named "%(pkgname)s"'), {'pkgname': pkgname})
continue
else:
name = match.group(1)
if name != package:
continue
version = try_cleanup_distro_version(match.group(2))
machine = host_machine
impl = factory('package:ports:%s:%s:%s' % \
(package, version, machine))
impl.version = model.parse_version(version)
impl.machine = machine
示例3: _add_with_helper
def _add_with_helper(self, required_digest, path):
"""Use 0store-secure-add to copy 'path' to the system store.
@param required_digest: the digest for path
@type required_digest: str
@param path: root of implementation directory structure
@type path: str
@return: True iff the directory was copied into the system cache successfully
"""
if required_digest.startswith('sha1='):
return False # Old digest alg not supported
helper = support.find_in_path('0store-secure-add-helper')
if not helper:
logger.info(_("'0store-secure-add-helper' command not found. Not adding to system cache."))
return False
import subprocess
env = os.environ.copy()
env['ENV_NOT_CLEARED'] = 'Unclean' # (warn about insecure configurations)
env['HOME'] = 'Unclean' # (warn about insecure configurations)
dev_null = os.open(os.devnull, os.O_RDONLY)
try:
logger.info(_("Trying to add to system cache using %s"), helper)
child = subprocess.Popen([helper, required_digest],
stdin = dev_null,
cwd = path,
env = env)
exit_code = child.wait()
finally:
os.close(dev_null)
if exit_code:
logger.warn(_("0store-secure-add-helper failed."))
return False
logger.info(_("Added succcessfully."))
return True
示例4: 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
示例5: generate_cache
def generate_cache(self):
cache = []
child = subprocess.Popen(["port", "-v", "installed"],
stdout = subprocess.PIPE, universal_newlines = True)
for line in child.stdout:
if not line.startswith(" "):
continue
if line.strip().count(" ") > 1:
package, version, extra = line.split(None, 2)
else:
package, version = line.split()
extra = ""
if not extra.startswith("(active)"):
continue
version = version.lstrip('@')
version = re.sub(r"\+.*", "", version) # strip variants
zi_arch = '*'
clean_version = try_cleanup_distro_version(version)
if clean_version:
match = re.match(r" platform='([^' ]*)( \d+)?' archs='([^']*)'", extra)
if match:
platform, major, archs = match.groups()
for arch in archs.split():
zi_arch = canonical_machine(arch)
cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch))
else:
cache.append('%s\t%s\t%s' % (package, clean_version, zi_arch))
else:
logger.warn(_("Can't parse distribution version '%(version)s' for package '%(package)s'"), {'version': version, 'package': package})
self._write_cache(cache)
child.stdout.close()
child.wait()
示例6: load_config
def load_config(handler = None):
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.warn(_("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
示例7: factory
def factory(id, only_if_missing = False, installed = True):
assert id.startswith('package:')
if id in feed.implementations:
if only_if_missing:
return None
logger.warn(_("Duplicate ID '%s' for DistributionImplementation"), id)
impl = model.DistributionImplementation(feed, id, self, item)
feed.implementations[id] = impl
new_impls.append(impl)
impl.installed = installed
impl.metadata = item_attrs
impl.requires = depends
if 'run' not in impl.commands:
item_main = item_attrs.get('main', None)
if item_main:
if item_main.startswith('/'):
impl.main = item_main
else:
raise model.InvalidInterface(_("'main' attribute must be absolute, but '%s' doesn't start with '/'!") %
item_main)
impl.upstream_stability = model.packaged
return impl
示例8: report_error
def report_error(self, exception, tb = None):
"""Report an exception to the user.
@param exception: the exception to report
@type exception: L{SafeException}
@param tb: optional traceback
@since: 0.25"""
logger.warn("%s", str(exception) or type(exception))
示例9: download_icon
def download_icon(self, interface, force=False):
"""Download an icon for this interface and add it to the
icon cache. If the interface has no icon do nothing.
@return: the task doing the import, or None
@rtype: L{tasks.Task}"""
logger.debug("download_icon %(interface)s", {"interface": interface})
modification_time = None
existing_icon = self.config.iface_cache.get_icon_path(interface)
if existing_icon:
file_mtime = os.stat(existing_icon).st_mtime
from email.utils import formatdate
modification_time = formatdate(timeval=file_mtime, localtime=False, usegmt=True)
feed = self.config.iface_cache.get_feed(interface.uri)
if feed is None:
return None
# Find a suitable icon to download
for icon in feed.get_metadata(XMLNS_IFACE, "icon"):
type = icon.getAttribute("type")
if type != "image/png":
logger.debug(_("Skipping non-PNG icon"))
continue
source = icon.getAttribute("href")
if source:
break
logger.warn(_('Missing "href" attribute on <icon> in %s'), interface)
else:
logger.info(_("No PNG icons found in %s"), interface)
return
dl = self.download_url(source, hint=interface, modification_time=modification_time)
@tasks.async
def download_and_add_icon():
stream = dl.tempfile
try:
yield dl.downloaded
tasks.check(dl.downloaded)
if dl.unmodified:
return
stream.seek(0)
import shutil, tempfile
icons_cache = basedir.save_cache_path(config_site, "interface_icons")
tmp_file = tempfile.NamedTemporaryFile(dir=icons_cache, delete=False)
shutil.copyfileobj(stream, tmp_file)
tmp_file.close()
icon_file = os.path.join(icons_cache, escape(interface.uri))
portable_rename(tmp_file.name, icon_file)
finally:
stream.close()
return download_and_add_icon()
示例10: _get_mtime
def _get_mtime(self, name, warn_if_missing = True):
timestamp_path = os.path.join(self.path, name)
try:
return os.stat(timestamp_path).st_mtime
except Exception as ex:
if warn_if_missing:
logger.warn("Failed to get time-stamp of %s: %s", timestamp_path, ex)
return 0
示例11: put
def put(self, key, value):
cache_path = os.path.join(self.cache_dir, self.cache_leaf)
self.cache[key] = value
try:
with open(cache_path, 'a') as stream:
stream.write('%s=%s\n' % (key, value))
except Exception as ex:
logger.warn("Failed to write to cache %s: %s=%s: %s", cache_path, key, value, ex)
示例12: get_last_checked
def get_last_checked(self):
"""Get the time of the last successful check for updates.
@return: the timestamp (or None on error)
@rtype: float | None"""
last_updated_path = os.path.join(self.path, "last-checked")
try:
return os.stat(last_updated_path).st_mtime
except Exception as ex:
logger.warn("Failed to get time-stamp of %s: %s", last_updated_path, ex)
return None
示例13: download_keys
def download_keys(self, fetcher, feed_hint = None, key_mirror = None):
"""Download any required GPG keys not already on our keyring.
When all downloads are done (successful or otherwise), add any new keys
to the keyring, L{recheck}.
@param fetcher: fetcher to manage the download (was Handler before version 1.5)
@type fetcher: L{fetch.Fetcher}
@param key_mirror: URL of directory containing keys, or None to use feed's directory
@type key_mirror: str
"""
downloads = {}
blockers = []
for x in self.sigs:
key_id = x.need_key()
if key_id:
try:
import urlparse
except ImportError:
from urllib import parse as urlparse # Python 3
key_url = urlparse.urljoin(key_mirror or self.url, '%s.gpg' % key_id)
logger.info(_("Fetching key from %s"), key_url)
dl = fetcher.download_url(key_url, hint = feed_hint)
downloads[dl.downloaded] = (dl, dl.tempfile)
blockers.append(dl.downloaded)
exception = None
any_success = False
from zeroinstall.support import tasks
while blockers:
yield blockers
old_blockers = blockers
blockers = []
for b in old_blockers:
dl, stream = downloads[b]
try:
tasks.check(b)
if b.happened:
stream.seek(0)
self._downloaded_key(stream)
any_success = True
stream.close()
else:
blockers.append(b)
except Exception:
_type, exception, tb = sys.exc_info()
logger.warn(_("Failed to import key for '%(url)s': %(exception)s"), {'url': self.url, 'exception': str(exception)})
stream.close()
if exception and not any_success:
raise_with_traceback(exception, tb)
self.recheck()
示例14: download
def download(self, dl):
# (changed if we get redirected)
current_url = dl.url
redirections_remaining = 10
original_exception = None
# Assign the Download to a Site based on its scheme, host and port. If the result is a redirect,
# reassign it to the appropriate new site. Note that proxy handling happens later; we want to group
# and limit by the target site, not treat everything as going to a single site (the proxy).
while True:
location_parts = urlparse.urlparse(current_url)
site_key = (location_parts.scheme,
location_parts.hostname,
location_parts.port or default_port.get(location_parts.scheme, None))
step = DownloadStep()
step.dl = dl
step.url = current_url
blocker = self._sites[site_key].download(step)
yield blocker
try:
tasks.check(blocker)
except download.DownloadError as ex:
if original_exception is None:
original_exception = ex
else:
logger.warn("%s (while trying mirror)", ex)
mirror_url = step.dl.get_next_mirror_url()
if mirror_url is None:
raise original_exception
# Try the mirror.
# There are actually two places where we try to use the mirror: this one
# looks to see if we have an exact copy of same file somewhere else. If this
# fails, Fetcher will also look for a different archive that would generate
# the required implementation.
logger.warn("%s: trying archive mirror at %s", ex, mirror_url)
step.redirect = mirror_url
redirections_remaining = 10
if not step.redirect:
break
current_url = step.redirect
if redirections_remaining == 0:
raise download.DownloadError("Too many redirections {url} -> {current}".format(
url = dl.url,
current = current_url))
redirections_remaining -= 1
示例15: _add_site_packages
def _add_site_packages(interface, site_packages, known_site_feeds):
for impl in os.listdir(site_packages):
if impl.startswith('.'): continue
feed = os.path.join(site_packages, impl, '0install', 'feed.xml')
if not os.path.exists(feed):
logger.warn(_("Site-local feed {path} not found").format(path = feed))
logger.debug("Adding site-local feed '%s'", feed)
# (we treat these as user overrides in order to let old versions of 0install
# find them)
interface.extra_feeds.append(Feed(feed, None, user_override = True, site_package = True))
known_site_feeds.add(feed)