mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Only try to push if a connection to the remote host succeeds within 5 seconds
This commit is contained in:
parent
4dac0c0a08
commit
5dc59bacc6
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import subprocess, tempfile, os, time
|
import subprocess, tempfile, os, time, socket
|
||||||
|
|
||||||
from setup import Command, installer_name
|
from setup import Command, installer_name
|
||||||
from setup.build_environment import HOST, PROJECT
|
from setup.build_environment import HOST, PROJECT
|
||||||
@ -36,6 +36,13 @@ def is_vm_running(name):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_host_reachable(name):
|
||||||
|
try:
|
||||||
|
socket.create_connection((name, 22), 5).close()
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
class Rsync(Command):
|
class Rsync(Command):
|
||||||
|
|
||||||
description = 'Sync source tree from development machine'
|
description = 'Sync source tree from development machine'
|
||||||
@ -50,6 +57,16 @@ class Rsync(Command):
|
|||||||
self.info(cmd)
|
self.info(cmd)
|
||||||
subprocess.check_call(cmd, shell=True, env=env)
|
subprocess.check_call(cmd, shell=True, env=env)
|
||||||
|
|
||||||
|
def push(host, vmname):
|
||||||
|
if vmname is None:
|
||||||
|
hostname = host.partition(':')[0].partition('@')[-1]
|
||||||
|
ok = is_host_reachable(hostname)
|
||||||
|
else:
|
||||||
|
ok = is_vm_running(vmname)
|
||||||
|
if ok:
|
||||||
|
rcmd = BASE_RSYNC + EXCLUDES + ['.', host]
|
||||||
|
print '\n\nPushing to:', vmname or host, '\n'
|
||||||
|
subprocess.check_call(rcmd, stdout=open(os.devnull, 'wb'))
|
||||||
|
|
||||||
class Push(Command):
|
class Push(Command):
|
||||||
|
|
||||||
@ -63,12 +80,9 @@ class Push(Command):
|
|||||||
'kovid@ox:calibre':None,
|
'kovid@ox:calibre':None,
|
||||||
r'kovid@win7:/cygdrive/c/Users/kovid/calibre':'Windows 7',
|
r'kovid@win7:/cygdrive/c/Users/kovid/calibre':'Windows 7',
|
||||||
'kovid@win7-x64:calibre-src':'win7-x64',
|
'kovid@win7-x64:calibre-src':'win7-x64',
|
||||||
|
'kovid@tiny:calibre':None,
|
||||||
}.iteritems():
|
}.iteritems():
|
||||||
if vmname is None or is_vm_running(vmname):
|
threads[vmname or host] = thread = Thread(target=push, args=(host, vmname,))
|
||||||
rcmd = BASE_RSYNC + EXCLUDES + ['.', host]
|
|
||||||
print '\n\nPushing to:', vmname or host, '\n'
|
|
||||||
threads[vmname or host] = thread = Thread(target=subprocess.check_call, args=(rcmd,),
|
|
||||||
kwargs={'stdout':open(os.devnull, 'wb')})
|
|
||||||
thread.start()
|
thread.start()
|
||||||
while threads:
|
while threads:
|
||||||
for name, thread in tuple(threads.iteritems()):
|
for name, thread in tuple(threads.iteritems()):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user