Home | Trees | Index | Help |
|
---|
Package dopal ::
Module scripting
|
|
This module is designed to provide an 'environment' that allows small scripts to be written without having to deal with the setting up and exception handling that you would normally have to deal with.
It also tries to make it straight-forward and distribute scripts without requiring any modification by another user to get it working on their system (most common change would be to personalise the script to work with a user's particular connection setup).
This module provides simple functionality for scripts - data persistency, error handling and logging - it even provides a mechanism for sending alerts to the user to be displayed in Azureus (via "Mr Slidey").
There are two main functions provided here:ext_run
- which provides all the
main functionality; and
run
- which calls ext_run with
the default settings, but allows these arguments to be modified
through command line arguments.
--setup-connection
command line
argument. This will provide the user with an input prompt to enter
connection values, and store it an appropriate directory (see determine_configuration_directory
).
That data is then used for all scripts using that module.
def script_function(env): ... # Do something here. if __name__ == '__main__': import dopal.scripting dopal.scripting.run("functionname", script_function)where "script_function" is the main body of the script (which takes one argument, a
ScriptEnvironment
instance) and
"functionname" which is used to define the script (in terms of
where persistent data is sent), and what the script is called when
sending alerts to Azureus.
Classes | |
---|---|
ScriptEnvironment |
The ScriptEnvironment class contains values and methods useful for a script to work with. |
Function Summary | |
---|---|
ask_for_connection_data()
| |
Determines an appropriate directory to store application data into. | |
Prepares a ScriptEnvironment object based on the
settings here, and executes the passed function. | |
get_stored_connection()
| |
input_connection_data()
| |
load_connection_data(error)
| |
Main entry point for script functions to be executed in a preconfigured environment. | |
save_connection_data(data_dict)
|
Function Details |
---|
determine_configuration_directory(mainname='DOPAL Scripts', subname=None, create_dir=True, preserve_case=False)Determines an appropriate directory to store application data into. This function will look at environmental settings and registry settings to determine an appropriate directory. The locations considered are in order:
(Note: this order may change between releases.) If an existing directory can be found, that will be returned. If no existing directory is found, then this function will try to create the directory in the most preferred location (based on the order of preference). If that fails - no existing directory was found and no directory could be created, then an OSError will be raised. If create_dir is False and no existing directory can be found, then the most preferred candidate directory will be returned. The main argument taken by this function is mainname. This should be
a directory name which is suitable for a Windows application directory
(e.g. "DOPAL Scripts"), as opposed to something which
resembles more Unix-based conventions (e.g.
".dopal_scripts"). This function will convert the
The
|
ext_run(name, function, connection=None, make_connection=True, timeout=15, use_repeatable_remote_notification=None, use_own_log_channel=False, remote_notify_on_run=False, remote_notify_on_error=True, logger=None, setup_logging=None, log_to_file=False, log_level=None, log_file=None, silent_on_connection_error=False, pause_on_exit=0, print_error_on_pause=1)Prepares a run function if you don't wish to
determine the environment settings to run in, and would prefer the
settings to be controlled through arguments on the command line.
|
run(name, function)Main entry point for script functions to be executed in a preconfigured environment. This function wraps up the majority of the functionality offered by
This function requires the You can find all the configuration options that are available by
running this function and passing the There are several options available which will affect how the script is executed, as well as other options which will do something different other than executing the script (such as configuring the default connection). This script can be passed This function does not return a value - if this method returns
cleanly, then it means the script has been executed (without any
problems). This function will raise 0 - Exit generated by optparse (normally when running with C{--help}). 2 - Required module is missing. 3 - No default connection stored. 4 - Error parsing command line arguments. 5 - Connection not established. 16 - Script not executed (command line options resulted in some other behaviour to occur). If an exception occurs inside the script, it will be passed back to
the caller of this function, but it will be wrapped in a ext_run , it will be passed back to the
caller of this function (rather than being suppressed).
|
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Wed May 03 14:22:33 2006 | http://epydoc.sf.net |