summaryrefslogtreecommitdiffstats
path: root/devel
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-02-11 05:07:21 +0100
committerDan McGee <dan@archlinux.org>2010-02-11 05:07:21 +0100
commit20767c7bab4d96bdd31fae4ced293d17c162fc2d (patch)
tree15f1789440aa2b89ff1efb65627e7fdb647d1000 /devel
parentc1697ab694fe549d7b6ff81a00737a2ad63e9461 (diff)
downloadarchweb-20767c7bab4d96bdd31fae4ced293d17c162fc2d.tar.gz
archweb-20767c7bab4d96bdd31fae4ced293d17c162fc2d.tar.xz
reporead: small touchups, mostly in argument validation
Check the arch, check the filename for existence, etc. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'devel')
-rwxr-xr-xdevel/management/commands/reporead.py53
1 files changed, 30 insertions, 23 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index b53e259..1906a44 100755
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -21,7 +21,7 @@ REPOVARS = ['arch', 'backup', 'base', 'builddate', 'conflicts', 'csize',
'replaces', 'size', 'url', 'version']
-from django.core.management.base import BaseCommand
+from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from django.db import models, transaction
from django.core import management
@@ -35,7 +35,7 @@ from datetime import datetime
from optparse import make_option
from cStringIO import StringIO
-from logging import WARNING,INFO,DEBUG
+from logging import ERROR, WARNING, INFO, DEBUG
from main.models import Arch, Package, Repo
@@ -53,14 +53,29 @@ logger = logging.getLogger()
class Command(BaseCommand):
option_list = BaseCommand.option_list
+ help = "Runs a package repository import for the given arch and file."
+ args = "<arch> <filename>"
def handle(self, arch=None, file=None, **options):
- logger.level = INFO
- if arch == None or file == None:
- usage()
- return 0
+ if not arch:
+ raise CommandError('Architecture is required.')
+ if not validate_arch(arch):
+ raise CommandError('Specified architecture %s is not currently known.' % arch)
+ if not file:
+ raise CommandError('Package database file is required.')
file = os.path.normpath(file)
- read_repo(arch, file)
+ if not os.path.exists(file) or not os.path.isfile(file):
+ raise CommandError('Specified package database file does not exist.')
+
+ v = int(options.get('verbosity', 0))
+ if v == 0:
+ logger.level = ERROR
+ elif v == 1:
+ logger.level = INFO
+ elif v == 2:
+ logger.level = DEBUG
+
+ return read_repo(arch, file)
class Pkg(object):
@@ -114,11 +129,6 @@ class Pkg(object):
return None
-def usage():
- """Print the usage of this application."""
- print __doc__.strip()
-
-
def populate_pkg(dbpkg, repopkg, timestamp=None):
if not timestamp: timestamp = datetime.now()
dbpkg.pkgbase = repopkg.base
@@ -300,23 +310,21 @@ def parse_repo(repopath):
logger.info("Finished repo parsing")
return pkgs
+def validate_arch(arch):
+ "Check if arch is valid."
+ available_arches = [x.name for x in Arch.objects.all()]
+ return arch in available_arches
+
@transaction.commit_on_success
-def read_repo(arch, file):
+def read_repo(primary_arch, file):
"""
Parses repo.db.tar.gz file and returns exit status.
"""
- # check if arch is valid
- available_arches = [x.name for x in Arch.objects.all()]
- if arch not in available_arches:
- usage()
- return 0
- else:
- primary_arch = arch
-
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] = []
@@ -328,9 +336,8 @@ def read_repo(arch, file):
package.name,package.arch))
#package.arch = primary_arch
-
logger.info('Starting database updates.')
- for (arch, pkgs) in packages_arches.iteritems():
+ for (arch, pkgs) in packages_arches.items():
if len(pkgs) > 0:
db_update(arch,pkgs)
logger.info('Finished database updates.')