Mercurial > hg > silvermirror
annotate silvermirror/unison.py @ 1:9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
author | k0s <k0scist@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 23:36:42 -0400 |
parents | |
children | 743c920bc041 |
rev | line source |
---|---|
1
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
1 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
2 unison backend for silvermirror |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
3 """ |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
4 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
5 import pexpect |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
6 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
7 from interface import Reflector |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
8 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
9 class unison(Reflector): |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
10 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
11 def sync(self, host, resource, ignore=(), password=None, test=False): |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
12 command = ['unison', '-auto', '-batch', resource, 'ssh://%s/%s' % (host, resource)] |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
13 for i in ignore: |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
14 command.extend(('-ignore', "'Name %s'" % i)) |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
15 |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
16 command = ' '.join(command) |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
17 print command # XXX debug -- should go to logging |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
18 if not test: |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
19 child = pexpect.spawn(command, timeout=36000, maxread=1) |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
20 child.expect('password: ') |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
21 child.sendline(password[host]) |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
22 print child.read() # XXX -> logging |
9b139702a8f9
use a real backend architecture with an inteface and vastly simplify unify.py
k0s <k0scist@gmail.com>
parents:
diff
changeset
|
23 |