check_port_listening: workaround for sheband limitation, reduce to a single file
The whole code is small enough and having the template in a separate file only made editing more annoying.
... | @@ -26,24 +26,34 @@ | ... | @@ -26,24 +26,34 @@ |
# | # | ||
############################################################################## | ############################################################################## | ||
from slapos.recipe.librecipe import GenericBaseRecipe | from slapos.recipe.librecipe import GenericBaseRecipe | ||
from zc.buildout.easy_install import _safe_arg, script_header | |||
import sys | import sys | ||
template = script_header + r""" | |||
|
|||
# BEWARE: This file is operated by slapgrid | |||
# BEWARE: It will be overwritten automatically | |||
import socket | |||
import sys | |||
addr = "%(hostname)s", %(port)s | |||
try: | |||
socket.create_connection(addr).close() | |||
except (socket.error, socket.timeout): | |||
sys.stderr.write("%%s on %%s isn't listening\n" %% addr) | |||
sys.exit(127) | |||
""" | |||
class Recipe(GenericBaseRecipe): | class Recipe(GenericBaseRecipe): | ||
""" | """ | ||
Check listening port promise | Check listening port promise | ||
""" | """ | ||
def install(self): | def install(self): | ||
config = dict( | promise = self.createExecutable(self.options['path'], template % { | ||
hostname=self.options['hostname'], | 'python': _safe_arg(sys.executable), | ||
port=self.options['port'], | 'hostname': self.options['hostname'], | ||
python_path=sys.executable, | 'port': self.options['port'], | ||
) | }) | ||
vnc_promise = self.createExecutable( | |||
self.options['path'], | |||
self.substituteTemplate( | |||
self.getTemplateFilename('socket_connection_attempt.py.in'), | |||
config)) | |||
return [vnc_promise] | return [promise] |