backend/satellite_tools/repo_plugins/yum_src.py | 30 +++++++++++---
backend/satellite_tools/reposync.py | 49 +++++++++++++++---------
2 files changed, 54 insertions(+), 25 deletions(-)
New commits:
commit ce49456bf7481d91a113e9476f8925e28526ba0f
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue Feb 23 16:02:14 2010 +0100
fixed --label warning condition
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index bf72094..b11e0f6 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -14,6 +14,7 @@
# in this software or its documentation.
#
import sys, os, time, grp
+import hashlib
from optparse import OptionParser
from server import rhnPackage, rhnSQL, rhnChannel, rhnPackageUpload
from common import CFG, initCFG, rhnLog, fetchTraceback
@@ -77,7 +78,7 @@ class RepoSync:
if not options.channel_label:
quit = True
self.error_msg("--channel must be specified")
- if not options.label:
+ if options.label:
self.error_msg("--label is obsoleted")
if options.mirror:
self.error_msg("--mirrorlist is obsoleted; mirrorlist is recognized
automatically")
commit 0b784eeee6d9bac077fa540ceb9de4c48b1cb4e0
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 17:04:00 2010 +0100
if not --url, use channel repo url from database
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index 9f56155..bf72094 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -59,8 +59,21 @@ class RepoSync:
quit = False
if not options.url:
- quit = True
- self.error_msg("--url must be specified")
+ if options.channel_label:
+ h = rhnSQL.prepare("""select s.source_url
+ from rhnChannelContentSource s,
+ rhnChannel c
+ where c.id = s.channel_id
+ and c.label = :label""")
+ h.execute(label=options.channel_label)
+ source_urls = h.fetchall_dict() or []
+ if source_urls:
+ self.url = source_urls[0]['source_url']
+ else:
+ quit = True
+ self.error_msg("Channel has no URL associated")
+ else:
+ self.url = options.url
if not options.channel_label:
quit = True
self.error_msg("--channel must be specified")
@@ -77,7 +90,6 @@ class RepoSync:
sys.exit(1)
self.type = options.type
- self.url = options.url
self.channel_label = options.channel_label
self.fail = options.fail
self.repo_label = self.short_hash(self.url)
commit 20352bb092944acda965d156319d0d8e2c505ee4
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 16:44:10 2010 +0100
let yum be default type
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index 7946697..9f56155 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -61,9 +61,6 @@ class RepoSync:
if not options.url:
quit = True
self.error_msg("--url must be specified")
- if not options.type:
- quit = True
- self.error_msg("--type must be specified")
if not options.channel_label:
quit = True
self.error_msg("--channel must be specified")
@@ -99,7 +96,7 @@ class RepoSync:
self.parser = OptionParser()
self.parser.add_option('-u', '--url', action='store',
dest='url', help='The url to sync')
self.parser.add_option('-c', '--channel', action='store',
dest='channel_label', help='The label of the channel to sync packages
to')
- self.parser.add_option('-t', '--type', action='store',
dest='type', help='The type of repo, currently only "yum" is
supported')
+ self.parser.add_option('-t', '--type', action='store',
dest='type', help='The type of repo, currently only "yum" is
supported', default='yum')
self.parser.add_option('-l', '--label',
action='store_true', dest='label', help='Ignored; for compatibility
with old versions')
self.parser.add_option('-f', '--fail',
action='store_true', dest='fail', default=False , help="If a package
import fails, fail the entire operation")
self.parser.add_option('-q', '--quiet',
action='store_true', dest='quiet', default=False, help="Print no
output, still logs output")
commit 263e1e93e50b0bacd2d643517d39cad7aa285d3d
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 15:58:22 2010 +0100
generate repolabel according to url
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index 170ef15..7946697 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -26,6 +26,7 @@ from server.importlib.packageImport import ChannelPackageSubscription
default_log_location = '/var/log/rhn/reposync/'
+default_hash = 'sha256'
class RepoSync:
@@ -46,10 +47,10 @@ class RepoSync:
(options, args) = self.process_args()
log_filename = 'reposync.log'
- if options.channel_label and options.label:
+ if options.channel_label:
date = time.localtime()
datestr = '%d.%02d.%02d-%02d:%02d:%02d' % (date.tm_year, date.tm_mon,
date.tm_mday, date.tm_hour, date.tm_min, date.tm_sec)
- log_filename = options.channel_label + '-' + options.label +
'-' + datestr + '.log'
+ log_filename = options.channel_label + '-' + datestr +
'.log'
rhnLog.initLOG(default_log_location + log_filename)
#os.fchown isn't in 2.4 :/
@@ -67,8 +68,7 @@ class RepoSync:
quit = True
self.error_msg("--channel must be specified")
if not options.label:
- quit = True
- self.error_msg("--label must be specified")
+ self.error_msg("--label is obsoleted")
if options.mirror:
self.error_msg("--mirrorlist is obsoleted; mirrorlist is recognized
automatically")
@@ -83,7 +83,7 @@ class RepoSync:
self.url = options.url
self.channel_label = options.channel_label
self.fail = options.fail
- self.repo_label = options.label
+ self.repo_label = self.short_hash(self.url)
self.quiet = options.quiet
self.channel = self.load_channel()
@@ -100,7 +100,7 @@ class RepoSync:
self.parser.add_option('-u', '--url', action='store',
dest='url', help='The url to sync')
self.parser.add_option('-c', '--channel', action='store',
dest='channel_label', help='The label of the channel to sync packages
to')
self.parser.add_option('-t', '--type', action='store',
dest='type', help='The type of repo, currently only "yum" is
supported')
- self.parser.add_option('-l', '--label', action='store',
dest='label', help='A friendly label to refer to the repo')
+ self.parser.add_option('-l', '--label',
action='store_true', dest='label', help='Ignored; for compatibility
with old versions')
self.parser.add_option('-f', '--fail',
action='store_true', dest='fail', default=False , help="If a package
import fails, fail the entire operation")
self.parser.add_option('-q', '--quiet',
action='store_true', dest='quiet', default=False, help="Print no
output, still logs output")
self.parser.add_option('-m', '--mirrorlist',
action='store_true', dest='mirror', default=False, help="Ignored; for
compatibility with old versions. Mirrorlist is recognized automatically.")
@@ -218,6 +218,9 @@ class RepoSync:
def log_msg(self, message):
rhnLog.log_clean(0, message)
+ def short_hash(self, str):
+ return hashlib.new(default_hash, str).hexdigest()[0:8]
+
class ContentPackage:
def __init__(self):
commit ce953139d8004c2dad6560343e1471c5cfd850e1
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 15:40:20 2010 +0100
made --mirrorlist obsolete
diff --git a/backend/satellite_tools/repo_plugins/yum_src.py
b/backend/satellite_tools/repo_plugins/yum_src.py
index 1bcfe50..3e9db13 100644
--- a/backend/satellite_tools/repo_plugins/yum_src.py
+++ b/backend/satellite_tools/repo_plugins/yum_src.py
@@ -34,13 +34,11 @@ class ContentSource:
url = None
name = None
repo = None
- mirrorlist = False
cache_dir = '/var/cache/rhn/reposync/'
- def __init__(self, url, name, mirrorlist):
+ def __init__(self, url, name):
self.url = url
self.name = name
self._clean_cache(self.cache_dir + name)
- self.mirrorlist = mirrorlist
def list_packages(self):
""" list packages"""
diff --git a/backend/satellite_tools/reposync.py b/backend/satellite_tools/reposync.py
index e808bf5..170ef15 100644
--- a/backend/satellite_tools/reposync.py
+++ b/backend/satellite_tools/reposync.py
@@ -38,7 +38,6 @@ class RepoSync:
fail = False
repo_label = None
quiet = False
- mirrorlist = False
def main(self):
initCFG('server')
@@ -70,6 +69,8 @@ class RepoSync:
if not options.label:
quit = True
self.error_msg("--label must be specified")
+ if options.mirror:
+ self.error_msg("--mirrorlist is obsoleted; mirrorlist is recognized
automatically")
self.log_msg("\nSync started: %s" % (time.asctime(time.localtime())))
self.log_msg(str(sys.argv))
@@ -83,7 +84,6 @@ class RepoSync:
self.channel_label = options.channel_label
self.fail = options.fail
self.repo_label = options.label
- self.mirrorlist = options.mirror
self.quiet = options.quiet
self.channel = self.load_channel()
@@ -91,7 +91,7 @@ class RepoSync:
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.mirrorlist)
+ self.plugin = self.load_plugin()(self.url, self.channel_label + "-" +
self.repo_label)
self.import_packages(self.plugin.list_packages())
self.print_msg("Sync complete")
@@ -103,7 +103,7 @@ 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")
self.parser.add_option('-q', '--quiet',
action='store_true', dest='quiet', default=False, help="Print no
output, still logs output")
- self.parser.add_option('-m', '--mirrorlist',
action='store_true', dest='mirror', default=False, help="Treat --url
as a mirror list (may not be supported by all content sources)")
+ self.parser.add_option('-m', '--mirrorlist',
action='store_true', dest='mirror', default=False, help="Ignored; for
compatibility with old versions. Mirrorlist is recognized automatically.")
return self.parser.parse_args()
def load_plugin(self):
commit 6bc72ee3923f7eab68376dc62c030901d4db8675
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Fri Feb 19 15:14:23 2010 +0100
added heuristic to recognize whether url is mirrorlist or plain repo
diff --git a/backend/satellite_tools/repo_plugins/yum_src.py
b/backend/satellite_tools/repo_plugins/yum_src.py
index 3af0637..1bcfe50 100644
--- a/backend/satellite_tools/repo_plugins/yum_src.py
+++ b/backend/satellite_tools/repo_plugins/yum_src.py
@@ -18,6 +18,18 @@ import shutil
from yum import config
from satellite_tools.reposync import ContentPackage
+class UrlIsNotMirror(Exception):
+ pass
+
+class SpacewalkYumRepository(yum.yumRepo.YumRepository):
+ def _readMirrorList(self, fo, url=None):
+ retval = yum.yumRepo.YumRepository._readMirrorList(self, fo, url)
+ # passed repo url as mirrorlist
+ if (len(retval[0]) == len(retval[1])
+ and retval[1][0][0:2] == '<!'):
+ raise UrlIsNotMirror
+ return retval
+
class ContentSource:
url = None
name = None
@@ -32,15 +44,21 @@ class ContentSource:
def list_packages(self):
""" list packages"""
- repo = yum.yumRepo.YumRepository(self.name)
+ repo = SpacewalkYumRepository(self.name)
self.repo = repo
repo.cache = 0
repo.metadata_expire = 0
- if self.mirrorlist:
+ repo.basecachedir = self.cache_dir
+
+ try: # try if url is mirrorlist
repo.mirrorlist = self.url
- else:
+ repo.baseurlSetup()
+ except UrlIsNotMirror, e:
+ # well, not a mirrorlist, just plain repo
+ repo.mirrorlist = None
repo.baseurl = [self.url]
- repo.basecachedir = self.cache_dir
+ repo.baseurlSetup()
+
repo.baseurlSetup()
repo.setup(False)
sack = repo.getPackageSack()