Esempio n. 1
0
def make_plugin(**config):
    if not config.has_key("secret") or not config["secret"]:
        raise ValueError("'secret' must not be None.")
    
    if config.has_key("timeout"):
        config["timeout"] = int(config["timeout"])
    if config.has_key("reissue_time"):
        config["reissue_time"] = int(config["reissue_time"])

    if config.has_key("timeout") and ( (not config.has_key("reissue_time")) or (config["reissue_time"] > config["timeout"]) ):
        raise ValueError('When timeout is specified, reissue_time must '
                         'be set to a lower value')
        
    return MidgardTokenAuth(config)
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """


    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        login_form_url = '/login'
        login_handler = '/login_handler'
        logout_handler = '/logout_handler'
        logout_url = '/logout'
        # Decide if the client is a (user-driven) browser or an application
        if config.has_key("who.config_file"):
            config_file = config["who.config_file"]
            config_who = ConfigParser.ConfigParser()
            config_who.readfp(open(config_file))
            login_form_url = config_who.get("plugin:friendlyform", "login_form_url")
            login_handler = config_who.get("plugin:friendlyform", "login_handler_path")
            logout_handler = config_who.get("plugin:friendlyform", "logout_handler_path")
            logout_url = config_who.get("plugin:friendlyform", "post_logout_url")

        path_info = environ['PATH_INFO']
        #request = Request(environ)
        #if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
        #    # In our view, any client who doesn't support HTML/XHTML is an "app",
        #    #   not a (user-driven) "browser".
        #    classifier = 'app'
        if not path_info in [login_form_url, login_handler, logout_handler, logout_url]:
            # In our view, any client who hasn't come in from the login url is an app
            classifier = 'app'
    return classifier
Esempio n. 3
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    # Teambox debugging.
    if config['debug']:
        app = TeamboxDebugMiddleware(app)

        # Production setup.
    else:
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

    # Handle special status codes.
    app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    # Change the url scheme when needed.
    if config.has_key('url_scheme'):
        app = UrlSchemeMiddleware(app, config['url_scheme'])

    return app
Esempio n. 4
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    # Teambox debugging.
    if config['debug']: app = TeamboxDebugMiddleware(app)
        
    # Production setup.
    else: app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
    
    # Handle special status codes.
    app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    # Change the url scheme when needed.
    if config.has_key('url_scheme'):
        app = UrlSchemeMiddleware(app, config['url_scheme'])

    return app
Esempio n. 5
0
	def check_config() :
	
		from pylons import config
		class ConfigError(Exception) : pass

		error_str = 'fbpylons requires that the following variables be set in your development.ini: %s. For details, see the Facebook API documentation.' % ( ', '.join(REQUIRED), )
		
		if not all( [config.has_key(r) for r in REQUIRED] ) : raise ConfigError(error_str)
		if not all( [config[r] for r in REQUIRED] ) : raise ConfigError(error_str)
	
		extraneous = []
		for k in config.keys() :
			if k.startswith('facebook.') and k not in REQUIRED and k not in OPTIONAL : extraneous.append(k)
	
		if len(extraneous) > 0 : raise ConfigError( extraneous )
Esempio n. 6
0
def send_mail_toeach(datatuple, fail_silently=False, 
                   auth_user=SMTP_USERNAME, 
                   auth_password=SMTP_PASSWORD):
    """
    Given a datatuple of (subject, message, from_email, recipient_list), sends
    each message to each recipient list. Returns the number of e-mails sent.

    If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
    If auth_user and auth_password are set, they're used to log in.
    """
    try:
        smtp_server = config.has_key('smtp_server') and config['smtp_server'] or None
        if smtp_server == None or smtp_server == '':
            return
        server = smtplib.SMTP(config['smtp_server'], 25)
        if auth_user and auth_password:
            server.login(auth_user, auth_password)
    except:
        if fail_silently:
            return
        raise
    num_sent = 0
    subject, message, from_email, recipient_list = datatuple
    for to_email in recipient_list:
        from_email = from_email or DEFAULT_FROM_EMAIL
        msg = SafeMIMEText(message, 'plain', DEFAULT_CHARSET)
        msg['Subject'] = subject
        msg['From'] = from_email
        msg['To'] = to_email
        msg['Date'] = rfc822.formatdate()
        try:
            server.sendmail(from_email, recipient_list, msg.as_string())
            num_sent += 1
        except:
            if not fail_silently:
                raise
            
    try:
        server.quit()
    except:
        if fail_silently:
            return
        raise
    return num_sent
Esempio n. 7
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    top = os.path.abspath(os.path.join(root, '../..'))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[
                     os.path.join(root, 'templates'),
                     os.path.join(top, 'templates/base')
                 ])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='kwmo', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = kwmo.lib.helpers

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8',
        output_encoding='utf-8',
        imports=['from webhelpers.html import escape'],
        default_filters=['escape'])

    # Get default master file path (if not defined in the paster configuration file).
    if not config.has_key('master_file_path'):
        config['master_file_path'] = RootConfigNode.master_file_path
    else:
        RootConfigNode.master_file_path = config['master_file_path']

    # Cache master config.
    cache_master_config(path=config['master_file_path'])

    # Initialize models.
    kcd_model.init_model()  # dependency - load before main model
    model.init_model()
Esempio n. 8
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    top = os.path.abspath(os.path.join(root, '../..'))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates'), os.path.join(top, 'templates/base')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='kwmo', paths=paths)

    config['routes.map'] = make_map()
    config['pylons.app_globals'] = app_globals.Globals()
    config['pylons.h'] = kwmo.lib.helpers

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', output_encoding='utf-8',
        imports=['from webhelpers.html import escape'],
        default_filters=['escape'])

    # Get default master file path (if not defined in the paster configuration file).
    if not config.has_key('master_file_path'):
        config['master_file_path'] = RootConfigNode.master_file_path
    else:
        RootConfigNode.master_file_path = config['master_file_path']
  
    # Cache master config.
    cache_master_config(path=config['master_file_path'])
 
    # Initialize models.
    kcd_model.init_model() # dependency - load before main model
    model.init_model()
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """

    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        login_form_url = '/login'
        login_handler = '/login_handler'
        logout_handler = '/logout_handler'
        logout_url = '/logout'
        # Decide if the client is a (user-driven) browser or an application
        if config.has_key("who.config_file"):
            config_file = config["who.config_file"]
            config_who = ConfigParser.ConfigParser()
            config_who.readfp(open(config_file))
            login_form_url = config_who.get("plugin:friendlyform",
                                            "login_form_url")
            login_handler = config_who.get("plugin:friendlyform",
                                           "login_handler_path")
            logout_handler = config_who.get("plugin:friendlyform",
                                            "logout_handler_path")
            logout_url = config_who.get("plugin:friendlyform",
                                        "post_logout_url")

        path_info = environ['PATH_INFO']
        #request = Request(environ)
        #if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
        #    # In our view, any client who doesn't support HTML/XHTML is an "app",
        #    #   not a (user-driven) "browser".
        #    classifier = 'app'
        if not path_info in [
                login_form_url, login_handler, logout_handler, logout_url
        ]:
            # In our view, any client who hasn't come in from the login url is an app
            classifier = 'app'
    return classifier
Esempio n. 10
0
    def __init__(self):
        """
            DOI service provided by the British Library on behalf of Datacite.org
            API Doc: https://api.datacite.org/
            Metadata requirements: http://datacite.org/schema/DataCite-MetadataKernel_v2.0.pdf
        """
        #Details pertaining to account with datacite
        self.account = "xx.xxxx"
        self.description = "Oxford University Library Service Databank"
        self.contact = "Name of contact person"
        self.email = "email_goes_here"
        self.password = "******"
        self.domain = "ox.ac.uk"
        self.prefix = "10.5072" #test-prefix
        self.quota = 500000

        if config.has_key("doi.count"):
            self.doi_count_file = config['doi.count']

        #Datacite api endpoint
        #self.endpoint_host = "api.datacite.org"
        self.endpoint_host = "mds.datacite.org"
        self.endpoint_path_doi = "/doi"
        self.endpoint_path_metadata = "/metadata"
Esempio n. 11
0
import os
import StringIO
import logging
log = logging.getLogger(__name__)

from pylons import config
config_path = config["here"] + '/config'
if config_path not in sys.path:
    sys.path.insert(0, config_path)
from localconfig import LocalConfig as cfg

sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from pysvnmanager import hooks

# i18n works only as pysvnmanager (a pylons app) model.
if not config.has_key('unittest'):
    from pylons.i18n import _
else:
    def _(message): return message

#reload(sys) # in Python2.5, method sys.setdefaultencoding 
            #will be delete after initialize. we need reload it.
#sys.setdefaultencoding('utf-8')

class Repos:
    
    def __init__(self, repos_root):
        if not repos_root or not os.path.exists(repos_root):
            raise Exception, _("Repos root does not exist: %s") % repos_root
        
        self.__repos_root = os.path.abspath(repos_root)
Esempio n. 12
0
 def set_defaults(self):
     for key in self.__dict__.keys():
         if config.has_key(key):
             setattr(self, key, config[key])
Esempio n. 13
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])
    app = SessionMiddleware(app, config)
    app = CacheMiddleware(app, config)

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    app = add_auth(app) # Add repoze.what Auth & Auth
    app = add_thumbs(app) # Add iw.thumbs Thumbnail generation

    if asbool(full_stack):
        # Handle Python exceptions
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

        # Display error documents for 401, 403, 404 status codes (and
        # 500 when debug is disabled)
        if asbool(config['debug']):
            app = StatusCodeRedirect(app)
        else:
            app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    if config.has_key('upload_dir'):
        upload_app = StaticURLParser(config['upload_dir'])
        app = Cascade([upload_app, app])

    return app
    def __init__(self):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """

        self.authz = authz
        #self.users = _USERS
        self.NAMESPACES = NAMESPACES
        self.PREFIXES = PREFIXES

        if config.has_key("granary.uri_root"):
            self.root = config['granary.uri_root']

        if config.has_key("granary.store"):
            self.granary = Granary(config['granary.store'])

        if config.has_key("redis.host"):
            self.redishost = config['redis.host']
            try:
                self.r = Redis(self.redishost)
            except:
                self.r = None
            if self.r and config.has_key("broadcast.to") and config[
                    'broadcast.to'] == "redis" and config.has_key(
                        "broadcast.queue"):
                self.b = BroadcastToRedis(config['redis.host'],
                                          config['broadcast.queue'])
        else:
            self.r = None
            self.redishost = None
            self.b = None

        if config.has_key("solr.host"):
            from solr import SolrConnection
            self.solrhost = config['solr.host']
            try:
                self.solr = SolrConnection(self.solrhost)
            except:
                self.solr = None
        else:
            self.solrhost = None
            self.solr = None

        if config.has_key("naming_rule"):
            self.naming_rule = config['naming_rule']

        if config.has_key("naming_rule_humanized"):
            self.naming_rule_humanized = config['naming_rule_humanized']
        elif config.has_key("naming_rule"):
            self.naming_rule_humanized = config['naming_rule']

        if config.has_key("metadata.embargoed"):
            self.metadata_embargoed = config['metadata.embargoed']
            if isinstance(self.metadata_embargoed, basestring):
                if self.metadata_embargoed.lower().strip() == 'true':
                    self.metadata_embargoed = True
                else:
                    self.metadata_embargoed = False
            elif not type(self.metadata_embargoed).__name__ == 'bool':
                self.metadata_embargoed = False
        else:
            self.metadata_embargoed = False

        if config.has_key("auth.file"):
            pwdfile = config['auth.file']
            self.passwdfile = HtpasswdFile(pwdfile)
            self.passwdfile.load()

        if config.has_key("auth.info"):
            self.userfile = config['auth.info']

        if config.has_key("doi.count"):
            self.doi_count_file = config['doi.count']

        if config.has_key("formats_served"):
            self.formats_served = config['formats_served']
        else:
            self.formats_served = [
                "text/html", "text/xhtml", "text/plain", "application/json",
                "application/rdf+xml", "text/xml"
            ]

        if config.has_key("publisher"):
            self.publisher = config['publisher']
        else:
            self.publisher = "Bodleian Libraries, University of Oxford"

        if config.has_key("rights"):
            self.rights = config['rights']

        if config.has_key("license"):
            self.license = config['license']

        if config.has_key("api.version"):
            self.api_version = config['api.version']

        try:
            sync_members(self.granary)
        except:
            pass
Esempio n. 15
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Undefer POST parsing by undoing DeferPOSTParsing middleware work.
    app = kwmo.lib.middlewares.UnDeferPOSTParsing(app)

    # KWMO session middleware
    app = KwmoSessionMiddleware(app, config)

    # KWMO middleware - wrap kwmo application.
    app = kwmo.lib.middlewares.KWMOMiddleware(app)

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])

    app = CacheMiddleware(app, config)

    # Catch KJsonifyException exceptions and send a json exception in the body.
    app = kwmo.lib.middlewares.JSONErrorMiddleware(app)

    # Teambox debugging.
    if config['debug']:
        app = kwmo.lib.middlewares.TeamboxDebugMiddleware(app)

        # Production setup.
    else:
        app = ErrorHandler(app, global_conf, **config['pylons.errorware'])

    # Handle special status codes.
    app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    app = kwmo.lib.middlewares.ContentLengthMiddleware(app)

    # Defer POST parsing by hiding the real input body file object and providing an empty StringIO() instead.
    app = kwmo.lib.middlewares.DeferPOSTParsing(app)

    # Change the url scheme when needed.
    if config.has_key('url_scheme'):
        app = kwmo.lib.middlewares.UrlSchemeMiddleware(app,
                                                       config['url_scheme'])

    return app
    def __init__(self,config):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """
        
        ##self.authz = authz
        #self.users = _USERS
        self.NAMESPACES = NAMESPACES
        self.PREFIXES = PREFIXES
        
        self.cache = ""
        self.api_version = ""

        if config.has_key("granary.uri_root"):
            self.root = config['granary.uri_root']
       
        if config.has_key("granary.host"):
            self.host = config['granary.host']
            
        if config.has_key("granary.store"):
            self.granary = Granary(config['granary.store'])
            
        if config.has_key("redis.host"):
            self.redishost = config['redis.host']
            try:
                self.r = Redis(self.redishost)
            except:
                self.r = None
            if self.r and config.has_key("broadcast.to") and config['broadcast.to'] == "redis" and  config.has_key("broadcast.queue"):
                self.b = BroadcastToRedis(config['redis.host'], config['broadcast.queue'])
        else:
            self.r = None
            self.redishost = None
            self.b = None
            
        if config.has_key("solr.host"):
            from solr import SolrConnection
            self.solrhost = config['solr.host']
            try:
                self.solr = SolrConnection(self.solrhost)
            except:
                self.solr = None
        else:
            self.solrhost = None
            self.solr = None
        
        if config.has_key("naming_rule"):
            self.naming_rule = config['naming_rule']

        if config.has_key("naming_rule_humanized"):
            self.naming_rule_humanized = config['naming_rule_humanized']
        elif config.has_key("naming_rule"):
            self.naming_rule_humanized = config['naming_rule']

        if config.has_key("metadata.embargoed"):
            self.metadata_embargoed = config['metadata.embargoed']
            if isinstance(self.metadata_embargoed, basestring):
                if self.metadata_embargoed.lower().strip() == 'true':
                    self.metadata_embargoed = True
                else:
                    self.metadata_embargoed = False
            elif not type(self.metadata_embargoed).__name__ == 'bool':
                self.metadata_embargoed = False
        else:
            self.metadata_embargoed = False

        if config.has_key("auth.file"):
            pwdfile = config['auth.file']
            self.passwdfile = HtpasswdFile(pwdfile)
            self.passwdfile.load()
         
        if config.has_key("auth.info"):
            self.userfile = config['auth.info']

        if config.has_key("doi.count"):
            self.doi_count_file = config['doi.count']
        
        if config.has_key("formats_served"):
            self.formats_served = config['formats_served']
        else:
            self.formats_served = ["text/html", "text/xhtml", "text/plain", "application/json", "application/rdf+xml", "text/xml"]

        if config.has_key("publisher"):
            self.publisher = config['publisher']
        else:
            self.publisher = "Bodleian Libraries, University of Oxford"

        if config.has_key("rights"):
            self.rights = config['rights']
      
        if config.has_key("license"):
            self.license = config['license']

        if config.has_key("api.version"):
            self.api_version = config['api.version']
Esempio n. 17
0
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
    """Create a Pylons WSGI application and return it

    ``global_conf``
        The inherited configuration for this application. Normally from
        the [DEFAULT] section of the Paste ini file.

    ``full_stack``
        Whether this application provides a full WSGI stack (by default,
        meaning it handles its own exceptions and errors). Disable
        full_stack when this application is "managed" by another WSGI
        middleware.

    ``static_files``
        Whether this application serves its own static files; disable
        when another web server is responsible for serving them.

    ``app_conf``
        The application's local configuration. Normally specified in
        the [app:<name>] section of the Paste ini file (where <name>
        defaults to main).

    """
    # Configure the Pylons environment
    load_environment(global_conf, app_conf)

    # The Pylons WSGI app
    app = PylonsApp()

    # Undefer POST parsing by undoing DeferPOSTParsing middleware work.
    app = kwmo.lib.middlewares.UnDeferPOSTParsing(app)

    # KWMO session middleware
    app = KwmoSessionMiddleware(app, config)

    # KWMO middleware - wrap kwmo application.
    app = kwmo.lib.middlewares.KWMOMiddleware(app)

    # Routing/Session/Cache Middleware
    app = RoutesMiddleware(app, config['routes.map'])

    app = CacheMiddleware(app, config)

    # Catch KJsonifyException exceptions and send a json exception in the body.
    app = kwmo.lib.middlewares.JSONErrorMiddleware(app)

    # Teambox debugging.
    if config['debug']: app = kwmo.lib.middlewares.TeamboxDebugMiddleware(app)
        
    # Production setup.
    else: app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
    
    # Handle special status codes.
    app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])

    # Establish the Registry for this application
    app = RegistryManager(app)

    if asbool(static_files):
        # Serve static files
        static_app = StaticURLParser(config['pylons.paths']['static_files'])
        app = Cascade([static_app, app])

    app = kwmo.lib.middlewares.ContentLengthMiddleware(app)

    # Defer POST parsing by hiding the real input body file object and providing an empty StringIO() instead.
    app = kwmo.lib.middlewares.DeferPOSTParsing(app)

    # Change the url scheme when needed.
    if config.has_key('url_scheme'):
        app = kwmo.lib.middlewares.UrlSchemeMiddleware(app, config['url_scheme'])

    return app
Esempio n. 18
0
def parseconfig(config, global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config`` object"""
    global tmplmoddir
    config.init_app(global_conf, app_conf, package='zeta', paths=paths)

    if config.has_key('zetaversion'):
        return

    # pylons configuration
    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = h
    config['zeta.pkg_path'] = pkg_path
    config['zeta.envpath'] = envpath
    config['zeta.pageheader'] = config['zeta.pageheader'] == 'True'
    # config['pylons.strict_tmpl_context'] = False

    # Parse fields that will be persisted in system table.
    config['zeta.siteadmin'] = unicode(config['zeta.siteadmin'])
    config['pylons.package'] = unicode(config['pylons.package'])
    config['zeta.timezone'] = unicode(config['zeta.timezone'])
    config['zeta.unicode_encoding'] = unicode(config['zeta.unicode_encoding'])
    config['zeta.sitename'] = unicode(config['zeta.sitename'])
    config['zeta.envpath'] = unicode(config['zeta.envpath'])
    config['zeta.welcomestring'] = unicode(config['zeta.welcomestring'])
    config['zeta.userrel_types'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.userrel_types']))
    config['zeta.projteamtypes'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.projteamtypes']))
    config['zeta.ticketstatus'] = map(lambda x: unicode(x),
                                      h.parse_csv(config['zeta.ticketstatus']))
    config['zeta.tickettypes'] = map(lambda x: unicode(x),
                                     h.parse_csv(config['zeta.tickettypes']))
    config['zeta.ticketseverity'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.ticketseverity']))
    config['zeta.reviewnatures'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.reviewnatures']))
    config['zeta.reviewactions'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.reviewactions']))
    config['zeta.wikitypes'] = map(lambda x: unicode(x),
                                   h.parse_csv(config['zeta.wikitypes']))
    config['zeta.vcstypes'] = map(lambda x: unicode(x),
                                  h.parse_csv(config['zeta.vcstypes']))
    config['zeta.ticketresolv'] = map(lambda x: unicode(x),
                                      h.parse_csv(config['zeta.ticketresolv']))
    config['zeta.specialtags'] = map(lambda x: unicode(x),
                                     h.parse_csv(config['zeta.specialtags']))
    config['zeta.def_wikitype'] = unicode(config['zeta.def_wikitype'])
    config['zeta.userpanes'] = map(lambda x: unicode(x),
                                   h.parse_csv(config['zeta.userpanes']))

    # Fields for run-time.
    config['dbversion'] = dbversion
    config['zetaversion'] = zetaversion
    if not config['zeta.mstnccodes']:
        config['zeta.mstnccodes'] = join(envpath, 'public', 'mstnccodes.json')
    if not config['zeta.tckccodes']:
        config['zeta.tckccodes'] = join(envpath, 'public', 'tckccodes.json')
    if not config.get('zeta.tckfilters', None):
        config['zeta.tckfilters'] = join(envpath, 'public', 'tckfilters.pyd')

    # Create the Mako TemplateLookup, with the default auto-escaping
    tmplmoddir = join(app_conf['cache_dir'], 'templates')
    config['pylons.app_globals'].mako_lookup = \
        TemplateLookup(
            directories=paths['templates'],
            error_handler=handle_mako_error,
            module_directory=tmplmoddir,
            input_encoding='utf-8',
            output_encoding=config['zeta.unicode_encoding'],
            #filesystem_checks=config['mako.filesystem_checks']
            imports=['from webhelpers.html import escape'],
            default_filters=['escape']
        )

    # Setup cache object.
    #from zeta.lib.upgradeenv import cleardata
    #cleardata( envpath )
    config['cachemgr'] = cachemanager(envpath)

    return config
Esempio n. 19
0
2. Edit config file to point to a new test database and tell it about a dump
   of the database to test migration from.
      sqlalchemy.url = postgres://tester:pass@localhost/ckantestmigrate
      test_migration_db_dump = ~/db_backup/ckan.net/ckan.net.2010-01-13.pg_dump

To run a test:
    $ nosetests ckan/migration/tests/test_15.py --with-pylons=testmigrate.ini
'''
import os
import sys
import subprocess

from pylons import config

assert config.has_key('here'), 'ERROR: You need to run nosetests with option: --with-pylons=testmigrate.ini'

CONFIG_FILE = 'testmigrate.ini'
DB_NAME = 'ckantestmigrate'
DB_USER = '******'
TEST_DUMPS_PATH = os.path.join(config['here'], 'ckan/migration/tests/test_dumps')
RESTORE_FILEPATH = config['test_migration_db_dump']

class TestMigrationBase(object):
    psqlbase = 'export PGPASSWORD=pass && psql -q -h localhost --user %s %s' % (DB_USER, DB_NAME)

    @classmethod
    def setup_db(cls, pg_dump_file=None):
        if not pg_dump_file:
            pg_dump_file = RESTORE_FILEPATH
        assert pg_dump_file