Exemplo n.º 1
0
 def testMultipleFlags(self):
     image_data = {'image_name': '1.JPG', 'site': 'a'}
     action_dict = {
         'image': '1.JPG',
         'action': 'invalidate',
         'reason': 'all_black',
         'shift_time_by_seconds': 0}
     apply_action(image_data, action_dict, flags)
     expected = {
             'image_name': '1.JPG',
             'site': 'a',
             'image_no_upload': '1',
             'image_was_deleted': '',
             'image_datetime_uncertain': '',
             'image_is_invalid': '1',
             'action_taken': 'invalidate',
             'action_taken_reason': 'all_black'}
     self.assertEqual(image_data, expected)
Exemplo n.º 2
0
 def testNormalCase(self):
     image_data = {'image_name': '1.JPG', 'site': 'a'}
     action_dict = {
         'image': '1.JPG',
         'action': 'mark_no_upload',
         'reason': 'rhino',
         'shift_time_by_seconds': 0}
     apply_action(image_data, action_dict, flags)
     expected = {
             'image_name': '1.JPG',
             'site': 'a',
             'image_no_upload': '1',
             'image_was_deleted': '',
             'image_datetime_uncertain': '',
             'image_is_invalid': '',
             'action_taken': 'mark_no_upload',
             'action_taken_reason': 'rhino'}
     self.assertEqual(image_data, expected)
Exemplo n.º 3
0
 def testTimeChange(self):
     image_data = {
         'image_name': '1.JPG', 'site': 'a',
         'datetime': '2000-01-01 00:00:00'}
     action_dict = {
         'image': '1.JPG',
         'action': 'timechange',
         'reason': 'camera clock off',
         'shift_time_by_seconds': 60}
     apply_action(image_data, action_dict, flags)
     expected = {
             'image_name': '1.JPG',
             'site': 'a',
             'image_no_upload': '',
             'image_was_deleted': '',
             'image_datetime_uncertain': '',
             'image_is_invalid': '',
             'datetime': '2000-01-01 00:01:00',
             'action_taken': 'timechange',
             'action_taken_reason': 'camera clock off'}
     self.assertEqual(image_data, expected)
 def mock_apply_action(image_data, action_dict, flags, mock_remove):
     apply_action(image_data, action_dict, flags)
    if not os.path.isfile(args['actions_to_perform']):
        raise FileNotFoundError(
            "actions_to_perform {} does not exist -- must be a file".format(
                args['actions_to_perform']))

    if not os.path.isfile(args['captures']):
        raise FileNotFoundError(
            "captures {} does not exist -- must be a file".format(
                args['captures']))

    # logging
    set_logging(args['log_dir'], args['log_filename'])
    logger = logging.getLogger(__name__)

    logger.info("Reading actions from {}".format(args['actions_to_perform']))
    actions = read_image_inventory(args['actions_to_perform'], unique_id=None)

    logger.info("Reading captures from {}".format(args['captures']))
    captures = read_image_inventory(args['captures'], unique_id='image_name')

    try:
        for _id, action in actions.items():
            apply_action(captures[action['image']], action, flags)
        logger.info("Successfully applied actions")
    except Exception as e:
        logger.error("Failed to apply actions", exc_info=True)

    export_inventory_to_csv(captures, args['captures'])

    logger.info("Updated captures file at: {}".format(args['captures']))