本文整理汇总了Python中pisi.package.Package类的典型用法代码示例。如果您正苦于以下问题:Python Package类的具体用法?Python Package怎么用?Python Package使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Package类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_package
def add_package(self, path, deltas, repo_uri):
package = Package(path, 'r')
md = package.get_metadata()
md.package.packageSize = os.path.getsize(path)
md.package.packageHash = util.sha1_file(path)
if ctx.config.options and ctx.config.options.absolute_urls:
md.package.packageURI = os.path.realpath(path)
else: # create relative path by default
# TODO: in the future well do all of this with purl/pfile/&helpers
# really? heheh -- future exa
md.package.packageURI = util.removepathprefix(repo_uri, path)
# check package semantics
errs = md.errors()
if md.errors():
ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name)
ctx.ui.error(unicode(Error(*errs)))
else:
# No need to carry these with index (#3965)
md.package.files = None
md.package.additionalFiles = None
if md.package.name in deltas:
for delta_path in deltas[md.package.name]:
delta = metadata.Delta()
delta.packageURI = util.removepathprefix(repo_uri, delta_path)
delta.packageSize = os.path.getsize(delta_path)
delta.packageHash = util.sha1_file(delta_path)
name, buildFrom, buildTo = util.parse_delta_package_name(delta_path)
delta.buildFrom = buildFrom
md.package.deltaPackages.append(delta)
self.packages.append(md.package)
示例2: locate_package_names
def locate_package_names(files):
for fn in files:
fn = fn.decode('utf-8')
if util.is_package_name(fn, package_name):
old_package_fn = os.path.join(root, fn)
ctx.ui.info('(found old version %s)' % old_package_fn)
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
if str(old_pkg.metadata.package.name) != package_name:
ctx.ui.warning('Skipping %s with wrong pkg name ' %
old_package_fn)
continue
old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) )
示例3: locate_old_package
def locate_old_package(old_package_fn):
if util.is_package_name(os.path.basename(old_package_fn), package_name):
try:
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
ctx.ui.info(_('(found old version %s)') % old_package_fn)
if str(old_pkg.metadata.package.name) != package_name:
ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
old_package_fn)
return
old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) )
except Error:
ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)
示例4: __init__
def __init__(self, package_fname):
"initialize from a file name"
self.package = Package(package_fname)
self.package.read()
self.metadata = self.package.metadata
self.files = self.package.files
self.pkginfo = self.metadata.package
示例5: Install
class Install(AtomicOperation):
"Install class, provides install routines for pisi packages"
def __init__(self, package_fname, ignore_dep = None):
"initialize from a file name"
super(Install, self).__init__(ignore_dep)
self.package = Package(package_fname)
self.package.read()
self.metadata = self.package.metadata
self.files = self.package.files
self.pkginfo = self.metadata.package
def install(self, ask_reinstall = True):
"entry point"
ctx.ui.status(_('Installing %s, version %s, release %s, build %s') %
(self.pkginfo.name, self.pkginfo.version,
self.pkginfo.release, self.pkginfo.build))
ctx.ui.notify(pisi.ui.installing, package = self.pkginfo, files = self.files)
self.ask_reinstall = ask_reinstall
self.check_requirements()
self.check_relations()
self.check_reinstall()
self.extract_install()
self.store_pisi_files()
if ctx.comar:
import pisi.comariface as comariface
self.register_comar_scripts()
ctx.ui.notify(pisi.ui.configuring, package = self.pkginfo, files = self.files)
comariface.run_postinstall(self.pkginfo.name)
ctx.ui.notify(pisi.ui.configured, package = self.pkginfo, files = self.files)
txn = ctx.dbenv.txn_begin()
try:
self.update_databases(txn)
txn.commit()
except db.DBError, e:
txn.abort()
raise e
self.update_environment()
ctx.ui.status()
if self.upgrade:
event = pisi.ui.upgraded
else:
event = pisi.ui.installed
ctx.ui.notify(event, package = self.pkginfo, files = self.files)
示例6: __init__
def __init__(self, package_fname, ignore_dep = None):
"initialize from a file name"
super(Install, self).__init__(ignore_dep)
self.package = Package(package_fname)
self.package.read()
self.metadata = self.package.metadata
self.files = self.package.files
self.pkginfo = self.metadata.package
示例7: locate_package_names
def locate_package_names(files):
for fn in files:
if util.is_package_name(fn, package_name):
old_package_fn = util.join_path(root, fn)
try:
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(util.join_path(ctx.config.tmp_dir(), 'oldpkg'))
ctx.ui.info(_('(found old version %s)') % old_package_fn)
if str(old_pkg.metadata.package.name) != package_name:
ctx.ui.warning(_('Skipping %s with wrong pkg name ') %
old_package_fn)
continue
old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) )
except:
ctx.ui.warning('Package file %s may be corrupt. Skipping.' % old_package_fn)
continue
示例8: __init__
def __init__(self, package_fname, ignore_dep = None):
"initialize from a file name"
super(Install, self).__init__(ignore_dep)
self.package = Package(package_fname)
ctx.ui.notify(pisi.ui.downloading, url = package_fname)
self.package.read()
self.metadata = self.package.metadata
self.files = self.package.files
self.pkginfo = self.metadata.package
示例9: add_package
def add_package(self, path, repo_uri):
package = Package(path, 'r')
md = package.get_metadata()
md.package.packageSize = os.path.getsize(path)
md.package.packageHash = util.sha1_file(path)
if ctx.config.options and ctx.config.options.absolute_urls:
md.package.packageURI = os.path.realpath(path)
else: # create relative path by default
# TODO: in the future well do all of this with purl/pfile/&helpers
# really? heheh -- future exa
md.package.packageURI = util.removepathprefix(repo_uri, path)
# check package semantics
errs = md.errors()
if md.errors():
ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name)
ctx.ui.error(unicode(Error(*errs)))
else:
self.packages.append(md.package)
示例10: add_package
def add_package(self, path, repo_uri):
package = Package(path, 'r')
# extract control files
util.clean_dir(ctx.config.install_dir())
package.extract_PISI_files(ctx.config.install_dir())
md = metadata.MetaData()
md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
if ctx.config.options and ctx.config.options.absolute_uris:
md.package.packageURI = os.path.realpath(path)
else: # create relative path by default
# TODO: in the future we'll do all of this with purl/pfile/&helpers
# After that, we'll remove the ugly repo_uri parameter from this
# function.
md.package.packageURI = util.removepathprefix(repo_uri, path)
# check package semantics
if md.has_errors():
ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
else:
self.packages.append(md.package)
示例11: calc_build_no
def calc_build_no(self, package_name):
"""Calculate build number"""
# find previous build in ctx.config.options.output_dir
found = []
for root, dirs, files in os.walk(ctx.config.options.output_dir):
for fn in files:
fn = fn.decode('utf-8')
if fn.startswith(package_name + '-') and \
fn.endswith(ctx.const.package_prefix):
old_package_fn = os.path.join(root, fn)
ctx.ui.info('(found old version %s)' % old_package_fn)
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) )
if not found:
return 0
ctx.ui.warning('(no previous build found, setting build no to 0.)')
else:
a = filter(lambda (x,y): y != None, found)
if a:
a.sort(lambda x,y : cmp(x[1],y[1]))
old_package_fn = a[0][0]
old_build = a[0][1]
else:
old_build = None
# compare old files.xml with the new one..
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
# FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
changed = False
fnew = self.files.list
fold = old_pkg.files.list
fold.sort(lambda x,y : cmp(x.path,y.path))
fnew.sort(lambda x,y : cmp(x.path,y.path))
if len(fnew) != len(fold):
changed = True
else:
for i in range(len(fold)):
fo = fold.pop(0)
fn = fnew.pop(0)
if fo.path != fn.path:
changed = True
break
else:
if fo.hash != fn.hash:
changed = True
break
# set build number
if old_build is None:
ctx.ui.warning('(old package lacks a build no, setting build no to 0.)')
return 0
elif changed:
return old_build + 1
else:
return old_build
示例12: add_package
def add_package(self, path, repo_uri):
package = Package(path, 'r')
# extract control files
util.clean_dir(ctx.config.install_dir())
package.extract_PISI_files(ctx.config.install_dir())
md = metadata.MetaData()
md.read(os.path.join(ctx.config.install_dir(), ctx.const.metadata_xml))
if ctx.config.options and ctx.config.options.absolute_uris:
# FIXME: the name "absolute_uris" does not seem to fit below :/
md.package.packageURI = os.path.realpath(path)
else: # create relative path by default
# TODO: in the future well do all of this with purl/pfile/&helpers
# really? heheh -- future exa
md.package.packageURI = util.removepathprefix(repo_uri, path)
# check package semantics
errs = md.errors()
if md.errors():
ctx.ui.error(_('Package %s: metadata corrupt') % md.package.name)
ctx.ui.error(str(Error(*errs)))
else:
self.packages.append(md.package)
示例13: calc_build_no
def calc_build_no(self, package_name):
"""Calculate build number"""
def found_package(fn):
"did we find the filename we were looking for?"
if fn.startswith(package_name + '-'):
if fn.endswith(ctx.const.package_prefix):
# get version string, skip separator '-'
verstr = fn[len(package_name) + 1:
len(fn)-len(ctx.const.package_prefix)]
import string
for x in verstr.split('-'):
# weak rule: version components start with a digit
if x is '' or (not x[0] in string.digits):
return False
return True
return False
# find previous build in ctx.config.options.output_dir
found = []
# for root, dirs, files in os.walk(ctx.config.options.output_dir):
# for fn in files:
# fn = fn.decode('utf-8')
# if found_package(fn):
# old_package_fn = os.path.join(root, fn)
# ctx.ui.info('(found old version %s)' % old_package_fn)
# old_pkg = Package(old_package_fn, 'r')
# old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
# if str(old_pkg.metadata.package.name) != package_name:
# ctx.ui.warning('Skipping %s with wrong pkg name ' %
# old_package_fn)
# continue
# old_build = old_pkg.metadata.package.build
# found.append( (old_package_fn, old_build) )
#
# FIXME: Following dirty lines of code just search in the output_dir and
# packages dir for previous packages. But we should find a neat way
# for this...
files = []
for f in os.listdir(ctx.config.options.output_dir):
fp = os.path.join(ctx.config.options.output_dir, f)
if os.path.isfile(fp):
files.append(fp)
packages_dir = ctx.config.packages_dir()
# FIXME: packages_dir() should be there!
if not os.path.exists(packages_dir):
os.makedirs(packages_dir)
for f in os.listdir(packages_dir):
fp = os.path.join(packages_dir, f)
if os.path.isfile(fp):
files.append(fp)
for fn in files:
fn = fn.decode('utf-8')
if found_package(os.path.basename(fn)):
old_package_fn = fn
ctx.ui.info('(found old version %s)' % old_package_fn)
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
if str(old_pkg.metadata.package.name) != package_name:
ctx.ui.warning('Skipping %s with wrong pkg name ' %
old_package_fn)
continue
old_build = old_pkg.metadata.package.build
found.append( (old_package_fn, old_build) )
if not found:
return 0
ctx.ui.warning('(no previous build found, setting build no to 0.)')
else:
a = filter(lambda (x,y): y != None, found)
ctx.ui.debug(str(a))
if a:
a.sort(lambda x,y : cmp(x[1],y[1]))
old_package_fn = a[0][0]
old_build = a[0][1]
else:
old_build = None
# compare old files.xml with the new one..
old_pkg = Package(old_package_fn, 'r')
old_pkg.read(os.path.join(ctx.config.tmp_dir(), 'oldpkg'))
# FIXME: TAKE INTO ACCOUNT MINOR CHANGES IN METADATA
changed = False
fnew = self.files.list
fold = old_pkg.files.list
fold.sort(lambda x,y : cmp(x.path,y.path))
fnew.sort(lambda x,y : cmp(x.path,y.path))
if len(fnew) != len(fold):
changed = True
else:
for i in range(len(fold)):
fo = fold.pop(0)
fn = fnew.pop(0)
if fo.path != fn.path:
changed = True
break
else:
if fo.hash != fn.hash:
#.........这里部分代码省略.........
示例14: build_packages
def build_packages(self):
"""Build each package defined in PSPEC file. After this process there
will be .pisi files hanging around, AS INTENDED ;)"""
for package in self.spec.packages:
# store additional files
c = os.getcwd()
os.chdir(self.pspecDir)
install_dir = self.bctx.pkg_dir() + ctx.const.install_dir_suffix
for afile in package.additionalFiles:
src = os.path.join(ctx.const.files_dir, afile.filename)
dest = os.path.join(install_dir + os.path.dirname(afile.target), os.path.basename(afile.target))
util.copy_file(src, dest)
if afile.permission:
# mode is octal!
os.chmod(dest, int(afile.permission, 8))
os.chdir(c)
name = util.package_name(package.name,
self.spec.source.version,
self.spec.source.release)
ctx.ui.action(_("** Building package %s") % package.name);
ctx.ui.action(_("Generating %s...") % ctx.const.files_xml)
self.gen_files_xml(package)
ctx.ui.info(_(" done."))
ctx.ui.action(_("Generating %s...") % ctx.const.metadata_xml)
self.gen_metadata_xml(package)
ctx.ui.info(_(" done."))
ctx.ui.action(_("Creating PISI package %s") % name)
pkg = Package(name, 'w')
# add comar files to package
os.chdir(self.pspecDir)
for pcomar in package.providesComar:
fname = os.path.join(ctx.const.comar_dir,
pcomar.script)
pkg.add_to_package(fname)
# add xmls and files
os.chdir(self.bctx.pkg_dir())
pkg.add_to_package(ctx.const.metadata_xml)
pkg.add_to_package(ctx.const.files_xml)
# Now it is time to add files to the packages using newly
# created files.xml
files = Files()
files.read(ctx.const.files_xml)
for finfo in files.list:
pkg.add_to_package("install/" + finfo.path)
pkg.close()
os.chdir(c)
self.set_state("buildpackages")
util.xterm_title_reset()
示例15: create_delta_package
def create_delta_package(old_package, new_package):
if old_package == new_package:
ctx.ui.error(_("Cannot create delta for same package!"))
return
oldpkg = Package(old_package, "r")
newpkg = Package(new_package, "r")
newmd = newpkg.get_metadata()
oldmd = oldpkg.get_metadata()
oldfiles = oldpkg.get_files()
newfiles = newpkg.get_files()
files_delta = find_delta(oldfiles, newfiles)
ctx.ui.info(_("Creating delta PiSi package between %s %s") % (old_package, new_package))
# Unpack new package to temp
newpkg_name = util.package_name(newmd.package.name, newmd.package.version, newmd.package.release, newmd.package.build, False)
newpkg_path = util.join_path(ctx.config.tmp_dir(), newpkg_name)
newpkg.extract_to(newpkg_path, True)
tar = archive.ArchiveTar(util.join_path(newpkg_path, ctx.const.install_tar_lzma), "tarlzma", False, False)
tar.unpack_dir(newpkg_path)
# Create delta package
deltaname = "%s-%s-%s%s" % (oldmd.package.name, oldmd.package.build, newmd.package.build, ctx.const.delta_package_suffix)
outdir = ctx.get_option("output_dir")
if outdir:
deltaname = util.join_path(outdir, deltaname)
deltapkg = Package(deltaname, "w")
c = os.getcwd()
os.chdir(newpkg_path)
# add comar files to package
for pcomar in newmd.package.providesComar:
fname = util.join_path(ctx.const.comar_dir, pcomar.script)
deltapkg.add_to_package(fname)
# add xmls and files
deltapkg.add_to_package(ctx.const.metadata_xml)
deltapkg.add_to_package(ctx.const.files_xml)
# only metadata information may change in a package, so no install.tar.lzma added to delta package
if files_delta:
ctx.build_leftover = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma)
tar = archive.ArchiveTar(util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma), "tarlzma")
for file in files_delta:
tar.add_to_archive(file.path)
tar.close()
os.chdir(ctx.config.tmp_dir())
deltapkg.add_to_package(ctx.const.install_tar_lzma)
deltapkg.close()
tmp_file = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma)
if os.path.exists(tmp_file):
os.unlink(tmp_file)
ctx.build_leftover = None
os.chdir(c)
ctx.ui.info(_("Done."))