import shutil import syslog import os import traceback """ Preparations to start web2py on later set readonly filesystem. """ __author__ = 'frank.sattelberger@bittwister.com' CONFIG_PATH = """/mnt/data/log/web2pylnksrcs/""" OLD_CONFIG_PATH = """/home/tool/config/web2pylnksrcs/""" WEB2PY = """/home/tool/web2py/""" def create_lnks(source, target, paths): try: if os.path.exists(OLD_CONFIG_PATH): shutil.rmtree(OLD_CONFIG_PATH) for path in paths: current_config_path = source + path current_web2py_path = target + path if not os.path.exists(target): os.makedirs(target) if not os.path.exists(current_web2py_path): if not os.path.exists(current_config_path): os.makedirs(current_config_path) #if os.path.exists(current_web2py_path): # shutil.rmtree(current_web2py_path) #print("Create symlink", current_config_path, current_web2py_path) syslog.syslog(syslog.LOG_INFO, "symlnk {0} {1}".format(current_config_path, current_web2py_path)) os.symlink(current_config_path, current_web2py_path) except: syslog.syslog(syslog.LOG_ERR, traceback.format_exc()) def prepare_for_web2py_start(): paths = ('deposit', 'site-packages', 'logs') # removed: 'applications', [that's no link!] create_lnks(CONFIG_PATH + """web2pyroot/""", WEB2PY, paths) appl_paths = ('cache', 'models', 'views', 'controllers', 'databases', 'modules', 'cron', 'errors', 'sessions', 'languages', 'static', 'private', 'uploads') for app in ('''BS350/''', '''admin/'''): create_lnks(CONFIG_PATH + app, WEB2PY + "applications/" + app, appl_paths)