MYSQL and dependencies in app_install()

This commit is contained in:
Kload 2013-02-25 19:54:23 +01:00
parent 0dea51f5cb
commit 7ed0094a14
2 changed files with 74 additions and 49 deletions

View file

@ -12,9 +12,14 @@ import ldap.modlist as modlist
import json
import re
import getpass
import random
import string
if not __debug__:
import traceback
def random_password(length=8):
char_set = string.ascii_uppercase + string.digits + string.ascii_lowercase
return ''.join(random.sample(char_set,length))
def colorize(astr, color):
"""

View file

@ -3,8 +3,9 @@
import os
import sys
import json
import shutil
from urllib import urlopen, urlretrieve
from yunohost import YunoHostError, YunoHostLDAP, win_msg
from yunohost import YunoHostError, YunoHostLDAP, win_msg, random_password
from yunohost_domain import domain_list, domain_add
def app_fetchlist(url=None, name=None):
@ -53,7 +54,6 @@ def app_list(offset=None, limit=None, filter=None, raw=False):
"""
# TODO: List installed applications
# TODO: Implement fields to fetch
if offset: offset = int(offset)
else: offset = 0
@ -113,14 +113,17 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
# Fetch | Extract sources
with YunoHostLDAP() as yldap:
install_tmp = '/tmp/yunohost/install'
try: os.listdir(install_tmp)
except OSError: os.makedirs(install_tmp)
# Install from file
if "." in app:
install_from_file = True
app_tmp_folder = install_tmp + '/from_file'
if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder)
os.makedirs(app_tmp_folder)
if ".zip" in app:
extract_result = os.system('cd '+ os.getcwd() +' && unzip '+ app +' -d '+ app_tmp_folder)
@ -135,9 +138,11 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
with open(app_tmp_folder + '/manifest.webapp') as json_manifest:
manifest = json.loads(str(json_manifest.read()))
# Install from git
else:
install_from_file = False
app_tmp_folder = install_tmp +'/'+ app
if os.path.exists(app_tmp_folder): shutil.rmtree(app_tmp_folder)
app_dict = app_list(raw=True)
@ -155,26 +160,41 @@ def app_install(app, domain, path='/', label=None, public=False, protected=True)
# TODO: Check if exists another instance
# Handle domain if ain't already created
try:
domain_list(filter="virtualdomain="+ domain)
except YunoHostError:
domain_add([domain])
if ('debian' in manifest['dependencies']) and (len(manifest['dependencies']['debian']) > 0):
#os.system('apt-get update')
if os.system('apt-get install "'+ '" "'.join(manifest['dependencies']['debian']) +'"') != 0:
raise YunoHostError(1, _("Dependency installation failed: ") + dependency)
# TODO: Install dependencies
# TODO: Install npm, pip, gem and pear dependencies
for dependency in manifest['dependencies']['debian']:
print dependency
if 'webapp' in manifest['yunohost']:
if 'db' in manifest['yunohost']['webapp']:
db_user = manifest['yunohost']['uid'] # TODO: app.instance
db_user_pwd = random_password()
# TODO: Exec install script
# Need MySQL DB ?
if 'has_mysql_db' in manifest['yunohost']['webapp']['db'] and ((manifest['yunohost']['webapp']['db']['has_mysql_db'] == 'true') or (manifest['yunohost']['webapp']['db']['has_mysql_db'] == 'yes')):
mysql_root_pwd = open('/etc/yunohost/mysql', 'rb').read().rstrip()
mysql_command = 'mysql -u root -p'+ mysql_root_pwd +' -e "CREATE DATABASE '+ db_user +' ; GRANT ALL PRIVILEGES ON '+ db_user +'.* TO \''+ db_user +'\'@localhost IDENTIFIED BY \''+ db_user_pwd +'\';"'
if os.system(mysql_command) != 0:
raise YunoHostError(1, _("MySQL DB creation failed"))
if 'mysql_init_script' in manifest['yunohost']['webapp']['db']:
if os.system('mysql -u '+ db_user +' -p'+ db_user_pwd +' '+ db_user +' < '+ app_tmp_folder + manifest['yunohost']['webapp']['db']['mysql_init_script'] +' ;') != 0:
raise YunoHostError(1, _("MySQL DB init failed"))
# TODO: Check if MYSQL DB is needed and create it, then init DB if needed
# TODO: PgSQL/MongoDB ?
# TODO: Copy files to the right place
# TODO: Exec postinstall script
# TODO: Create appsettings
# TODO: Create appsettings and chmod it
# TODO: Configure apache/lemon with NPZE's scripts