Mercurial > hg > silvermirror
changeset 15:743c920bc041
fix password prompt
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 09 May 2013 21:42:37 -0700 |
parents | 5f95af14b51c |
children | 76eac0c9953a |
files | setup.py silvermirror/unify.py silvermirror/unison.py |
diffstat | 3 files changed, 22 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Sun Mar 24 12:46:35 2013 -0700 +++ b/setup.py Thu May 09 21:42:37 2013 -0700 @@ -1,10 +1,10 @@ from setuptools import setup, find_packages -version = '0.1.1' +version = '0.2' setup(name='silvermirror', version=version, - description="mirror files", + description="mirror files across hosts", long_description="""\ """, classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
--- a/silvermirror/unify.py Sun Mar 24 12:46:35 2013 -0700 +++ b/silvermirror/unify.py Thu May 09 21:42:37 2013 -0700 @@ -2,7 +2,6 @@ import getpass import os -import pexpect import socket import subprocess import sys @@ -27,9 +26,16 @@ main['basedir'] = home() main['ignore'] = main.get('ignore', '').split() # patterns to ignore - not used main['hosts'] = main.get('hosts', '').split() - main['password'] = main.get('password', 'true') # XXX not used main['timeout'] = float(main.get('timeout', '10.')) + # password prompt + truth = dict([(str(i).lower(), i) for i in (True, False)]) + password = main.get('password', 'true') + try: + main['password'] = truth[password.lower()] + except KeyError: + raise KeyError("password must be True or False (You gave: '%s')" % password) + ### resources for resource in config: @@ -71,7 +77,7 @@ s.settimeout(conf['main']['timeout']) if test: print 'Resolving %s' % host - try: + try: s.connect((host, 22)) s.close() except (socket.gaierror, socket.timeout, socket.error): @@ -115,7 +121,7 @@ os.chdir(conf['main']['basedir']) for resource in resources: for host in hosts: - reflector.sync(host, resource, resources[resource]['ignore'], pw, test) + reflector.sync(host, resource, resources[resource]['ignore'], pw.get('host'), test) os.chdir(cwd) def main(args=sys.argv[1:]): @@ -127,7 +133,7 @@ action='append', default=None) parser.add_option('--no-password', dest='password', action='store_false', default=True) - parser.add_option('--test', dest='test', + parser.add_option('--test', dest='test', action='store_true', default=False) (options, args) = parser.parse_args()
--- a/silvermirror/unison.py Sun Mar 24 12:46:35 2013 -0700 +++ b/silvermirror/unison.py Thu May 09 21:42:37 2013 -0700 @@ -3,7 +3,7 @@ """ import pexpect - +import subprocess from interface import Reflector class unison(Reflector): @@ -16,8 +16,11 @@ 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 - + if password: + child = pexpect.spawn(command, timeout=36000, maxread=1) + child.expect('password: ') + child.sendline(password) + print child.read() # XXX -> logging + else: + # XXX should not use shell=True + subprocess.call(command, shell=True)