euscanwww: management commands are validators aware

Management commands should create objects that don't raise
ValidationError

Signed-off-by: volpino <fox91@anche.no>
This commit is contained in:
volpino 2012-05-28 22:57:33 +02:00
parent b46e9acc08
commit fce8ef347b
3 changed files with 39 additions and 40 deletions

View File

@ -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

View File

@ -203,9 +203,10 @@ 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}
)
if not created:
obj.alive = True
obj.packaged = True
obj.save()
@ -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()

View File

@ -56,9 +56,10 @@ 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}
)
if not created:
obj.alive = True
obj.urls = url
obj.packaged = False
@ -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()