def init_updater(): from maraschino.updater import checkGithub, gitCurrentVersion global USE_GIT, CURRENT_COMMIT, COMMITS_BEHIND if os.name == 'nt': USE_GIT = False else: USE_GIT = os.path.isdir(os.path.join(RUNDIR, '.git')) if USE_GIT: gitCurrentVersion() version_file = os.path.join(DATA_DIR, 'Version.txt') if os.path.isfile(version_file): f = open(version_file, 'r') CURRENT_COMMIT = f.read() f.close() else: COMMITS_BEHIND = -1 threading.Thread(target=checkGithub).start()
def initialize(): with INIT_LOCK: global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \ CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT if __INITIALIZED__: return False # Set up logger if not LOG_FILE: LOG_FILE = os.path.join(RUNDIR, 'logs', 'maraschino.log') FILENAME = os.path.basename(LOG_FILE) LOG_DIR = LOG_FILE[:-len(FILENAME)] if not os.path.exists(LOG_DIR): try: os.makedirs(LOG_DIR) except OSError: if VERBOSE: print 'Unable to create the log directory.' logger = maraschinoLogger(LOG_FILE, VERBOSE) # check if database exists or create it from database import init_db try: logger.log('Opening database at: %s' %(DATABASE), 'INFO') open(DATABASE) except IOError, e: logger.log('Opening database failed', 'CRITICAL') try: logger.log('Checking if PATH exists: %s' %(DATABASE), 'WARNING') dbpath = os.path.dirname(DATABASE) if not os.path.exists(dbpath): try: logger.log('It does not exist, creating it...', 'WARNING') os.makedirs(dbpath) except: logger.log('Could not create %s.'% (DATABASE) , 'CRITICAL') print 'Could not create %s.'% (DATABASE) quit() except: logger.log('Could not create %s.' % (DATABASE) , 'CRITICAL') quit() logger.log('Database successfully initialised' , 'INFO') init_db() # Web server settings from tools import get_setting_value if get_setting_value('maraschino_webroot') != None or '': if '--webroot' not in str(ARGS): WEBROOT = get_setting_value('maraschino_webroot') if get_setting_value('maraschino_port') != None or '': port_arg = False for arg in ARGS: if arg == '--port' or '-p': port_arg = True if not port_arg: PORT = int(get_setting_value('maraschino_port')) # Set up AUTH username = get_setting_value('maraschino_username') password = get_setting_value('maraschino_password') if username and password != None: AUTH = { 'username': username, 'password': password } # Set up web server if WEBROOT: if WEBROOT[0] != '/': WEBROOT = '/' + WEBROOT d = wsgiserver.WSGIPathInfoDispatcher({WEBROOT: app}) else: d = wsgiserver.WSGIPathInfoDispatcher({'/': app}) SERVER = wsgiserver.CherryPyWSGIServer(('0.0.0.0', PORT), d) # Set up webroot for .less less_webroot = os.path.join(RUNDIR, 'static/less/webroot.less') f = open(less_webroot, 'w') f.write('@webroot: "http://127.0.0.1:%i%s";' % (PORT, WEBROOT)) f.close() # Set up the updater from maraschino.updater import checkGithub, gitCurrentVersion if os.name == 'nt': USE_GIT = False else: USE_GIT = os.path.isdir(os.path.join(RUNDIR, '.git')) if USE_GIT: gitCurrentVersion() version_file = os.path.join(RUNDIR, 'Version.txt') if os.path.isfile(version_file): f = open(version_file, 'r') CURRENT_COMMIT = f.read() f.close() else: COMMITS_BEHIND = -1 threading.Thread(target=checkGithub).start() __INITIALIZED__ = True return True