forked from blallo/Feedati
boyska
0ff7263d8e
- default task (up) - automatic clean actions: doit clean -a now works! - FIX some commands (shell errors in clean actions) - private tasks (doit list is not a mess anymore; doit list -p is)
68 lines
1.8 KiB
Python
68 lines
1.8 KiB
Python
import subprocess
|
|
|
|
from doit import loader
|
|
|
|
def wait_net_service(server, port, timeout=None):
|
|
""" Wait for network service to appear
|
|
@param timeout: in seconds, if None or 0 wait forever
|
|
@return: True of False, if timeout is None may return only True or
|
|
throw unhandled network exception
|
|
"""
|
|
import socket
|
|
import errno
|
|
|
|
s = socket.socket()
|
|
if timeout:
|
|
from time import time as now
|
|
# time module is needed to calc timeout shared between two exceptions
|
|
end = now() + timeout
|
|
|
|
while True:
|
|
try:
|
|
if timeout:
|
|
next_timeout = end - now()
|
|
if next_timeout < 0:
|
|
return False
|
|
else:
|
|
s.settimeout(next_timeout)
|
|
s.connect((server, port))
|
|
except socket.timeout as err:
|
|
# this exception occurs only if timeout is set
|
|
if timeout:
|
|
return False
|
|
except socket.error as err:
|
|
# catch timeout exception from underlying network library
|
|
# this one is different from socket.timeout
|
|
if type(err.args) != tuple or err[0] != errno.ETIMEDOUT:
|
|
raise
|
|
else:
|
|
s.close()
|
|
return True
|
|
|
|
|
|
def up2date_anyimages():
|
|
cmd = "docker images -q feedati/*".split()
|
|
output = subprocess.check_output(cmd).strip()
|
|
if output:
|
|
return True
|
|
return False
|
|
|
|
|
|
def run(cmd, **kwargs):
|
|
def fun():
|
|
subprocess.check_call(cmd, **kwargs)
|
|
return True
|
|
return fun
|
|
|
|
|
|
def run_task_func(taskf):
|
|
ret = taskf()
|
|
tasks = loader.generate_tasks(taskf.__name__, ret, taskf.__doc__)
|
|
|
|
def fun():
|
|
for task in tasks:
|
|
task.execute()
|
|
return True
|
|
if tasks:
|
|
fun.__doc__ = '\n'.join(t.doc for t in tasks)
|
|
return fun
|