Commit cb4f9605 authored by Łukasz Nowak's avatar Łukasz Nowak

- follow PEP8 specification of code


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44084 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a894ec56
...@@ -476,14 +476,14 @@ class Recipe(BaseSlapRecipe): ...@@ -476,14 +476,14 @@ class Recipe(BaseSlapRecipe):
apache_conf['pid_file'] = os.path.join(self.run_directory, apache_conf['pid_file'] = os.path.join(self.run_directory,
prefix + '.pid') prefix + '.pid')
apache_conf['lock_file'] = os.path.join(self.run_directory, apache_conf['lock_file'] = os.path.join(self.run_directory,
prefix+'.lock') prefix + '.lock')
apache_conf['ip'] = ip apache_conf['ip'] = ip
apache_conf['port'] = port apache_conf['port'] = port
apache_conf['server_admin'] = 'admin@' apache_conf['server_admin'] = 'admin@'
apache_conf['error_log'] = os.path.join(self.log_directory, apache_conf['error_log'] = os.path.join(self.log_directory,
prefix+'-error.log') prefix + '-error.log')
apache_conf['access_log'] = os.path.join(self.log_directory, apache_conf['access_log'] = os.path.join(self.log_directory,
prefix+'-access.log') prefix + '-access.log')
return apache_conf return apache_conf
def _writeApacheConfiguration(self, prefix, apache_conf): def _writeApacheConfiguration(self, prefix, apache_conf):
...@@ -498,14 +498,14 @@ class Recipe(BaseSlapRecipe): ...@@ -498,14 +498,14 @@ class Recipe(BaseSlapRecipe):
backend_port=self.backend_port, backend_port=self.backend_port,
backend_path='/', backend_path='/',
port=apache_conf['port'], port=apache_conf['port'],
vhname=path.replace('/',''), vhname=path.replace('/', ''),
) )
rewrite_rule = rewrite_rule_template % d rewrite_rule = rewrite_rule_template % d
apache_conf.update(**dict( apache_conf.update(**dict(
path_enable=path, path_enable=path,
rewrite_rule=rewrite_rule rewrite_rule=rewrite_rule
)) ))
return self.createConfigurationFile(prefix+'.conf', return self.createConfigurationFile(prefix + '.conf',
pkg_resources.resource_string(__name__, pkg_resources.resource_string(__name__,
'template/apache.zope.conf.in') % apache_conf) 'template/apache.zope.conf.in') % apache_conf)
...@@ -520,21 +520,21 @@ SSLRandomSeed connect builtin ...@@ -520,21 +520,21 @@ SSLRandomSeed connect builtin
self.getLocalIPv4Address(), CONFIG['login_apache_port_base'] + index) self.getLocalIPv4Address(), CONFIG['login_apache_port_base'] + index)
apache_conf['server_name'] = '%s' % apache_conf['ip'] apache_conf['server_name'] = '%s' % apache_conf['ip']
apache_conf['ssl_snippet'] = ssl_template % CONFIG apache_conf['ssl_snippet'] = ssl_template % CONFIG
apache_config_file = self._writeApacheConfiguration('login_apache_%s'% index, apache_config_file = self._writeApacheConfiguration('login_apache_%s' % index,
apache_conf) apache_conf)
self.path_list.append(apache_config_file) self.path_list.append(apache_config_file)
self.path_list.extend(zc.buildout.easy_install.scripts([( self.path_list.extend(zc.buildout.easy_install.scripts([(
'login_apache_%s'% index, 'login_apache_%s' % index,
__name__+'.apache', 'runApache')], self.ws, __name__ + '.apache', 'runApache')], self.ws,
sys.executable, self.wrapper_directory, arguments=[ sys.executable, self.wrapper_directory, arguments=[
dict( dict(
required_path_list = [CONFIG['login_certificate'], required_path_list=[CONFIG['login_certificate'],
CONFIG['login_key']], CONFIG['login_key']],
binary=self.options['httpd_binary'], binary=self.options['httpd_binary'],
config=apache_config_file config=apache_config_file
) )
])) ]))
self.connection_dict['login_%s'% index] = '%(ip)s:%(port)s'% apache_conf self.connection_dict['login_%s' % index] = '%(ip)s:%(port)s' % apache_conf
def installKeyAuthorisationApache(self, index): def installKeyAuthorisationApache(self, index):
ssl_template = """SSLEngine on ssl_template = """SSLEngine on
...@@ -548,7 +548,7 @@ SSLCARevocationPath %(ca_crl)s""" ...@@ -548,7 +548,7 @@ SSLCARevocationPath %(ca_crl)s"""
self.getLocalIPv4Address(), self.getLocalIPv4Address(),
CONFIG['key_auth_apache_port_base'] + index) CONFIG['key_auth_apache_port_base'] + index)
apache_conf['ssl_snippet'] = ssl_template % CONFIG apache_conf['ssl_snippet'] = ssl_template % CONFIG
prefix = 'ssl_key_auth_apache_%s'% index prefix = 'ssl_key_auth_apache_%s' % index
rewrite_rule_template = \ rewrite_rule_template = \
"RewriteRule (.*) http://%(backend_ip)s:%(backend_port)s%(key_auth_path)s$1 [L,P]" "RewriteRule (.*) http://%(backend_ip)s:%(backend_port)s%(key_auth_path)s$1 [L,P]"
path_template = pkg_resources.resource_string(__name__, path_template = pkg_resources.resource_string(__name__,
...@@ -560,7 +560,7 @@ SSLCARevocationPath %(ca_crl)s""" ...@@ -560,7 +560,7 @@ SSLCARevocationPath %(ca_crl)s"""
backend_port=self.backend_port, backend_port=self.backend_port,
backend_path='/', backend_path='/',
port=apache_conf['port'], port=apache_conf['port'],
vhname=path.replace('/',''), vhname=path.replace('/', ''),
key_auth_path=self.parameter_dict['key_auth_path'], key_auth_path=self.parameter_dict['key_auth_path'],
) )
rewrite_rule = rewrite_rule_template % d rewrite_rule = rewrite_rule_template % d
...@@ -568,24 +568,24 @@ SSLCARevocationPath %(ca_crl)s""" ...@@ -568,24 +568,24 @@ SSLCARevocationPath %(ca_crl)s"""
path_enable=path, path_enable=path,
rewrite_rule=rewrite_rule rewrite_rule=rewrite_rule
)) ))
apache_config_file = self.createConfigurationFile(prefix+'.conf', apache_config_file = self.createConfigurationFile(prefix + '.conf',
pkg_resources.resource_string(__name__, pkg_resources.resource_string(__name__,
'template/apache.zope.conf.in') % apache_conf) 'template/apache.zope.conf.in') % apache_conf)
self.path_list.append(apache_config_file) self.path_list.append(apache_config_file)
self.path_list.extend(zc.buildout.easy_install.scripts([( self.path_list.extend(zc.buildout.easy_install.scripts([(
'key_auth_apache_%s'% index, 'key_auth_apache_%s' % index,
__name__+'.apache', 'runApache')], self.ws, __name__ + '.apache', 'runApache')], self.ws,
sys.executable, self.wrapper_directory, arguments=[ sys.executable, self.wrapper_directory, arguments=[
dict( dict(
required_path_list = [CONFIG['key_auth_certificate'], required_path_list=[CONFIG['key_auth_certificate'],
CONFIG['key_auth_key'], CONFIG['ca_certificate'], CONFIG['key_auth_key'], CONFIG['ca_certificate'],
CONFIG['ca_crl']], CONFIG['ca_crl']],
binary=self.options['httpd_binary'], binary=self.options['httpd_binary'],
config=apache_config_file config=apache_config_file
) )
])) ]))
self.connection_dict['key_auth_%s'% index] = \ self.connection_dict['key_auth_%s' % index] = \
'%(ip)s:%(port)s'% apache_conf '%(ip)s:%(port)s' % apache_conf
def installMysqlServer(self): def installMysqlServer(self):
mysql_conf = dict( mysql_conf = dict(
...@@ -631,11 +631,11 @@ SSLCARevocationPath %(ca_crl)s""" ...@@ -631,11 +631,11 @@ SSLCARevocationPath %(ca_crl)s"""
mysql_script = pkg_resources.resource_string(__name__, mysql_script = pkg_resources.resource_string(__name__,
'template/initmysql.sql.in') % mysql_conf 'template/initmysql.sql.in') % mysql_conf
self.path_list.extend(zc.buildout.easy_install.scripts([('mysql_update', self.path_list.extend(zc.buildout.easy_install.scripts([('mysql_update',
__name__+'.mysql', 'updateMysql')], self.ws, __name__ + '.mysql', 'updateMysql')], self.ws,
sys.executable, self.wrapper_directory, arguments=[mysql_command_list, sys.executable, self.wrapper_directory, arguments=[mysql_command_list,
mysql_script])) mysql_script]))
self.path_list.extend(zc.buildout.easy_install.scripts([('mysqld', self.path_list.extend(zc.buildout.easy_install.scripts([('mysqld',
__name__+'.mysql', 'runMysql')], self.ws, __name__ + '.mysql', 'runMysql')], self.ws,
sys.executable, self.wrapper_directory, arguments=[ sys.executable, self.wrapper_directory, arguments=[
initialise_command_list, { initialise_command_list, {
'mysqld_binary':self.options['mysqld_binary'], 'mysqld_binary':self.options['mysqld_binary'],
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import sys import sys
import time import time
def runApache(args): def runApache(args):
sleep = 60 sleep = 60
conf = args[0] conf = args[0]
......
...@@ -2,6 +2,7 @@ import os ...@@ -2,6 +2,7 @@ import os
import subprocess import subprocess
import time import time
def popenCommunicate(command_list, input=None): def popenCommunicate(command_list, input=None):
subprocess_kw = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT) subprocess_kw = dict(stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
if input is not None: if input is not None:
...@@ -15,6 +16,7 @@ def popenCommunicate(command_list, input=None): ...@@ -15,6 +16,7 @@ def popenCommunicate(command_list, input=None):
result)) result))
return result return result
def checkCertificateAuthority(ca_conf): def checkCertificateAuthority(ca_conf):
file_list = [ file_list = [
ca_conf['ca_key'], ca_conf['ca_key'],
...@@ -47,8 +49,9 @@ def checkCertificateAuthority(ca_conf): ...@@ -47,8 +49,9 @@ def checkCertificateAuthority(ca_conf):
pass pass
raise raise
def checkCertificate(common_name, key, certificate, ca_conf): def checkCertificate(common_name, key, certificate, ca_conf):
file_list = [ key, certificate ] file_list = [key, certificate]
ready = True ready = True
for f in file_list: for f in file_list:
if not os.path.exists(f): if not os.path.exists(f):
...@@ -87,10 +90,12 @@ def checkLoginCertificate(ca_conf): ...@@ -87,10 +90,12 @@ def checkLoginCertificate(ca_conf):
checkCertificate('Login Based Access', ca_conf['login_key'], checkCertificate('Login Based Access', ca_conf['login_key'],
ca_conf['login_certificate'], ca_conf) ca_conf['login_certificate'], ca_conf)
def checkKeyAuthCertificate(ca_conf): def checkKeyAuthCertificate(ca_conf):
checkCertificate('Key Based Access', ca_conf['key_auth_key'], checkCertificate('Key Based Access', ca_conf['key_auth_key'],
ca_conf['key_auth_certificate'], ca_conf) ca_conf['key_auth_certificate'], ca_conf)
def runCertificateAuthority(args): def runCertificateAuthority(args):
ca_conf = args[0] ca_conf = args[0]
while True: while True:
......
...@@ -4,12 +4,15 @@ import signal ...@@ -4,12 +4,15 @@ import signal
import subprocess import subprocess
import time import time
def execute(args): def execute(args):
"""Portable execution with process replacement""" """Portable execution with process replacement"""
# Note: Candidate for slapos.lib.recipe # Note: Candidate for slapos.lib.recipe
os.execv(args[0], args) os.execv(args[0], args)
child_pg = None child_pg = None
def sig_handler(signal, frame): def sig_handler(signal, frame):
print 'Received signal %r, killing children and exiting' % signal print 'Received signal %r, killing children and exiting' % signal
if child_pg is not None: if child_pg is not None:
...@@ -21,6 +24,7 @@ signal.signal(signal.SIGINT, sig_handler) ...@@ -21,6 +24,7 @@ signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler) signal.signal(signal.SIGQUIT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler) signal.signal(signal.SIGTERM, sig_handler)
def execute_with_signal_translation(args): def execute_with_signal_translation(args):
"""Run process as children and translate from SIGTERM to another signal""" """Run process as children and translate from SIGTERM to another signal"""
child = subprocess.Popen(args, close_fds=True, preexec_fn=os.setsid) child = subprocess.Popen(args, close_fds=True, preexec_fn=os.setsid)
......
...@@ -3,12 +3,13 @@ import subprocess ...@@ -3,12 +3,13 @@ import subprocess
import sys import sys
import time import time
def runMysql(args): def runMysql(args):
sleep = 60 sleep = 60
initialise_command_list = args[0] initialise_command_list = args[0]
mysql_conf = args[1] mysql_conf = args[1]
mysql_wrapper_list = [mysql_conf['mysqld_binary'], mysql_wrapper_list = [mysql_conf['mysqld_binary'],
'--defaults-file=%s'%mysql_conf['configuration_file']] '--defaults-file=%s' % mysql_conf['configuration_file']]
while True: while True:
# XXX: Protect with proper root password # XXX: Protect with proper root password
popen = subprocess.Popen(initialise_command_list, popen = subprocess.Popen(initialise_command_list,
...@@ -25,6 +26,7 @@ def runMysql(args): ...@@ -25,6 +26,7 @@ def runMysql(args):
sys.stderr.flush() sys.stderr.flush()
os.execl(mysql_wrapper_list[0], *mysql_wrapper_list) os.execl(mysql_wrapper_list[0], *mysql_wrapper_list)
def updateMysql(args): def updateMysql(args):
mysql_command_list = args[0] mysql_command_list = args[0]
mysql_script = args[1] mysql_script = args[1]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment