pyjld.system: various system level utilities (e.g. daemon, cross-platform registry, command-line tools)
This package contains various system level utilities.
0.4
0.3
0.2
pyjld.system.daemon
This module borrows heavily from python_daemon available at Pypi
Controller class for a callable running in a separate background process
The principal methods are:
The PID lock file is derived from app.name in the following way
${app.pid_directory}/${app.name}.pid
and by default is located in the /var/run directory; this directory can be customized through the app.pid_directory attribute.
The exceptions generated by this class contain pseudo-messages which are really meant as index to human readable messages. This way, customization is easier to handle.
Exceptions raised
All exceptions specific to this class are raised with DaemonRunnerException and the following message identifiers are defined:
- error_pidfile_locked
- error_pidfile_not_locked
- error_daemon_aborted
- error_daemon_open
- error_daemon_terminate_process
- error_daemon_openfilepath
- error_application_method_not_found
The parameter app must be a callable with, as minimum, the following attributes:
Optional attributes are:
The exit() is called when the daemon is shutting down eg. it received a SIGTERM signal ( called also during the cmd_stop() ).
Starts the daemon for app
The method app.before_start() is called prior to actually daemonizing; the method can abort the process by raising ...
The method app.before_start() need not to exist (a validity check is performed).
DaemonRunner Exception base class
Allows for easier customization of error messages. Use duck typing to inspect the Exception for the msg_id & params attributes.
Used as model of an app
pyjld.system.command.base
Base class for command line utilities
The functionality of this class includes:
Iterator for the configuration parameters
Iterates through all the class attributes starting with config_.
pyjld.system.command.ui
Base class for Command Line UI
| Parameters: |
|
|---|
Messages object
This object can be controlled with through template_factory; the latter must implement a safe_substitute method for rendering the message_id with the given parameters to a message string.
Copies all var entries from the source dictionary following the ref_options dictionary into the target dictionary.
| Parameters: |
|
|---|
Processes command line options
| Parameters: |
|
|---|
Displays, if required, an appropriate user message corresponding to an error condition.
| Parameters: |
|
|---|---|
| Return type: | boolean True if the exception was handled successfully i.e. a message was found and rendered correctly. |
Integrate values from the registry where None values are found in the cmd object
| Parameters: |
|
|---|---|
| Return type: | keys list for all replacement performed |
Prepare the command cmd object
Updates the registry from the command-line args
Goes through the args, verifies if the reg option is to be found in the ref_options dictionary and updates accordingly the registry.
| Parameters: |
|
|---|
The registry is a dictionary.
Enhances the standard library’s OptionParser class
Adds the method ex_add_options()
Adds options through a keyword dictionary only. This constrasts to add_options() which goes through hoops to support both positional & keyword based argument list.
This method translates the options_list for the base class.
| Parameters: |
|
|---|
Each dictionary entry (i.e. each list item) will be translated to comply with the standard base class OptionParser. Furthermore, only options which are supported by the base class are passed to the OptionParser: this behavior allows for extending the options_list entries (i.e. each dictionary item) with custom keys without breaking OptionParser.
[ { option } ... ]
Thus, a full option list can be passed to ex_add_options() without worrying about the special cases short and long positional arguments.
pyjld.system.registry.base
Facade for the cross-platform Registry
Can be accessed like a dictionary: for this functionality, an instance must be constructed with the ‘file’ parameter specified.