Patch to some of the python scripts in cobbler to do the following: 1. There was a bug in action_reposync.py:createrepo_walker that caused createrepo to be run on every subdirectory of the repository being synced. The core problem was fnames = [] which creates a new list instead of del fnames [:] which modifies the list in place. 2. Added a new parameter to repos (--createrepo-flags) to be used for passing useful flags like "-c cache -C -g repodata/comps.xml" when createrepo is called. This touched a few of the python scripts. 3. Modified createrepo in action_import to use the -c cache flag so that future syncs using this repo don't have to regenerate everything. Please let me know if you have any comments on any of the above changes. Signed-off-by: Perry Myers (pmyers@xxxxxxxxxx) Thanks, Perry -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 703 362 9622 -=| diff -Naur cobbler/cobbler/action_import.py cobbler-mod/cobbler/action_import.py --- cobbler/cobbler/action_import.py 2007-06-06 16:33:33.000000000 -0400 +++ cobbler-mod/cobbler/action_import.py 2007-06-07 09:36:02.000000000 -0400 @@ -339,7 +339,7 @@ if not self.processed_repos.has_key(comps_path): utils.remove_yum_olddata(comps_path) #cmd = "createrepo --basedir / --groupfile %s %s" % (os.path.join(comps_path, masterdir, comps_file), comps_path) - cmd = "createrepo --groupfile %s %s" % (os.path.join(comps_path, masterdir, comps_file), comps_path) + cmd = "createrepo -c cache --groupfile %s %s" % (os.path.join(comps_path, masterdir, comps_file), comps_path) print _("- %s") % cmd sub_process.call(cmd,shell=True) self.processed_repos[comps_path] = 1 diff -Naur cobbler/cobbler/action_reposync.py cobbler-mod/cobbler/action_reposync.py --- cobbler/cobbler/action_reposync.py 2007-06-06 16:33:33.000000000 -0400 +++ cobbler-mod/cobbler/action_reposync.py 2007-06-07 09:43:40.000000000 -0400 @@ -45,7 +45,7 @@ self.systems = config.systems() self.settings = config.settings() self.repos = config.repos() - + # ================================================================================== def run(self,verbose=True): @@ -59,13 +59,11 @@ mirror = repo.mirror if not os.path.isdir(repo_path) and not repo.mirror.lower().startswith("rhn://"): os.makedirs(repo_path) - # if path contains http:// or ftp://, use with yum's reposync. - # else do rsync - lower = mirror.lower() - if lower.startswith("http://") or lower.startswith("ftp://") or lower.startswith("rhn://"): - self.do_reposync(repo) - else: + + if repo.is_rsync_mirror(): self.do_rsync(repo) + else: + self.do_reposync(repo) return True @@ -178,8 +176,7 @@ # now run createrepo to rebuild the index - arg = None - os.path.walk(dest_path, self.createrepo_walker, arg) + os.path.walk(dest_path, self.createrepo_walker, repo) # create the config file the hosts will use to access the repository. @@ -210,9 +207,8 @@ rc = sub_process.call(cmd, shell=True) if rc !=0: raise CX(_("cobbler reposync failed")) - arg = {} print _("- walking: %s") % dest_path - os.path.walk(dest_path, self.createrepo_walker, arg) + os.path.walk(dest_path, self.createrepo_walker, repo) self.create_local_file(repo, dest_path) # ================================================================================== @@ -243,19 +239,19 @@ # ================================================================================== - def createrepo_walker(self, arg, dirname, fname): + def createrepo_walker(self, repo, dirname, fnames): """ Used to run createrepo on a copied mirror. """ target_dir = os.path.dirname(dirname).split("/")[-1] - print _("- scanning: %s") % target_dir - if target_dir.lower() in [ "i386", "x86_64", "ia64" ] or (arg is None): + if target_dir.lower() in [ "i386", "x86_64", "ia64" ] or not repo.is_rsync_mirror(): utils.remove_yum_olddata(dirname) try: - cmd = "createrepo %s" % dirname + cmd = "createrepo %s %s" % (repo.createrepo_flags, dirname) print _("- %s") % cmd sub_process.call(cmd, shell=True) except: print _("- createrepo failed. Is it installed?") - fnames = [] # we're in the right place + del fnames[:] # we're in the right place + diff -Naur cobbler/cobbler/cobbler.py cobbler-mod/cobbler/cobbler.py --- cobbler/cobbler/cobbler.py 2007-06-06 16:33:33.000000000 -0400 +++ cobbler-mod/cobbler/cobbler.py 2007-06-07 09:36:02.000000000 -0400 @@ -432,7 +432,8 @@ '--mirror' : lambda(a): repo.set_mirror(a), '--keep-updated' : lambda(a): repo.set_keep_updated(a), '--local-filename' : lambda(a): repo.set_local_filename(a), - '--rpm-list' : lambda(a): repo.set_rpm_list(a) + '--rpm-list' : lambda(a): repo.set_rpm_list(a), + '--createrepo-flags' : lambda(a): repo.set_createrepo_flags(a), } def on_ok(): if newname is not None: diff -Naur cobbler/cobbler/item_repo.py cobbler-mod/cobbler/item_repo.py --- cobbler/cobbler/item_repo.py 2007-06-06 16:33:33.000000000 -0400 +++ cobbler-mod/cobbler/item_repo.py 2007-06-07 09:36:02.000000000 -0400 @@ -30,14 +30,16 @@ self.mirror = None # is required self.keep_updated = 1 # has reasonable defaults self.local_filename = "" # off by default - self.rpm_list = "" # just get selected RPMs + deps + self.rpm_list = "" # just get selected RPMs + deps + self.createrepo_flags = "" # none by default def from_datastruct(self,seed_data): - self.name = self.load_item(seed_data, 'name') - self.mirror = self.load_item(seed_data, 'mirror') - self.keep_updated = self.load_item(seed_data, 'keep_updated') - self.local_filename = self.load_item(seed_data, 'local_filename') - self.rpm_list = self.load_item(seed_data, 'rpm_list') + self.name = self.load_item(seed_data, 'name') + self.mirror = self.load_item(seed_data, 'mirror') + self.keep_updated = self.load_item(seed_data, 'keep_updated') + self.local_filename = self.load_item(seed_data, 'local_filename') + self.rpm_list = self.load_item(seed_data, 'rpm_list') + self.createrepo_flags = self.load_item(seed_data, 'createrepo_flags') return self def set_name(self,name): @@ -98,6 +100,14 @@ pass self.rpm_list = rpmlist + def set_createrepo_flags(self,createrepo_flags): + """ + Flags passed to createrepo when it is called. Common flags to use would be + -c cache or -g comps.xml to generate group information. + """ + self.createrepo_flags = createrepo_flags + return True + def is_valid(self): """ A repo is valid if it has a name and a mirror URL @@ -110,18 +120,30 @@ def to_datastruct(self): return { - 'name' : self.name, - 'mirror' : self.mirror, - 'keep_updated' : self.keep_updated, - 'local_filename' : self.local_filename, - 'rpm_list' : self.rpm_list + 'name' : self.name, + 'mirror' : self.mirror, + 'keep_updated' : self.keep_updated, + 'local_filename' : self.local_filename, + 'rpm_list' : self.rpm_list, + 'createrepo_flags' : self.createrepo_flags } def printable(self): - buf = _("repo : %s\n") % self.name - buf = buf + _("mirror : %s\n") % self.mirror - buf = buf + _("keep updated : %s\n") % self.keep_updated - buf = buf + _("local filename : %s\n") % self.local_filename - buf = buf + _("rpm list : %s\n") % self.rpm_list + buf = _("repo : %s\n") % self.name + buf = buf + _("mirror : %s\n") % self.mirror + buf = buf + _("keep updated : %s\n") % self.keep_updated + buf = buf + _("local filename : %s\n") % self.local_filename + buf = buf + _("rpm list : %s\n") % self.rpm_list + buf = buf + _("createrepo_flags : %s\n") % self.createrepo_flags return buf + def is_rsync_mirror(self): + """ + Returns True if this mirror is synchronized using rsync, False otherwise + """ + lower = self.mirror.lower() + if lower.startswith("http://") or lower.startswith("ftp://") or lower.startswith("rhn://"): + return False + else: + return True +