Exemplo n.º 1
0
def update_project(project):
    """Updates the duration of the project's time"""
    duration = None

    # set local timezone
    timezone = get_localzone()
    local_tz = timezone.zone

    # collect all of the logs that are part of this project
    logs = Log.select().where(Log.project_id == project.id)

    # iterate over the logs and accumulate the duration of each log
    for n, log in enumerate(logs):
        start = parse(log.start_time).datetime(to_timezone=local_tz,
                                               naive=True)
        stop = parse(log.stop_time).datetime(to_timezone=local_tz, naive=True)

        if n == 0:
            duration = MayaInterval.from_datetime(start, stop).timedelta
        else:
            duration += MayaInterval.from_datetime(start, stop).timedelta

    # update the project
    project.duration = duration
    project.status = 0
    project.save()
    print('Deactivating: {} with total time of {}'.format(
        project.name, project.duration))
Exemplo n.º 2
0
def reset_db(safe=True):
    """Reset the database"""
    if safe:
        print('WARNING: You are about to delete all records!')
        answer = input('Are you sure (y/n/): ')
        if 'y' in answer.lower():
            p = Project.delete()
            p.execute()
            l = Log.delete()
            l.execute()
            print('All records have been removed.')
        else:
            print('Aborted')
    else:
        p = Project.delete()
        p.execute()
        l = Log.delete()
        l.execute()
Exemplo n.º 3
0
def start_tracking():
    """Starts active tracking of project"""
    # ensure that there are no current active projects
    active = get_active()

    if active:
        print('Already tracking {}!'.format(active.name))
    else:
        project = get_selected(display=False)
        log = Log.create(project=project, start_time=now().datetime())
        log.save()
        project.status = 1
        project.save()
        print('Activating: {}'.format(project.name))
Exemplo n.º 4
0
def stop_tracking():
    """Stops active tracking of project"""
    # ensure that we are closing an active project
    active = get_active()

    if active:
        logs = Log.select().where(Log.project_id == active.id)

        # close out the log that doesn't have a stop_time entry
        for log in logs:
            if not log.stop_time:
                log.stop_time = now().datetime()
                log.save()
                # update the project's status and duration time
                update_project(active)
    else:
        print('There are currently no active projects...')