Skip to content

Commit

Permalink
mass interactive select + test code for set_categories
Browse files Browse the repository at this point in the history
  • Loading branch information
tobixen committed Oct 1, 2023
1 parent ac23a2b commit f02c924
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 22 deletions.
3 changes: 2 additions & 1 deletion plann/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def _set_attr_options(verb="", desc=""):
return lambda func: _set_attr_options_(func, verb, desc)

@cli.group()
@click.option('--interactive/--no-interactive-select', help="interactive filtering")
@click.option('--interactive/--no-interactive-select', help="line based interactive filtering")
@click.option('--mass-interactive/--no-mass-interactive-select', help="editor based interactive filtering")
@click.option('--all/--none', default=None, help='Select all (or none) of the objects. Overrides all other selection options.')
@click.option('--uid', multiple=True, help='select an object with a given uid (or select more object with given uids). Overrides all other selection options')
@click.option('--abort-on-missing-uid/--ignore-missing-uid', default=False, help='Abort if (one or more) uids are not found (default: silently ignore missing uids). Only effective when used with --uid')
Expand Down
29 changes: 21 additions & 8 deletions plann/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,32 @@
from plann.panic_planning import timeline_suggestion
from plann.timespec import _now, _ensure_ts, parse_dt, parse_add_dur, parse_timespec, tz
from plann.lib import _summary, _procrastinate, _relships_by_type, _summary, _relationship_text, _adjust_relations, parentlike, childlike, _remove_reverse_relations, _process_set_arg, attr_txt_one, attr_txt_many, attr_time, attr_int, _set_something, _list, _add_category
from plann.interactive import command_edit, _interactive_ical_edit, _interactive_relation_edit, _set_relations_from_text_list, interactive_split_task, _editor, _command_line_edit, interactive_split_task, _mass_interactive_edit
from plann.interactive import command_edit, _interactive_ical_edit, _interactive_relation_edit, _set_relations_from_text_list, interactive_split_task, _editor, _command_line_edit, interactive_split_task, _mass_interactive_edit, _get_obj_from_line

def _select(ctx, interactive=False, **kwargs):
def _select(ctx, interactive=False, mass_interactive=False, **kwargs):
"""
wrapper function for __select. Will honor the --interactive flag.
"""
__select(ctx, **kwargs)
if interactive:
objs = ctx.obj['objs']
ctx.obj['objs'] = []
for obj in objs:
if click.confirm(f"select {_summary(obj)}?"):
ctx.obj['objs'].append(obj)
## TODO: move the rest to interactive module?
if (interactive or mass_interactive) and ctx.obj['objs']:
if mass_interactive:
objs = ctx.obj['objs']
ctx.obj['objs'] = []
select_list = "\n".join(_list(
objs, echo=False,
template="{UID}: {SUMMARY:?{DESCRIPTION:?(no summary given)?}?} (STATUS={STATUS:-})"))
edited = _editor("## delete things that should not be selected:\n" + select_list)
for objectline in edited.split("\n"):
foo = objectline.split(': ')
obj = _get_obj_from_line(objectline, objs[0].parent)
if obj:
ctx.obj['objs'].append(obj)

if interactive:
for obj in objs:
if click.confirm(f"select {_summary(obj)}?"):
ctx.obj['objs'].append(obj)

def __select(ctx, extend_objects=False, all=None, uid=[], abort_on_missing_uid=None, sort_key=[], skip_parents=None, skip_children=None, limit=None, offset=None, freebusyhack=None, pinned_tasks=None, **kwargs_):
"""
Expand Down
29 changes: 23 additions & 6 deletions plann/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,34 @@ def _editor(sometext):
os.unlink(fn)
return ret

def _command_line_edit(line, calendar, interactive=True):
def _strip_line(line):
strip1 = re.compile("#.*$")
regexp = re.compile("((?:set [^ ]*=[^ ]*)|(?:postpone [0-9]+[smhdwy])|[^ ]*) (.*?)(: |$)")
line = strip1.sub('', line)
line = line.strip()
return line

def _get_obj_from_line(line, calendar):
uid_re = re.compile("^(.+?)(: .*)?$")
line = _strip_line(line)
if not line:
return None
found = uid_re.match(line)
assert found
uid = found.group(1)
obj = calendar.object_by_uid(uid)
return obj

def _command_line_edit(line, calendar, interactive=True):
regexp = re.compile("((?:set [^ ]*=[^ ]*)|(?:postpone [0-9]+[smhdwy])|[^ ]*) (.*)$")
line = _strip_line(line)
if not line:
return
splitted = regexp.match(line)
assert splitted
command = splitted.group(1)
uid = splitted.group(2)
obj = calendar.object_by_uid(uid)
command_edit(obj, command, interactive)

obj = _get_obj_from_line(splitted.group(2), calendar)
if obj:
command_edit(obj, command, interactive)
else:
import pdb; pdb.set_trace()

7 changes: 3 additions & 4 deletions plann/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ def _process_set_arg(arg, value):
k,v = split1.split('=')
rrule[k] = v
ret[arg] = rrule
elif arg == 'category':
ret['categories'] = [ value ]
elif arg == 'categories':
ret['categories'] = value.split(',')
elif arg in ('category', 'categories'):
if hasattr(value, 'split'):
ret['categories'] = value.split(',')
else:
ret[arg] = value
return ret
Expand Down
6 changes: 3 additions & 3 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ def dag(obj, reltype, observed=None):
return ret

## We create two tasks todo1 and todo2, todo2 being a child of todo1
todo1 = _add_todo(ctx, summary=['make plann good'], set_due='2012-12-20 23:15:00', set_dtstart='2012-12-20 22:15:00', set_uid='todo1')
todo1 = _add_todo(ctx, summary=['make plann good'], set_due='2012-12-20 23:15:00', set_dtstart='2012-12-20 22:15:00', set_uid='todo1', set_categories='plann,keyboard')
uid1 = str(todo1.icalendar_component['uid'])
todo2 = _add_todo(ctx, summary=['fix some bugs in plann'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo2')
todo2 = _add_todo(ctx, summary=['fix some bugs in plann'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo2', set_categories=('plann', 'keyboard'))
uid2 = str(todo2.icalendar_component['uid'])

## Selecting the tasks should yield ... 2 (but only one if skip_children or skip_parents is used)
Expand Down Expand Up @@ -290,7 +290,7 @@ def dag(obj, reltype, observed=None):
assert cal_post_interactive_relation_edit == cal_pre_interactive_relation_edit

## Let's add some more tasks
todo3 = _add_todo(ctx, summary=['fix some more features in plann'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo3')
todo3 = _add_todo(ctx, summary=['fix some more features in plann'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo3', set_category='plann')
todo4 = _add_todo(ctx, summary=['make plann even better'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo4')
todo5 = _add_todo(ctx, summary=['use plann on a daily basis to find more bugs and missing features'], set_parent=[uid1], set_due='2012-12-21 23:15:00', set_dtstart='2012-12-21 22:15:00', set_uid='todo5')

Expand Down

0 comments on commit f02c924

Please sign in to comment.