本文整理汇总了Python中pisi.uri.URI.filename方法的典型用法代码示例。如果您正苦于以下问题:Python URI.filename方法的具体用法?Python URI.filename怎么用?Python URI.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pisi.uri.URI
的用法示例。
在下文中一共展示了URI.filename方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
def __init__(self, packagefn, mode='r'):
self.filepath = packagefn
url = URI(packagefn)
if url.is_remote_file():
from fetcher import fetch_url
dest = ctx.config.packages_dir()
self.filepath = join(dest, url.filename())
# FIXME: exists is not enough, also sha1sum check needed \
# when implemented in pisi-index.xml
if not exists(self.filepath):
fetch_url(url, dest, ctx.ui.Progress)
else:
ctx.ui.info(_('%s [cached]') % url.filename())
self.impl = archive.ArchiveZip(self.filepath, 'zip', mode)
示例2: read_uri
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
def read_uri(self, filename, repo = None):
"""Read PSPEC file"""
self.filepath = filename
url = URI(filename)
if url.is_remote_file():
from fetcher import fetch_url
assert repo
dest = os.path.join(ctx.config.index_dir(), repo)
if not os.path.exists(dest):
os.makedirs(dest)
fetch_url(url, dest, ctx.ui.Progress)
self.filepath = os.path.join(dest, url.filename())
self.read(self.filepath)
示例3: __init__
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
class SourceArchive:
"""source archive. this is a class responsible for fetching
and unpacking a source archive"""
def __init__(self, spec, pkg_work_dir):
self.url = URI(spec.source.archive.uri)
self.pkg_work_dir = pkg_work_dir
self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
self.archive = spec.source.archive
def fetch(self, interactive=True):
if not self.is_cached(interactive):
if interactive:
progress = ctx.ui.Progress
else:
progress = None
try:
fetch_url(self.url, ctx.config.archives_dir(), progress)
except pisi.fetcher.FetchError:
# if archive can not be reached from the url, try the fallback
# address.
if ctx.config.values.build.fallback:
archive = basename(self.url.get_uri())
src = join(ctx.config.values.build.fallback, archive)
fetch_url(src, ctx.config.archives_dir(), progress)
else:
raise
def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK):
return False
# check hash
if util.check_file_hash(self.archiveFile, self.archive.sha1sum):
if interactive:
ctx.ui.info(_('%s [cached]') % self.archive.name)
return True
return False
def unpack(self, clean_dir=True):
# check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archive.sha1sum):
raise Error, _("unpack: check_file_hash failed")
archive = Archive(self.archiveFile, self.archive.type)
archive.unpack(self.pkg_work_dir, clean_dir)
示例4: rebuild_repo
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
def rebuild_repo(repo):
ctx.ui.info(_('* Rebuilding \'%s\' named repo... ') % repo)
if ctx.repodb.has_repo(repo):
repouri = URI(ctx.repodb.get_repo(repo).indexuri.get_uri())
indexname = repouri.filename()
index = Index()
indexpath = pisi.util.join_path(ctx.config.index_dir(), repo, indexname)
tmpdir = os.path.join(ctx.config.tmp_dir(), 'index')
pisi.util.clean_dir(tmpdir)
pisi.util.check_dir(tmpdir)
try:
index.read_uri(indexpath, tmpdir, force=True) # don't look for sha1sum there
except IOError, e:
ctx.ui.warning(_("Input/Output error while reading %s: %s") % (indexpath, unicode(e)))
return
ctx.txn_proc(lambda txn : index.update_db(repo, txn=txn))
示例5: read
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
def read(self, filename, repo = None):
"""Read PSPEC file"""
self.filepath = filename
url = URI(filename)
if url.is_remote_file():
from fetcher import fetch_url
dest = os.path.join(ctx.config.index_dir(), repo)
if not os.path.exists(dest):
os.makedirs(dest)
fetch_url(url, dest, ctx.ui.Progress)
self.filepath = os.path.join(dest, url.filename())
self.readxml(self.filepath)
# find all binary packages
packageElts = self.getAllNodes("Package")
self.packages = [metadata.PackageInfo(p) for p in packageElts]
self.unlink()
示例6: __init__
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
class SourceArchive:
"""source archive. this is a class responsible for fetching
and unpacking a source archive"""
def __init__(self, bctx):
self.url = URI(bctx.spec.source.archiveUri)
self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
self.archiveName = bctx.spec.source.archiveName
self.archiveType = bctx.spec.source.archiveType
self.archiveSHA1 = bctx.spec.source.archiveSHA1
self.bctx = bctx
def fetch(self, interactive=True):
if not self.is_cached(interactive):
if interactive:
progress = ctx.ui.Progress
else: progress = None
fetch_url(self.url, ctx.config.archives_dir(), progress)
def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK):
return False
# check hash
if util.check_file_hash(self.archiveFile, self.archiveSHA1):
if interactive:
ctx.ui.info('%s [cached]' % self.archiveName)
return True
return False
def unpack(self, cleanDir=True):
# check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archiveSHA1):
raise SourceArchiveError, "unpack: check_file_hash failed"
archive = Archive(self.archiveFile, self.archiveType)
archive.unpack(self.bctx.pkg_work_dir(), cleanDir)
示例7: __init__
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
class SourceArchive:
"""source archive. this is a class responsible for fetching
and unpacking a source archive"""
def __init__(self, spec, pkg_work_dir):
self.url = URI(spec.source.archive.uri)
self.pkg_work_dir = pkg_work_dir
self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
self.archive = spec.source.archive
def fetch(self, interactive=True):
if not self.is_cached(interactive):
if interactive:
progress = ctx.ui.Progress
else:
progress = None
fetch_url(self.url, ctx.config.archives_dir(), progress)
def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK):
return False
# check hash
if util.check_file_hash(self.archiveFile, self.archive.sha1sum):
if interactive:
ctx.ui.info(_('%s [cached]') % self.archive.name)
return True
return False
def unpack(self, clean_dir=True):
# check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archive.sha1sum):
raise Error, _("unpack: check_file_hash failed")
archive = Archive(self.archiveFile, self.archive.type)
archive.unpack(self.pkg_work_dir, clean_dir)
示例8: rebuild_repo
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
def rebuild_repo(repo):
ctx.ui.info(_('* Rebuilding \'%s\' named repo... ') % repo, noln=True)
index = Index()
if ctx.repodb.has_repo(repo):
repouri = URI(ctx.repodb.get_repo(repo).indexuri.get_uri())
indexname = repouri.filename()
indexpath = pisi.util.join_path(ctx.config.lib_dir(), 'index', repo, indexname)
uri_str = repouri.get_uri()
if os.path.exists(indexpath):
uri_str = indexpath
try:
index.read_uri(uri_str, repo, force = True)
except IOError:
ctx.ui.warning(_("Repo index file \'%s\' not found.") % uri_str)
return
else:
raise Error(_('No repository named %s found.') % repo)
ctx.txn_proc(lambda txn : index.update_db(repo, txn=txn))
ctx.ui.info(_('OK.'))
示例9: __init__
# 需要导入模块: from pisi.uri import URI [as 别名]
# 或者: from pisi.uri.URI import filename [as 别名]
class SourceArchive:
"""source archive. this is a class responsible for fetching
and unpacking a source archive"""
def __init__(self, spec, pkg_work_dir):
self.url = URI(spec.source.archive.uri)
self.pkg_work_dir = pkg_work_dir
self.archiveFile = join(ctx.config.archives_dir(), self.url.filename())
self.archive = spec.source.archive
def fetch(self, interactive=True):
if not self.is_cached(interactive):
if interactive:
self.progress = ctx.ui.Progress
else:
self.progress = None
try:
if self.url.get_uri().startswith("mirrors://"):
self.fetch_from_mirror()
else:
fetch_url(self.url, ctx.config.archives_dir(), self.progress)
except pisi.fetcher.FetchError:
if ctx.config.values.build.fallback:
self.fetch_from_fallback()
else:
raise
def fetch_from_fallback(self):
archive = basename(self.url.get_uri())
src = join(ctx.config.values.build.fallback, archive)
ctx.ui.warning(_('Trying fallback address: %s') % src)
fetch_url(src, ctx.config.archives_dir(), self.progress)
def fetch_from_mirror(self):
uri = self.url.get_uri()
sep = uri[len("mirrors://"):].split("/")
name = sep.pop(0)
archive = "/".join(sep)
mirrors = Mirrors().get_mirrors(name)
if not mirrors:
raise Error(_("%s mirrors are not defined.") % name)
for mirror in mirrors:
try:
url = join(mirror, archive)
ctx.ui.warning(_('Fetching source from mirror: %s') % url)
fetch_url(url, ctx.config.archives_dir(), self.progress)
return
except pisi.fetcher.FetchError:
pass
raise pisi.fetcher.FetchError(_('Could not fetch source from %s mirrors.') % name);
def is_cached(self, interactive=True):
if not access(self.archiveFile, R_OK):
return False
# check hash
if util.check_file_hash(self.archiveFile, self.archive.sha1sum):
if interactive:
ctx.ui.info(_('%s [cached]') % self.archive.name)
return True
return False
def unpack(self, clean_dir=True):
# check archive file's integrity
if not util.check_file_hash(self.archiveFile, self.archive.sha1sum):
raise Error, _("unpack: check_file_hash failed")
archive = Archive(self.archiveFile, self.archive.type)
archive.unpack(self.pkg_work_dir, clean_dir)