view silvermirror/unison.py @ 7:d3d0b9414e19

add idea for portable silvermirror
author k0s <k0scist@gmail.com>
date Sun, 20 Dec 2009 18:56:12 -0500
parents 9b139702a8f9
children 743c920bc041
line wrap: on
line source

"""
unison backend for silvermirror
"""

import pexpect

from interface import Reflector

class unison(Reflector):

    def sync(self, host, resource, ignore=(), password=None, test=False):
        command = ['unison', '-auto', '-batch', resource, 'ssh://%s/%s' % (host, resource)]
        for i in ignore:
            command.extend(('-ignore', "'Name %s'" % i))

        command = ' '.join(command)
        print command # XXX debug -- should go to logging
        if not test:
            child = pexpect.spawn(command, timeout=36000, maxread=1)
            child.expect('password: ')
            child.sendline(password[host])
            print child.read() # XXX -> logging