From fce8ef347b9b6c10669bce43d22bfc23d2609a9a Mon Sep 17 00:00:00 2001 From: volpino Date: Mon, 28 May 2012 22:57:33 +0200 Subject: [PATCH] euscanwww: management commands are validators aware Management commands should create objects that don't raise ValidationError Signed-off-by: volpino --- .../management/commands/scan_metadata.py | 16 ++++---- .../management/commands/scan_portage.py | 24 ++++++------ .../management/commands/scan_upstream.py | 39 +++++++++---------- 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/euscanwww/djeuscan/management/commands/scan_metadata.py b/euscanwww/djeuscan/management/commands/scan_metadata.py index 153a18e..c8e926a 100644 --- a/euscanwww/djeuscan/management/commands/scan_metadata.py +++ b/euscanwww/djeuscan/management/commands/scan_metadata.py @@ -100,7 +100,10 @@ class ScanMetadata(object): name = '{nil}' name = name.strip("\r").strip("\n").strip("\t").strip() - herd, created = Herd.objects.get_or_create(herd=name) + herd, created = Herd.objects.get_or_create( + herd=name, + defaults={"email": email} + ) if created and not self.quiet: sys.stdout.write('+ [h] %s <%s>\n' % (name, email)) @@ -116,19 +119,16 @@ class ScanMetadata(object): if not name: name = '{nil}' - maintainer, created = Maintainer.objects.get_or_create(email=email) + maintainer, created = Maintainer.objects.get_or_create( + email=email, + defaults={"name": name} + ) if created: if not self.quiet: sys.stdout.write( '+ [m] %s <%s>\n' % (name.encode('utf-8'), email) ) - - if not maintainer.name or \ - name not in [maintainer.name, email, '{nil}']: - maintainer.name = name - maintainer.save() - return maintainer diff --git a/euscanwww/djeuscan/management/commands/scan_portage.py b/euscanwww/djeuscan/management/commands/scan_portage.py index e38f081..58997ad 100644 --- a/euscanwww/djeuscan/management/commands/scan_portage.py +++ b/euscanwww/djeuscan/management/commands/scan_portage.py @@ -203,12 +203,13 @@ class ScanPortage(object): obj, created = Version.objects.get_or_create( package=package, slot=slot, revision=rev, version=ver, - overlay=overlay + overlay=overlay, + defaults={"alive": True, "packaged": True} ) - - obj.alive = True - obj.packaged = True - obj.save() + if not created: + obj.alive = True + obj.packaged = True + obj.save() if created: self.cache_store_version(obj) @@ -258,15 +259,14 @@ def purge_versions(options): if options['no-log']: continue - entry = VersionLog.objects.create( + VersionLog.objects.create( package=version.package, - action=VersionLog.VERSION_REMOVED + action=VersionLog.VERSION_REMOVED, + slot=version.slot, + revision=version.revision, + version=version.version, + overlay=version.overlay ) - entry.slot = version.slot - entry.revision = version.revision - entry.version = version.version - entry.overlay = version.overlay - entry.save() Version.objects.filter(packaged=True, alive=False).delete() diff --git a/euscanwww/djeuscan/management/commands/scan_upstream.py b/euscanwww/djeuscan/management/commands/scan_upstream.py index 6dbdcfd..f6e78c3 100644 --- a/euscanwww/djeuscan/management/commands/scan_upstream.py +++ b/euscanwww/djeuscan/management/commands/scan_upstream.py @@ -56,13 +56,14 @@ class ScanUpstream(object): def store_version(self, package, ver, url): obj, created = Version.objects.get_or_create( - package=package, slot='', revision='r0', version=ver, overlay='' + package=package, slot='', revision='r0', version=ver, overlay='', + defaults={"alive": True, "urls": url, "packaged": True} ) - - obj.alive = True - obj.urls = url - obj.packaged = False - obj.save() + if not created: + obj.alive = True + obj.urls = url + obj.packaged = False + obj.save() # If it's not a new version, just update the object and continue if not created: @@ -71,15 +72,14 @@ class ScanUpstream(object): if not self.options['quiet']: sys.stdout.write('+ [u] %s %s\n' % (obj, url)) - entry = VersionLog.objects.create( + VersionLog.objects.create( package=package, - action=VersionLog.VERSION_ADDED + action=VersionLog.VERSION_ADDED, + slot='', + revision='r0', + version=ver, + overlay='' ) - entry.slot = '' - entry.revision = 'r0' - entry.version = ver - entry.overlay = '' - entry.save() package.n_versions += 1 package.save() @@ -128,15 +128,14 @@ class ScanUpstream(object): def purge_versions(options): # For each dead versions for version in Version.objects.filter(packaged=False, alive=False): - entry = VersionLog.objects.create( + VersionLog.objects.create( package=version.package, - action=VersionLog.VERSION_REMOVED + action=VersionLog.VERSION_REMOVED, + slot=version.slot, + revision=version.revision, + version=version.version, + overlay=version.overlay ) - entry.slot = version.slot - entry.revision = version.revision - entry.version = version.version - entry.overlay = version.overlay - entry.save() version.package.n_versions -= 1 version.package.save()