Example #1
0
File: __init__.py Project: fhats/ct
def main():
    home_ct = os.path.join(os.environ['HOME'], '.ct')
    if 'CT_HOME' not in os.environ or not os.path.isdir(os.environ['CT_HOME']):
        if not os.path.isdir(home_ct):
            log.info('Creating ~/.ct')
            os.mkdir(home_ct)
        os.environ['CT_HOME'] = os.path.join(os.environ['HOME'], '.ct')

    parser = argparse.ArgumentParser(prog='ct',
                                     description='Time tracking tool')

    subparsers = parser.add_subparsers(title='subcommands',
                                       help='Type "ct [command] --help" for more information.')

    for name, cmd in commands.viewitems():
        new_parser = subparsers.add_parser(name, description=cmd.description)
        new_parser.add_argument('--config', default=False, action='store_true',
                                dest='config', help='update configuration options')
        cmd.add_arguments(new_parser)
        new_parser.set_defaults(func=cmd.execute)

    parser.add_argument('--config', default=False, action='store_true',
                        dest='config', help='update configuration options')

    args = parser.parse_args()
    if args.config:
        load_config(reset=True)
    args.func(args)
Example #2
0
File: commands.py Project: fhats/ct
    def execute(self, args, allow_adium_update=True):
        clockout_time = parse_date(args.time) if args.time else now

        project, clockin_time = self.clocked_in_info()

        if project:
            if clockout_time >= clockin_time:
                write_clockout(clockout_time)

                log.info("Clocked out of %s at %s" % (project, clockout_time.strftime(user_date_format)))

                conf = load_config()
                if allow_adium_update and conf["adium"]:
                    time_str = clockout_time.strftime(user_date_format)
                    adium_str = (
                        "Not currently tracking time. Last seen at %(location)s working on %(project)s. (updated %(time)s)"
                        % dict(location=conf["location"], project=project, time=time_str)
                    )
                    if set_adium_status(adium_str + blurb, args.away):
                        log.info("Updated Adium status to: %s" % adium_str)
                    else:
                        log.info("Couldn't update Adium status")
            else:
                log.info("Clockout time is before last clockin time. Clockout failed.")
        else:
            log.info("Not clocked into anything. Clockout failed.")
Example #3
0
File: commands.py Project: fhats/ct
    def execute(self, args):
        project, clockin_time = self.clocked_in_info()
        if project:
            commands["clockout"].execute(args, allow_adium_update=False)

        clockin_time = parse_date(args.time) if args.time else now

        write_clockin(args.project, clockin_time)

        log.info("Clocked into %s at %s" % (args.project, clockin_time.strftime(user_date_format)))

        conf = load_config()
        if conf["adium"]:
            time_str = clockin_time.strftime(user_date_format)
            adium_str = "At %(location)s working on %(project)s. (updated %(time)s)" % dict(
                location=conf["location"], project=args.project, time=time_str
            )
            if set_adium_status(adium_str + blurb, args.away):
                log.info("Updated Adium status to: %s" % adium_str)
            else:
                log.info("Couldn't update Adium status")