1# Copyright 2013-2016 The Distro Tracker Developers 

2# See the COPYRIGHT file at the top-level directory of this distribution and 

3# at https://deb.li/DTAuthors 

4# 

5# This file is part of Distro Tracker. It is subject to the license terms 

6# in the LICENSE file found in the top-level directory of this 

7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker, 

8# including this file, may be copied, modified, propagated, or distributed 

9# except according to the terms contained in the LICENSE file. 

10""" 

11Implements a command to start a number of available Distro Tracker tasks. 

12A task is a subclass of :class:`distro_tracker.core.tasks.BaseTask`. 

13""" 

14import logging 

15 

16from django.core.management.base import BaseCommand 

17 

18from distro_tracker.core.tasks import run_task 

19 

20logger = logging.getLogger('distro_tracker.tasks') 

21 

22 

23class Command(BaseCommand): 

24 """ 

25 A management command which starts a number of Distro Tracker tasks. 

26 A task is a subclass of :class:`distro_tracker.core.tasks.BaseTask`. 

27 """ 

28 help = "Start all the Distro Tracker tasks given by name." # noqa 

29 

30 def add_arguments(self, parser): 

31 parser.add_argument('tasks', nargs='+', help='Tasks to be run') 

32 parser.add_argument( 

33 '--force-update', 

34 action='store_true', 

35 dest='force_update', 

36 default=False, 

37 help=( 

38 'Force the update. ' 

39 'This clears any caches and makes a full update.' 

40 ) 

41 ) 

42 parser.add_argument( 

43 '--fake-update', 

44 action='store_true', 

45 dest='fake_update', 

46 default=False, 

47 help=( 

48 'Instruct the task to not do anything except recording that ' 

49 'everything has been done.' 

50 ) 

51 ) 

52 

53 def handle(self, *args, **kwargs): 

54 params = {} 

55 if kwargs['force_update']: 

56 params['force_update'] = True 

57 if kwargs['fake_update']: 

58 params['fake_update'] = True 

59 for task_name in kwargs['tasks']: 

60 if isinstance(task_name, bytes): 60 ↛ 61line 60 didn't jump to line 61, because the condition on line 60 was never true

61 task_name = task_name.decode('utf-8') 

62 logger.info("./manage.py tracker_run_task %s", task_name) 

63 if not run_task(task_name, **params): 

64 self.stderr.write('Task {} failed to run.\n'.format(task_name))