1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
#
# $Id: sync.py,v 1.2 1999/12/16 10:00:32 rob Exp $
#
# Copyright 1999 Rob Tillotson <robt@debian.org>
# All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and
# its documentation for any purpose and without fee or royalty is
# hereby granted, provided that the above copyright notice appear in
# all copies and that both the copyright notice and this permission
# notice appear in supporting documentation or portions thereof,
# including modifications, that you you make.
#
# THE AUTHOR ROB TILLOTSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE!
#
"""Synchronization command-line utility.
"""
__version__ = '$Id: sync.py,v 1.2 1999/12/16 10:00:32 rob Exp $'
__copyright__ = 'Copyright 1999 Rob Tillotson <robt@debian.org>'
import string, sys, os, traceback
import Pyrite
from Pyrite import _
from Pyrite.Application import Application
class App(Application):
name = 'Pyrite Sync'
version = Pyrite.version
author = Pyrite.author
description = _("Run a series of conduits.")
extra_help = _("At the moment, this only works for the default user.")
def __init__(self):
Application.__init__(self)
self.config_path = 'Pyrite::Sync'
def run_conduits(self, conduits=[]):
cl = []
for c in conduits:
try:
p = self.get_plugin('Conduit', c)
cl.append(p)
except:
self.error(_("failed to load conduit '%s'") % c, 'warning')
continue
# do pre-sync
cl0 = []
for c in cl:
try:
if c.presync(self):
cl0.append(c)
else:
self.log(_("conduit '%s' has nothing to do, skipping it") % c.name)
except:
a = sys.exc_info()
self.error(_("during presync: %s: %s") % (a[0].__name__, a[1].args), 'error')
if self.has_option('debug'):
traceback.print_tb(a[2])
self.log(_("Connecting"))
self.connect(immediate=1)
# actual sync
for c in cl0:
try: c(self)
except:
a = sys.exc_info()
self.error(_("during sync: %s: %s") % (a[0].__name__, a[1].args), 'error')
if self.has_option('debug'):
traceback.print_tb(a[2])
self.log(_("Disconnecting"))
self.disconnect()
# postsync
for c in cl:
try: c.postsync(self)
except:
a = sys.exc_info()
self.error(_("during postsync: %s: %s") % (a[0].__name__, a[1].args), 'error')
if self.has_option('debug'):
traceback.print_tb(a[2])
def run_session(self):
c = self.registry.get('Pyrite::Sync::conduits',
self.registry.get('Pyrite::Sync::Conduits',''))
if type(c) == type(''):
c = filter(None, map(string.strip, string.split(c, ',')))
if not c: return None
self.run_conduits(c)
def run(self, argv):
self.run_session()
|