def add_package(self, path, deltas, repo_uri): package = pisi.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)
def add_package(params): try: path, deltas, repo_uri = params ctx.ui.info( "%-80.80s\r" % (_('Adding package to index: %s') % os.path.basename(path)), noln=True) package = pisi.package.Package(path, 'r') md = package.get_metadata() md.package.packageSize = long(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: md.package.packageURI = util.removepathprefix(repo_uri, path) # check package semantics errs = md.errors() if md.errors(): ctx.ui.info("") 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: name, version, release, distro_id, arch = \ util.split_package_filename(path) for delta_path in deltas[md.package.name]: src_release, dst_release, delta_distro_id, delta_arch = \ util.split_delta_package_filename(delta_path)[1:] # Add only delta to latest build of the package if dst_release != md.package.release or \ (delta_distro_id, delta_arch) != (distro_id, arch): continue delta = metadata.Delta() delta.packageURI = util.removepathprefix( repo_uri, delta_path) delta.packageSize = long(os.path.getsize(delta_path)) delta.packageHash = util.sha1_file(delta_path) delta.releaseFrom = src_release md.package.deltaPackages.append(delta) return md.package except KeyboardInterrupt: # Handle KeyboardInterrupt exception to prevent ugly backtrace of all # worker processes and propagate the exception to main process. # # Probably it's better to use just 'raise' here, but multiprocessing # module has some bugs about that: (python#8296, python#9205 and # python#9207 ) # # For now, worker processes do not propagate exceptions other than # Exception (like KeyboardInterrupt), so we have to manually propagate # KeyboardInterrupt exception as an Exception. raise Exception