Пример #1
0
 def handler(act):
     if act is 'R':
         actions.remove()
     elif act is 'C':
         actions.create()
     elif act is 'A':
         actions.add()
     elif act is 'E':
         actions.edit()
     else:
         print("Action error")
         main()
Пример #2
0
def main(argsList):
    if cmd == 'create':
        create(argsList)

    elif cmd == 'lookup':
        lookup(argsList)

    elif cmd in 'add':
        add(argsList)

    elif cmd in 'change':
        change(argsList)

    elif cmd in 'remove':
        remove(argsList)

    elif cmd in 'reverse-lookup':
        reverseLookup(argsList)

    else:
        print 'The command you type doesn\'t been exit'
Пример #3
0
def main(argsList):
    if cmd == 'create':
        create(argsList)

    elif cmd == 'lookup':
        lookup(argsList)

    elif cmd in 'add':
        add(argsList)

    elif cmd in 'change':
        change(argsList)

    elif cmd in 'remove':
        remove(argsList)

    elif cmd in 'reverse-lookup':
        reverseLookup(argsList)

    else:
        print 'The command you type doesn\'t been exit'
Пример #4
0
def handle_action_commands(args):
    """coordinates receiving, parsing, executing action commands"""
    tasks = collect_tasks()
    addition = None

    #  grab addition if exists
    if args[0] == 'add':
        args.pop(0)
        args, addition = extract_addition(args)
        target = len(tasks)
    # or pop first element off as target if is digit
    elif args[0].isdigit():
        target = int(args.pop(0)) - 1
    # if the first arg is neither a target nor "add", the next int
    # has to be the target
    else:
        args, target = extract_target(args)

    command_list = make_command_list(args, action_commands)

    # add the target into the arg list of every command
    if target is not None:
        for _, args in command_list:
            args.insert(0, target)
    else:
        print('Error: you must specify a target')

    # if addition, add task so other commands can act upon it
    if addition:
        tasks = actions.add(tasks, addition)

    try:
        tasks = execute_command_list(tasks, command_list, action_commands)
    except IndexError:
        print("Error: task number is invalid")
        raise

    write_tasks(tasks)
Пример #5
0
def main():

    try:
        commands = []
        for argument in sys.argv[1:]:
            if argument.startswith('-'):
                keyAndValue = argument.split('=')
                key = keyAndValue[0].strip().lstrip('-')
                if key == 'help':
                    commands.insert(0, 'help')
                if len(keyAndValue) > 1:
                    value = keyAndValue[1].strip()
                    if value == 'false':
                        config.overrides[key] = False
                    elif value == 'true':
                        config.overrides[key] = True
                    else:
                        config.overrides[key] = value
            else:
                commands.append(argument.strip())

        daysData = storage.yaml.load(config.log_path())
        days = importer.getDays(daysData)

        if not commands:
            output.status(days)
        elif commands[0] == 'timer':
            if len(commands) > 1:
                actions.timer(days, commands[1])
            else:
                actions.timer(days)
        elif commands[0] == 'update':
            if len(commands) > 1:
                actions.change(days, commands[1])
        elif commands[0] == 'pause':
            actions.pause(days)
        elif commands[0] == 'log':
            actions.log()
        elif commands[0] == 'export':
            actions.export(days)
        elif commands[0] == 'report':
            if len(commands) > 1 and commands[1] == 'text':
                actions.export(days)
            elif len(commands) > 1 and commands[1] == 'ods':
                actions.report.export_ods(days)
            else:
                actions.report.export_excel(days)
        elif commands[0] == 'import':
            if len(commands) > 1:
                actions.add(commands[1], days)
            else:
                print("No file to import given.")
        elif commands[0] == 'sync':
            actions.syncDown()
            actions.syncUp()
        else:
            print("WorkTimer " + __version__ +
                  " by Max Melzer (moehrenzahn.de)")
            print("")
            print("Usage: run worktimer.py to display current timer stats.")
            print("   Use param 'timer [category]' to start or stop timer")
            print(
                "   Use param 'update [category]' to change the currently tracked category"
            )
            print("   Use param 'pause' to start or stop pause")
            print(
                "   Use param 'sync' to attempt synchronisation with remote repository"
            )
            print("   Use param 'log' to open the log file in default editor")
            print(
                "   Use param 'export' to export your log to a human-readable text file"
            )
            print("   Use param 'report' to create a work report spreadsheet")
            print(
                "      'report excel --xlsx_template='template.xlsx'' for Excel"
            )
            print(
                "      'report ods --ods_template='template.ods'' for Open Document"
            )
            print(
                "   Use param 'import [file]' to import a log into your existing database"
            )
            print("")
            print("Options (see config_default.json) for complete list:")
            print("   --hours_per_day=8")
            print("   --log=path/to/your/work/log")
            print("   --sync_automatically=false")
            return 2
        return 0
    except ValueError as e:
        output.notification('Critical Error', str(e))
        return 1
Пример #6
0
 def action(self):
     actions.load_database(self.conf, self.loader)
     actions.add(self.conf, self.args.name, self.args.username,
                 self.args.comment, self.args.nonce, self.args.length,
                 self.args.entropy, self.args.generator)
     actions.save_database(self.conf, self.loader)