def uploadPackages(info, source=0, force=0, caller=None): log_debug(4, source, force, caller) batch = Collection() packageList = info.get("packages") or [] if not packageList: raise Exception("Nothing to do") org_id = info.get('orgId') if org_id == '': org_id = None if source: channelList = [] else: channelList = info.get("channels") or [] for package in packageList: p = __processPackage(package, org_id, channelList, source) batch.append(p) if CFG.DB_BACKEND == ORACLE: from spacewalk.server.importlib.backendOracle import OracleBackend backend = OracleBackend() elif CFG.DB_BACKEND == POSTGRESQL: from spacewalk.server.importlib.backendOracle import PostgresqlBackend backend = PostgresqlBackend() backend.init() importer = packageImporter(batch, backend, source, caller=caller) importer.setUploadForce(force) importer.run() if not source: importer.subscribeToChannels() # Split the result in two lists - already uploaded and new packages newpkgs = [] uploaded = [] for pkg in importer.status(): if pkg.ignored or pkg.diff: uploaded.append(pkg) else: newpkgs.append(pkg) # Schedule an errata cache update only if we touched the channels if not source: # makes sense only for binary packages schedule_errata_cache_update(importer.affected_channels) taskomatic.add_to_repodata_queue_for_channel_package_subscription( importer.affected_channels, batch, caller) rhnSQL.commit() return _formatStatus(uploaded), _formatStatus(newpkgs)
def associate_package(self, pack): caller = "server.app.yumreposync" if CFG.DB_BACKEND == ORACLE: from spacewalk.server.importlib.backendOracle import OracleBackend backend = OracleBackend() elif CFG.DB_BACKEND == POSTGRESQL: from spacewalk.server.importlib.backendOracle import PostgresqlBackend backend = PostgresqlBackend() backend.init() package = {} package['name'] = pack.name package['version'] = pack.version package['release'] = pack.release package['epoch'] = pack.epoch package['arch'] = pack.arch package['checksum'] = pack.checksum package['checksum_type'] = pack.checksum_type package['channels'] = [{'label':self.channel_label, 'id':self.channel['id']}] package['org_id'] = self.channel['org_id'] try: self._importer_run(package, caller, backend) except: package['epoch'] = '' self._importer_run(package, caller, backend) backend.commit()
'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 12345, }), KickstartFile().populate({ 'relative_path': 'foo/foo4', 'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 123456, }), KickstartFile().populate({ 'relative_path': 'foo/foo3', 'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 1234567, }), ], }), ] rhnSQL.initDB() backend = OracleBackend() backend.init() ki = KickstartableTreeImport(ks_trees, backend) ki.run()
'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 12345, }), KickstartFile().populate({ 'relative_path': 'foo/foo4', 'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 123456, }), KickstartFile().populate({ 'relative_path': 'foo/foo3', 'checksum_type': 'md5', 'checksum': 'axbycz', 'last_modified': '2003-10-11 12:13:14', 'file_size': 1234567, }), ], }), ] rhnSQL.initDB() backend = OracleBackend() backend.init() ki = KickstartableTreeImport(ks_trees, backend) ki.run()
def _channelPackageSubscription(self, authobj, info): # Authorize the org id passed authobj.authzOrg(info) packageList = info.get('packages') or [] if not packageList: log_debug(1, "No packages found; done") return 0 if not info.has_key('channels') or not info['channels']: log_debug(1, "No channels found; done") return 0 channelList = info['channels'] authobj.authzChannels(channelList) # Have to turn the channel list into a list of Channel objects channelList = map(lambda x: Channel().populate({'label' : x}), channelList) # Since we're dealing with superusers, we allow them to change the org # id # XXX check if we don't open ourselves too much (misa 20030422) org_id = info.get('orgId') if org_id == '': org_id = None batch = Collection() package_keys = ['name', 'version', 'release', 'epoch', 'arch'] for package in packageList: for k in package_keys: if not package.has_key(k): raise Exception("Missing key %s" % k) if package['arch'] == 'src' or package['arch'] == 'nosrc': # Source package - no reason to continue continue _checksum_sql_filter = "" checksum_exists = 0 if 'md5sum' in package: # for old rhnpush compatibility package['checksum_type'] = 'md5' package['checksum'] = package['md5sum'] if package.has_key('checksum') and CFG.ENABLE_NVREA: checksum_exists = 1 _checksum_sql_filter = """and c.checksum = :checksum and c.checksum_type = :checksum_type""" h = rhnSQL.prepare(self._get_pkg_info_query % \ _checksum_sql_filter) pkg_epoch = None if package['epoch'] != '': pkg_epoch = package['epoch'] if checksum_exists: h.execute(pkg_name=package['name'], \ pkg_epoch=pkg_epoch, \ pkg_version=package['version'], \ pkg_rel=package['release'],pkg_arch=package['arch'], \ orgid = org_id, \ checksum_type = package['checksum_type'], \ checksum = package['checksum']) else: h.execute(pkg_name=package['name'], \ pkg_epoch=pkg_epoch, \ pkg_version=package['version'], \ pkg_rel=package['release'], \ pkg_arch=package['arch'], orgid = org_id ) row = h.fetchone_dict() package['checksum_type'] = row['checksum_type'] package['checksum'] = row['checksum'] package['org_id'] = org_id package['channels'] = channelList batch.append(IncompletePackage().populate(package)) caller = "server.app.channelPackageSubscription" if CFG.DB_BACKEND == ORACLE: from spacewalk.server.importlib.backendOracle import OracleBackend backend = OracleBackend() elif CFG.DB_BACKEND == POSTGRESQL: from spacewalk.server.importlib.backendOracle import PostgresqlBackend backend = PostgresqlBackend() backend.init() importer = ChannelPackageSubscription(batch, backend, caller=caller) try: importer.run() except IncompatibleArchError, e: raise rhnFault(50, string.join(e.args), explain=0)