summaryrefslogtreecommitdiff
path: root/commcrawler/management/commands/launch_crawl.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-08-02 18:30:26 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-08-02 18:30:26 +0200
commitc6b3188e49049cf689658654a1458a3276304782 (patch)
treeb5aac4bbba112d51bbf514e40790d7b082f8b002 /commcrawler/management/commands/launch_crawl.py
parent2703a7334e02ff60dcfb0b47625b6aff4fbfe150 (diff)
downloadComm-on-net-c6b3188e49049cf689658654a1458a3276304782.tar.bz2
Comm-on-net-c6b3188e49049cf689658654a1458a3276304782.zip
Launch crawl command: more options
Diffstat (limited to 'commcrawler/management/commands/launch_crawl.py')
-rw-r--r--commcrawler/management/commands/launch_crawl.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/commcrawler/management/commands/launch_crawl.py b/commcrawler/management/commands/launch_crawl.py
index 050a54d..92c3081 100644
--- a/commcrawler/management/commands/launch_crawl.py
+++ b/commcrawler/management/commands/launch_crawl.py
@@ -11,29 +11,51 @@ class Command(BaseCommand):
help = 'Launch a crawl'
def add_arguments(self, parser):
+ parser.add_argument('--crawl-id', default=None, type=int,
+ dest="crawl_id")
+ parser.add_argument(
+ '--first-available', dest="first_available", action='store_true',
+ help="Crawl the first available crawler"
+ )
parser.add_argument(
'--quiet', dest='quiet', action='store_true',
help='Quiet output')
def handle(self, *args, **options):
quiet = options['quiet']
+ crawl_id = options['crawl_id']
+ first_available = options['first_available']
+ if crawl_id and first_available:
+ sys.stdout.write('--first-available and --crawl-id are '
+ 'incompatible. Exit.\n')
+ return
+
q = Crawl.objects.filter(status="C")
if not q.count():
sys.stdout.write('No crawl waiting. Exit.\n')
return
-
- crawls = dict([(c.pk, c) for c in q.all()])
- available_ids = crawls.keys()
- c_id = None
- while c_id not in available_ids:
- sys.stdout.write('Which crawl to launch (type the number):\n')
- for crawl_id, crawl in crawls.items():
- sys.stdout.write('* {} - {}\n'.format(crawl_id, crawl))
- sys.stdout.flush()
- try:
- c_id = int(input("# "))
- except ValueError:
- c_id = None
- current_crawl = crawls[c_id]
+ if first_available:
+ q = q.order_by("-pk")
+ current_crawl = q.all()[0]
+ elif crawl_id:
+ q = q.filter(pk=crawl_id)
+ if not q.count():
+ sys.stdout.write('Crawl with this ID do not exist. Exit.\n')
+ return
+ current_crawl = q.all()[0]
+ else:
+ crawls = dict([(c.pk, c) for c in q.all()])
+ available_ids = crawls.keys()
+ c_id = None
+ while c_id not in available_ids:
+ sys.stdout.write('Which crawl to launch (type the number):\n')
+ for crawl_id, crawl in crawls.items():
+ sys.stdout.write('* {} - {}\n'.format(crawl_id, crawl))
+ sys.stdout.flush()
+ try:
+ c_id = int(input("# "))
+ except ValueError:
+ c_id = None
+ current_crawl = crawls[c_id]
launch_crawl(current_crawl)