示例#1
0
文件: rep_tl.py 项目: karibou/tl
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--logfile',
                        nargs=1,
                        metavar='LOGFILE',
                        help='Path to the gtimelog logfile to be use')
    args = parser.parse_args()

    if args.logfile is not None:
        LogFile = set_logfile(args.logfile)
    else:
        LogFile = set_logfile()

    (week_first, week_last) = get_time()
    Log = TimeLog(LogFile, virtual_midnight)
    log_entries = Log.window_for(week_first, week_last)
    total_work, _ = log_entries.totals()
    _, totals = log_entries.categorized_work_entries()

    ordered_by_time = [(time, cat) for cat, time in totals.items()]
    ordered_by_time.sort(reverse=True)
    max_cat_length = max([len(cat) for cat in totals.keys()])
    line_format = '  %-' + str(max_cat_length + 4) + 's %+5s\t %.0f%%'
    print("\nTotal work done so far : %s\n" %
          format_duration_short(total_work))
    print('Categories by time spent:')
    for time, cat in ordered_by_time:
        print(line_format %
              (cat, format_duration_short(time), time / total_work * 100))
示例#2
0
class GtimelogParser(object):
    def __init__(self, config):
        self.settings = Settings()
        self.timelog = TimeLog(self.settings.get_timelog_file(),
                               self.settings.virtual_midnight)
        self.aliases = config.get('aliases', {})

    def skip_entry(self, entry):
        if '**' in entry:
            return True
        if entry.strip() in ('arrive', 'arrived', 'start'):
            return True
        return False

    def get_entries(self, date_window):
        window = self.timelog.window_for(date_window.start, date_window.stop)

        worklogs = []
        attendances = []
        for start, stop, duration, tags, entry in window.all_entries():
            if self.skip_entry(entry):
                continue
            if attendances and attendances[-1][1] == start:
                attendances[-1] = (attendances[-1][0], stop)
            else:
                attendances += [(start, stop)]
            try:
                issue, description = [
                    x.strip() for x in entry.split(':', 1) if x.strip()
                ]
            except ValueError:
                print(
                    'Entry must be in the format `task: description`. '
                    'Got ', entry)
                continue

            # no matter what we find as `issue`:
            # if we have an alias override it takes precedence
            if issue in self.aliases:
                issue = self.aliases[issue]
            worklogs.append(
                MultiLog(None, issue, int(duration.total_seconds()),
                         start.date(), description))

        # Dangling attendance for today
        if attendances and attendances[-1][1].date() == date.today():
            attendances[-1] = (attendances[-1][0], None)

        return attendances, worklogs
示例#3
0
文件: tl_sum.py 项目: karibou/tl
def task_summary(category, task=None):

    total_delta = datetime.timedelta()
    today = datetime.datetime.today()
    epoch = datetime.datetime(1970, 10, 1)
    Log = TimeLog(LogFile, virtual_midnight)
    log_entries = Log.window_for(epoch, today)
    entries, _ = log_entries.categorized_work_entries()

    for (_, entry, entry_time) in entries[Categories[category] + ' ']:
        if entry.lstrip() == task:
            total_delta += entry_time
    print("total time spent on %s : %d.%d" % (
        task, int(total_delta.seconds / 3600) + int(total_delta.days * 24),
        int(total_delta.seconds / 60 % 60)))
    return 0
示例#4
0
文件: weekly_tl.py 项目: karibou/tl
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--logfile',
                        nargs=1,
                        metavar='LOGFILE',
                        help='Path to the gtimelog logfile to be use')
    parser.add_argument('-u',
                        '--user',
                        nargs=1,
                        metavar='USER',
                        help='User Identification to be used for report')
    parser.add_argument('-n',
                        '--no-time',
                        help='Print weekly report without spent time',
                        action='store_true')
    parser.add_argument('-m',
                        '--minutes',
                        help='Print weekly report with spent time in minutes',
                        action='store_true')
    parser.add_argument('-d',
                        '--days',
                        help='Print weekly report with spent time in days',
                        action='store_true')
    parser.add_argument('-b',
                        '--back',
                        help='Print weekly report back # of weeks',
                        nargs=1)
    args = parser.parse_args()

    if args.logfile is not None:
        LogFile = set_logfile(args.logfile)
    else:
        LogFile = set_logfile()

    if args.user is not None:
        UserId = set_userid(args.user)
    else:
        UserId = set_userid()

    (week_first, week_last) = get_time(args.back)
    Log = TimeLog(LogFile, virtual_midnight)
    log_entries = Log.window_for(week_first, week_last)
    total_work, _ = log_entries.totals()
    entries, totals = log_entries.categorized_work_entries()

    print("[ACTIVITY] %s to %s (%s)" %
          (week_first.isoformat().split("T")[0],
           week_last.isoformat().split("T")[0], UserId))
    if entries:
        if None in entries:
            categories = sorted(entries)
            categories.append('No category')
            entries['No category'] = e
            t = totals.pop(None)
            totals['No category'] = t
        else:
            categories = sorted(entries)
        for cat in categories:
            print('%s:' % cat)

            work = [(entry, duration)
                    for start, entry, duration in entries[cat]]
            work.sort()
            for entry, duration in work:
                if not duration:
                    continue  # skip empty "arrival" entries

                entry = entry[:1].upper() + entry[1:]
                if args.no_time:
                    print(u"  %-61s  " % entry)
                elif args.minutes:
                    print(u"  %-85s  %+5s %+4s" %
                          (entry, format_duration_short(duration),
                           as_minutes(duration)))
                elif args.days:
                    print(u"  %-85s  %+5s %.1f" %
                          (entry, format_duration_short(duration),
                           as_minutes(duration) / 480))
                else:
                    print(u"  %-85s  %+5s" %
                          (entry, format_duration_short(duration)))

            if args.no_time:
                print("")
            else:
                if args.minutes:
                    print('-' * 100)
                    print(u"%+94s %4s" % (format_duration_short(
                        totals[cat]), as_minutes(totals[cat])))
                elif args.days:
                    print('-' * 98)
                    print(u"%+94s %.1f" % (format_duration_short(
                        totals[cat]), as_minutes(totals[cat]) / 480))
                else:
                    print('-' * 94)
                    print(u"%+94s" % (format_duration_short(totals[cat])))

        print("Total work done : %s" % format_duration_short(total_work))
示例#5
0
文件: daily_tl.py 项目: karibou/tl
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-l',
                        '--logfile',
                        nargs=1,
                        metavar='LOGFILE',
                        help='Path to the gtimelog logfile to be use')
    parser.add_argument('-u',
                        '--user',
                        nargs=1,
                        metavar='USER',
                        help='User Identification to be used for report')
    parser.add_argument('-t',
                        '--time',
                        help='Print daily report with spent time',
                        action='store_false')
    parser.add_argument('-H',
                        '--header',
                        help='Print category headers',
                        action='store_true')
    parser.add_argument('-m',
                        '--minutes',
                        help='Print daily report with spent time in minutes',
                        action='store_true')
    parser.add_argument('-b',
                        '--back',
                        help='Print daily report back # of days',
                        metavar='BACK',
                        type=int)
    args = parser.parse_args()

    if args.logfile is not None:
        LogFile = set_logfile(args.logfile)
    else:
        LogFile = set_logfile()

    if args.user is not None:
        UserId = set_userid(args.user)
    else:
        UserId = set_userid()

    day_start = datetime.datetime.today().replace(hour=0,
                                                  minute=0,
                                                  second=0,
                                                  microsecond=0)
    if args.back:
        day_start = day_start - datetime.timedelta(days=args.back)
    day_end = day_start.replace(hour=23, minute=59, second=59, microsecond=999)
    Log = TimeLog(LogFile, virtual_midnight)
    log_entries = Log.window_for(day_start, day_end)
    total_work, _ = log_entries.totals()
    entries, totals = log_entries.categorized_work_entries()

    print("Today's work for %s" % UserId)
    if entries:
        if None in entries:
            categories = sorted(entries)
            categories.append('No category')
            entries['No category'] = e
            t = totals.pop(None)
            totals['No category'] = t
        else:
            categories = sorted(entries)
        for cat in categories:
            if args.header:
                print('- %s:' % cat)

            work = [(entry, duration)
                    for start, entry, duration in entries[cat]]
            work.sort()
            for entry, duration in work:
                if not duration:
                    continue  # skip empty "arrival" entries

                entry = entry[:1].upper() + entry[1:]
                if args.time:
                    print(u"  - %-61s  " % entry)
                else:
                    if args.minutes:
                        print(u"  - %-59s  %+5s %+4s" %
                              (entry, format_duration_short(duration),
                               as_minutes(duration)))
                    else:
                        print(u"  - %-59s  %+5s" %
                              (entry, format_duration_short(duration)))

            if args.time:
                pass
                # print("")
            else:
                if args.minutes:
                    print('-' * 75)
                    print(u"%+70s %4s" % (format_duration_short(
                        totals[cat]), as_minutes(totals[cat])))
                else:
                    print('-' * 70)
                    print(u"%+70s" % (format_duration_short(totals[cat])))
        print("Total work done : %s" % format_duration_short(total_work))