Commit 829c040a authored by Alain Takoudjou's avatar Alain Takoudjou

Update lamp recipe and remove MySQLdb dependance

parent f009116a
...@@ -157,16 +157,29 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -157,16 +157,29 @@ class BaseRecipe(BaseSlapRecipe):
"""Start process which can launch python scripts, move or remove files or """Start process which can launch python scripts, move or remove files or
directories when installing software. directories when installing software.
""" """
if not self.options.has_key('delete') and not \ if not self.options.has_key('delete') and not self.options.has_key('rename') and not\
self.options.has_key('rename') and not self.options.has_key('script'): self.options.has_key('chmod') and not self.options.has_key('script'):
return return
delete = [] delete = []
chmod = []
data = []
rename = [] rename = []
rename_list = "" rename_list = ""
data = {} argument = [self.options['lampconfigure_directory'].strip()]
if not self.options.has_key('file_token'):
argument = argument + ["-d", mysql_conf['mysql_database'],
"-H", mysql_conf['mysql_host'], "-P", mysql_conf['mysql_port'],
"-p", mysql_conf['mysql_password'], "-u", mysql_conf['mysql_user'],
"--table", self.options['table_name'].strip(), "--cond",
self.options['constraint'].strip()]
else:
argument = argument + ["-f", self.options['file_token'].strip()]
argument += ["-t", document_root]
if self.options.has_key('delete'): if self.options.has_key('delete'):
delete = ["delete"]
for fname in self.options['delete'].split(','): for fname in self.options['delete'].split(','):
delete.append(os.path.join(document_root, fname.strip())) delete.append(fname.strip())
if self.options.has_key('rename'): if self.options.has_key('rename'):
for fname in self.options['rename'].split(','): for fname in self.options['rename'].split(','):
if fname.find("=>") < 0: if fname.find("=>") < 0:
...@@ -176,28 +189,22 @@ class BaseRecipe(BaseSlapRecipe): ...@@ -176,28 +189,22 @@ class BaseRecipe(BaseSlapRecipe):
fname.append(old_name + '-' + mysql_conf['mysql_user']) fname.append(old_name + '-' + mysql_conf['mysql_user'])
else: else:
fname = fname.split("=>") fname = fname.split("=>")
rename.append(dict(old = os.path.join(document_root, fname[0].strip()), cmd = ["rename"]
new = os.path.join(document_root, fname[1].strip()) if self.options.has_key('rename_chmod'):
)) cmd += ["--chmod", self.options['rename_chmod'].strip()]
rename_list += fname[0] + "=> " + fname[1] + ", " rename.append(cmd + [fname[0].strip(), fname[1].strip()])
if not self.options.has_key('file_token'): rename_list += fname[0] + "=>" + fname[1] + " "
token = dict( if self.options.has_key('chmod'):
table = self.options['table_name'].strip(), chmod = ["chmod ", self.options['mode'].strip()]
constraint=self.options['constraint'].strip() for fname in self.options['chmod'].split(','):
) chmod.append(fname.strip())
else:
token = os.path.join(document_root, self.options['file_token'].strip())
if self.options.has_key('script') and \ if self.options.has_key('script') and \
self.options['script'].strip().endswith(".py"): self.options['script'].strip().endswith(".py"):
data = dict(htdocs = document_root, data = ["run", self.options['script'].strip(), "-v", base_url]
base_url = url,
script = self.options['script'].strip(),
renamed = rename_list
)
self.path_list.extend(zc.buildout.easy_install.scripts( self.path_list.extend(zc.buildout.easy_install.scripts(
[('configureInstall', __name__ + '.runner', 'executeRunner')], self.ws, [('configureInstall', __name__ + '.runner', 'executeRunner')], self.ws,
sys.executable, self.wrapper_directory, arguments=[delete, rename, sys.executable, self.wrapper_directory, arguments=[argument, delete, rename,
token, mysql_conf,data])) chmod, data]))
return rename_list return rename_list
class Static(BaseRecipe): class Static(BaseRecipe):
......
import os
import time
import sys import sys
import shutil import subprocess
import MySQLdb
def executeRunner(args): def executeRunner(args):
"""Start the instance runner. this may run a python script, move or/and rename """Start the instance configure. this may run a python script, move or/and rename
file or directory when dondition is filled. the condition may be when file exist or when an entry file or directory when dondition is filled. the condition may be when file exist or when an entry
exist into database. exist into database.
""" """
delete, rename, token, mysql_config, script_data = args arguments, delete, rename, chmod, data = args
timeout = 5; if delete != []:
while True: print "Calling lampconfigure with 'delete' arguments"
if not checkAction(token, mysql_config): result = subprocess.Popen(arguments + delete)
print "Waiting for 3s and retrying" result.wait()
time.sleep(3) if rename != []:
continue for parameters in rename:
time.sleep(timeout) print "Calling lampconfigure with 'rename' arguments"
for path in delete: result = subprocess.Popen(arguments + parameters)
if not os.path.exists(path): result.wait()
print "Error when deleting: '%s': no such file or directory" % path if chmod != []:
continue print "Calling lampconfigure with 'chmod' arguments"
if os.path.isdir(path): result = subprocess.Popen(arguments + chmod)
shutil.rmtree(path) result.wait()
else: if data != []:
os.remove(path) print "Calling lampconfigure with 'run' arguments"
for data in rename: result = subprocess.Popen(arguments + data)
if not os.path.exists(data['old']): result.wait()
print "Error when moving: '%s': no such file or directory" % data['old']
continue
os.rename(data['old'], data['new'])
if script_data != {}:
script = script_data['script']
if os.path.exists(script):
import subprocess
#run python script with predefined data
return_code = subprocess.call([sys.executable, script, script_data['base_url'],
script_data['htdocs'], script_data['renamed'],
mysql_config['mysql_user'], mysql_config['mysql_password'],
mysql_config['mysql_database'], mysql_config['mysql_host']])
if return_code != 0:
print "Error: execution of script %r failed with code: %s" % (script, return_code)
else:
print "Error: can not read file '%s'" % script
return return
def checkAction(token, mysql_config):
"""Check if condition is filled. If token is string(that represent a path), the function check if file exist
otherwise token is a dictionary and mysql_config is used to check condition into database
"""
if type(token) is dict:
try:
conn = MySQLdb.connect (host = mysql_config['mysql_host'],
port = int(mysql_config['mysql_port']),
user = mysql_config['mysql_user'],
passwd = mysql_config['mysql_password'],
db = mysql_config['mysql_database'])
except:
#Mysql is not ready yet?...
return False
if token['table'] == "**":
#only detect if mysql has been started
conn.close()
return True
cursor = conn.cursor ()
cursor.execute("SHOW TABLES LIKE '%" + token['table'] + "'") #Check if table has been created
row = cursor.fetchone ()
if row == None:
conn.close()
return False
else:
token['table'] = row[0]
cursor.execute ("SELECT * FROM " + token['table'] + " WHERE " + token['constraint'])
row = cursor.fetchone ()
conn.close()
if row == None:
return False
else:
return True
else:
return os.path.exists(token)
\ No newline at end of file
<?php
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
$i = 0;
$i++;
/* Server parameters */
$cfg['Servers'][$i]['host'] = '%(mysql_host)s';
$cfg['Servers'][$i]['port'] = '%(mysql_port)s';
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['user'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
/* rajk - for blobstreaming */
$cfg['Servers'][$i]['bs_garbage_threshold'] = 50;
$cfg['Servers'][$i]['bs_repository_threshold'] = '32M';
$cfg['Servers'][$i]['bs_temp_blob_timeout'] = 600;
$cfg['Servers'][$i]['bs_temp_log_threshold'] = '32M';
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>
...@@ -34,13 +34,14 @@ extends = ...@@ -34,13 +34,14 @@ extends =
../component/lxml-python/buildout.cfg ../component/lxml-python/buildout.cfg
../component/zlib/buildout.cfg ../component/zlib/buildout.cfg
../component/stunnel/buildout.cfg ../component/stunnel/buildout.cfg
../component/pycrypto-python/buildout.cfg
../component/mysql-python/buildout.cfg ../component/mysql-python/buildout.cfg
[eggs] [eggs]
recipe = zc.recipe.egg recipe = zc.recipe.egg
eggs = eggs =
${lxml-python:egg} ${lxml-python:egg}
${mysql-python:egg} ${pycrypto-python:egg}
[application] [application]
#XXX-Cedric : ugly hack to work around h.r.cmmi unrespectful behavior, so that #XXX-Cedric : ugly hack to work around h.r.cmmi unrespectful behavior, so that
......
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