feedwarrior

Slim, portable tooling for creating and distributing decentralized append logs
git clone git://git.defalsify.org/logwarrior.git
Log | Files | Refs | README | LICENSE

common.py (1112B)


      1 # standard imports
      2 import uuid
      3 import hashlib
      4 import logging
      5 
      6 # third-party imports
      7 import tasklib
      8 
      9 logg = logging.getLogger(__file__)
     10 
     11 defaulthashers = [hashlib.sha256, hashlib.sha1]
     12 
     13 
     14 def parse_uuid(uu):
     15     if type(uu).__name__ == 'str':
     16         return uuid.UUID('urn:uuid:' + uu)
     17     elif type(uu).__name__ == 'UUID':
     18         return uu
     19     raise ValueError('invalid uuid')
     20 
     21 
     22 def task_ids_to_uuids(task_path, task_ids):
     23     task_uuids = []
     24     tw = tasklib.TaskWarrior(task_path)
     25     for task_id in task_ids:
     26         # third-party imports
     27         t = tw.tasks.pending().get(id=task_id)
     28         task_uuid = t['uuid']
     29         logg.debug('resolved task uuid {} for id {}'.format(task_uuid, task_id))
     30         task_uuids.append(task_uuid)
     31     return task_uuids
     32 
     33 
     34 def check_task_uuids(task_path, task_uuids):
     35     task_ok_uuids = []
     36     tw = tasklib.TaskWarrior(task_path)
     37     for task_uuid in task_uuids:
     38         t = tw.tasks.pending().get(uuid=task_uuid)
     39         task_uuid = t['uuid']
     40         logg.debug('verified task uuid {}'.format(task_uuid))
     41         task_ok_uuids.append(task_uuid)
     42     return task_ok_uuids
     43 
     44