def load_checksum_from_header(self): if self.path is None: raise rhnFault(50, "Unable to load package", explain=0) self.a_pkg = rhn_pkg.package_from_filename(self.path) self.a_pkg.read_header() self.a_pkg.payload_checksum() self.a_pkg.input_stream.close()
def _processFile(filename, relativeDir=None, source=None, nosig=None): """ Processes a file Returns a hash containing: header packageSize checksum relativePath nvrea """ # Is this a file? if not os.access(filename, os.R_OK): raise UploadError("Could not stat the file %s" % filename) if not os.path.isfile(filename): raise UploadError("%s is not a file" % filename) # Size size = os.path.getsize(filename) try: a_pkg = package_from_filename(filename) a_pkg.read_header() a_pkg.payload_checksum() assert a_pkg.header except: raise UploadError("%s is not a valid package" % filename), None, sys.exc_info()[2] if nosig is None and not a_pkg.header.is_signed(): raise UploadError("ERROR: %s: unsigned rpm (use --nosig to force)" % filename) # Get the name, version, release, epoch, arch lh = [] for k in ['name', 'version', 'release', 'epoch']: lh.append(a_pkg.header[k]) # Fix the epoch if lh[3] is None: lh[3] = "" else: lh[3] = str(lh[3]) if source: lh.append('src') else: lh.append(a_pkg.header['arch']) # Build the header hash to be sent info = {'header' : Binary(a_pkg.header.unload()), 'checksum_type' : a_pkg.checksum_type, 'checksum' : a_pkg.checksum, 'packageSize' : size, 'header_start' : a_pkg.header_start, 'header_end' : a_pkg.header_end} if relativeDir: # Append the relative dir too info["relativePath"] = "%s/%s" % (relativeDir, os.path.basename(filename)) info['nvrea'] = tuple(lh) return info
def _processFile(filename, relativeDir=None, source=None, nosig=None): """ Processes a file Returns a hash containing: header packageSize checksum relativePath nvrea """ # Is this a file? if not os.access(filename, os.R_OK): raise UploadError("Could not stat the file %s" % filename) if not os.path.isfile(filename): raise UploadError("%s is not a file" % filename) # Size size = os.path.getsize(filename) try: a_pkg = package_from_filename(filename) a_pkg.read_header() a_pkg.payload_checksum() assert a_pkg.header except: raise UploadError("%s is not a valid package" % filename), None, sys.exc_info()[2] if nosig is None and not a_pkg.header.is_signed(): raise UploadError("ERROR: %s: unsigned rpm (use --nosig to force)" % filename) # Get the name, version, release, epoch, arch lh = [] for k in ['name', 'version', 'release', 'epoch']: lh.append(a_pkg.header[k]) # Fix the epoch if lh[3] is None: lh[3] = "" else: lh[3] = str(lh[3]) if source: lh.append('src') else: lh.append(a_pkg.header['arch']) # Build the header hash to be sent info = {'header': Binary(a_pkg.header.unload()), 'checksum_type': a_pkg.checksum_type, 'checksum': a_pkg.checksum, 'packageSize': size, 'header_start': a_pkg.header_start, 'header_end': a_pkg.header_end} if relativeDir: # Append the relative dir too info["relativePath"] = "%s/%s" % (relativeDir, os.path.basename(filename)) info['nvrea'] = tuple(lh) return info
def load_checksum_from_header(self): if self.path is None: raise rhnFault(50, "Unable to load package", explain=0) self.a_pkg = rhn_pkg.package_from_filename(self.path) self.a_pkg.read_header() if self.checksum_type: self.a_pkg.set_checksum_type(self.checksum_type) if not self.a_pkg.checksum: self.a_pkg.payload_checksum() self.a_pkg.input_stream.close() if self.checksum != self.a_pkg.checksum: raise rhnFault(50, "checksums did not match %s vs %s" % (self.checksum, self.a_pkg.checksum), explain=0)
def upload(self, filename, fileChecksumType, fileChecksum): """ Uploads a file. Returns (http_error_code, error_message) Sets: self.package_name self.package_epoch self.package_version self.package_release self.package_arch """ try: a_pkg = package_from_filename(filename) a_pkg.read_header() except InvalidPackageError: return -1, "Not an RPM: %s" % filename # Set some package data members self.package_name = a_pkg.header['name'] self.package_epoch = a_pkg.header['epoch'] self.package_version = a_pkg.header['version'] self.package_release = a_pkg.header['release'] if a_pkg.header.is_source: if 1051 in a_pkg.header.keys(): self.package_arch = 'nosrc' else: self.package_arch = 'src' else: self.package_arch = a_pkg.header['arch'] self.packaging = a_pkg.header.packaging nvra = [self.package_name, self.package_version, self.package_release, self.package_arch] if isinstance(nvra[3], IntType): # Old rpm format return -1, "Deprecated RPM format: %s" % filename self.nvra = nvra # use the precomputed passed checksum self.checksum_type = fileChecksumType self.checksum = fileChecksum # Set headers self.set_header("Content-Type", "application/x-rpm") self.set_header("User-Agent", self.user_agent) # Custom RHN headers prefix = self.header_prefix self.set_header("%s-%s" % (prefix, "Package-Name"), nvra[0]) self.set_header("%s-%s" % (prefix, "Package-Version"), nvra[1]) self.set_header("%s-%s" % (prefix, "Package-Release"), nvra[2]) self.set_header("%s-%s" % (prefix, "Package-Arch"), nvra[3]) self.set_header("%s-%s" % (prefix, "Packaging"), self.packaging) if self.checksum_type == 'md5': self.set_header("%s-%s" % (prefix, "File-MD5sum"), self.checksum) else: self.set_header("%s-%s" % (prefix, "File-Checksum-Type"), self.checksum_type) self.set_header("%s-%s" % (prefix, "File-Checksum"), self.checksum) a_pkg.input_stream.seek(0, 0) self._response = self.send_http('POST', stream_body=a_pkg.input_stream) a_pkg.input_stream.close() retval = self.process_response() self.connection.close() return retval
def check_package_exists(self): self.warn( 2, "Computing checksum and package info. This may take some time ...") pkg_hash = {} digest_hash = {} for pkg in self.files: pkg_info = {} pkg_key = (pkg.strip()).split('/')[-1] if not os.access(pkg, os.R_OK): if not self.options.tolerant: self.die(-1, "Could not read file %s" % pkg) self.warn(-1, "Could not read file %s" % pkg) continue try: a_pkg = package_from_filename(pkg) a_pkg.read_header() a_pkg.payload_checksum() except InvalidPackageError: if not self.options.tolerant: self.die( -1, "ERROR: %s: This file doesn't appear to be a package" % pkg) self.warn( 2, "ERROR: %s: This file doesn't appear to be a package" % pkg) continue except IOError: if not self.options.tolerant: self.die( -1, "ERROR: %s: No such file or directory available" % pkg) self.warn( 2, "ERROR: %s: No such file or directory available" % pkg) continue digest_hash[pkg_key] = (a_pkg.checksum_type, a_pkg.checksum) a_pkg.input_stream.close() for tag in ('name', 'version', 'release', 'epoch', 'arch'): val = a_pkg.header[tag] if val is None: val = '' pkg_info[tag] = val #b195903:the arch for srpms should be obtained by is_source check #instead of checking arch in header if a_pkg.header.is_source: if not self.options.source: self.die( -1, "ERROR: Trying to Push src rpm, Please re-try with --source." ) if RPMTAG_NOSOURCE in a_pkg.header.keys(): pkg_info['arch'] = 'nosrc' else: pkg_info['arch'] = 'src' pkg_info['checksum_type'] = a_pkg.checksum_type pkg_info['checksum'] = a_pkg.checksum pkg_hash[pkg_key] = pkg_info if self.options.nullorg: #to satisfy xmlrpc from None values. orgid = 'null' else: orgid = '' info = { 'packages': pkg_hash, 'channels': self.channels, 'org_id': orgid, 'force': self.options.force or 0 } # rpc call to get checksum info for all the packages to be uploaded if not self.options.source: # computing checksum and other info is expensive process and session # could have expired.Make sure its re-authenticated. self.authenticate() if uploadLib.exists_getPackageChecksumBySession(self.server): checksum_data = uploadLib.getPackageChecksumBySession( self.server, self.session.getSessionString(), info) else: # old server only md5 capable checksum_data = uploadLib.getPackageMD5sumBySession( self.server, self.session.getSessionString(), info) else: # computing checksum and other info is expensive process and session # could have expired.Make sure its re-authenticated. self.authenticate() if uploadLib.exists_getPackageChecksumBySession(self.server): checksum_data = uploadLib.getSourcePackageChecksumBySession( self.server, self.session.getSessionString(), info) else: # old server only md5 capable checksum_data = uploadLib.getSourcePackageMD5sumBySession( self.server, self.session.getSessionString(), info) return (checksum_data, pkg_hash, digest_hash)
def check_package_exists(self): self.warn(2, "Computing checksum and package info. This may take some time ...") pkg_hash = {} digest_hash = {} for pkg in self.files: pkg_info = {} pkg_key = (pkg.strip()).split('/')[-1] if not os.access(pkg, os.R_OK): if not self.options.tolerant: self.die(-1, "Could not read file %s" % pkg) self.warn(-1, "Could not read file %s" % pkg) continue try: a_pkg = package_from_filename(pkg) a_pkg.read_header() a_pkg.payload_checksum() except InvalidPackageError: if not self.options.tolerant: self.die(-1, "ERROR: %s: This file doesn't appear to be a package" % pkg) self.warn(2, "ERROR: %s: This file doesn't appear to be a package" % pkg) continue except IOError: if not self.options.tolerant: self.die(-1, "ERROR: %s: No such file or directory available" % pkg) self.warn(2, "ERROR: %s: No such file or directory available" % pkg) continue digest_hash[pkg_key] = (a_pkg.checksum_type, a_pkg.checksum) a_pkg.input_stream.close() for tag in ('name', 'version', 'release', 'epoch', 'arch'): val = a_pkg.header[tag] if val is None: val = '' pkg_info[tag] = val # b195903:the arch for srpms should be obtained by is_source check # instead of checking arch in header if a_pkg.header.is_source: if not self.options.source: self.die(-1, "ERROR: Trying to Push src rpm, Please re-try with --source.") if RPMTAG_NOSOURCE in a_pkg.header.keys(): pkg_info['arch'] = 'nosrc' else: pkg_info['arch'] = 'src' pkg_info['checksum_type'] = a_pkg.checksum_type pkg_info['checksum'] = a_pkg.checksum pkg_hash[pkg_key] = pkg_info if self.options.nullorg: # to satisfy xmlrpc from None values. orgid = 'null' else: orgid = '' info = { 'packages': pkg_hash, 'channels': self.channels, 'org_id': orgid, 'force': self.options.force or 0 } # rpc call to get checksum info for all the packages to be uploaded if not self.options.source: # computing checksum and other info is expensive process and session # could have expired.Make sure its re-authenticated. self.authenticate() if uploadLib.exists_getPackageChecksumBySession(self.server): checksum_data = uploadLib.getPackageChecksumBySession(self.server, self.session.getSessionString(), info) else: # old server only md5 capable checksum_data = uploadLib.getPackageMD5sumBySession(self.server, self.session.getSessionString(), info) else: # computing checksum and other info is expensive process and session # could have expired.Make sure its re-authenticated. self.authenticate() if uploadLib.exists_getPackageChecksumBySession(self.server): checksum_data = uploadLib.getSourcePackageChecksumBySession(self.server, self.session.getSessionString(), info) else: # old server only md5 capable checksum_data = uploadLib.getSourcePackageMD5sumBySession(self.server, self.session.getSessionString(), info) return (checksum_data, pkg_hash, digest_hash)