2012-06-04 11:06:47 +02:00
|
|
|
import subprocess
|
|
|
|
from StringIO import StringIO
|
|
|
|
|
2012-05-30 22:54:55 +02:00
|
|
|
from celery.task import task
|
|
|
|
from celery.task.sets import TaskSet
|
|
|
|
|
2012-06-04 11:06:47 +02:00
|
|
|
from django.conf import settings
|
2012-05-30 22:54:55 +02:00
|
|
|
|
2012-06-04 11:06:47 +02:00
|
|
|
from djeuscan.models import Package
|
2012-05-30 22:54:55 +02:00
|
|
|
from djeuscan.management.commands.regen_rrds import regen_rrds
|
|
|
|
from djeuscan.management.commands.update_counters import update_counters
|
|
|
|
from djeuscan.management.commands.scan_metadata import ScanMetadata
|
|
|
|
from djeuscan.management.commands.scan_portage import ScanPortage, \
|
|
|
|
purge_versions as scan_portage_purge
|
|
|
|
from djeuscan.management.commands.scan_upstream import ScanUpstream, \
|
|
|
|
purge_versions as scan_upstream_purge
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def regen_rrds_task():
|
|
|
|
regen_rrds()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def update_counters_task():
|
|
|
|
update_counters()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_metadata_task(query, obj=None):
|
2012-05-31 09:11:40 +02:00
|
|
|
logger = scan_metadata_task.get_logger()
|
|
|
|
logger.info("Starting metadata scanning for package %s ...", query)
|
|
|
|
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_metadata = ScanMetadata()
|
2012-06-03 09:43:49 +02:00
|
|
|
scan_metadata.scan(query, obj)
|
2012-05-30 22:54:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_metadata_all_task():
|
|
|
|
job = TaskSet(tasks=[
|
|
|
|
scan_metadata_task.subtask(('%s/%s' % (pkg.category, pkg.name), pkg))
|
|
|
|
for pkg in Package.objects.all()
|
|
|
|
])
|
|
|
|
job.apply_async()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_portage_all_task(purge=False):
|
2012-05-31 09:11:40 +02:00
|
|
|
logger = scan_portage_all_task.get_logger()
|
|
|
|
logger.info("Starting Portage scanning...")
|
|
|
|
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_portage = ScanPortage()
|
|
|
|
scan_portage.scan()
|
|
|
|
|
|
|
|
if purge:
|
2012-05-31 09:11:40 +02:00
|
|
|
logger.info("Purging")
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_portage_purge()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_portage_task(query, purge=False):
|
2012-05-31 09:11:40 +02:00
|
|
|
logger = scan_portage_task.get_logger()
|
|
|
|
logger.info("Starting Portage package scanning: %s ...", query)
|
|
|
|
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_portage = ScanPortage()
|
|
|
|
scan_portage.scan(query)
|
|
|
|
|
|
|
|
if purge:
|
2012-05-31 09:11:40 +02:00
|
|
|
logger.info("Purging")
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_portage_purge()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_portage_purge_task():
|
|
|
|
scan_portage_purge()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_upstream_all_task(purge=False):
|
2012-05-31 09:11:40 +02:00
|
|
|
tasks = [scan_upstream_task.subtask(('%s/%s' % (pkg.category, pkg.name), ))
|
2012-05-30 22:54:55 +02:00
|
|
|
for pkg in Package.objects.all()]
|
|
|
|
|
|
|
|
if purge:
|
|
|
|
tasks.append(scan_upstream_purge_task.subtask())
|
|
|
|
|
|
|
|
job = TaskSet(tasks=tasks)
|
|
|
|
job.apply_async()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_upstream_task(query):
|
2012-05-31 09:11:40 +02:00
|
|
|
logger = scan_upstream_task.get_logger()
|
|
|
|
logger.info("Starting upstream scanning for package %s ...", query)
|
|
|
|
|
2012-05-30 22:54:55 +02:00
|
|
|
scan_upstream = ScanUpstream()
|
|
|
|
scan_upstream.scan(query)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def scan_upstream_purge_task():
|
|
|
|
scan_upstream_purge()
|
2012-06-03 09:43:49 +02:00
|
|
|
|
|
|
|
|
2012-06-04 11:06:47 +02:00
|
|
|
def _launch_command(cmd):
|
|
|
|
fp = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE)
|
|
|
|
output = StringIO(fp.communicate()[0])
|
|
|
|
return output.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def emerge_sync():
|
|
|
|
cmd = ["emerge", "--sync", "--root", settings.PORTAGE_ROOT,
|
|
|
|
"--config-root", settings.PORTAGE_CONFIGROOT]
|
|
|
|
return _launch_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def layman_sync():
|
|
|
|
cmd = ["layman", "-S", "--config", settings.LAYMAN_CONFIG]
|
|
|
|
return _launch_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def emerge_regen():
|
|
|
|
cmd = [
|
|
|
|
"emerge", "--regen", "--jobs", settings.EMERGE_REGEN_JOBS, "--root",
|
|
|
|
settings.PORTAGE_ROOT, "--config-root", settings.PORTAGE_CONFIGROOT
|
|
|
|
]
|
|
|
|
return _launch_command(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@task
|
|
|
|
def eix_update():
|
|
|
|
cmd = ["eix-update"]
|
|
|
|
return _launch_command(cmd)
|
|
|
|
|
|
|
|
|
2012-06-03 09:43:49 +02:00
|
|
|
launchable_tasks = [
|
|
|
|
regen_rrds_task,
|
|
|
|
update_counters_task,
|
|
|
|
scan_metadata_task,
|
|
|
|
scan_metadata_all_task,
|
|
|
|
scan_portage_all_task,
|
|
|
|
scan_portage_task,
|
|
|
|
scan_portage_purge_task,
|
|
|
|
scan_upstream_all_task,
|
|
|
|
scan_upstream_task,
|
|
|
|
scan_upstream_purge_task,
|
2012-06-04 11:06:47 +02:00
|
|
|
emerge_sync,
|
|
|
|
layman_sync,
|
|
|
|
emerge_regen,
|
|
|
|
eix_update,
|
2012-06-03 09:43:49 +02:00
|
|
|
]
|