entry.py (1636B)
1 # standard imports 2 import os 3 import email 4 import logging 5 import uuid 6 import json 7 import gzip 8 9 # local imports 10 import feedwarrior 11 from feedwarrior import entry as feedentry 12 from feedwarrior.adapters import fileadapter 13 from feedwarrior.common import task_ids_to_uuids, check_task_uuids 14 15 logg = logging.getLogger() 16 17 18 def parse_args(argparser): 19 argparser.add_argument('-z', action='store_true', help='compress entry with gzip') 20 argparser.add_argument('--task-id', dest='task_id', type=int, action='append', help='add taskwarrior task id relations translated to uuis (cannot be used with --task-uuid') 21 argparser.add_argument('--task-uuid', dest='task_uuid', type=str, action='append', help='add taskwarrior task uuid relations (cannot be used with --task-id') 22 argparser.add_argument('path', help='multipart file to use for content') 23 return True 24 25 26 def check_args(args): 27 pass 28 29 30 # TODO: move logic to package to get symmetry with the show.py logic 31 def execute(config, feed, args): 32 task_uuids = [] 33 if args.task_id != None: 34 task_uuids += task_ids_to_uuids(config.task_dir, args.task_id) 35 36 if args.task_uuid != None: 37 task_uuids += check_task_uuids(config.task_dir, args.task_uuid) 38 39 entry = feedentry.from_multipart_file(args.path) 40 for t in task_uuids: 41 uu = feedwarrior.common.parse_uuid(t) 42 entry.add_extension(feedwarrior.extension.TASKWARRIOR, uu) 43 44 uu = str(entry.uuid) 45 logg.debug('adding entry {}'.format(uu)) 46 47 fa = fileadapter(config.data_dir, feed.uuid) 48 fa.put(entry.uuid, entry, compress=args.z) 49 50 feed.add(entry) 51 return str(entry.uuid)