コード例 #1
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_resume(parser, args) -> None:
    check_if_setup_is_needed()

    authentication = utils.auth_from_config()

    # Check if there is already a timer running & give choice if there is
    if utils.is_timer_running(authentication):
        sys.exit('There is a timer currently running.')

    timers.resume_timer(authentication)
コード例 #2
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_create(parser, args) -> None:
    check_if_setup_is_needed()

    authentication = utils.auth_from_config()

    if args.request == 'project':
        workspace_id = utils.workspace_selection(verbose=False)

        timers.create_project(authentication=authentication,
                              workspace_id=workspace_id,
                              project_name=args.name)

    # Reconfigure the config file with new changes
    command_reconfig(parser, args)
コード例 #3
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_reconfig(parser, args) -> None:
    check_if_setup_is_needed()

    auth = utils.auth_from_config()

    utils.delete_user_data()

    if utils.are_credentials_valid(auth):
        utils.add_user_data_to_config(auth)
        utils.add_projects_to_config(auth)
    else:
        sys.exit(
            "\nCredentials error. Please run 'tgl setup' to reconfigure the credential data."
        )
コード例 #4
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_delete(parser, args) -> None:
    check_if_setup_is_needed()

    if not utils.are_there_projects():
        sys.exit(
            'There are no projects available in the config file.\nIf you recently '
            'added a project to your account, please use "tgl reconfig" to reconfigure your data.'
        )

    authentication = utils.auth_from_config()

    if args.request == 'project':
        timers.delete_project(authentication=authentication)

    command_reconfig(parser, args)
コード例 #5
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_start(parser, args) -> None:
    check_if_setup_is_needed()

    authentication = utils.auth_from_config()

    # Check if authentication is correct/api_key wasn't changed
    if not utils.are_credentials_valid(authentication):
        sys.exit(
            "ERROR: Authentication error.\nRun 'tgl setup' to reconfigure the data."
        )

    # Check if there is already a timer running & give choice if there is
    if utils.is_timer_running(authentication):
        print("There is a timer currently running.")
        user_input = input(
            "Do you want to stop the current timer and start a new one? (y/N): "
        )

        if user_input != 'y':
            sys.exit(
                "\nCurrent timer not stopped. You can use 'tgl current' for more information of the current timer."
            )

    # Workspaces need to be checked first so that the project selection can be accurate
    if args.workspace:
        workspace_id = utils.workspace_selection()
    else:
        workspace_id = utils.get_default_workspace()

    # Check if user adds the project argument then calls a function to check
    # if there are projects in the users account then call the function that asks
    # the user what project to use.
    project_id = ""
    if args.project:
        if utils.are_there_projects():
            project_id = utils.project_selection(workspace_id)
        else:
            print(
                "WARNING: You don't have any projects in your account.\n"
                "  If you created one recently, please run 'tgl reconfig' to reconfigure your data.\n"
                "  Timer will be crated without project.\n")

    timers.start_timer(description=args.description,
                       authentication=authentication,
                       workspace_id=workspace_id,
                       project_id=project_id,
                       tags=args.tags,
                       billable=args.billable)
コード例 #6
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_pause(parser, args) -> None:
    check_if_setup_is_needed()

    authentication = utils.auth_from_config()

    timers.stop_timer(authentication, for_resume=True)
コード例 #7
0
ファイル: main.py プロジェクト: rluzuriaga/tgl
def command_stop(parser, args) -> None:
    check_if_setup_is_needed()

    authentication = utils.auth_from_config()

    timers.stop_timer(authentication)