diff --git a/euscanwww/djeuscan/tasks.py b/euscanwww/djeuscan/tasks.py index 89a90dc..2f36f95 100644 --- a/euscanwww/djeuscan/tasks.py +++ b/euscanwww/djeuscan/tasks.py @@ -1,8 +1,12 @@ +import subprocess +from StringIO import StringIO + from celery.task import task from celery.task.sets import TaskSet -from djeuscan.models import Package +from django.conf import settings +from djeuscan.models import Package 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 @@ -97,6 +101,41 @@ def scan_upstream_purge_task(): scan_upstream_purge() +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) + + launchable_tasks = [ regen_rrds_task, update_counters_task, @@ -108,4 +147,8 @@ launchable_tasks = [ scan_upstream_all_task, scan_upstream_task, scan_upstream_purge_task, + emerge_sync, + layman_sync, + emerge_regen, + eix_update, ] diff --git a/euscanwww/euscanwww/settings.py b/euscanwww/euscanwww/settings.py index d84e340..46182c0 100644 --- a/euscanwww/euscanwww/settings.py +++ b/euscanwww/euscanwww/settings.py @@ -202,6 +202,12 @@ LOGGING = { } +PORTAGE_ROOT = "/usr/portage/" +PORTAGE_CONFIGROOT = PORTAGE_ROOT +LAYMAN_CONFIG = "/etc/layman/layman.cfg" +EMERGE_REGEN_JOBS = 4 + + # Celery config import djcelery djcelery.setup_loader() @@ -213,7 +219,7 @@ try: from local_settings import * except ImportError, ex: import sys - sys.stderr.write(\ - ("settings.py: error importing local settings file:\n" + \ - "\t%s\n" + \ - "Do you have a local_settings.py module?\n") % str(ex)) + sys.stderr.write( + "settings.py: error importing local settings file:\n" + "\t%s\nDo you have a local_settings.py module?\n" % str(ex) + ) diff --git a/euscanwww/scripts/euscan.fcgi b/euscanwww/scripts/euscan.fcgi index d9d5b91..166bbdb 100755 --- a/euscanwww/scripts/euscan.fcgi +++ b/euscanwww/scripts/euscan.fcgi @@ -1,6 +1,7 @@ #!/usr/bin/python -import sys, os +import sys +import os import os.path PROJECT = '/path/to/euscanwww'