コード例 #1
0
ファイル: app.py プロジェクト: bookmarklets-org/wakarimasen
def check_setup(environ, start_response):
    import os, config
    import interboard
    from template import TEMPLATES_DIR, CACHE_DIR

    issues = []

    ENV_CHECKS = ['DOCUMENT_ROOT', 'SCRIPT_NAME', 'SERVER_NAME']
    MISSING_ENV = [x for x in ENV_CHECKS if x not in environ]
    if MISSING_ENV:
        return [
            'Environment not complete. Missing: %s\n' % ', '.join(MISSING_ENV)
        ]

    full_board_dir = os.path.join(environ['DOCUMENT_ROOT'], config.BOARD_DIR)
    if not os.access(full_board_dir, os.W_OK):
        issues.append("No write access to DOCUMENT_ROOT+BOARD_DIR (%s)" %
                      full_board_dir)

    include_dir = os.path.join(environ['DOCUMENT_ROOT'], config.BOARD_DIR,
                               "include")
    if not os.access(include_dir, os.F_OK | os.R_OK):
        issues.append("No read access to includes dir (%s). Wrong BOARD_DIR?" %
                      include_dir)

    script_name_dir = os.path.join(
        environ['DOCUMENT_ROOT'],
        os.path.dirname(environ['SCRIPT_NAME']).lstrip("/"))
    if not os.access(script_name_dir, os.W_OK):
        issues.append("No write access to DOCUMENT_ROOT+SCRIPT_NAME dir (%s)" %
                      script_name_dir)

    templates_dir = os.path.abspath(TEMPLATES_DIR)
    if not os.access(templates_dir, os.W_OK):
        issues.append("No write access to templates dir (%s)" % templates_dir)

    cache_dir = os.path.abspath(CACHE_DIR)
    if not os.access(cache_dir, os.W_OK):
        issues.append("No write access to templates cache dir (%s)" %
                      cache_dir)

    try:
        model.metadata.create_all(model.engine)
        interboard.remove_old_bans()
        interboard.remove_old_backups()
    except model.OperationalError, e:
        issues.append("Error writing to database: %s" % e.args[0])
コード例 #2
0
ファイル: app.py プロジェクト: dequis/wakarimasen
def check_setup(environ, start_response):
    import os, config
    import interboard
    from template import TEMPLATES_DIR, CACHE_DIR

    issues = []

    ENV_CHECKS = ['DOCUMENT_ROOT', 'SCRIPT_NAME', 'SERVER_NAME']
    MISSING_ENV = [x for x in ENV_CHECKS if x not in environ]
    if MISSING_ENV:
        return ['Environment not complete. Missing: %s\n' %
                ', '.join(MISSING_ENV)]

    full_board_dir = os.path.join(environ['DOCUMENT_ROOT'], config.BOARD_DIR)
    if not os.access(full_board_dir, os.W_OK):
        issues.append("No write access to DOCUMENT_ROOT+BOARD_DIR (%s)" %
            full_board_dir)

    include_dir = os.path.join(environ['DOCUMENT_ROOT'],
        config.BOARD_DIR, "include")
    if not os.access(include_dir, os.F_OK | os.R_OK):
        issues.append("No read access to includes dir (%s). Wrong BOARD_DIR?" %
            include_dir)

    script_name_dir = os.path.join(environ['DOCUMENT_ROOT'],
        os.path.dirname(environ['SCRIPT_NAME']).lstrip("/"))
    if not os.access(script_name_dir, os.W_OK):
        issues.append("No write access to DOCUMENT_ROOT+SCRIPT_NAME dir (%s)" %
            script_name_dir)

    templates_dir = os.path.abspath(TEMPLATES_DIR)
    if not os.access(templates_dir, os.W_OK):
        issues.append("No write access to templates dir (%s)" % templates_dir)

    cache_dir = os.path.abspath(CACHE_DIR)
    if not os.access(cache_dir, os.W_OK):
        issues.append("No write access to templates cache dir (%s)" % cache_dir)

    try:
        model.metadata.create_all(model.engine)
        interboard.remove_old_bans()
        interboard.remove_old_backups()
    except model.OperationalError, e:
        issues.append("Error writing to database: %s" % e.args[0])
コード例 #3
0
ファイル: wakarimasen.py プロジェクト: dequis/wakarimasen
        if boardname:
            environ['waka.board'] = Board(boardname)
        elif task not in ('entersetup', 'setup', 'loginpanel'):
            raise WakaError("No board parameter set")
        elif task == 'loginpanel':
            raise WakaError("No board parameter set. "
                "If you haven't created boards yet, do it now.")
    except WakaError, e:
        return app.error(environ, start_response, e)

    # the task function if it exists, otherwise no_task()
    function = getattr(app, 'task_%s' % task.lower(), app.no_task)

    try:
        interboard.remove_old_bans()
        interboard.remove_old_backups()
    except model.OperationalError, e:
        return ["Error initializing database: %s" % e.args[0]]

    try:
        # wrap with list() to run inside this try..except
        return list(function(environ, start_response))
    except WakaError, e:
        return app.error(environ, start_response, e)
    except:
        environ['waka.status'] = '503 Service unavailable'
        traceback.print_exc()
        return app.error(environ, start_response)


def cleanup(*args, **kwargs):
コード例 #4
0
        if boardname:
            environ['waka.board'] = Board(boardname)
        elif task not in ('entersetup', 'setup', 'loginpanel'):
            raise WakaError("No board parameter set")
        elif task == 'loginpanel':
            raise WakaError("No board parameter set. "
                "If you haven't created boards yet, do it now.")
    except WakaError, e:
        return app.fffffff(environ, start_response, e)

    # the task function if it exists, otherwise no_task()
    function = getattr(app, 'task_%s' % task.lower(), app.no_task)

    try:
        interboard.remove_old_bans()
        interboard.remove_old_backups()
        return function(environ, start_response)
    except WakaError, e:
        return app.fffffff(environ, start_response, e)

def cleanup(*args, **kwargs):
    '''Destroy the thread-local session and environ'''
    session = model.Session()
    session.commit()
    session.transaction = None  # fix for a circular reference
    model.Session.remove()
    local.environ = {}

application = util.cleanup(application, cleanup)

def worker_commands(command, args):