diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/orm/management/commands/lsupdates.py | 2 | ||||
-rw-r--r-- | lib/orm/models.py | 4 | ||||
-rwxr-xr-x | lib/srtmain/management/commands/update.py | 41 |
3 files changed, 45 insertions, 2 deletions
diff --git a/lib/orm/management/commands/lsupdates.py b/lib/orm/management/commands/lsupdates.py index 7bae1720..ce085a11 100644 --- a/lib/orm/management/commands/lsupdates.py +++ b/lib/orm/management/commands/lsupdates.py @@ -338,7 +338,7 @@ class Command(BaseCommand): data_sources=DataSource.objects.all().order_by('key') for source in data_sources: - if source.loaded: + if source.loaded and not (source.update_frequency == DataSource.ONSTARTUP): logger.info("Skipping source data from %s",source.description) print("Skipping datasource %s (already loaded)" % (source.description)) _log("Skipping datasource %s (already loaded)" % (source.description)) diff --git a/lib/orm/models.py b/lib/orm/models.py index 99438285..8d95c319 100644 --- a/lib/orm/models.py +++ b/lib/orm/models.py @@ -148,6 +148,7 @@ class DataSource(models.Model): WEEKLY = 3 MONTHLY = 4 ONDEMAND = 5 + ONSTARTUP = 6 FREQUENCY = ( (MINUTELY, 'Minute'), (HOURLY, 'Hourly'), @@ -155,6 +156,7 @@ class DataSource(models.Model): (WEEKLY, 'Weekly'), (MONTHLY, 'Monthly'), (ONDEMAND, 'OnDemand'), + (ONSTARTUP, 'OnStartup'), ) key = models.CharField(max_length=20) @@ -273,7 +275,7 @@ class Cve(models.Model): packages = models.TextField(blank=True) - score_date = models.DateField(null=True, blank=True) + score_date = models.DateField(default=0) srt_updated = models.DateTimeField(auto_now=True) @property diff --git a/lib/srtmain/management/commands/update.py b/lib/srtmain/management/commands/update.py new file mode 100755 index 00000000..8f746aea --- /dev/null +++ b/lib/srtmain/management/commands/update.py @@ -0,0 +1,41 @@ +from django.core.management.base import BaseCommand, CommandError +from django.core.exceptions import ObjectDoesNotExist +from django.db import OperationalError +import os + +class Command(BaseCommand): + help = "Trigger a data source update" + + def add_arguments(self, parser): + parser.add_argument('--cron-start', action='store_const', const='cron_start', dest='command', help='Start the SRTool backgroud updater') + parser.add_argument('--cron-stop', action='store_const', const='cron_stop', dest='command', help='Stop the SRTool backgroud updater') + + parser.add_argument('--list', '-l', action='store_const', const='list', dest='command', help='List data sources') + parser.add_argument('--run-updates', '-u', action='store_const', const='run-updates', dest='command', help='update scheduled data sources') + parser.add_argument('--force', '-f', action='store_true', dest='force', help='Force the update') + parser.add_argument('--name-filter', '-n', nargs='+', type=str, dest='name_filter', help='Filter for datasource name') + + parser.add_argument('--verbose', action='store_true', dest='verbose', help='Debugging: verbose output') + parser.add_argument('--trial', '-t', action='store_true', dest='is_trial', help='Debugging: trial run') + + def handle(self, *args, **options): + #print("UPDATE:%s|%s" % (str(args),str(options))) + + command = '' + if 'cron_start' == options['command']: command = '--cron-start' + if 'cron_stop' == options['command']: command = '--cron-stop' + if 'list' == options['command']: command = '--list' + if 'run-updates' == options['command']: command = '--run-updates' + + # NOTE: we have to do shenanigans with name_filter to support spaces + name_filter = '--name-filter "%s"' % ' '.join(options['name_filter']) if options['name_filter'] else '' + + force = '--force' if options['force'] else '' + is_trial = '--trial' if options['is_trial'] else '' + verbose = '--verbose' if options['verbose'] or (options['verbosity'] > 1) else '' + context = '> /dev/null 2>&1 &' if 'cron_start' == options['command'] else '' + + update_command = "./bin/common/srtool_update.py %s %s %s %s %s %s" % (command,name_filter,force,is_trial,verbose,context) + print("RUN: %s" % (update_command)) + os.chdir(os.environ['SRT_BASE_DIR']) + os.system("%s" % (update_command)) |