Package CedarBackup2 :: Module cli
[show private | hide private]
[frames | no frames]

Module CedarBackup2.cli

Provides command-line interface implementation for the cback script.

Summary

The functionality in this module encapsulates the command-line interface for the cback script. The cback script itself is very short, basically just an invokation of one function implemented here. That, in turn, makes it simpler to validate the command line interface (for instance, it's easier to run pychecker against a module, and unit tests are easier, too).

The objects and functions implemented in this module are probably not useful to any code external to Cedar Backup. Anyone else implementing their own command-line interface would have to reimplement (or at least enhance) all of this anyway.

Backwards Compatibility

The command line interface has changed between Cedar Backup 1.x and Cedar Backup 2.x. Some new switches have been added, and the actions have become simple arguments rather than switches (which is a much more standard command line format). Old 1.x command lines are generally no longer valid.

Author: Kenneth J. Pronovici <pronovic@ieee.org>

Classes
Options Class representing command-line options for the cback script.

Function Summary
  cli()
Implements the command-line interface for the cback script.

Variable Summary
str DEFAULT_CONFIG: The default configuration file.
str DEFAULT_LOGFILE: The default log file path.
list DEFAULT_OWNERSHIP: Default ownership for the logfile.
int DEFAULT_MODE: Default file permissions mode on the logfile.
list VALID_ACTIONS: List of valid actions.
list COMBINE_ACTIONS: List of actions which can be combined with other actions.
list NONCOMBINE_ACTIONS: List of actions which cannot be combined with other actions.

Function Details

cli()

Implements the command-line interface for the cback script.

Essentially, this is the "main routine" for the cback script. It does all of the argument processing for the script, and then sets about executing the indicated actions.

As a general rule, only the actions indicated on the command line will be executed. We will accept any of the standard actions and any of the configured extended actions (which makes action list verification a two- step process).

The 'all' action has a special meaning. Normally, it means that the standard set of actions (collect, stage, store, purge) will all be executed, in that order. Extended actions will be ignored as part of the 'all' action.

Raised exceptions always result in an immediate return. Otherwise, we generally return when all specified actions have been completed. Actions are ignored if the help, version or validate flags are set.

A different error code is returned for each type of failure:
  • 1: The Python interpreter version is < 2.3
  • 2: Error processing command-line arguments
  • 3: Error configuring logging
  • 4: Error parsing indicated configuration file
  • 5: Backup was interrupted with a CTRL-C or similar
  • 6: Error executing specified backup actions
Returns:
Error code as described above.

Notes:

  • This function contains a good amount of logging at the INFO level, because this is the right place to document high-level flow of control (i.e. what the command-line options were, what config file was being used, etc.)
  • We assume that anything that must be seen on the screen is logged at the ERROR level. Errors that occur before logging can be configured are written to sys.stderr.


Variable Details

DEFAULT_CONFIG

The default configuration file.
Type:
str
Value:
'/etc/cback.conf'                                                      

DEFAULT_LOGFILE

The default log file path.
Type:
str
Value:
'/var/log/cback.log'                                                   

DEFAULT_OWNERSHIP

Default ownership for the logfile.
Type:
list
Value:
['root', 'adm']                                                        

DEFAULT_MODE

Default file permissions mode on the logfile.
Type:
int
Value:
416                                                                   

VALID_ACTIONS

List of valid actions.
Type:
list
Value:
['collect', 'stage', 'store', 'purge', 'rebuild', 'validate', 'all']   

COMBINE_ACTIONS

List of actions which can be combined with other actions.
Type:
list
Value:
['collect', 'stage', 'store', 'purge']                                 

NONCOMBINE_ACTIONS

List of actions which cannot be combined with other actions.
Type:
list
Value:
['rebuild', 'validate', 'all']                                         

Generated by Epydoc 2.1 on Thu Dec 22 20:45:14 2005 http://epydoc.sf.net