Example #1
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {'root': root_path,
             'controllers': os.path.join(root_path, 'controllers'),
             'templates': [os.path.join(root_path, 'templates')],
             }

    if ConfigValue.bool(global_conf.get('uncompressedJS')):
        paths['static_files'] = os.path.join(root_path, 'public')
    else:
        paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')

    config.init_app(global_conf, app_conf, package='r2',
                    template_engine='mako', paths=paths)

    g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        g.plugins.declare_queues(g.queues)
        r2.config.cache = g.cache
    g.plugins.load_plugins()
    config['r2.plugins'] = g.plugins
    g.startup_timer.intermediate("plugins")

    config['pylons.h'] = r2.lib.helpers
    config['routes.map'] = routing.make_map()

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates', False)
    tmpl_options['mako.default_filters'] = ["mako_websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe, mako_websafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]

    # when mako loads a previously compiled template file from its cache, it
    # doesn't check that the original template path matches the current path.
    # in the event that a new plugin defines a template overriding a reddit
    # template, unless the mtime newer, mako doesn't update the compiled
    # template. as a workaround, this makes mako store compiled templates with
    # the original path in the filename, forcing it to update with the path.
    def mako_module_path(filename, uri):
        module_directory = tmpl_options['mako.module_directory']
        filename = filename.lstrip('/').replace('/', '-')
        path = os.path.join(module_directory, filename + ".py")
        return os.path.abspath(path)

    tmpl_options['mako.modulename_callable'] = mako_module_path

    if setup_globals:
        g.setup_complete()
Example #2
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {
        'root': root_path,
        'controllers': os.path.join(root_path, 'controllers'),
        'templates': tmpl_dirs,
    }

    if ConfigValue.bool(global_conf.get('uncompressedJS')):
        paths['static_files'] = os.path.join(root_path, 'public')
    else:
        paths['static_files'] = os.path.join(os.path.dirname(root_path),
                                             'build/public')

    config.init_app(global_conf,
                    app_conf,
                    package='r2',
                    template_engine='mako',
                    paths=paths)

    g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        r2.config.cache = g.cache

    config['pylons.h'] = r2.lib.helpers

    g.plugins = config['r2.plugins'] = PluginLoader().load_plugins(
        g.config.get('plugins', []))
    config['routes.map'] = routing.make_map()

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    #tmpl_options = {}
    #tmpl_options['myghty.log_errors'] = True
    #tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates',
                                                     False)
    tmpl_options['mako.default_filters'] = ["mako_websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe, mako_websafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]
Example #3
0
def load_environment(global_conf={}, app_conf={}):
    map = make_map(global_conf, app_conf)
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {
        'root': root_path,
        'controllers': os.path.join(root_path, 'controllers'),
        'templates': tmpl_dirs,
        'static_files': os.path.join(root_path, 'public')
    }

    config.init_app(global_conf,
                    app_conf,
                    package='r2',
                    template_engine='mako',
                    paths=paths)

    config['pylons.g'] = app_globals.Globals(global_conf, app_conf, paths)
    config['pylons.h'] = r2.lib.helpers
    config['routes.map'] = map

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    #tmpl_options = {}
    #tmpl_options['myghty.log_errors'] = True
    #tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.output_encoding'] = 'utf-8'
    tmpl_options['mako.input_encoding'] = 'utf-8'
    tmpl_options['mako.default_filters'] = ["websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]

    # Add your own template options config options here,
    # note that all config options will override
    # any Pylons config options
    g = config['pylons.g']
    reddit_config.cache = g.cache
Example #4
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {
        "root": root_path,
        "controllers": os.path.join(root_path, "controllers"),
        "templates": [os.path.join(root_path, "templates")],
    }

    if ConfigValue.bool(global_conf.get("uncompressedJS")):
        paths["static_files"] = os.path.join(root_path, "public")
    else:
        paths["static_files"] = os.path.join(os.path.dirname(root_path), "build/public")

    config.init_app(global_conf, app_conf, package="r2", template_engine="mako", paths=paths)

    g = config["pylons.g"] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        r2.config.cache = g.cache
    g.plugins.load_plugins()
    config["r2.plugins"] = g.plugins

    config["pylons.h"] = r2.lib.helpers
    config["routes.map"] = routing.make_map()

    # override the default response options
    config["pylons.response_options"]["headers"] = {}

    # The following template options are passed to your template engines
    # tmpl_options = {}
    # tmpl_options['myghty.log_errors'] = True
    # tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config["buffet.template_options"]
    tmpl_options["mako.filesystem_checks"] = getattr(g, "reload_templates", False)
    tmpl_options["mako.default_filters"] = ["mako_websafe"]
    tmpl_options["mako.imports"] = [
        "from r2.lib.filters import websafe, unsafe, mako_websafe",
        "from pylons import c, g, request",
        "from pylons.i18n import _, ungettext",
    ]
Example #5
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {'root': root_path,
             'controllers': os.path.join(root_path, 'controllers'),
             'templates': tmpl_dirs,
             }

    if ConfigValue.bool(global_conf.get('uncompressedJS')):
        paths['static_files'] = os.path.join(root_path, 'public')
    else:
        paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')

    config.init_app(global_conf, app_conf, package='r2',
                    template_engine='mako', paths=paths)

    g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        reddit_config.cache = g.cache

    config['pylons.h'] = r2.lib.helpers

    g.plugins = config['r2.plugins'] = PluginLoader().load_plugins(g.config.get('plugins', []))
    config['routes.map'] = routing.make_map()

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    #tmpl_options = {}
    #tmpl_options['myghty.log_errors'] = True
    #tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates', False)
    tmpl_options['mako.default_filters'] = ["mako_websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe, mako_websafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]
Example #6
0
def load_environment(global_conf={}, app_conf={}):
    map = make_map(global_conf, app_conf)
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {
        "root": root_path,
        "controllers": os.path.join(root_path, "controllers"),
        "templates": tmpl_dirs,
        "static_files": os.path.join(root_path, "public"),
    }

    config.init_app(global_conf, app_conf, package="r2", template_engine="mako", paths=paths)

    config["pylons.g"] = app_globals.Globals(global_conf, app_conf, paths)
    config["pylons.h"] = r2.lib.helpers
    config["routes.map"] = map

    # override the default response options
    config["pylons.response_options"]["headers"] = {}

    # The following template options are passed to your template engines
    # tmpl_options = {}
    # tmpl_options['myghty.log_errors'] = True
    # tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config["buffet.template_options"]
    tmpl_options["mako.filesystem_checks"] = False
    tmpl_options["mako.default_filters"] = ["mako_websafe"]
    tmpl_options["mako.imports"] = [
        "from r2.lib.filters import websafe, unsafe, mako_websafe",
        "from pylons import c, g, request",
        "from pylons.i18n import _, ungettext",
    ]

    # Add your own template options config options here,
    # note that all config options will override
    # any Pylons config options
    g = config["pylons.g"]
    reddit_config.cache = g.cache
Example #7
0
def load_environment(global_conf={}, app_conf={}):
    map = make_map(global_conf, app_conf)
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {'root': root_path,
             'controllers': os.path.join(root_path, 'controllers'),
             'templates': tmpl_dirs,
             'static_files': os.path.join(root_path, 'public')
             }

    config.init_app(global_conf, app_conf, package='r2',
                    template_engine='mako', paths=paths)

    config['pylons.g'] = app_globals.Globals(global_conf, app_conf, paths)
    config['pylons.h'] = r2.lib.helpers
    config['routes.map'] = map

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    #tmpl_options = {}
    #tmpl_options['myghty.log_errors'] = True
    #tmpl_options['myghty.escapes'] = dict(l=webhelpers.auto_link, s=webhelpers.simple_format)

    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.output_encoding'] = 'utf-8'
    tmpl_options['mako.input_encoding'] = 'utf-8'
    tmpl_options['mako.default_filters'] = ["websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]

    # Add your own template options config options here,
    # note that all config options will override
    # any Pylons config options
    g = config['pylons.g']
    reddit_config.cache = g.cache
Example #8
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {'root': root_path,
             'controllers': os.path.join(root_path, 'controllers'),
             'templates': [os.path.join(root_path, 'templates')],
             }

    if ConfigValue.bool(global_conf.get('uncompressedJS')):
        paths['static_files'] = os.path.join(root_path, 'public')
    else:
        paths['static_files'] = os.path.join(os.path.dirname(root_path), 'build/public')

    config.init_app(global_conf, app_conf, package='r2',
                    template_engine='mako', paths=paths)

    # don't put action arguments onto c automatically
    config['pylons.c_attach_args'] = False
    # when accessing non-existent attributes on c, return "" instead of dying
    config['pylons.strict_c'] = False

    g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        g.plugins.declare_queues(g.queues)
    g.plugins.load_plugins()
    config['r2.plugins'] = g.plugins
    g.startup_timer.intermediate("plugins")

    config['pylons.h'] = r2.lib.helpers
    config['routes.map'] = routing.make_map()

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # when mako loads a previously compiled template file from its cache, it
    # doesn't check that the original template path matches the current path.
    # in the event that a new plugin defines a template overriding a reddit
    # template, unless the mtime newer, mako doesn't update the compiled
    # template. as a workaround, this makes mako store compiled templates with
    # the original path in the filename, forcing it to update with the path.
    if "cache_dir" in app_conf:
        module_directory = os.path.join(app_conf['cache_dir'], 'templates')

        def mako_module_path(filename, uri):
            filename = filename.lstrip('/').replace('/', '-')
            path = os.path.join(module_directory, filename + ".py")
            return os.path.abspath(path)
    else:
        # we're probably in "paster run standalone" mode. we'll just avoid
        # caching templates since we don't know where they should go.
        module_directory = mako_module_path = None

    # set up the templating system
    config["pylons.g"].mako_lookup = TemplateLookup(
        directories=paths["templates"],
        error_handler=handle_mako_error,
        module_directory=module_directory,
        input_encoding="utf-8",
        default_filters=["mako_websafe"],
        filesystem_checks=getattr(g, "reload_templates", False),
        imports=[
            "from r2.lib.filters import websafe, unsafe, mako_websafe",
            "from pylons import c, g, request",
            "from pylons.i18n import _, ungettext",
        ],
        modulename_callable=mako_module_path,
    )

    if setup_globals:
        g.setup_complete()
Example #9
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    r2_path = get_r2_path()
    root_path = os.path.join(r2_path, "r2")

    paths = {
        "root": root_path,
        "controllers": os.path.join(root_path, "controllers"),
        "templates": [os.path.join(root_path, "templates")],
    }

    if ConfigValue.bool(global_conf.get("uncompressedJS")):
        paths["static_files"] = get_raw_statics_path()
    else:
        paths["static_files"] = get_built_statics_path()

    config = PylonsConfig()

    config.init_app(global_conf, app_conf, package="r2", paths=paths)

    # don't put action arguments onto c automatically
    config["pylons.c_attach_args"] = False

    # when accessing non-existent attributes on c, return "" instead of dying
    config["pylons.strict_tmpl_context"] = False

    g = Globals(config, global_conf, app_conf, paths)
    config["pylons.app_globals"] = g

    if setup_globals:
        config["r2.import_private"] = ConfigValue.bool(global_conf["import_private"])
        g.setup()
        g.plugins.declare_queues(g.queues)

    g.plugins.load_plugins(config)
    config["r2.plugins"] = g.plugins
    g.startup_timer.intermediate("plugins")

    config["pylons.h"] = r2.lib.helpers
    config["routes.map"] = make_map(config)

    # override the default response options
    config["pylons.response_options"]["headers"] = {}

    # when mako loads a previously compiled template file from its cache, it
    # doesn't check that the original template path matches the current path.
    # in the event that a new plugin defines a template overriding a reddit
    # template, unless the mtime newer, mako doesn't update the compiled
    # template. as a workaround, this makes mako store compiled templates with
    # the original path in the filename, forcing it to update with the path.
    if "cache_dir" in app_conf:
        module_directory = os.path.join(app_conf["cache_dir"], "templates")

        def mako_module_path(filename, uri):
            filename = filename.lstrip("/").replace("/", "-")
            path = os.path.join(module_directory, filename + ".py")
            return os.path.abspath(path)

    else:
        # disable caching templates since we don't know where they should go.
        module_directory = mako_module_path = None

    # set up the templating system
    config["pylons.app_globals"].mako_lookup = TemplateLookup(
        directories=paths["templates"],
        error_handler=handle_mako_error,
        module_directory=module_directory,
        input_encoding="utf-8",
        default_filters=["conditional_websafe"],
        filesystem_checks=getattr(g, "reload_templates", False),
        imports=[
            "from r2.lib.filters import websafe, unsafe, conditional_websafe",
            "from pylons import request",
            "from pylons import tmpl_context as c",
            "from pylons import app_globals as g",
            "from pylons.i18n import _, ungettext",
        ],
        modulename_callable=mako_module_path,
    )

    if setup_globals:
        g.setup_complete()

    return config
Example #10
0
def load_environment(global_conf={}, app_conf={}, setup_globals=True):
    # Setup our paths
    root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

    paths = {
        'root': root_path,
        'controllers': os.path.join(root_path, 'controllers'),
        'templates': [os.path.join(root_path, 'templates')],
    }

    if ConfigValue.bool(global_conf.get('uncompressedJS')):
        paths['static_files'] = os.path.join(root_path, 'public')
    else:
        paths['static_files'] = os.path.join(os.path.dirname(root_path),
                                             'build/public')

    config.init_app(global_conf,
                    app_conf,
                    package='r2',
                    template_engine='mako',
                    paths=paths)

    g = config['pylons.g'] = Globals(global_conf, app_conf, paths)
    if setup_globals:
        g.setup()
        g.plugins.declare_queues(g.queues)
        r2.config.cache = g.cache
    g.plugins.load_plugins()
    config['r2.plugins'] = g.plugins
    g.startup_timer.intermediate("plugins")

    config['pylons.h'] = r2.lib.helpers
    config['routes.map'] = routing.make_map()

    #override the default response options
    config['pylons.response_options']['headers'] = {}

    # The following template options are passed to your template engines
    tmpl_options = config['buffet.template_options']
    tmpl_options['mako.filesystem_checks'] = getattr(g, 'reload_templates',
                                                     False)
    tmpl_options['mako.default_filters'] = ["mako_websafe"]
    tmpl_options['mako.imports'] = \
                                 ["from r2.lib.filters import websafe, unsafe, mako_websafe",
                                  "from pylons import c, g, request",
                                  "from pylons.i18n import _, ungettext"]

    # when mako loads a previously compiled template file from its cache, it
    # doesn't check that the original template path matches the current path.
    # in the event that a new plugin defines a template overriding a reddit
    # template, unless the mtime newer, mako doesn't update the compiled
    # template. as a workaround, this makes mako store compiled templates with
    # the original path in the filename, forcing it to update with the path.
    def mako_module_path(filename, uri):
        module_directory = tmpl_options['mako.module_directory']
        filename = filename.lstrip('/').replace('/', '-')
        path = os.path.join(module_directory, filename + ".py")
        return os.path.abspath(path)

    tmpl_options['mako.modulename_callable'] = mako_module_path

    if setup_globals:
        g.setup_complete()