euscanwww: add --category to scan_metadata, remove homepage and description
Signed-off-by: Corentin Chary <corentin.chary@gmail.com>
This commit is contained in:
parent
0e32ccf46e
commit
ba805536ad
@ -19,6 +19,11 @@ class Command(BaseCommand):
|
||||
dest='all',
|
||||
default=False,
|
||||
help='Scan all packages'),
|
||||
make_option('--category',
|
||||
action='store',
|
||||
dest='category',
|
||||
default=None,
|
||||
help='Scan only this category'),
|
||||
)
|
||||
args = '<package package ...>'
|
||||
help = 'Scans metadata and fills database'
|
||||
@ -26,7 +31,7 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
set_verbosity_level(logger, options.get("verbosity", 1))
|
||||
|
||||
if options['all']:
|
||||
if options['all'] or options['category']:
|
||||
packages = None
|
||||
|
||||
elif len(args):
|
||||
@ -34,4 +39,8 @@ class Command(BaseCommand):
|
||||
else:
|
||||
packages = [pkg[:-1] for pkg in sys.stdin.readlines()]
|
||||
|
||||
scan_metadata(packages=packages, logger=logger)
|
||||
scan_metadata(
|
||||
packages=packages,
|
||||
category=options['category'],
|
||||
logger=logger
|
||||
)
|
||||
|
@ -1,3 +1,5 @@
|
||||
import os.path
|
||||
|
||||
from gentoolkit.query import Query
|
||||
from gentoolkit.errors import GentoolkitFatalError
|
||||
|
||||
@ -8,17 +10,19 @@ from django.core.exceptions import ValidationError
|
||||
from djeuscan.models import Package, Herd, Maintainer
|
||||
from djeuscan.processing import FakeLogger
|
||||
|
||||
|
||||
class ScanMetadata(object):
|
||||
def __init__(self, logger=None):
|
||||
self.style = color_style()
|
||||
self.logger = logger or FakeLogger()
|
||||
|
||||
@commit_on_success
|
||||
def scan(self, query=None, obj=None):
|
||||
matches = Query(query).find(
|
||||
matches = Query(query).smart_find(
|
||||
in_installed=True,
|
||||
in_porttree=True,
|
||||
in_overlay=True,
|
||||
include_masked=True,
|
||||
in_installed=False,
|
||||
show_progress=False,
|
||||
no_matches_fatal=False,
|
||||
)
|
||||
|
||||
if not matches:
|
||||
@ -39,20 +43,12 @@ class ScanMetadata(object):
|
||||
else:
|
||||
created = False
|
||||
|
||||
try:
|
||||
obj.homepage = pkg.environment("HOMEPAGE")
|
||||
obj.description = pkg.environment("DESCRIPTION")
|
||||
except GentoolkitFatalError, err:
|
||||
self.logger.error(
|
||||
self.style.ERROR(
|
||||
"Gentoolkit fatal error: '%s'" % str(err)
|
||||
)
|
||||
)
|
||||
|
||||
if created:
|
||||
self.logger.info('+ [p] %s/%s' % (pkg.category, pkg.name))
|
||||
|
||||
if pkg.metadata:
|
||||
if not pkg.metadata:
|
||||
return
|
||||
|
||||
herds = dict(
|
||||
[(herd[0], herd) for herd in pkg.metadata.herds(True)]
|
||||
)
|
||||
@ -65,12 +61,8 @@ class ScanMetadata(object):
|
||||
old_herds = set(existing_herds).difference(herds.keys())
|
||||
|
||||
existing_maintainers = [m.email for m in obj.maintainers.all()]
|
||||
new_maintainers = set(
|
||||
maintainers.keys()).difference(existing_maintainers
|
||||
)
|
||||
old_maintainers = set(
|
||||
existing_maintainers).difference(maintainers.keys()
|
||||
)
|
||||
new_maintainers = set(maintainers.keys()).difference(existing_maintainers)
|
||||
old_maintainers = set(existing_maintainers).difference(maintainers.keys())
|
||||
|
||||
for herd in obj.herds.all():
|
||||
if herd.herd in old_herds:
|
||||
@ -97,7 +89,6 @@ class ScanMetadata(object):
|
||||
(maintainer.name, maintainer.email))
|
||||
)
|
||||
obj.save()
|
||||
return True
|
||||
|
||||
def store_herd(self, name, email):
|
||||
if not name:
|
||||
@ -134,15 +125,18 @@ class ScanMetadata(object):
|
||||
)
|
||||
return maintainer
|
||||
|
||||
|
||||
def scan_metadata(packages=None, logger=None):
|
||||
@commit_on_success
|
||||
def scan_metadata(packages=None, category=None, logger=None):
|
||||
scan_handler = ScanMetadata(logger=logger)
|
||||
if not packages:
|
||||
|
||||
if category:
|
||||
packages = Package.objects.filter(category=category)
|
||||
elif not packages:
|
||||
packages = Package.objects.all()
|
||||
|
||||
for pkg in packages:
|
||||
if isinstance(pkg, Package):
|
||||
result = scan_handler.scan('%s/%s' % (pkg.category, pkg.name), pkg)
|
||||
scan_handler.scan('%s/%s' % (pkg.category, pkg.name), pkg)
|
||||
else:
|
||||
result = scan_handler.scan(pkg)
|
||||
return result
|
||||
scan_handler.scan(pkg)
|
||||
|
||||
|
@ -302,4 +302,4 @@ def scan_portage(packages=None, category=None, no_log=False, purge_packages=Fals
|
||||
scan_handler.scan(pkg)
|
||||
|
||||
logger.info('Done.')
|
||||
return True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user