Back to index

obnam  1.1
Public Member Functions | Public Attributes
obnamlib.app.App Class Reference

List of all members.

Public Member Functions

def add_settings
def deduce_client_name
def setup_hooks
def plugins_dir
def setup_logging
def process_args
def log_config
def setup_ttystatus
def open_repository
def time

Public Attributes

 pm
 fsf
 hooks
 ts

Detailed Description

Main program for backup program.

Definition at line 31 of file app.py.


Member Function Documentation

Definition at line 35 of file app.py.

00035 
00036     def add_settings(self):
00037         devel_group = obnamlib.option_group['devel']
00038         perf_group = obnamlib.option_group['perf']
00039     
00040         self.settings.string(['repository', 'r'], 'name of backup repository')
00041 
00042         self.settings.string(['client-name'], 'name of client (%default)',
00043                            default=self.deduce_client_name())
00044 
00045         self.settings.bytesize(['node-size'],
00046                              'size of B-tree nodes on disk '
00047                                  '(default: %default)',
00048                               default=obnamlib.DEFAULT_NODE_SIZE,
00049                               group=perf_group)
00050 
00051         self.settings.bytesize(['chunk-size'],
00052                             'size of chunks of file data backed up '
00053                                  '(default: %default)',
00054                              default=obnamlib.DEFAULT_CHUNK_SIZE,
00055                               group=perf_group)
00056 
00057         self.settings.bytesize(['upload-queue-size'],
00058                             'length of upload queue for B-tree nodes '
00059                                  '(default: %default)',
00060                             default=obnamlib.DEFAULT_UPLOAD_QUEUE_SIZE,
00061                             group=perf_group)
00062 
00063         self.settings.bytesize(['lru-size'],
00064                              'size of LRU cache for B-tree nodes '
00065                                  '(default: %default)',
00066                              default=obnamlib.DEFAULT_LRU_SIZE,
00067                              group=perf_group)
00068 
00069         self.settings.string_list(['trace'],
00070                                 'add to filename patters for which trace '
00071                                 'debugging logging happens')
00072 
00073         
00074         self.settings.integer(['idpath-depth'],
00075                               'depth of chunk id mapping',
00076                               default=obnamlib.IDPATH_DEPTH,
00077                               group=perf_group)
00078         self.settings.integer(['idpath-bits'],
00079                               'chunk id level size',
00080                               default=obnamlib.IDPATH_BITS,
00081                               group=perf_group)
00082         self.settings.integer(['idpath-skip'],
00083                               'chunk id mapping lowest bits skip',
00084                               default=obnamlib.IDPATH_SKIP,
00085                               group=perf_group)
00086 
00087         self.settings.boolean(['quiet'], 'be silent')
00088 
00089         self.settings.boolean(['pretend', 'dry-run', 'no-act'],
00090                            'do not actually change anything (works with '
00091                            'backup, forget and restore only, and may only '
00092                            'simulate approximately real behavior)')
00093                            
00094         self.settings.string(['pretend-time'],
00095                              'pretend it is TIMESTAMP (YYYY-MM-DD HH:MM:SS); '
00096                                 'this is only useful for testing purposes',
00097                              metavar='TIMESTAMP',
00098                              group=devel_group)
00099 
00100         self.settings.integer(['lock-timeout'],
00101                               'when locking in the backup repository, '
00102                                 'wait TIMEOUT seconds for an existing lock '
00103                                 'to go away before giving up',
00104                               metavar='TIMEOUT',
00105                               default=60)
00106 
00107         self.settings.integer(['crash-limit'],
00108                               'artificially crash the program after COUNTER '
00109                                 'files written to the repository; this is '
00110                                 'useful for crash testing the application, '
00111                                 'and should not be enabled for real use; '
00112                                 'set to 0 to disable (disabled by default)',
00113                               metavar='COUNTER',
00114                               group=devel_group)
00115 
00116         # The following needs to be done here, because it needs
00117         # to be done before option processing. This is a bit ugly,
00118         # but the best we can do with the current cliapp structure.
00119         # Possibly cliapp will provide a better hook for us to use
00120         # later on, but this is reality now.
00121 
00122         self.setup_ttystatus()
00123 
00124         self.pm = obnamlib.PluginManager()
00125         self.pm.locations = [self.plugins_dir()]
00126         self.pm.plugin_arguments = (self,)
00127         
00128         self.setup_hooks()
00129 
00130         self.fsf = obnamlib.VfsFactory()
00131 
00132         self.pm.load_plugins()
00133         self.pm.enable_plugins()
00134         self.hooks.call('plugins-loaded')

Here is the call graph for this function:

Definition at line 135 of file app.py.

00135 
00136     def deduce_client_name(self):
00137         return socket.gethostname()

Here is the caller graph for this function:

Log current configuration into the log file.

Definition at line 178 of file app.py.

00178 
00179     def log_config(self):
00180         '''Log current configuration into the log file.'''
00181         f = StringIO.StringIO()
00182         self.settings.dump_config(f)
00183         logging.debug('Current configuration:\n%s' % f.getvalue())

Here is the caller graph for this function:

def obnamlib.app.App.open_repository (   self,
  create = False,
  repofs = None 
)

Definition at line 189 of file app.py.

00189 
00190     def open_repository(self, create=False, repofs=None): # pragma: no cover
00191         logging.debug('opening repository (create=%s)' % create)
00192         tracing.trace('repofs=%s' % repr(repofs))
00193         repopath = self.settings['repository']
00194         if repofs is None:
00195             repofs = self.fsf.new(repopath, create=create)
00196             if self.settings['crash-limit'] > 0:
00197                 repofs.crash_limit = self.settings['crash-limit']
00198             repofs.connect()
00199         else:
00200             repofs.reinit(repopath)
00201         return obnamlib.Repository(repofs, 
00202                                     self.settings['node-size'],
00203                                     self.settings['upload-queue-size'],
00204                                     self.settings['lru-size'],
00205                                     self.hooks,
00206                                     self.settings['idpath-depth'],
00207                                     self.settings['idpath-bits'],
00208                                     self.settings['idpath-skip'],
00209                                     self.time,
00210                                     self.settings['lock-timeout'],
00211                                     self.settings['client-name'])

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 152 of file app.py.

00152 
00153     def plugins_dir(self):
00154         return os.path.join(os.path.dirname(obnamlib.__file__), 'plugins')

def obnamlib.app.App.process_args (   self,
  args 
)

Definition at line 162 of file app.py.

00162 
00163     def process_args(self, args):
00164         try:
00165             if self.settings['quiet']:
00166                 self.ts.disable()
00167             self.log_config()
00168             for pattern in self.settings['trace']:
00169                 tracing.trace_add_pattern(pattern)
00170             self.hooks.call('config-loaded')
00171             cliapp.Application.process_args(self, args)
00172             self.hooks.call('shutdown')
00173             logging.info('Obnam ends')
00174         except larch.Error, e:
00175             logging.critical(str(e))
00176             sys.stderr.write('ERROR: %s\n' % str(e))
00177             sys.exit(1)

Here is the call graph for this function:

Definition at line 138 of file app.py.

00138 
00139     def setup_hooks(self):
00140         self.hooks = obnamlib.HookManager()
00141         self.hooks.new('plugins-loaded')
00142         self.hooks.new('config-loaded')
00143         self.hooks.new('shutdown')
00144 
00145         # The Repository class defines some hooks, but the class
00146         # won't be instantiated until much after plugins are enabled,
00147         # and since all hooks must be defined when plugins are enabled,
00148         # we create one instance here, which will immediately be destroyed.
00149         # FIXME: This is fugly.
00150         obnamlib.Repository(None, 1000, 1000, 100, self.hooks, 10, 10, 10,
00151                             self.time, 0, '')

Definition at line 155 of file app.py.

00155 
00156     def setup_logging(self):
00157         log = self.settings['log']
00158         if log and log != 'syslog' and not os.path.exists(log):
00159             fd = os.open(log, os.O_WRONLY | os.O_CREAT, 0600)
00160             os.close(fd)
00161         cliapp.Application.setup_logging(self)

Definition at line 184 of file app.py.

00184 
00185     def setup_ttystatus(self):
00186         self.ts = ttystatus.TerminalStatus(period=0.25)
00187         if self.settings['quiet']:
00188             self.ts.disable()

Here is the caller graph for this function:

def obnamlib.app.App.time (   self)
Return current time in seconds since epoch.

This is a wrapper around time.time() so that it can be overridden
with the --pretend-time setting.

Definition at line 212 of file app.py.

00212 
00213     def time(self):
00214         '''Return current time in seconds since epoch.
00215         
00216         This is a wrapper around time.time() so that it can be overridden
00217         with the --pretend-time setting.
00218         
00219         '''
00220 
00221         s = self.settings['pretend-time']
00222         if s:
00223             t = time.strptime(s, '%Y-%m-%d %H:%M:%S')
00224             return time.mktime(t)
00225         else:
00226             return time.time()
00227 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 129 of file app.py.

Definition at line 139 of file app.py.

Definition at line 123 of file app.py.

Definition at line 185 of file app.py.


The documentation for this class was generated from the following file: