From 8ec2e404514770cce407a34b8149097d51192a40 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 16 Apr 2010 20:02:22 -0500 Subject: reporead: allow removal of last package in an arch We had a situation where the last 'any' architecture package was present in the [testing] repo and never got removed because we never did the db_update() call on that architecture. Instead of looping all possible architectures and only calling if len() > 0, always call db_update() for both the primary architecture and the 'any' architecture. Signed-off-by: Dan McGee --- devel/management/commands/reporead.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py index 32e7929e..777bc5dd 100644 --- a/devel/management/commands/reporead.py +++ b/devel/management/commands/reporead.py @@ -188,7 +188,7 @@ def populate_files(dbpkg, repopkg, force=False): dbpkg.files_last_update = datetime.now() dbpkg.save() -def db_update(archname, pkgs, options): +def db_update(archname, reponame, pkgs, options): """ Parses a list and updates the Arch dev database accordingly. @@ -199,7 +199,7 @@ def db_update(archname, pkgs, options): logger.info('Updating Arch: %s' % archname) force = options.get('force', False) filesonly = options.get('filesonly', False) - repository = Repo.objects.get(name__iexact=pkgs[0].repo) + repository = Repo.objects.get(name__iexact=reponame) architecture = Arch.objects.get(name__iexact=archname) dbpkgs = Package.objects.filter(arch=architecture, repo=repository) # It makes sense to fully evaluate our DB query now because we will @@ -362,7 +362,7 @@ def parse_repo(repopath): tpkg.write('\n') # just in case repodb.close() logger.info("Finished repo parsing") - return pkgs + return (reponame, pkgs) def validate_arch(arch): "Check if arch is valid." @@ -374,25 +374,23 @@ def read_repo(primary_arch, file, options): """ Parses repo.db.tar.gz file and returns exit status. """ - packages = parse_repo(file) + repo, packages = parse_repo(file) # sort packages by arch -- to handle noarch stuff packages_arches = {} - available_arches = [x.name for x in Arch.objects.all()] - for arch in available_arches: - packages_arches[arch] = [] + packages_arches['any'] = [] + packages_arches[primary_arch] = [] for package in packages: if package.arch in ('any', primary_arch): packages_arches[package.arch].append(package) else: + # we don't include mis-arched packages logger.warning("Package %s arch = %s" % ( package.name,package.arch)) - #package.arch = primary_arch logger.info('Starting database updates.') for (arch, pkgs) in packages_arches.items(): - if len(pkgs) > 0: - db_update(arch, pkgs, options) + db_update(arch, repo, pkgs, options) logger.info('Finished database updates.') return 0 -- cgit v1.2.3-54-g00ecf