From ab362be63792f3802e91a5b39349422228c19ed4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 27 Apr 2013 22:55:02 +0200 Subject: [PATCH] support -e/-i & changelog entry Signed-off-by: Nico Schottelius --- bin/ctt | 13 +++++++++---- changelog | 5 +++++ lib/ctt/__init__.py | 2 +- lib/ctt/report.py | 16 ++++++++++------ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/bin/ctt b/bin/ctt index 25aae20..28c7235 100755 --- a/bin/ctt +++ b/bin/ctt @@ -67,11 +67,16 @@ def parse_argv(argv, version): parents=[parser['loglevel']]) parser['report'].set_defaults(func=Report.commandline) parser['report'].add_argument("project", help="Project to report time for", nargs=1) - parser['report'].add_argument("-s", "--start", help="Start date (default: first of last month, format: %s)" % ctt.DATEFORMAT_PLAIN, - nargs=1) - parser['report'].add_argument("-e", "--end", help="End date (default: last of last month, format: %s)" % ctt.DATEFORMAT_PLAIN, nargs=1, default=None) + parser['report'].add_argument("--sd", "--start", help="Start date (default: first of last month, format: %s)" % ctt.DATEFORMAT_PLAIN, + nargs=1, dest="start") + parser['report'].add_argument("--ed", "--end", help="End date (default: last of last month, format: %s)" % ctt.DATEFORMAT_PLAIN, + nargs=1, default=None, dest="end") - parser['report'].add_argument("-f", "--format", help="Output format (default: %s)" % ctt.REPORTFORMAT, default=ctt.REPORTFORMAT, dest="output_format") + parser['report'].add_argument("-e", "--regexp", help="Regular expression to match", + default=None) + parser['report'].add_argument("-i", "--ignore-case", help="Ignore case distinctions", action="store_true") + parser['report'].add_argument("-f", "--format", help="Output format (default: %s)" % ctt.REPORTFORMAT, + default=ctt.REPORTFORMAT, dest="output_format") #parser['track'].add_argument("-t", "--tag", help="Add tags", # action="store_true") diff --git a/changelog b/changelog index 5a693fa..567fa16 100644 --- a/changelog +++ b/changelog @@ -1,5 +1,10 @@ Changelog --------- +0.8: 2013-04-27 + * Added -e / --regexp support for filtering entries on report + * Added -i / --ignore-case support + * Renamed -s/-e to --sd / --ed (to allow -e for expression) + 0.7: * Added -f / --format support for reporting diff --git a/lib/ctt/__init__.py b/lib/ctt/__init__.py index 95d29a9..17577e3 100644 --- a/lib/ctt/__init__.py +++ b/lib/ctt/__init__.py @@ -23,7 +23,7 @@ import os import os.path -VERSION = "0.6" +VERSION = "0.8" FILE_DELTA = "delta" FILE_COMMENT = "comment" DATEFORMAT = "%Y-%m-%d" diff --git a/lib/ctt/report.py b/lib/ctt/report.py index d3ee545..4282f00 100755 --- a/lib/ctt/report.py +++ b/lib/ctt/report.py @@ -38,19 +38,26 @@ log = logging.getLogger(__name__) class Report(object): """Create a report on tracked time""" - def __init__(self, project, start_date, end_date, output_format): + def __init__(self, project, start_date, end_date, + output_format, regexp, ignore_case): self.project = project self.project_dir = ctt.project_dir(self.project) self.output_format = output_format + self.regexp = regexp + + if ignore_case: + self.search_flags = re.IGNORECASE + else: + self.search_flags = 0 self._init_date(start_date, end_date) self._init_report_db() @classmethod def commandline(cls, args): - report = cls(args.project[0], args.start, args.end, args.output_format) + report = cls(args.project[0], args.start, args.end, args.output_format, args.regexp, args.ignore_case) report.report() @@ -95,9 +102,6 @@ class Report(object): if not os.path.isdir(self.project_dir): raise ctt.Error("Project does not exist: %s" % (self.project)) - # self.regexp = "^rails19" - self.regexp = None - self._report_db = {} for dirname in os.listdir(self.project_dir): dir_datetime = datetime.datetime.strptime(dirname, ctt.DISKFORMAT) @@ -112,7 +116,7 @@ class Report(object): comment = fd.read().rstrip('\n') # If regular expression given, but not matching, skip entry - if self.regexp and not re.search(self.regexp, comment): + if self.regexp and not re.search(self.regexp, comment, self.search_flags): continue