Exemplo n.º 1
0
 def test_parse_add(self):
     argv = [
         None, "a", "p:something", "This is", "urg:m", "+tag1", "-tag2",
         "the description"
     ]
     expected = '[{"mods": {}, "pointers": []}, ["add"], {"project": ' + \
                '["something"], "urgency": ["m"], "tags": ["+tag1", "-tag2"]}, "This is the description"]'
     result = json.dumps(args.parse(argv))
     self.assertEqual(expected, result)
Exemplo n.º 2
0
def main():
    rolling_backup()

    # Create or update database schema
    models.create_all()

    with db.get_session() as session:
        """:type : orm.session"""
        db.session = session

    first_arg = ""
    if len(sys.argv) > 1:
        first_arg = sys.argv[1]
    if first_arg.startswith("h"):
        print_help()

    filters, command, mods, description = args.parse(sys.argv)
    print(
        "...................................................................")
    print("debug:")
    print("filters", filters)
    print("command", command)
    print("mods", mods)
    print("description", description)
    print(
        "...................................................................")
    print()

    cmd_task = cmd.task.Task()
    response = None

    if command is None:
        print_help()

    elif command[0] == "ls":
        if len(filters["pointers"]) > 0:
            # List timesheet entries
            for pointer_id in filters["pointers"]:
                task = cmd_task.get_task(pointer_id)
                response = cmd_task.list_entries(task.uuid)

        else:
            # List tasks
            if "description" not in filters["mods"] and description is not None:
                filters["mods"]["description"] = description
            response = cmd_task.ls(filters)

    elif command[0] == "timesheet":
        cmd_timesheet = cmd.timesheet.Timesheet()
        response = cmd_timesheet.report(filters)

    elif command[0] == "add":
        params = {"description": description}

        if "project" in mods:
            if len(mods["project"]) > 1:
                raise exceptions.ModMustHaveOneValue('"project"')
            params["project"] = mods["project"][0]

        if "urgency" in mods:
            if len(mods["project"]) > 1:
                raise exceptions.ModMustHaveOneValue('"urgency"')
            params["urgency"] = mods["urgency"][0]

        if "tags" in mods:
            params["tags"] = mods["tags"]

        response = cmd_task.add(**params)

    elif command[0] == "mod":
        args.pointer_required(filters)
        for pointer_id in filters["pointers"]:
            params = {"uuid": pointer_id, "description": description}

            if "project" in mods:
                params["project"] = mods["project"][0]

            if "urgency" in mods:
                params["urgency"] = mods["urgency"][0]

            if "tags" in mods:
                params["tags"] = mods["tags"]

            response = cmd_task.mod(**params)

    elif command[0] == "done":
        args.pointer_required(filters)
        for pointer_id in filters["pointers"]:
            task = cmd_task.get_task(pointer_id)
            response = cmd_task.done(task.uuid)

    elif command == ["start", "stop"]:
        # Stop or start task if pointer given
        if len(filters["pointers"]) > 0:
            for pointer_id in filters["pointers"]:
                task = cmd_task.get_task(pointer_id)
                try:
                    # Try to stop this task
                    response = cmd_task.stop(task.uuid)
                except exceptions.TaskNotStarted:
                    # Task not started, start it
                    response = cmd_task.start(task.uuid)
        else:
            # List started tasks
            filters["mods"]["started"] = True
            response = cmd_task.ls(filters)

    elif command[0] == "remove":
        args.pointer_required(filters)
        for pointer_id in filters["pointers"]:
            task = cmd_task.get_task(pointer_id)
            response = cmd_task.remove(task.uuid)

    else:
        print_help()

    if response is not None:
        response.print()

    print()
Exemplo n.º 3
0
 def test_parse_timesheet(self):
     argv = [None, "m:t", "t"]
     expected = '[{"mods": {"modified": "today"}, "pointers": []}, ' + \
                '["timesheet"], {}, null]'
     result = json.dumps(args.parse(argv))
     self.assertEqual(expected, result)
Exemplo n.º 4
0
 def test_parse_mod(self):
     argv = [None, "mo", "p:foo", "u:l"]
     expected = '[{"mods": {}, "pointers": []}, ["mod"], {"project": ' + \
                '["foo"], "urgency": ["l"]}, null]'
     result = json.dumps(args.parse(argv))
     self.assertEqual(expected, result)
Exemplo n.º 5
0
 def test_parse_list(self):
     argv = [None, "l", "foo"]
     expected = '[{"mods": {}, "pointers": []}, ["ls"], {}, "foo"]'
     result = json.dumps(args.parse(argv))
     self.assertEqual(expected, result)
Exemplo n.º 6
0
 def test_parse_start(self):
     argv = [None, "1", "st"]
     expected = '[{"mods": {}, "pointers": ["1"]}, ["start", "stop"], {}, null]'
     result = json.dumps(args.parse(argv))
     self.assertEqual(expected, result)