Example #1
0
    def test_log(self):
        "Tests log command"
        # this tests needs separate log file
        helpers.LOG_FILE = self.test_dir + '/auto_fake_log.txt'

        args = parse_args(['log', 'loging message'])
        args.func(args)
        self.assertEqual(len(helpers.read_log_file_lines()), 1)
        # get message without datetime string and colon sign at the end of it
        msg_line = helpers.read_log_file_lines()[0]
        msg = msg_line[helpers.DATETIME_LEN+1:]
        self.assertEqual(msg, 'loging message\n')

        args = parse_args(['log', 'second loging message'])
        args.func(args)
        self.assertEqual(len(helpers.read_log_file_lines()), 2)
        # get message without datetime string and colon sign at the end of it
        msg_line = helpers.read_log_file_lines()[1]
        msg = msg_line[helpers.DATETIME_LEN+1:]
        self.assertEqual(msg, 'second loging message\n')

        # as this test creates separate log file - remove it
        try:
            # if test file is not the same as real log file - remove it
            if helpers.LOG_FILE is not self.real_log_file:
                os.remove(helpers.LOG_FILE)
        except OSError:
            pass
Example #2
0
def parse_lines():
    """Returns a list of objects representing log file"""
    lines = read_log_file_lines()
    data = []
    for line in lines:
        data.append(parse_line(line))
    return data
Example #3
0
def stats(args):
    today = False
    if args.yesterday:
        yesterday_obj = dt.now() - timedelta(days=1)
        date_from = date_to = yesterday_obj.strftime(DATE_FORMAT)
    elif args.day:
        date_from = date_to = args.day
    elif args.week:
        date_from, date_to = get_week_range(args.week)
    elif args.last_week:
        date_from,  date_to = get_last_week()
    elif args.month:
        date_from,  date_to = get_month_range(args.month)
    elif args.last_month:
        date_from,  date_to = get_last_month()
    elif args._from and not args.to:
        date_from = args._from
        date_to = dt.now().strftime(DATE_FORMAT)
    elif args._from and args.to:
        date_from = args._from
        date_to = args.to
    else:
        # default action is to show today's  stats
        date_from = date_to = dt.now().strftime(DATE_FORMAT)
        today = True

    lines = read_log_file_lines()
    work_time, slack_time, today_work_time = calculate_stats(lines, date_from, date_to, today=today)
    if args.report:
        work_report, slack_report = calculate_report(lines, date_from, date_to)

        print_report(work_report, slack_report, work_time, slack_time, colorize=args.color)
        print_today_work_time(today_work_time)
    else:
        print_stats(work_time, slack_time, today_work_time)
        print_today_work_time(today_work_time)