Skip to content

Commit

Permalink
Revert "Add --ignore-project and --ignore-tag to report (jazzband#288)"
Browse files Browse the repository at this point in the history
This reverts commit 699ccda.
  • Loading branch information
lefi7z committed Jul 4, 2022
1 parent ee1c825 commit 0debcba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 92 deletions.
9 changes: 3 additions & 6 deletions docs/user-guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,9 @@ respectively.
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.

You can limit the report to a project or a tag using the `--project`,
`--tag`, `--ignore-project` and `--ignore-tag` options. They can be
specified several times each to add or ignore multiple projects or
tags to the report.
You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.

If you are outputting to the terminal, you can selectively enable a pager
through the `--pager` option.
Expand Down Expand Up @@ -565,8 +564,6 @@ Flag | Help
`-a, --all` | Reports all activities.
`-p, --project TEXT` | Reports activity only for the given project. You can add other projects by using this option several times.
`-T, --tag TEXT` | Reports activity only for frames containing the given tag. You can add several tags by using this option multiple times
`--ignore-project TEXT` | Reports activity for all projects but the given ones. You can ignore several projects by using the option multiple times. Any given project will be ignored
`--ignore-tag TEXT` | Reports activity for all tags but the given ones. You can ignore several tags by using the option multiple times. Any given tag will be ignored
`-j, --json` | Format output in JSON instead of plain text
`-s, --csv` | Format output in CSV instead of plain text
`-g, --pager / -G, --no-pager` | (Don't) view output through a pager.
Expand Down
36 changes: 0 additions & 36 deletions tests/test_watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,29 +771,6 @@ def test_report(watson):
assert len(report['projects'][0]['tags']) == 1
assert report['projects'][0]['tags'][0]['name'] == 'B'

watson.start('baz', tags=['D'])
watson.stop()

report = watson.report(arrow.now(), arrow.now(), projects=["foo"])
assert len(report['projects']) == 1

report = watson.report(arrow.now(), arrow.now(), ignore_projects=["bar"])
assert len(report['projects']) == 2

report = watson.report(arrow.now(), arrow.now(), tags=["A"])
assert len(report['projects']) == 1

report = watson.report(arrow.now(), arrow.now(), ignore_tags=["D"])
assert len(report['projects']) == 2

with pytest.raises(WatsonError):
watson.report(
arrow.now(), arrow.now(), projects=["foo"], ignore_projects=["foo"]
)

with pytest.raises(WatsonError):
watson.report(arrow.now(), arrow.now(), tags=["A"], ignore_tags=["A"])


# renaming project updates frame last_updated time
def test_rename_project_with_time(mock, watson):
Expand Down Expand Up @@ -886,16 +863,3 @@ def test_add_failure(mock, watson):
with pytest.raises(WatsonError):
watson.add(project="test_project", tags=['fuu', 'bar'],
from_date=7000, to_date=6000)


def test_validate_report_options(mock, watson):
assert watson._validate_report_options(["project_foo"], None)
assert watson._validate_report_options(None, ["project_foo"])
assert not watson._validate_report_options(["project_foo"],
["project_foo"])
assert watson._validate_report_options(["project_foo"], ["project_bar"])
assert not watson._validate_report_options(["project_foo", "project_bar"],
["project_foo"])
assert not watson._validate_report_options(["project_foo", "project_bar"],
["project_foo", "project_bar"])
assert watson._validate_report_options(None, None)
27 changes: 9 additions & 18 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def convert(self, value, param, ctx):
# expected by the user, so that midnight is midnight in the local
# timezone, not in UTC. Cf issue #16.
date.tzinfo = tz.tzlocal()

# Add an offset to match the week beginning specified in the
# configuration
if param.name == "week":
Expand Down Expand Up @@ -446,14 +447,6 @@ def status(watson, project, tags, elapsed):
help="Reports activity only for frames containing the given "
"tag. You can add several tags by using this option multiple "
"times")
@click.option('--ignore-project', 'ignore_projects', multiple=True,
help="Reports activity for all projects but the given ones. You "
"can ignore several projects by using the option multiple "
"times. Any given project will be ignored")
@click.option('--ignore-tag', 'ignore_tags', multiple=True,
help="Reports activity for all tags but the given ones. You can "
"ignore several tags by using the option multiple times. Any "
"given tag will be ignored")
@click.option('-j', '--json', 'output_format', cls=MutuallyExclusiveOption,
flag_value='json', mutually_exclusive=['csv'],
multiple=True,
Expand All @@ -469,9 +462,9 @@ def status(watson, project, tags, elapsed):
@click.option('-g/-G', '--pager/--no-pager', 'pager', default=None,
help="(Don't) view output through a pager.")
@click.pass_obj
def report(watson, current, from_, to, projects, tags, ignore_projects,
ignore_tags, year, month, week, day, luna, all, output_format,
pager, aggregated=False):
def report(watson, current, from_, to, projects, tags, year, month,
week, day, luna, all, output_format, pager,
aggregated=False):
"""
Display a report of the time spent on each project.
Expand All @@ -489,10 +482,9 @@ def report(watson, current, from_, to, projects, tags, ignore_projects,
The shortcut `--luna` sets the timespan to the current moon cycle with
the last full moon marking the start of the cycle.
You can limit the report to a project or a tag using the `--project`,
`--tag`, `--ignore-project` and `--ignore-tag` options. They can be
specified several times each to add or ignore multiple projects or
tags to the report.
You can limit the report to a project or a tag using the `--project` and
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.
If you are outputting to the terminal, you can selectively enable a pager
through the `--pager` option.
Expand Down Expand Up @@ -587,11 +579,10 @@ def report(watson, current, from_, to, projects, tags, ignore_projects,

try:
report = watson.report(from_, to, current, projects, tags,
ignore_projects, ignore_tags,
year=year, month=month, week=week, day=day,
luna=luna, all=all)
except _watson.WatsonError as e:
raise click.ClickException(e.message)
except watson.WatsonError as e:
raise click.ClickException(e)

if 'json' in output_format and not aggregated:
click.echo(json.dumps(report, indent=4, sort_keys=True))
Expand Down
13 changes: 1 addition & 12 deletions watson/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,22 +143,11 @@ def new_frame(self, project, start, stop, tags=None, id=None,
def dump(self):
return tuple(frame.dump() for frame in self._rows)

def filter(
self,
projects=None,
tags=None,
ignore_projects=None,
ignore_tags=None,
span=None,
):
def filter(self, projects=None, tags=None, span=None):
return (
frame for frame in self._rows
if (projects is None or frame.project in projects) and
(ignore_projects is None
or frame.project not in ignore_projects) and
(tags is None or any(tag in frame.tags for tag in tags)) and
(ignore_tags is None
or all(tag not in frame.tags for tag in ignore_tags)) and
(span is None or frame in span)
)

Expand Down
26 changes: 6 additions & 20 deletions watson/watson.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,19 @@ def merge_report(self, frames_with_conflict):

return conflicting, merging

def _validate_report_options(self, filtrate, ignored):
return not bool(
filtrate and ignored and set(filtrate).intersection(set(ignored)))

def report(self, from_, to, current=None, projects=None, tags=None,
ignore_projects=None, ignore_tags=None, year=None,
month=None, week=None, day=None, luna=None, all=None):
year=None, month=None, week=None, day=None, luna=None,
all=None):
for start_time in (_ for _ in [day, week, month, year, luna, all]
if _ is not None):
from_ = start_time

if not self._validate_report_options(projects, ignore_projects):
raise WatsonError(
"given projects can't be ignored at the same time")

if not self._validate_report_options(tags, ignore_tags):
raise WatsonError("given tags can't be ignored at the same time")

if from_ > to:
raise WatsonError("'from' must be anterior to 'to'")

if tags is None:
tags = []

if self.current:
if current or (current is None and
self.config.getboolean(
Expand All @@ -476,10 +468,7 @@ def report(self, from_, to, current=None, projects=None, tags=None,

frames_by_project = sorted_groupby(
self.frames.filter(
projects=projects or None, tags=tags or None,
ignore_projects=ignore_projects or None,
ignore_tags=ignore_tags or None,
span=span
projects=projects or None, tags=tags or None, span=span
),
operator.attrgetter('project')
)
Expand Down Expand Up @@ -509,9 +498,6 @@ def report(self, from_, to, current=None, projects=None, tags=None,
'tags': []
}

if tags is None:
tags = []

tags_to_print = sorted(
set(tag for frame in frames for tag in frame.tags
if tag in tags or not tags)
Expand Down

0 comments on commit 0debcba

Please sign in to comment.