flexget.manager module#
- class flexget.manager.Manager(args)[source]#
Bases:
objectManager class for FlexGet.
Fires events:
manager.initialize
The first time the manager is initialized, before config is loaded
manager.before_config_load
Before the config file is loaded from disk
manager.before_config_validate
When updating the config, before the validator is run on it
manager.config_updated
After a configuration file has been loaded or changed (and validated) this event is fired
manager.startup
After manager has been initialized. This is when application becomes ready to use, however no database lock is present, so the database must not be modified on this event.
manager.lock_acquired
The manager does not always require a lock on startup, if one is requested, this event will run when it has been acquired successfully
manager.upgrade
If any plugins have declared a newer schema version than exists in the database, this event will be fired to allow plugins to upgrade their tables
manager.shutdown_requested
When shutdown has been requested. Any plugins which might add to execution queue should stop when this is fired.
manager.shutdown
When the manager is exiting
manager.execute.completed
If execution in current process was completed
manager.daemon.started
manager.daemon.completed
manager.db_cleanup
- static parse_initial_options(args)[source]#
Parse what we can from cli args before plugins are loaded.
- Parameters:
- Return type:
- _init_config(create=False)[source]#
Find and load the configuration file.
- Parameters:
create (bool) – If a config file is not found, and create is True, one will be created in the home folder
- Raises:
OSError when no config file could be found, and create is False.
- Return type:
None
- _read_lock()[source]#
Read the values from the lock file. Returns None if there is no current lock file.
- Return type:
dict | None
- acquire_lock(event=True)[source]#
- Parameters:
event (bool) – If True, the ‘manager.lock_acquired’ event will be fired after a lock is obtained
- Return type:
Iterator
- check_ipc_info()[source]#
If a daemon has a lock on the database, return info to connect to IPC.
- Return type:
dict | None
- config_changed()[source]#
Make sure that all tasks will have the config_modified flag come out true on the next run.
Useful when changing the db and all tasks need to be completely reprocessed.
- Return type:
None
- crash_report()[source]#
Be called when handling an unexpected exception.
Will create a new log file containing the last 50 debug messages as well as the crash traceback.
- Return type:
- daemon_command(options)[source]#
Handle the ‘daemon’ CLI command.
Fires events:
manager.daemon.started
manager.daemon.completed
- Parameters:
options (argparse.Namespace) – argparse options
- Return type:
None
- db_cleanup(force=False)[source]#
Perform database cleanup if cleanup interval has been met.
Fires events:
manager.db_cleanup
If interval was met. Gives session to do the cleanup as a parameter.
- Parameters:
force (bool) – Run the cleanup no matter whether the interval has been met.
- Return type:
None
- execute(options=None, priority=1, suppress_warnings=None)[source]#
Run all (can be limited with options) tasks from the config.
- Parameters:
options (dict | argparse.Namespace | None) – Either an
argparse.Namespaceinstance, or a dict, containing options for executionpriority (int) – If there are other executions waiting to be run, they will be run in priority order, lowest first.
suppress_warnings (Sequence[str] | None) – Allows suppressing log warning about missing plugin in key phases
- Returns:
a list of
threading.Eventinstances which will be set when each respective task has finished running- Return type:
list[tuple[str, str, threading.Event]]
- execute_command(options)[source]#
Handle the ‘execute’ CLI command.
If there is already a task queue running in this process, adds the execution to the queue. If FlexGet is being invoked with this command, starts up a task queue and runs the execution.
Fires events:
manager.execute.started
manager.execute.completed
- Parameters:
options (argparse.Namespace) – argparse options
- Return type:
None
- handle_cli(options=None)[source]#
Dispatch a cli command to the appropriate function.
CLI plugin callback function
The manager should have a lock and be initialized before calling this method.
- Parameters:
options (argparse.Namespace | None) – argparse options for command. Defaults to options that manager was instantiated with.
- Return type:
None
- initialize()[source]#
Load plugins, database, and config.
Also initialize (but do not start) the task queue and ipc server. This should only be called after obtaining a lock.
- Return type:
None
- load_config(output_to_console=True, config_file_hash=None)[source]#
Load the config file from disk, validate and activate it.
- shutdown(finish_queue=True)[source]#
Request manager shutdown.
- Parameters:
finish_queue (bool) – Should scheduler finish the task queue
- Return type:
None
- start()[source]#
Run as the starting point when executing from commandline, dispatch execution to correct destination.
If there is a FlexGet process with an ipc server already running, the command will be sent there for execution and results will be streamed back. If not, this will attempt to obtain a lock, initialize the manager, and run the command here.
- Return type:
None
- update_config(config)[source]#
Provide a new config for the manager to use.
- Raises:
ValueError and rolls back to previous config if the provided config is not valid.
- Parameters:
config (dict)
- Return type:
None
- validate_config(config=None)[source]#
Check all root level keywords are valid.
Config may be modified by before_config_validate hooks. Modified config will be returned.
- options: argparse.Namespace#
- unit_test = False#