mirror of
https://git.webmeisterei.com/webmeisterei/todoist-taskwarrior.git
synced 2023-12-21 10:23:00 +01:00
Add hierarchical project handling
This commit is contained in:
parent
287f5600a6
commit
1ec6da17b3
@ -31,3 +31,6 @@ def test_validate_map():
|
|||||||
with pytest.raises(click.BadParameter):
|
with pytest.raises(click.BadParameter):
|
||||||
assert validate(utils.validate_map, ('FOO',)) == None
|
assert validate(utils.validate_map, ('FOO',)) == None
|
||||||
|
|
||||||
|
# Hierarchical src
|
||||||
|
assert validate(utils.validate_map, ('foo.bar=bazz',)) == {'foo.bar': 'bazz'}
|
||||||
|
assert validate(utils.validate_map, ('foo bar.bazz=bazz',)) == {'foo bar.bazz': 'bazz'}
|
||||||
|
@ -89,11 +89,16 @@ def migrate(ctx, interactive, sync, map_project, map_tag):
|
|||||||
whether to skip, rename, change the priority, or change the tags, before
|
whether to skip, rename, change the priority, or change the tags, before
|
||||||
moving on to the next task.
|
moving on to the next task.
|
||||||
|
|
||||||
Use --map-project to change or remove the project. For example, in the
|
Use --map-project to change or remove the project. Project hierarchies will
|
||||||
following invocation, the project FOO will be changed to BAR and the
|
be period-delimited during conversion. For example in the following,
|
||||||
project property will be unset when it is BAZ:
|
'Work Errands' and 'House Errands' will be both be changed to 'errands',
|
||||||
|
'Programming.Open Source' will be changed to 'oss', and the project will be
|
||||||
|
removed when it is 'Taxes':
|
||||||
\r
|
\r
|
||||||
--map-project FOO=BAR --map-project BAZ=
|
--map-project 'Work Errands'=errands
|
||||||
|
--map-project 'House Errands'=errands
|
||||||
|
--map-project 'Programming.Open Source'=oss
|
||||||
|
--map-project Taxes=
|
||||||
|
|
||||||
This command can be run multiple times and will not duplicate tasks.
|
This command can be run multiple times and will not duplicate tasks.
|
||||||
This is tracked in Taskwarrior by setting and detecting the
|
This is tracked in Taskwarrior by setting and detecting the
|
||||||
@ -109,15 +114,31 @@ def migrate(ctx, interactive, sync, map_project, map_tag):
|
|||||||
data = {}
|
data = {}
|
||||||
tid = data['tid'] = task['id']
|
tid = data['tid'] = task['id']
|
||||||
name = data['name'] = task['content']
|
name = data['name'] = task['content']
|
||||||
data['project'] = utils.try_map(
|
|
||||||
|
# Project
|
||||||
|
p = todoist.projects.get_by_id(task['project_id'])
|
||||||
|
project_hierarchy = [p]
|
||||||
|
while p['parent_id']:
|
||||||
|
p = todoist.projects.get_by_id(p['parent_id'])
|
||||||
|
project_hierarchy.insert(0, p)
|
||||||
|
|
||||||
|
project_name = '.'.join(p['name'] for p in project_hierarchy)
|
||||||
|
project_name = utils.try_map(
|
||||||
map_project,
|
map_project,
|
||||||
todoist.projects.get_by_id(task['project_id'])['name'],
|
project_name
|
||||||
)
|
)
|
||||||
|
data['project'] = utils.maybe_quote_ws(project_name)
|
||||||
|
|
||||||
|
# Priority
|
||||||
data['priority'] = utils.parse_priority(task['priority'])
|
data['priority'] = utils.parse_priority(task['priority'])
|
||||||
|
|
||||||
|
# Tags
|
||||||
data['tags'] = [
|
data['tags'] = [
|
||||||
utils.try_map(map_tag, todoist.labels.get_by_id(l_id)['name'])
|
utils.try_map(map_tag, todoist.labels.get_by_id(l_id)['name'])
|
||||||
for l_id in task['labels']
|
for l_id in task['labels']
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Dates
|
||||||
data['entry'] = utils.parse_date(task['date_added'])
|
data['entry'] = utils.parse_date(task['date_added'])
|
||||||
data['due'] = utils.parse_date(task['due_date_utc'])
|
data['due'] = utils.parse_date(task['due_date_utc'])
|
||||||
data['recur'] = utils.parse_recur(task['date_string'])
|
data['recur'] = utils.parse_recur(task['date_string'])
|
||||||
|
@ -41,6 +41,14 @@ def parse_priority(priority):
|
|||||||
"""
|
"""
|
||||||
return PRIORITY_MAP[int(priority)]
|
return PRIORITY_MAP[int(priority)]
|
||||||
|
|
||||||
|
""" Strings """
|
||||||
|
|
||||||
|
def maybe_quote_ws(value):
|
||||||
|
"""Surrounds a value with single quotes if it contains whitespace. """
|
||||||
|
if any(x == ' ' or x == '\t' for x in value):
|
||||||
|
return "'" + value + "'"
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
""" Dates """
|
""" Dates """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user