~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to setup/installer/__init__.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-02-27 07:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 74.
  • Revision ID: package-import@ubuntu.com-20140227074806-64wdebb3ptosxhhx
Tags: upstream-1.25.0+dfsg
ImportĀ upstreamĀ versionĀ 1.25.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
7
7
__docformat__ = 'restructuredtext en'
8
8
 
9
 
import subprocess, tempfile, os, time
 
9
import subprocess, tempfile, os, time, socket
10
10
 
11
11
from setup import Command, installer_name
12
12
from setup.build_environment import HOST, PROJECT
36
36
            return True
37
37
    return False
38
38
 
 
39
def is_host_reachable(name):
 
40
    try:
 
41
        socket.create_connection((name, 22), 5).close()
 
42
        return True
 
43
    except:
 
44
        return False
 
45
 
39
46
class Rsync(Command):
40
47
 
41
48
    description = 'Sync source tree from development machine'
50
57
        self.info(cmd)
51
58
        subprocess.check_call(cmd, shell=True, env=env)
52
59
 
 
60
def push(host, vmname, available):
 
61
    if vmname is None:
 
62
        hostname = host.partition(':')[0].partition('@')[-1]
 
63
        ok = is_host_reachable(hostname)
 
64
    else:
 
65
        ok = is_vm_running(vmname)
 
66
    if ok:
 
67
        available[vmname or host] = True
 
68
        rcmd = BASE_RSYNC + EXCLUDES + ['.', host]
 
69
        print '\n\nPushing to:', vmname or host, '\n'
 
70
        subprocess.check_call(rcmd, stdout=open(os.devnull, 'wb'))
53
71
 
54
72
class Push(Command):
55
73
 
57
75
 
58
76
    def run(self, opts):
59
77
        from threading import Thread
60
 
        threads = {}
 
78
        threads, available = {}, {}
61
79
        for host, vmname in {
62
80
                r'Owner@winxp:/cygdrive/c/Documents\ and\ Settings/Owner/calibre':'winxp',
63
81
                'kovid@ox:calibre':None,
64
82
                r'kovid@win7:/cygdrive/c/Users/kovid/calibre':'Windows 7',
65
83
                'kovid@win7-x64:calibre-src':'win7-x64',
 
84
                'kovid@tiny:calibre':None,
66
85
                }.iteritems():
67
 
            if vmname is None or is_vm_running(vmname):
68
 
                rcmd = BASE_RSYNC + EXCLUDES + ['.', host]
69
 
                print '\n\nPushing to:', vmname or host, '\n'
70
 
                threads[vmname or host] = thread = Thread(target=subprocess.check_call, args=(rcmd,),
71
 
                    kwargs={'stdout':open(os.devnull, 'wb')})
 
86
                threads[vmname or host] = thread = Thread(target=push, args=(host, vmname, available))
72
87
                thread.start()
73
88
        while threads:
74
89
            for name, thread in tuple(threads.iteritems()):
75
90
                thread.join(0.01)
76
91
                if not thread.is_alive():
77
 
                    print '\n\n', name, 'done'
 
92
                    if available.get(name, False):
 
93
                        print '\n\n', name, 'done'
78
94
                    threads.pop(name)
79
95
 
80
96