def _delete_all(force): if not force: if input("This will irrevocably delete all your tasks, proceed? [y/N] ").lower() != "y": return None for task in TaskList().tasks: task.delete_schedule()
def list_( tablefmt: str = typer.Option( "simple", "-f", "--format", help="Table format", callback=tablefmt_callback ) ): """Get list of user's scheduled tasks as a table with columns: id, interval, at (hour:minute/minute past), status (enabled/disabled), command. Note: This script provides an overview of all tasks. Once a task id is known and some specific data is required it's more convenient to get it using `pa schedule get` command instead of parsing the table. """ logger = get_logger(set_info=True) headers = "id", "interval", "at", "status", "command" attrs = "task_id", "interval", "printable_time", "enabled", "command" def stringify_values(task, attr): value = getattr(task, attr) if attr == "enabled": value = "enabled" if value else "disabled" return value table = [[stringify_values(task, attr) for attr in attrs] for task in TaskList().tasks] msg = tabulate(table, headers, tablefmt=tablefmt) if table else snakesay("No scheduled tasks") logger.info(msg)
def test_instatiates_task_list_calling_proper_methods(self, task_specs, mocker): mock_get_list = mocker.patch("pythonanywhere.api.schedule.Schedule.get_list") mock_get_list.return_value = [task_specs] mock_from_specs = mocker.patch("pythonanywhere.task.Task.from_api_specs") TaskList() assert mock_from_specs.call_args == call(task_specs) assert mock_from_specs.call_count == len(mock_get_list.return_value) assert mock_get_list.call_count == 1
def main(tablefmt): logger = get_logger(set_info=True) headers = "id", "interval", "at", "status", "command" attrs = "task_id", "interval", "printable_time", "enabled", "command" def get_right_value(task, attr): value = getattr(task, attr) if attr == "enabled": value = "enabled" if value else "disabled" return value table = [[get_right_value(task, attr) for attr in attrs] for task in TaskList().tasks] msg = tabulate(table, headers, tablefmt=tablefmt) if table else snakesay("No scheduled tasks") logger.info(msg)
def delete_all_tasks( force: bool = typer.Option( False, "-f", "--force", help="Turns off user confirmation before deleting tasks" ), ): get_logger(set_info=True) if not force: user_response = typer.confirm( "This will irrevocably delete all your tasks, proceed?" ) if not user_response: return None for task in TaskList().tasks: task.delete_schedule()