2011-04-13 19:00:31 +02:00
|
|
|
import subprocess
|
|
|
|
import portage
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
|
|
|
from portage import versions
|
|
|
|
from optparse import make_option
|
|
|
|
|
|
|
|
from django.db.transaction import commit_on_success
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
from euscanwww.euscan.models import Package, Herd, Maintainer
|
|
|
|
|
|
|
|
from gentoolkit.query import Query
|
2011-04-14 08:52:26 +02:00
|
|
|
from gentoolkit.errors import GentoolkitFatalError
|
2011-04-13 19:00:31 +02:00
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
_overlays = {}
|
|
|
|
|
|
|
|
option_list = BaseCommand.option_list + (
|
|
|
|
make_option('--all',
|
|
|
|
action='store_true',
|
|
|
|
dest='all',
|
|
|
|
default=False,
|
|
|
|
help='Scan all packages'),
|
|
|
|
make_option('--quiet',
|
|
|
|
action='store_true',
|
|
|
|
dest='quiet',
|
|
|
|
default=False,
|
|
|
|
help='Be quiet'),
|
|
|
|
)
|
|
|
|
args = '<package package ...>'
|
|
|
|
help = 'Scans metadata and fills database'
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
if len(args) == 0 and options['all'] == False:
|
|
|
|
raise CommandError('You must specify a package or use --all')
|
|
|
|
|
|
|
|
if len(args) == 0:
|
|
|
|
for pkg in Package.objects.all():
|
|
|
|
self.scan(options, '%s/%s' % (pkg.category, pkg.name))
|
|
|
|
else:
|
|
|
|
for package in args:
|
|
|
|
self.scan(options, package)
|
|
|
|
|
|
|
|
@commit_on_success
|
|
|
|
def scan(self, options, query=None):
|
|
|
|
matches = Query(query).find(
|
|
|
|
include_masked=True,
|
2011-08-25 15:39:54 +02:00
|
|
|
in_installed=False,
|
2011-04-13 19:00:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
if not matches:
|
|
|
|
sys.stderr.write(self.style.ERROR("Unknown package '%s'\n" % query))
|
|
|
|
return
|
|
|
|
|
|
|
|
matches = sorted(matches)
|
|
|
|
pkg = matches.pop()
|
2011-04-25 22:27:32 +02:00
|
|
|
if '9999' in pkg.version and len(matches):
|
2011-04-13 19:00:31 +02:00
|
|
|
pkg = matches.pop()
|
|
|
|
|
|
|
|
obj, created = Package.objects.get_or_create(category=pkg.category, name=pkg.name)
|
|
|
|
|
2011-04-14 08:52:26 +02:00
|
|
|
try:
|
|
|
|
obj.homepage = pkg.environment("HOMEPAGE")
|
|
|
|
obj.description = pkg.environment("DESCRIPTION")
|
|
|
|
except GentoolkitFatalError, err:
|
|
|
|
sys.stderr.write(self.style.ERROR("Gentoolkit fatal error: '%s'\n" % str(err)))
|
2011-04-13 19:00:31 +02:00
|
|
|
|
2011-08-25 15:39:54 +02:00
|
|
|
if created and not options['quiet']:
|
|
|
|
sys.stdout.write('+ [p] %s/%s\n' % (pkg.category, pkg.name))
|
2011-04-14 08:52:26 +02:00
|
|
|
if pkg.metadata:
|
2011-04-15 19:28:37 +02:00
|
|
|
obj.herds.clear()
|
|
|
|
obj.maintainers.clear()
|
|
|
|
|
2011-04-14 08:52:26 +02:00
|
|
|
for herd in pkg.metadata.herds(True):
|
|
|
|
herd = self.store_herd(options, herd[0], herd[1])
|
|
|
|
obj.herds.add(herd)
|
2011-04-13 19:00:31 +02:00
|
|
|
|
2011-04-14 08:52:26 +02:00
|
|
|
for maintainer in pkg.metadata.maintainers():
|
|
|
|
maintainer = self.store_maintainer(options, maintainer.name, maintainer.email)
|
|
|
|
obj.maintainers.add(maintainer)
|
2011-04-13 19:00:31 +02:00
|
|
|
|
|
|
|
obj.save()
|
|
|
|
|
|
|
|
def store_herd(self, options, name, email):
|
2011-04-15 19:28:37 +02:00
|
|
|
if not name:
|
|
|
|
name = '{nil}'
|
|
|
|
name = name.strip("\r").strip("\n").strip("\t").strip()
|
|
|
|
|
2011-04-13 19:00:31 +02:00
|
|
|
herd, created = Herd.objects.get_or_create(herd=name)
|
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
if created and not options['quiet']:
|
|
|
|
sys.stdout.write('+ [h] %s <%s>\n' % (name, email))
|
2011-04-13 19:00:31 +02:00
|
|
|
|
2011-08-31 15:38:32 +02:00
|
|
|
herd.email = email
|
|
|
|
herd.save()
|
2011-04-13 19:00:31 +02:00
|
|
|
|
|
|
|
return herd
|
|
|
|
|
|
|
|
def store_maintainer(self, options, name, email):
|
|
|
|
if not name:
|
|
|
|
name = email
|
2011-04-15 19:28:37 +02:00
|
|
|
if not name:
|
|
|
|
name = '{nil}'
|
2011-04-13 19:00:31 +02:00
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
maintainer, created = Maintainer.objects.get_or_create(email=email)
|
2011-04-13 19:00:31 +02:00
|
|
|
|
|
|
|
if created:
|
|
|
|
if not options['quiet']:
|
2011-08-25 15:39:54 +02:00
|
|
|
sys.stdout.write('+ [m] %s <%s>\n' % (name.encode('utf-8'), email))
|
2011-04-13 19:00:31 +02:00
|
|
|
|
2011-04-15 19:28:37 +02:00
|
|
|
maintainer.name = name
|
2011-04-13 19:00:31 +02:00
|
|
|
maintainer.save()
|
|
|
|
|
|
|
|
return maintainer
|