Exemplo n.º 1
0
 def clocked_in_info(self):
     """Return (project, date) if a user is configured and the last action was a
     clockin, otherwise (None, None)
     """
     with file_for_current_user() as f:
         if f:
             last_line = f.readlines()[-1]
             if 'clockin' in last_line:
                 return parse_clockin(last_line)
             else:
                 return None, None
         else:
             return None, None
Exemplo n.º 2
0
 def file_summary(self, file_path, from_time, to_time, projects):
     project_sums = defaultdict(lambda: datetime.timedelta())
     total_time = datetime.timedelta()
     with open(file_path, 'r') as f:
         for line in f:
             this_proj, clockin_time = parse_clockin(line)
             if projects is None or this_proj in projects:
                 try:
                     clockout_time = parse_clockout(f.next())
                 except StopIteration:
                     clockout_time = now
                 time_in_range = self.time_in_range(clockin_time, clockout_time,
                                                    from_time, to_time)
                 project_sums[this_proj] += time_in_range
                 total_time += time_in_range
     return project_sums, total_time
Exemplo n.º 3
0
    def _file_data(self, file_path, from_time=None, to_time=None, projects=None):
        """Given a file and user-supplied parameters, return (projects, from_time, to_time),
        where projects is a set, and from_time and to_time are datetime objects. No return
        value will be None.
        """
        scraped_projects = set()
        min_datetime = None
        max_datetime = None
        with open(file_path, 'r') as f:
            for line in f:
                this_proj, clockin_time = parse_clockin(line)
                if projects is None or this_proj in projects:
                    scraped_projects.add(this_proj)

                    if min_datetime is None:
                        min_datetime = clockin_time
                    else:
                        min_datetime = min(min_datetime, clockin_time)

                    try:
                        clockout_time = parse_clockout(f.next())
                    except StopIteration:
                        clockout_time = now

                    if max_datetime is None:
                        max_datetime = clockout_time
                    else:
                        max_datetime = max(max_datetime, clockout_time)
        if None in (min_datetime, max_datetime):
            new_from, new_to = now, now
        else:
            new_from, new_to = min_datetime, max_datetime
        if from_time is None or new_from > from_time:
            from_time = new_from
        if to_time is None or new_to < to_time:
            to_time = new_to
        return scraped_projects, from_time, to_time