Пример #1
0
def config(configfile, schemafile=None, features=()):
    # Load the configuration schema
    if schemafile is None:
        schemafile = os.path.join(
            os.path.dirname(appsetup.__file__), 'schema', 'schema.xml')

    # Let's support both, an opened file and path
    if isinstance(schemafile, basestring):
        schema = ZConfig.loadSchema(schemafile)
    else:
        schema = ZConfig.loadSchemaFile(schemafile)

    # Load the configuration file
    # Let's support both, an opened file and path
    try:
        if isinstance(configfile, basestring):
            options, handlers = ZConfig.loadConfig(schema, configfile)
        else:
            options, handlers = ZConfig.loadConfigFile(schema, configfile)
    except ZConfig.ConfigurationError as msg:
        sys.stderr.write("Error: %s\n" % str(msg))
        sys.exit(2)

    # Insert all specified Python paths
    if options.path:
        sys.path[:0] = [os.path.abspath(p) for p in options.path]

    # Parse product configs
    zope.app.appsetup.product.setProductConfigurations(
        options.product_config)

    # Setup the event log
    options.eventlog()

    # Setup other defined loggers
    for logger in options.loggers:
        logger()

    # Insert the devmode feature, if turned on
    if options.devmode:
        features += ('devmode',)
        logging.warning("Developer mode is enabled: this is a security risk "
            "and should NOT be enabled on production servers. Developer mode "
            "can usually be turned off by setting the `devmode` option to "
            "`off` or by removing it from the instance configuration file "
            "completely.")

    # Execute the ZCML configuration.
    appsetup.config(options.site_definition, features=features)

    # Connect to and open the database, notify subscribers.
    db = appsetup.multi_database(options.databases)[0][0]
    notify(zope.processlifetime.DatabaseOpened(db))

    return db
Пример #2
0
def config(configfile, schemafile=None, features=()):
    # Load the configuration schema
    if schemafile is None:
        schemafile = os.path.join(os.path.dirname(appsetup.__file__), 'schema',
                                  'schema.xml')

    # Let's support both, an opened file and path
    if isinstance(schemafile, basestring):
        schema = ZConfig.loadSchema(schemafile)
    else:
        schema = ZConfig.loadSchemaFile(schemafile)

    # Load the configuration file
    # Let's support both, an opened file and path
    try:
        if isinstance(configfile, basestring):
            options, handlers = ZConfig.loadConfig(schema, configfile)
        else:
            options, handlers = ZConfig.loadConfigFile(schema, configfile)
    except ZConfig.ConfigurationError as msg:
        sys.stderr.write("Error: %s\n" % str(msg))
        sys.exit(2)

    # Insert all specified Python paths
    if options.path:
        sys.path[:0] = [os.path.abspath(p) for p in options.path]

    # Parse product configs
    zope.app.appsetup.product.setProductConfigurations(options.product_config)

    # Setup the event log
    options.eventlog()

    # Setup other defined loggers
    for logger in options.loggers:
        logger()

    # Insert the devmode feature, if turned on
    if options.devmode:
        features += ('devmode', )
        logging.warning(
            "Developer mode is enabled: this is a security risk "
            "and should NOT be enabled on production servers. Developer mode "
            "can usually be turned off by setting the `devmode` option to "
            "`off` or by removing it from the instance configuration file "
            "completely.")

    # Execute the ZCML configuration.
    appsetup.config(options.site_definition, features=features)

    # Connect to and open the database, notify subscribers.
    db = appsetup.multi_database(options.databases)[0][0]
    notify(zope.processlifetime.DatabaseOpened(db))

    return db
Пример #3
0
def main(config=None, file=None):

    parser = OptionParser()
    parser.add_option('-f',
                      '--file',
                      metavar='FILE',
                      dest='file',
                      default=None,
                      help='a file as mail source code')

    parser.add_option('-c',
                      '--config',
                      metavar='FILE',
                      dest='config',
                      default=None,
                      help='path to configuration file')

    options, args = parser.parse_args()
    
    
    configparser = ConfigParser()
    if options.config is not None:
        config = options.config
    if not config:
        raise ValueError('missing configuration file. -c /path/config.cfg')


    configparser.read(config)
    
    zcml = os.path.join(os.path.dirname(__file__),'site.zcml')
    
    raw_configurator(ini_file=config, local_conf_key='mailtosql', here=__file__)
    
    appsetup.config(zcml)

    from raptus.mailcone.mailtosql.parser import Parser
    if options.file is not None:
        for f in files(options.file):
            Parser(open(f,'r').read())
    elif file is not None:
        for f in files(file):
            Parser(open(f, 'r').read())
    else:
        Parser(sys.stdin.read())
Пример #4
0
        if isinstance(configfile, basestring):
            options, handlers = ZConfig.loadConfig(schema, configfile)
        else:
            options, handlers = ZConfig.loadConfigFile(schema, configfile)
    except ZConfig.ConfigurationError, msg:
        sys.stderr.write("Error: %s\n" % str(msg))
        sys.exit(2)

    # Insert all specified Python paths
    if options.path:
        sys.path[:0] = [os.path.abspath(p) for p in options.path]

    # Setup the event log
    options.eventlog()

    # Insert the devmode feature, if turned on
    if options.devmode:
        features += ('devmode',)

    # Configure the application
    appsetup.config(options.site_definition, features=features)

    # Connect to and open the database
    db = appsetup.multi_database(options.databases)[0][0]

    # Send out an event that the database has been opened
    notify(appsetup.interfaces.DatabaseOpened(db))

    # Create the WSGI application
    return WSGIPublisherApplication(db, requestFactory)
 def test_sets_HTTP_500_if_devmode_is_set(self):
     from zope.app.appsetup import appsetup
     appsetup.config(self.zcml_file, ('devmode',))
     view = self.callVUT()
     self.assertEqual(500, view.request.response.getStatus())