Better docstrings and debug messages for non-commit cycles

pull/15/head
Andrew Williams 2016-02-20 17:25:35 +00:00
parent 0307069826
commit 70acdf031f
1 changed files with 10 additions and 5 deletions

View File

@ -12,7 +12,7 @@ from datetime import datetime
def get_subitems(items, parent_item=None): def get_subitems(items, parent_item=None):
"""Search a flat item list for child items""" """Search a flat item list for child items."""
result_items = [] result_items = []
found = False found = False
if parent_item: if parent_item:
@ -35,7 +35,7 @@ def get_subitems(items, parent_item=None):
def main(): def main():
"""Main process function."""
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-a', '--api_key', help='Todoist API Key') parser.add_argument('-a', '--api_key', help='Todoist API Key')
parser.add_argument('-l', '--label', help='The next action label to use', default='next_action') parser.add_argument('-l', '--label', help='The next action label to use', default='next_action')
@ -78,7 +78,7 @@ def main():
sys.exit(1) sys.exit(1)
def get_project_type(project_object): def get_project_type(project_object):
"""Identifies how a project should be handled""" """Identifies how a project should be handled."""
name = project_object['name'].strip() name = project_object['name'].strip()
if project['name'] == 'Inbox': if project['name'] == 'Inbox':
return args.inbox return args.inbox
@ -88,7 +88,7 @@ def main():
return 'serial' return 'serial'
def get_item_type(item): def get_item_type(item):
"""Identifies how a item with sub items should be handled""" """Identifies how a item with sub items should be handled."""
name = item['content'].strip() name = item['content'].strip()
if name[-1] == args.parallel_suffix: if name[-1] == args.parallel_suffix:
return 'parallel' return 'parallel'
@ -121,6 +121,7 @@ def main():
if project_type: if project_type:
logging.debug('Project %s being processed as %s', project['name'], project_type) logging.debug('Project %s being processed as %s', project['name'], project_type)
# Get all items for the project, sort by the item_order field.
items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order']) items = sorted(api.items.all(lambda x: x['project_id'] == project['id']), key=lambda x: x['item_order'])
for item in items: for item in items:
@ -165,12 +166,16 @@ def main():
elif project_type == 'parallel': elif project_type == 'parallel':
add_label(item, label_id) add_label(item, label_id)
logging.debug('%d changes queued for sync... commiting if needed', len(api.queue))
if len(api.queue): if len(api.queue):
logging.debug('%d changes queued for sync... commiting to Todoist.', len(api.queue))
api.commit() api.commit()
else:
logging.debug('No changes queued, skipping sync.')
# If onetime is set, exit after first execution.
if args.onetime: if args.onetime:
break break
logging.debug('Sleeping for %d seconds', args.delay) logging.debug('Sleeping for %d seconds', args.delay)
time.sleep(args.delay) time.sleep(args.delay)