Tasks
- class jogger.tasks.base.Task(prog, name, conf, default_stdout, default_stderr, argv=None)
An advanced
joggertask capable of defining its own arguments, calling nested tasks, and other more advanced features.- help
The help text for this task, output when the task is invoked with
-h/--help.
- default_long_input_editor
The editor program to launch when invoking the
long_input()method and no system default editor can be determined. Defaults to'nano'.
- settings
The dictionary containing any settings for this task that were included in a supported config file.
- project_dir
The absolute path to the project directory, as determined by the location of the
jog.pyfile.
- stdout
A proxy for the stream to write general messages to, offering more control over output from the task. See Controlling Output for details on writing to output proxies. Defaults to the system’s
stdoutstream, but can be changed using the--stdoutargument, e.g.:jog test --stdout /home/myuser/logs/test/out.log
- stderr
A proxy for the stream to write error messages to, offering more control over output from the task. See Controlling Output for details on writing to output proxies. Defaults to the system’s
stderrstream, but can be changed using the--stderrargument, e.g.:jog test --stderr /home/myuser/logs/test/err.log
- add_arguments(parser)
Custom tasks should override this method to add any custom command line arguments they require.
- handle(*args, **kwargs)
The actual logic of the task. Subclasses must implement this method.
- cli(cmd, capture=False)
Run a command on the system’s command line, in the context of the task’s
stdoutandstderroutput streams. Output can be captured rather than displayed usingcapture=True.- Parameters:
cmd – The command string to execute.
capture –
Trueto capture all output from the command rather than writing it to the configured output streams.
- Returns:
The command result object.
- get_task_proxy(task_name, *args)
Return an object representing the task matching the given name, configured with the given arguments, if any. This proxy object can be used to execute the task, regardless of whether it is defined as a string, function, or class:
proxy = self.get_task_proxy('test') proxy.execute()
Arguments should be provided as individual strings, e.g.:
proxy = get_task_proxy('test', '-v', '2', 'myapp.tests', '--keepdb')
Depending on the type of task (string, function, or class based), common arguments of the source task will be propagated automatically, including (where relevant):
--stdout,--stderr,--no-color, and-v/--verbosity.- Parameters:
task_name – The task name as a string.
args – Extra task arguments, as individual strings.
- Returns:
The task proxy instance.
- long_input(default=None, editor=None)
Replacement for Python’s
input()builtin that uses the system’s default editor to ask for user input.- Parameters:
default – Default text to populate the editor with.
editor – The editor to use. The system default will be used if this is not provided.
- Returns:
The text entered by the user.
- class jogger.tasks.django.DjangoTask(*args, **kwargs)
A Task that requires a configured Django environment in order to run. Such task classes require that the
django_settings_moduleattribute be specified, naming the Django settings module to use. E.g.:class MyDjangoTask(DjangoTask): django_settings_module = 'my_project.settings'
The configured Django settings object is available as
self.django_settings, avoiding the need to importdjango.conf.settingsmanually (as a standard module-level import would not work).- django_settings_module = None
The Django settings module to use when running the task.
- django_settings
The configured and imported Django settings object.
- jogger.tasks.django.configure_django(project_dir, settings_module)
Configure the Django environment for the current process.
This function is intended for use in scripts that need to run Django code outside of a normal Django context, e.g. function-based or class-based jogger tasks.
- Parameters:
project_dir – The absolute path to the project directory.
settings_module – The dotted path to the Django settings module to use, relative to
project_dir.
- Returns:
The configured and imported Django settings object.