euscanwww: add --purge to scan-portage
Signed-off-by: Corentin Chary <corentincj@iksaif.net>
This commit is contained in:
parent
244e7d64fd
commit
120ae425af
@ -20,6 +20,11 @@ class Command(BaseCommand):
|
|||||||
dest='all',
|
dest='all',
|
||||||
default=False,
|
default=False,
|
||||||
help='Scan all packages'),
|
help='Scan all packages'),
|
||||||
|
make_option('--purge',
|
||||||
|
action='store_true',
|
||||||
|
dest='purge',
|
||||||
|
default=False,
|
||||||
|
help='Purge old packages'),
|
||||||
make_option('--quiet',
|
make_option('--quiet',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='quiet',
|
dest='quiet',
|
||||||
@ -36,11 +41,11 @@ class Command(BaseCommand):
|
|||||||
if not options['quiet']:
|
if not options['quiet']:
|
||||||
self.stdout.write('Scanning portage tree...\n')
|
self.stdout.write('Scanning portage tree...\n')
|
||||||
|
|
||||||
for package in args:
|
|
||||||
self.scan(options, package)
|
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
self.scan(options)
|
self.scan(options)
|
||||||
|
else:
|
||||||
|
for package in args:
|
||||||
|
self.scan(options, package)
|
||||||
|
|
||||||
if not options['quiet']:
|
if not options['quiet']:
|
||||||
self.stdout.write('Done.\n')
|
self.stdout.write('Done.\n')
|
||||||
@ -83,11 +88,22 @@ class Command(BaseCommand):
|
|||||||
output = output.strip().strip('\n')
|
output = output.strip().strip('\n')
|
||||||
|
|
||||||
if len(output) == 0:
|
if len(output) == 0:
|
||||||
if package:
|
if not query:
|
||||||
sys.stderr.write(self.style.ERROR("Unknown package '%s'\n" % package))
|
return
|
||||||
|
if options['purge']:
|
||||||
|
if not options['quiet']:
|
||||||
|
sys.stdout.write('[gc] %s\n' % (query))
|
||||||
|
if '/' in query:
|
||||||
|
cat, pkg = portage.catsplit(query)
|
||||||
|
Package.objects.filter(category=cat, name=pkg).delete()
|
||||||
|
else:
|
||||||
|
Package.objects.filter(name=query).delete()
|
||||||
|
else:
|
||||||
|
sys.stderr.write(self.style.ERROR("Unknown package '%s'\n" % query))
|
||||||
return
|
return
|
||||||
|
|
||||||
output = output.split('\n')
|
output = output.split('\n')
|
||||||
|
packages = {}
|
||||||
|
|
||||||
line_re = re.compile(r'^(?P<cpv>.*?):(?P<slot>.*?) \[(?P<overlay>.*?)\]$')
|
line_re = re.compile(r'^(?P<cpv>.*?):(?P<slot>.*?) \[(?P<overlay>.*?)\]$')
|
||||||
|
|
||||||
@ -105,11 +121,21 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
cat, pkg, ver, rev = portage.catpkgsplit(cpv)
|
cat, pkg, ver, rev = portage.catpkgsplit(cpv)
|
||||||
|
|
||||||
|
packages['%s/%s' % (cat, pkg)] = True
|
||||||
|
continue
|
||||||
if not package or not (cat == package.category and pkg == package.name):
|
if not package or not (cat == package.category and pkg == package.name):
|
||||||
package = self.store_package(options, cat, pkg)
|
package = self.store_package(options, cat, pkg)
|
||||||
|
|
||||||
self.store_version(options, package, cpv, slot, overlay)
|
self.store_version(options, package, cpv, slot, overlay)
|
||||||
|
|
||||||
|
if options['purge'] and not query:
|
||||||
|
for package in Package.objects.all():
|
||||||
|
cp = "%s/%s" % (package.category, package.name)
|
||||||
|
if cp not in packages:
|
||||||
|
if not options['quiet']:
|
||||||
|
sys.stdout.write('[gc] %s\n' % (cp))
|
||||||
|
package.delete()
|
||||||
|
|
||||||
def store_package(self, options, cat, pkg):
|
def store_package(self, options, cat, pkg):
|
||||||
obj, created = Package.objects.get_or_create(category=cat, name=pkg)
|
obj, created = Package.objects.get_or_create(category=cat, name=pkg)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user