backend/satellite_tools/repo_plugins/yum_src.py | 9 ++--- backend/satellite_tools/reposync.py | 40 +++++++++++++----------- backend/satellite_tools/spacewalk-repo-sync | 14 +------- 3 files changed, 29 insertions(+), 34 deletions(-)
New commits: commit 353e94dfc2ce49c6cd0ba61e4bb67ec901767884 Author: Pradeep Kilambi pkilambi@redhat.com Date: Mon Jul 27 12:39:16 2009 -0400
some clean up on repo sync stuff
diff --git a/backend/satellite_tools/repo_plugins/yum_src.py b/backend/satellite_tools/repo_plugins/yum_src.py index fd39518..fb3859f 100644 --- a/backend/satellite_tools/repo_plugins/yum_src.py +++ b/backend/satellite_tools/repo_plugins/yum_src.py @@ -16,8 +16,8 @@ import yum from yum import config from reposync import ContentPackage -class ContentSource:
+class ContentSource: url = None name = None repo = None @@ -31,7 +31,7 @@ class ContentSource: repo = yum.yumRepo.YumRepository(self.name) self.repo = repo repo.cache = 0 - repo.metadata_expire = 5 + repo.metadata_expire = 0 repo.baseurl = [self.url] repo.basecachedir = '/var/cache/rhn/reposync/' # repo.cachedir = '/var/cache/rhn/reposync/' @@ -42,7 +42,8 @@ class ContentSource: to_return = [] for pack in list: new_pack = ContentPackage() - new_pack.setNVREA(pack.name, pack.version, pack.release, pack.epoch, pack.arch) + new_pack.setNVREA(pack.name, pack.version, pack.release, + pack.epoch, pack.arch) new_pack.unique_id = pack for cs in pack.checksums: new_pack.checksums[cs[0]] = cs[1] @@ -52,5 +53,3 @@ class ContentSource: def get_package(self, package): """ get package """ return self.repo.getPackage(package.unique_id) - - diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py index 5abcc1c..0fd24d2 100644 --- a/backend/satellite_tools/reposync.py +++ b/backend/satellite_tools/reposync.py @@ -23,8 +23,6 @@ from server.importlib.backendOracle import OracleBackend from server.importlib.packageImport import ChannelPackageSubscription
class RepoSync: - - parser = None type = None url = None @@ -34,7 +32,6 @@ class RepoSync: fail = False repo_label = None
- def main(self): initCFG('server') db_string = CFG.DEFAULT_DB #"rhnsat/rhnsat@rhnsat" @@ -59,15 +56,14 @@ class RepoSync: self.repo_label = options.label self.channel = self.load_channel()
- if not self.channel or not rhnChannel.isCustomChannel(self.channel['id']): + if not self.channel or not \ + rhnChannel.isCustomChannel(self.channel['id']): print "Channel does not exist or is not custom" sys.exit(1)
self.plugin = self.load_plugin()(self.url, self.channel_label + "-" + self.repo_label) self.import_packages(self.plugin.list_packages())
- - def process_args(self): self.parser = OptionParser() self.parser.add_option('-u', '--url', action='store', dest='url', help='The url to sync') @@ -76,7 +72,6 @@ class RepoSync: self.parser.add_option('-l', '--label', action='store', dest='label', help='A friendly label to refer to the repo') self.parser.add_option('-f', '--fail', action='store_true', dest='fail', default=False , help="If a package import fails, fail the entire operation") return self.parser.parse_args() -
def load_plugin(self): sys.path.append("repo_plugins") @@ -94,18 +89,24 @@ class RepoSync: elif pack.checksums.has_key('sha256'): """lookup by sha256""" if pid == None: - if self.channel_label not in rhnPackage.get_channels_for_package([pack.name, pack.version, pack.release, pack.epoch, pack.arch]) and \ - self.channel_label not in rhnPackage.get_channels_for_package([pack.name, pack.version, pack.release, '', pack.arch]): + if self.channel_label not in \ + rhnPackage.get_channels_for_package([pack.name, \ + pack.version, pack.release, pack.epoch, pack.arch]) and \ + self.channel_label not in \ + rhnPackage.get_channels_for_package([pack.name, \ + pack.version, pack.release, '', pack.arch]): to_download.append(pack)
for (index, pack) in enumerate(to_download): """download each package""" try: - print(str(index) + "/" + str(len(to_download)) + " : "+ pack.getNVREA()) + print(str(index) + "/" + str(len(to_download)) + " : "+ \ + pack.getNVREA()) path = self.plugin.get_package(pack) md5 = rhnLib.getFileMD5(filename=path) - pid = rhnPackage.get_package_for_md5sum(self.channel['org_id'], md5) + pid = rhnPackage.get_package_for_md5sum( + self.channel['org_id'], md5) if pid is None: self.upload_package(pack, path, md5) self.associate_package(pack, md5) @@ -138,7 +139,8 @@ class RepoSync: package_dict, diff_level = rhnPackageUpload.push_package(header, payload_stream, md5sum, force=False, header_start=header_start, header_end=header_end, - relative_path=rel_package_path, org_id=self.channel['org_id']) + relative_path=rel_package_path, + org_id=self.channel['org_id']) temp_file.close() if self.url.find("file://") < 0: os.remove(path) @@ -158,21 +160,26 @@ class RepoSync: package['epoch'] = pack.epoch package['arch'] = pack.arch package['md5sum'] = md5sum - package['channels'] = [{'label':self.channel_label, 'id':self.channel['id']}] + package['channels'] = [{'label':self.channel_label, + 'id':self.channel['id']}] package['org_id'] = self.channel['org_id']
try: - importer = ChannelPackageSubscription([IncompletePackage().populate(package)], backend, caller=caller) + importer = ChannelPackageSubscription( + [IncompletePackage().populate(package)], + backend, caller=caller) importer.run() except: package['epoch'] = '0' - importer = ChannelPackageSubscription([IncompletePackage().populate(package)], backend, caller=caller) + importer = ChannelPackageSubscription( + [IncompletePackage().populate(package)], + backend, caller=caller) importer.run() backend.commit() + def load_channel(self): return rhnChannel.channel_info(self.channel_label)
- class ContentPackage:
#map of checksums. Valid keys are 'md5sum' & 'sha256' @@ -198,4 +205,3 @@ class ContentPackage: return self.name + '-' + self.version + '-' + self.release + '-' + self.epoch + '.' + self.arch else: return self.name + '-' + self.version + '-' + self.release + '.' + self.arch - diff --git a/backend/satellite_tools/spacewalk-repo-sync b/backend/satellite_tools/spacewalk-repo-sync index 244c260..a14ad76 100755 --- a/backend/satellite_tools/spacewalk-repo-sync +++ b/backend/satellite_tools/spacewalk-repo-sync @@ -22,7 +22,6 @@ if __name__ != '__main__': import sys def systemExit(code, msgs=None): "Exit with a code and optional message(s). Saved a few lines of code." - if msgs: if type(msgs) not in [type([]), type(())]: msgs = (msgs, ) @@ -30,7 +29,6 @@ def systemExit(code, msgs=None): sys.stderr.write(str(msg)+'\n') sys.exit(code)
- try: import os import socket @@ -45,16 +43,12 @@ except ImportError: sys.stderr.write("Unable to find RHN code tree.\n" "Path not correct? '%s'\n" % _LIBPATH)
- - - def releaseLOCK(): global LOCK if LOCK: LOCK.release() LOCK = None
- def main():
# quick check to see if you are a super-user. @@ -62,19 +56,16 @@ def main(): sys.stderr.write('ERROR: must be root to execute\n') sys.exit(8)
- LOCK = None try: - LOCK = rhnLockfile.Lockfile('/var/run/spacewalk-sync.pid') + LOCK = rhnLockfile.Lockfile('/var/run/spacewalk-repo-sync.pid') except rhnLockfile.LockfileLockedException: - systemExit(1, "SYNC ERROR: attempting to run more than one instance of satellite-sync. Exiting.") - + systemExit(1, "ERROR: attempting to run more than one instance of spacewalk-repo-sync Exiting.") sync = reposync.RepoSync() sync.main() releaseLOCK() return 0
- if __name__ == '__main__': try: sys.exit(abs(main() or 0)) @@ -86,4 +77,3 @@ if __name__ == '__main__': except Exception, e: releaseLOCK() raise -