Ejemplo n.º 1
0
def initialize():
    """Init function for this module"""
    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, HOST, KIOSK, DATA_DIR, THREADS

        if __INITIALIZED__:
            return False

        # Set up logger
        if not LOG_FILE:
            LOG_FILE = os.path.join(DATA_DIR, "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

        if KIOSK:
            logger.log("Running in KIOSK Mode, settings disabled.", "INFO")

        try:
            logger.log("Opening database at: %s" % (DATABASE), "INFO")
            open(DATABASE)

        except IOError:
            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_port"):
            port_arg = False
            for arg in ARGS:
                if arg == "--port" or arg == "-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" not in str(ARGS):
            WEBROOT = get_setting_value("maraschino_webroot")
            if WEBROOT is None:
                WEBROOT = ""

        if WEBROOT:
            if WEBROOT[0] != "/":
                WEBROOT = "/" + WEBROOT
            d = wsgiserver.WSGIPathInfoDispatcher({WEBROOT: app})
        else:
            d = wsgiserver.WSGIPathInfoDispatcher({"/": app})
        SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d)

        __INITIALIZED__ = True
        return True
Ejemplo n.º 2
0
def initialize():
    """Init function for this module"""
    with INIT_LOCK:

        global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \
                UPDATER, CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR, SCRIPT_DIR, \
                THREADS, FIRST_RUN

        if __INITIALIZED__:
            return False

        # Set up logger
        if not LOG_FILE:
            LOG_FILE = os.path.join(DATA_DIR, '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)

        #set up script dir
        if not SCRIPT_DIR:
            SCRIPT_DIR = os.path.join(RUNDIR, 'scripts')

        # check if database exists or create it
        from database import init_db

        if KIOSK:
            logger.log('Running in KIOSK Mode, settings disabled.', 'INFO')

        try:
            logger.log('Opening database at: %s' % (DATABASE), 'INFO')
            open(DATABASE)
        except IOError:
            logger.log('Opening database failed', 'WARNING')

            #Check if a version file exists. If not assume latest revision.
            version_file = os.path.join(DATA_DIR, 'Version.txt')
            if not os.path.exists(version_file):
                FIRST_RUN = 1

            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_port'):
            port_arg = False
            for arg in ARGS:
                if arg == '--port' or arg == '-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' not in str(ARGS):
            WEBROOT = get_setting_value('maraschino_webroot')
            if WEBROOT is None or DEVELOPMENT:
                WEBROOT = ''

        if WEBROOT:
            if WEBROOT[0] != '/':
                WEBROOT = '/' + WEBROOT
            d = wsgiserver.WSGIPathInfoDispatcher({WEBROOT: app})
        else:
            d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
        SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d)

        __INITIALIZED__ = True
        return True
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
def initialize():
    """Init function for this module"""
    with INIT_LOCK:

        global __INITIALIZED__, app, FULL_PATH, RUNDIR, ARGS, DAEMON, PIDFILE, VERBOSE, LOG_FILE, LOG_DIR, logger, PORT, SERVER, DATABASE, AUTH, \
                UPDATER, CURRENT_COMMIT, LATEST_COMMIT, COMMITS_BEHIND, COMMITS_COMPARE_URL, USE_GIT, WEBROOT, HOST, KIOSK, DATA_DIR, SCRIPT_DIR, \
                THREADS, FIRST_RUN

        if __INITIALIZED__:
            return False

        # Set up logger
        if not LOG_FILE:
            LOG_FILE = os.path.join(DATA_DIR, '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)

        #set up script dir
        if not SCRIPT_DIR:
            SCRIPT_DIR = os.path.join(DATA_DIR, 'scripts')
            if not os.path.exists(SCRIPT_DIR):
                os.makedirs(SCRIPT_DIR)

        # check if database exists or create it
        from database import init_db

        if KIOSK:
            logger.log('Running in KIOSK Mode, settings disabled.', 'INFO')

        try:
            logger.log('Opening database at: %s' % (DATABASE), 'INFO')
            open(DATABASE)
        except IOError:
            logger.log('Opening database failed', 'WARNING')

            #Check if a version file exists. If not assume latest revision.
            version_file = os.path.join(DATA_DIR, 'Version.txt')
            if not os.path.exists(version_file):
                FIRST_RUN = 1

            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_port'):
            port_arg = False
            for arg in ARGS:
                if arg == '--port' or arg == '-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' not in str(ARGS):
            WEBROOT = get_setting_value('maraschino_webroot')
            if WEBROOT is None or DEVELOPMENT:
                WEBROOT = ''

        if WEBROOT:
            if WEBROOT[0] != '/':
                WEBROOT = '/' + WEBROOT
            d = wsgiserver.WSGIPathInfoDispatcher({WEBROOT: app})
        else:
            d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
        SERVER = wsgiserver.CherryPyWSGIServer((HOST, PORT), d)

        __INITIALIZED__ = True
        return True