Пример #1
0
def setUp():
    """Setup the temporary SFLvault server"""
    # Remove the test database on each run.
    if os.path.exists(dbfile):
        os.unlink(dbfile)

    # Remove the test config on each run
    if os.path.exists(confile):
        os.unlink(confile)

    cmd = paste.script.appinstall.SetupCommand('setup-app')
    cmd.run([test_file])

    cfg = ConfigParser()
    cfg.read(test_file)
    sinfos = cfg._sections['server:main']
    wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
    server = serve(wsgiapp, sinfos['host'], sinfos['port'],
                   socket_timeout=1, start_loop=False)
    globs['server'] = server
    t = threading.Thread(target=server.serve_forever)
    t.setDaemon(True)
    t.start()

    wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
    app = paste.fixture.TestApp(wsgiapp)

    # Create the vault test obj.
    if 'SFLVAULT_ASKPASS' in os.environ:
        del(os.environ['SFLVAULT_ASKPASS'])
    os.environ['SFLVAULT_CONFIG'] = config['sflvault.testconfig']        
Пример #2
0
def manage(*args):
    settings = utils.get_settings(apps=('django_extensions',))
    del settings.DEBUG
    config = utils.get_config_file()
    app = loadapp('config:%s' % config) # NOQA
    from django.core import management
    management.setup_environ = lambda *args: os.getcwd
    loadapp('config:%s' % config)
    from django.conf import settings as sets # NOQA
    args = args or sys.argv[1:]

    if not args:
        return sys.exit(management.execute_manager(settings))

    cmd = args[0]
    config = ConfigParser()
    config.read(os.path.expanduser('~/.djangodevkitrc'))
    try:
        alias = config.get('aliases', cmd)
    except:
        cmds = [args]
    else:
        sargs = ' '.join(args[1:])
        cmds = [a.replace('[]', sargs) for a in alias.split('\n') if a.strip()]
        cmds = [a.split() for a in cmds]
    for cmd in cmds:
        sys.argv[1:] = cmd
        management.execute_manager(settings)
Пример #3
0
def main(serve=serve):
    port = int(os.environ.get("PORT", 6543))
    scheme = os.environ.get("SCHEME", "https")
    if "SETTINGS" in os.environ:
        settings = os.environ.get("SETTINGS")
        app = loadapp("config:" + settings, relative_to=".")
    else:
        app = loadapp("config:production.ini", relative_to=path.join(PACKAGE_DIR, "config-templates"))
    return serve(app, host="0.0.0.0", port=port, url_scheme=scheme)
Пример #4
0
def core_loadapp(config_name=None):
    from paste.deploy import loadapp
    if not config_name:
        if os.path.exists('local.ini'):
            config_name = 'config:local.ini'
        else:
            config_name = 'config:development.ini'
    here_dir = os.getcwd()
    loadapp(config_name, relative_to=here_dir)
Пример #5
0
def setup_config_test(config_file=None, force=False):
    '''
    This may be necessary to use within test setup that needs the app config loaded
    '''
    if not config_file:
        config_file = get_config_file()
    already_loaded = tg.config.get('tg.app_globals')
    if not already_loaded or force:
        loadapp('config:' + config_file)
Пример #6
0
def test_main():
    app = loadapp("config:sample_configs/basic_app.ini", relative_to=here)
    assert app is fakeapp.apps.basic_app
    app = loadapp("config:sample_configs/basic_app.ini#main", relative_to=here)
    assert app is fakeapp.apps.basic_app
    app = loadapp("config:sample_configs/basic_app.ini", relative_to=here, name="main")
    assert app is fakeapp.apps.basic_app
    app = loadapp("config:sample_configs/basic_app.ini#ignored", relative_to=here, name="main")
    assert app is fakeapp.apps.basic_app
Пример #7
0
def start(cname=None):
    if cname is None:
        log.warn('No config filename specified, trying production.ini')
        cname='production.ini'
    try:
        app=loadapp('config:%s' % cname, name='main', relative_to='.')
    except OSError:
        if cname != 'development.ini':
            log.warn('Config file %s not found, trying development.ini' % cname)
            cname='development.ini'
            app=loadapp('config:%s' % cname, name='main', relative_to='.')
Пример #8
0
def manage(*args):
    settings = utils.get_settings(apps=('django_extensions',))
    del settings.DEBUG
    config = utils.get_config_file()
    app = loadapp('config:%s' % config)
    from django.core import management
    management.setup_environ = lambda *args: os.getcwd
    loadapp('config:%s' % config)
    from django.core.management import execute_manager
    from django.conf import settings as sets
    sys.argv[1:1] = args
    management.execute_manager(settings)
Пример #9
0
    def __init__(self):
      self.apps = {}
      # application specified in same trac.ini
      if hasattr(self, "config"):
      #self.app = loadapp("config:%s"%(self.config.filename))
        for key, value in self.config.options('webapps'):
          if value.find(":") == -1:
            self.apps[key] = loadapp("config:%s"%(self.config.filename), name=value)
          else:
            self.apps[key] = loadapp(value)

      self.pattern = '/(%s)/?'%("|".join(self.apps.keys()))
Пример #10
0
def test_main():
    app = loadapp('config:sample_configs/basic_app.ini',
                  relative_to=here)
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:sample_configs/basic_app.ini#main',
                  relative_to=here)
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:sample_configs/basic_app.ini',
                  relative_to=here, name='main')
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:sample_configs/basic_app.ini#ignored',
                  relative_to=here, name='main')
    assert app is fakeapp.apps.basic_app
Пример #11
0
def setup_config_test(config_file=None, force=False):
    '''
    This may be necessary to use within test setup that needs the app config loaded,
    especially so that the tests can be run from any directory.
    When run from the ./Allura/ dir, the setup.cfg file there causes a pylons plugin
    for nose to run, which runs `loadapp` (among other things).
    This function lets a test run from any directory.
    '''
    if not config_file:
        config_file = get_config_file()
    already_loaded = pylons.config.get('pylons.app_globals')
    if not already_loaded or force:
        loadapp('config:' + config_file)
Пример #12
0
def test_main():
    app = loadapp('config:test_func.ini',
                  relative_to=config_path)
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:test_func.ini#main',
                  relative_to=config_path)
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:test_func.ini',
                  relative_to=config_path, name='main')
    assert app is fakeapp.apps.basic_app
    app = loadapp('config:test_func.ini#ignored',
                  relative_to=config_path, name='main')
    assert app is fakeapp.apps.basic_app
Пример #13
0
    def command_autogenerate(self, opts):
        config_name = 'config:%s' % opts.config

        here_dir = os.getcwd()
        sys.path.insert(0, here_dir)

        # Load the wsgi app first so that everything is initialized right
        loadapp(config_name, relative_to=here_dir)

        self.alembic_commands.revision(self.alembic_cfg, opts.name, autogenerate=True)

        log.warn('!!! REMEMBER TO EDIT THE AUTOGENERATED MIGRATION, '
                 'it will usually drop any support table which is not '
                 'registered into your application metadata.')
Пример #14
0
def get_or_load_app():
    global app
    if app is None:
        pkg_root_dir = pkg_resources.get_distribution('OpenFisca-Web-API').location
        conf_file_path = os.path.join(pkg_root_dir, CONF_FILE_NAME)
        app = loadapp(u'config:{}#main'.format(conf_file_path))
    return app
Пример #15
0
    def __init__(self, *args, **kwargs):
        '''
        initialize the test class
        '''
        TestCase.__init__(self, *args, **kwargs)

        LOG.error("ConfigFile: %s " % config['__file__'])

        conffile = config['__file__']

        if pylons.test.pylonsapp:
            wsgiapp = pylons.test.pylonsapp
        else:
            wsgiapp = loadapp('config: %s' % config['__file__'])

        self.app = TestApp(wsgiapp)

        conf = None
        if conffile.startswith('/'):
            conf = appconfig('config:%s' % config['__file__'], relative_to=None)
        else:
            raise Exception('dont know how to load the application relatively')
        #conf = appconfig('config: %s' % config['__file__'], relative_to=rel)

        load_environment(conf.global_conf, conf.local_conf)
        self.appconf = conf

        url._push_object(URLGenerator(config['routes.map'], environ))

        self.isSelfTest = False
        if env.has_key("privacyidea.selfTest"):
            self.isSelfTest = True

        self.license = 'CE'
        return
def load_paste_app(app_name, options, args):
    """
    Builds and returns a WSGI app from a paste config file.

    We search for the paste config file in the following order:
    * If --config-file option is used, use that
    * If args[0] is a file, use that
    * Search for quantum.conf in standard directories:
        * .
        * ~.quantum/
        * ~
        * /etc/quantum
        * /etc

    :param app_name: Name of the application to load
    :param options: Set of typed options returned from parse_options()
    :param args: Command line arguments from argv[1:]

    :raises RuntimeError when config file cannot be located or application
            cannot be loaded from config file
    """
    conf_file, conf = load_paste_config(app_name, options, args)

    try:
        app = deploy.loadapp("config:%s" % conf_file, name=app_name)
    except (LookupError, ImportError), e:
        raise RuntimeError("Unable to load %(app_name)s from "
                           "configuration file %(conf_file)s."
                           "\nGot: %(e)r" % locals())
Пример #17
0
    def _load_app(self):
        config_file = self.options.config_file
        if not os.path.isfile(config_file):
            raise BadCommand('Error: CONFIG_FILE not found at: %s\nPlease specify a CONFIG_FILE' % config_file)

        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()

        if self.options.verbose:
            # Configure logging from the config file
            self.logging_file_config(config_file)

        self.config = appconfig(config_name, relative_to=here_dir)
        self.config.update({'app_conf': self.config.local_conf,
                            'global_conf': self.config.global_conf})
        paste.deploy.config.CONFIG.push_thread_config(self.config)

        # Load locals and populate with objects for use in shell
        sys.path.insert(0, here_dir)

        # Load the wsgi app first so that everything is initialized right
        self.wsgiapp = loadapp(config_name, relative_to=here_dir)
        self.app = paste.fixture.TestApp(self.wsgiapp)

        # Query the test app to setup the environment
        tresponse = self.app.get('/_test_vars')
        request_id = int(tresponse.body)

        # Disable restoration during app requests
        self.app.pre_request_hook = lambda self: paste.registry.restorer.restoration_end()
        self.app.post_request_hook = lambda self: paste.registry.restorer.restoration_begin(request_id)

        paste.registry.restorer.restoration_begin(request_id)
Пример #18
0
    def load_app(self):
        ini_path = os.path.normpath(os.path.join(sys.modules[self.__module__].__file__, os.pardir, 'api-paste.ini'))
        if not os.path.isfile(ini_path):
            print("Cannot find %s.\n" % ini_path)
            exit(1)

        return deploy.loadapp('config:' + ini_path)
Пример #19
0
    def command(self):
        """Main command to create a new shell"""
        self.verbose = 3
        if len(self.args) == 0:
            # Assume the .ini file is ./development.ini
            config_file = 'development.ini'
            if not os.path.isfile(config_file):
                raise BadCommand('%sError: CONFIG_FILE not found at: .%s%s\n'
                                 'Please specify a CONFIG_FILE' % \
                                 (self.parser.get_usage(), os.path.sep,
                                  config_file))
        else:
            config_file = self.args[0]

        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()

        if not self.options.quiet:
            # Configure logging from the config file
            self.logging_file_config(config_file)

        # Load the wsgi app first so that everything is initialized right
        wsgiapp = loadapp(config_name, relative_to=here_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        # Query the test app to setup the environment and get the mapper
        tresponse = test_app.get('/_test_vars')
        mapper = tresponse.config.get('routes.map')
        if mapper:
            print mapper
Пример #20
0
    def __init__(self, app, extra_environ=None, relative_to=None):
        """
        Wraps a WSGI application in a more convenient interface for
        testing.

        ``app`` may be an application, or a Paste Deploy app
        URI, like ``'config:filename.ini#test'``.

        ``extra_environ`` is a dictionary of values that should go
        into the environment for each request.  These can provide a
        communication channel with the application.

        ``relative_to`` is a directory, and filenames used for file
        uploads are calculated relative to this.  Also ``config:``
        URIs that aren't absolute.
        """
        if isinstance(app, (str, unicode)):
            from paste.deploy import loadapp

            # @@: Should pick up relative_to from calling module's
            # __file__
            app = loadapp(app, relative_to=relative_to)
        self.app = app
        self.relative_to = relative_to
        if extra_environ is None:
            extra_environ = {}
        self.extra_environ = extra_environ
        self.reset()
Пример #21
0
def application(environ, start_response):
    if __app_objs__.get(environ['kp.paste_source']):
        app = __app_objs__[environ['kp.paste_source']]
    else:
        app = loadapp(environ['kp.paste_source'])
        
    return app(environ, start_response)
Пример #22
0
    def command(self):

        self.verbose = 3
        if len(self.args) == 0:
            config_file = "development.ini"
            if not os.path.isfile(config_file):
                raise BadCommand(
                    "%sError: CONFIG_FILE not found at: .%s%s\n"
                    "Please specify a CONFIG_FILE" % (self.parser.get_usage(), os.path.sep, config_file)
                )
        else:
            config_file = self.args[0]

        config_name = "config:%s" % config_file
        here_dir = os.getcwd()

        if not self.options.quiet:
            self.logging_file_config(config_file)

        wsgiapp = loadapp(config_name, relative_to=here_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        tresponse = test_app.get("/_test_vars")
        mapper = tresponse.config.get("routes.map")
        if mapper:
            print mapper
Пример #23
0
    def begin(self):
        """Called before any tests are collected or run

        Loads the application, and in turn its configuration.

        """
        global pylonsapp
        path = os.getcwd()
        sys.path.insert(0, path)
        pkg_resources.working_set.add_entry(path)
        self.app = pylonsapp = loadapp('config:' + self.config_file,
                                       relative_to=path)

        # Setup the config and app_globals, only works if we can get
        # to the config object
        conf = getattr(pylonsapp, 'config')
        if conf:
            pylons.config._push_object(conf)

            if 'pylons.app_globals' in conf:
                pylons.app_globals._push_object(conf['pylons.app_globals'])

        # Initialize a translator for tests that utilize i18n
        translator = _get_translator(pylons.config.get('lang'))
        pylons.translator._push_object(translator)
Пример #24
0
def get_app(config_file, name, loadapp=loadapp):
    """ Return the WSGI application named ``name`` in the PasteDeploy
    config file ``config_file``"""
    config_name = 'config:%s' % config_file
    here_dir = os.getcwd()
    app = loadapp(config_name, name=name, relative_to=here_dir)
    return app
Пример #25
0
def setup():
    global app
    here_dir = os.path.dirname(os.path.abspath(__file__))
    proj_dir = os.path.join(here_dir, 'TG2TestApp')
    
    pkg_resources.working_set.add_entry(proj_dir)

    from tg2testapp.model import DBSession, metadata, User, Group
    app = loadapp('config:development.ini', relative_to=proj_dir)
    app = TestApp(app)
    metadata.drop_all()
    metadata.create_all()

    session = DBSession
    user = User()
    user.user_name = u'asdf'
    user.email = u"*****@*****.**"
    user.password = u"asdf"
    
    session.save(user)
    
    for i in range (50):
        group = Group()
        group.group_name=unicode(i)
        session.save(group)
        user.groups.append(group)

    session.save(user)
    session.commit()
    session.flush()
Пример #26
0
def load_paste_app(app_name=None):
    """Builds and returns a WSGI app from a paste config file.
    We assume the last config file specified in the supplied ConfigOpts
    object is the paste config file.
    :param app_name: name of the application to load
    :raises RuntimeError when config file cannot be located or application
            cannot be loaded from config file
    """
    if app_name is None:
        app_name = CONF.prog

    # append the deployment flavor to the application name,
    # in order to identify the appropriate paste pipeline
    app_name += _get_deployment_flavor()

    conf_file = _get_deployment_config_file()

    try:
        logger = logging.getLogger(__name__)
        logger.debug("Loading {app_name} from {conf_file}".format(
            conf_file=conf_file, app_name=app_name))

        app = deploy.loadapp("config:%s" % conf_file, name=app_name)

        return app
    except (LookupError, ImportError) as e:
        msg = _("Unable to load %(app_name)s from configuration file"
                " %(conf_file)s. \nGot: %(e)r") % {'conf_file': conf_file,
                                                   'app_name': app_name,
                                                   'e': e}
        logger.error(msg)
        raise RuntimeError(msg)
Пример #27
0
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises ConfigFilesNotFoundError when config file cannot be located
    :raises RuntimeError when application cannot be loaded from config file
    """

    config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
    if not config_path:
        raise cfg.ConfigFilesNotFoundError(
            config_files=[cfg.CONF.api_paste_config])
    config_path = os.path.abspath(config_path)
    LOG.info(_LI("Config paste file: %s"), config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") %
               {'app_name': app_name,
                'config_path': config_path})
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app
Пример #28
0
def main():
    parser = optparse.OptionParser(description=__doc__, usage="%prog [options] queue_path")
    parser.add_option(
        "-C",
        "--config",
        dest="config",
        default=None,
        help="Path to configuration file (defaults to $CWD/etc/karl.ini)",
        metavar="FILE",
    )
    parser.add_option("--daemon", "-D", dest="daemon", action="store_true", default=False, help="Run in daemon mode.")
    parser.add_option(
        "--interval",
        "-i",
        dest="interval",
        type="int",
        default=6 * 3600,
        help="Interval, in seconds, between executions when in " "daemon mode.",
    )
    parser.add_option(
        "--server", "-s", dest="hostname", default="localhost", help="SMTP server host name", metavar="HOST"
    )
    parser.add_option("--port", "-P", dest="port", type="int", default=25, help="Port of SMTP server", metavar="PORT")
    parser.add_option("--username", "-u", dest="username", default=None, help="Username, if authentication is required")
    parser.add_option("--password", "-p", dest="password", default=None, help="Password, if authentication is required")
    parser.add_option(
        "--force-tls", "-f", dest="force_tls", action="store_true", default=False, help="Require that TLS be used."
    )
    parser.add_option(
        "--no-tls", "-n", dest="no_tls", action="store_true", default=False, help="Require that TLS not be used."
    )

    options, args = parser.parse_args()

    if not args:
        parser.error("Please specify queue path.")
    elif len(args) > 1:
        parser.error("Too many arguments.")
    queue_path = args[0]

    config = options.config
    if config is None:
        config = get_default_config()
    app = loadapp("config:%s" % config, "karl")
    set_subsystem("mailout")

    mailer = SMTPMailer(
        hostname=options.hostname,
        port=options.port,
        username=options.username,
        password=options.password,
        no_tls=options.no_tls,
        force_tls=options.force_tls,
    )
    qp = QueueProcessor(mailer, queue_path)

    if options.daemon:
        run_daemon("digest", qp.send_messages, options.interval)
    else:
        qp.send_messages()
Пример #29
0
 def _load_paste_app(self):
     try:
         app = deploy.loadapp("config:%s" % os.path.join(BASE_DIR, self.paste_conf), name=self.app_name)
         return app
     except (LookupError, ImportError) as e:
         logging.error(str(e))
         raise RuntimeError(str(e))
Пример #30
0
 def __init__(self, *args, **kwargs):
     wsgiapp = loadapp('config:%s' % self.__class__.CONFIG_FILENAME, 
                       relative_to=self.__class__.HERE_DIR)
     
     self.app = paste.fixture.TestApp(wsgiapp)
      
     BaseTestCase.__init__(self, *args, **kwargs)
Пример #31
0
def load_app(conf):
    global APPCONFIGS

    # Build the WSGI app
    cfg_path = conf.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = conf.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])

    config = dict(conf=conf)
    configkey = uuidutils.generate_uuid()
    APPCONFIGS[configkey] = config

    LOG.info('Full WSGI config used: %s', cfg_path)

    appname = "vitrage+" + conf.api.auth_mode
    return deploy.loadapp("config:" + cfg_path,
                          name=appname,
                          global_conf={'configkey': configkey})
Пример #32
0
def load_paste_app(app_name=None):
    """
    Builds and returns a WSGI app from a paste config file.

    We assume the last config file specified in the supplied ConfigOpts
    object is the paste config file.

    :param app_name: name of the application to load

    :raises RuntimeError when config file cannot be located or application
            cannot be loaded from config file
    """
    if app_name is None:
        app_name = CONF.prog

    # append the deployment flavor to the application name,
    # in order to identify the appropriate paste pipeline
    app_name += _get_deployment_flavor()

    conf_file = _get_deployment_config_file()

    try:
        # Setup logging early
        setup_logging()
        logger = logging.getLogger(app_name)

        logger.debug(_("Loading %(app_name)s from %(conf_file)s"),
                     {'conf_file': conf_file, 'app_name': app_name})

        app = deploy.loadapp("config:%s" % conf_file, name=app_name)

        # Log the options used when starting if we're in debug mode...
        if CONF.debug:
            CONF.log_opt_values(logger, logging.DEBUG)

        return app
    except (LookupError, ImportError), e:
        raise RuntimeError("Unable to load %(app_name)s from "
                           "configuration file %(conf_file)s."
                           "\nGot: %(e)r" % locals())
Пример #33
0
def main():
    parser = optparse.OptionParser(description=__doc__)
    parser.add_option('-C', '--config', dest='config',
        default=None,
        help='Path to configuration file (defaults to $CWD/etc/karl.ini)',
        metavar='FILE')
    parser.add_option('-l', '--log-file', dest='log_file',
        default=None,
        help="log file name (default to stderr)")
    parser.add_option('--daemon', '-D', dest='daemon',
                      action='store_true', default=False,
                      help='Run in daemon mode.')
    parser.add_option('--interval', '-i', dest='interval', type='int',
                      default=6*3600,
                      help='Interval, in seconds, between executions when in '
                           'daemon mode.')

    options, args = parser.parse_args()

    if options.log_file:
        logging.basicConfig(filename=options.log_file)
    else:
        logging.basicConfig() # log to stderr

    config = options.config
    if config is None:
        config = get_default_config()
    app = loadapp('config:%s' % config, 'karl')
    alerts = queryUtility(IAlerts, default=Alerts())

    def run():
        set_subsystem('digest')
        root, closer = get_root(app)
        alerts.send_digests(root)
        closer()

    if options.daemon:
        run_daemon('digest', run, options.interval)
    else:
        run()
Пример #34
0
    def __init__(self, app, extra_environ=None, relative_to=None,
                 use_unicode=True, cookiejar=None, parser_features=None,
                 json_encoder=None, lint=True):

        if 'WEBTEST_TARGET_URL' in os.environ:
            app = os.environ['WEBTEST_TARGET_URL']
        if isinstance(app, string_types):
            if app.startswith('http'):
                try:
                    from wsgiproxy import HostProxy
                except ImportError:  # pragma: no cover
                    raise ImportError((
                        'Using webtest with a real url requires WSGIProxy2. '
                        'Please install it with: '
                        'pip install WSGIProxy2'))
                if '#' not in app:
                    app += '#httplib'
                url, client = app.split('#', 1)
                app = HostProxy(url, client=client)
            else:
                from paste.deploy import loadapp
                # @@: Should pick up relative_to from calling module's
                # __file__
                app = loadapp(app, relative_to=relative_to)
        self.app = app
        self.lint = lint
        self.relative_to = relative_to
        if extra_environ is None:
            extra_environ = {}
        self.extra_environ = extra_environ
        self.use_unicode = use_unicode
        if cookiejar is None:
            cookiejar = http_cookiejar.CookieJar(policy=CookiePolicy())
        self.cookiejar = cookiejar
        if parser_features is None:
            parser_features = 'html.parser'
        self.RequestClass.ResponseClass.parser_features = parser_features
        if json_encoder is None:
            json_encoder = json.JSONEncoder
        self.JSONEncoder = json_encoder
Пример #35
0
    def setUp(self):
        conf_dir = os.path.dirname(__file__)
        self.app = loadapp('config:tests.ini', relative_to=conf_dir)

        self.testapp = UlearnhubTestApp(self)

        self.rabbit = RabbitClient(TEST_VHOST_URL)
        self.rabbit.management.cleanup(delete_all=True)
        self.rabbit.declare()

        httpretty.enable()
        http_mock_info()
        http_mock_checktoken()

        create_defaults(self.testapp.testapp.app.registry,
                        BASE_DOMAIN,
                        quiet=True)
        self.initialize_test_deployment()
        self.initialize_test_domain()

        self.patches = []
        self.clients = {}
Пример #36
0
    def init(self):
        "init"
        if len(self.args) == 0:
            config_file = '/etc/baruwa/production.ini'
        else:
            config_file = self.args[0]

        if not os.path.isfile(config_file):
            raise BadCommand('%sError: CONFIG_FILE not found at: %s, '
                             'Please specify a CONFIG_FILE' %
                             (self.parser.get_usage(), config_file))

        here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        here = os.path.dirname(here)
        config_name = 'config:' + config_file
        self.logging_file_config(config_file)
        conf = appconfig(config_name, relative_to=here)
        conf.update(dict(app_conf=conf.local_conf,
                    global_conf=conf.global_conf))

        wsgiapp = loadapp(config_name, relative_to=here)
        self.conf = conf
Пример #37
0
def main():
    # Init logger
    root_path = os.path.abspath(os.path.dirname(sys.argv[0]))
    log_config_path = root_path + '/conf/logging.conf'
    logging.config.fileConfig(log_config_path)
    logging.getLogger("sqlalchemy.engine.base.Engine").setLevel(
        logging.WARNING)
    logging.getLogger("requests.packages.urllib3.connectionpool").setLevel(
        logging.WARNING)
    logger = logging.getLogger("HttpServer")
    logger.info('Http Server Start')

    # Start heartbeat for primary site
    process = multiprocessing.Process(target=heartbeat, args=())
    process.start()

    # Start drcontroller http service
    conf = "conf/api-paste.ini"
    appname = "main"
    # commands.getoutput('mkdir -p /home/eshufan/dr_log/')
    app = loadapp("config:%s" % os.path.abspath(conf), appname)
    wsgi.server(eventlet.listen(('', 80)), app)
Пример #38
0
    def _get_initialized_app_context(parsed_args):
        """
        :param parsed_args: parsed args (eg. from take_action)
        :return: (wsgi_app, test_app)
        """
        config_file = parsed_args.config_file
        config_name = 'config:%s' % config_file
        here_dir = os.getcwd()

        # Load locals and populate with objects for use in shell
        sys.path.insert(0, here_dir)

        # Load the wsgi app first so that everything is initialized right
        wsgi_app = loadapp(config_name, relative_to=here_dir, global_conf={
            'disable_daemons': 'true',
        })
        test_app = TestApp(wsgi_app)

        # Make available the tg.request and other global variables
        tresponse = test_app.get('/_test_vars')

        return wsgi_app, test_app
Пример #39
0
def get_app(config_uri, name=None, options=None, loadapp=loadapp):
    """ Return the WSGI application named ``name`` in the PasteDeploy
    config file specified by ``config_uri``.

    ``options``, if passed, should be a dictionary used as variable assignments
    like ``{'http_port': 8080}``.  This is useful if e.g. ``%(http_port)s`` is
    used in the config file.

    If the ``name`` is None, this will attempt to parse the name from
    the ``config_uri`` string expecting the format ``inifile#name``.
    If no name is found, the name will default to "main"."""
    path, section = _getpathsec(config_uri, name)
    config_name = 'config:%s' % path
    here_dir = os.getcwd()
    if options:
        kw = {'global_conf': options}
    else:
        kw = {}

    app = loadapp(config_name, name=section, relative_to=here_dir, **kw)

    return app
Пример #40
0
def load_app(conf):
    global APPCONFIGS

    # Build the WSGI app
    cfg_file = None
    cfg_path = conf.api_paste_config
    if not os.path.isabs(cfg_path):
        cfg_file = conf.find_file(cfg_path)
    elif os.path.exists(cfg_path):
        cfg_file = cfg_path

    if not cfg_file:
        raise cfg.ConfigFilesNotFoundError([conf.api_paste_config])

    configkey = str(uuid.uuid4())
    APPCONFIGS[configkey] = conf

    LOG.info("Full WSGI config used: %s", cfg_file)
    LOG.warning("Note: Ceilometer API is deprecated; use APIs from "
                "Aodh (alarms), Gnocchi (metrics) and/or Panko (events).")
    return deploy.loadapp("config:" + cfg_file,
                          global_conf={'configkey': configkey})
Пример #41
0
def load_app(conf):
    global APPCONFIGS

    # Build the WSGI app
    cfg_path = conf.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = conf.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])

    config = dict(conf=conf)
    configkey = str(uuid.uuid4())
    APPCONFIGS[configkey] = config

    LOG.info("WSGI config used: %s", cfg_path)
    return deploy.loadapp("config:" + cfg_path,
                          name="aodh+" + (
                              conf.api.auth_mode
                              if conf.api.auth_mode else "noauth"
                          ),
                          global_conf={'configkey': configkey})
Пример #42
0
    def get_wsgi_app(self, name=None, defaults=None):
        """
        Reads the configuration source and finds and loads a WSGI
        application defined by the entry with name ``name`` per the
        PasteDeploy configuration format and loading mechanism.

        :param name: The named WSGI app to find, load and return. Defaults to
            ``None`` which becomes ``main`` inside
            :func:`paste.deploy.loadapp`.
        :param defaults: The ``global_conf`` that will be used during app
            instantiation.
        :return: A WSGI application.

        """
        name = self._maybe_get_default_name(name)
        defaults = self._get_defaults(defaults)
        return loadapp(
            self.pastedeploy_spec,
            name=name,
            relative_to=self.relative_to,
            global_conf=defaults,
        )
Пример #43
0
    def __init__(self, id):
        """ Initialize worker.
            id will be part of the pid-file.
        """
        #FIXME: There must be a smarter way to handle PID-files. I'm no console scripting expert :) /Robin
        self.id = id

        #Buildout path
        me = sys.argv[0]
        me = os.path.abspath(me)        
        self.buildoutpath = os.path.dirname(os.path.dirname(me))
        
        if len(sys.argv) < 2:
            sys.exit("Must specify paster.ini file to run")

        #setup logging
        self._setup_log()

        #PID file name
        rel = os.path.join(self.buildoutpath, 'var', 'worker_%s.pid' % self.id)
        self.pidfile = os.path.abspath(os.path.normpath(rel))
        
        #Check if PID exists
        if os.path.exists(self.pidfile):
            #Is this correct?
            msg = "PID-file already exists. Maybe the script is already running?"
            self.logger.exception(msg)
            sys.exit(msg)

        #Start wsgi stuff
        config = os.path.join(self.buildoutpath, sys.argv[1])
        self.app = loadapp('config:%s' % config, name='VoteIT')
        self.root, self.closer = get_root(self.app)
        
        print 'Worker initialized'

        #write pid
        self._write_pid_file()
Пример #44
0
def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('-p', '--port', action = 'store', default = 2000, help = "port to serve on")
    args = parser.parse_args()

    port = int(args.port)
    hostname = 'localhost'
    conf_file_path = os.path.join(sys.prefix, 'share', 'openfisca', 'openfisca-web-api', 'development-france.ini')

    # If openfisca_web_api has been installed with --editable
    if not os.path.isfile(conf_file_path):
        import pkg_resources
        api_sources_path = pkg_resources.get_distribution("openfisca_web_api").location
        conf_file_path = os.path.join(api_sources_path, 'development-france.ini')

    fileConfig(conf_file_path)
    application = loadapp('config:{}'.format(conf_file_path))
    httpd = make_server(hostname, port, application)
    print u'Serving on http://{}:{}/'.format(hostname, port)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        return
Пример #45
0
def init_application(name):
    conf_files = _get_config_files()

    # NOTE(melwitt): The init_application method can be called multiple times
    # within a single python interpreter instance if any exception is raised
    # during it (example: DBConnectionError while setting up the service) and
    # apache/mod_wsgi reloads the init_application script. So, we initialize
    # global data separately and decorate the method to run only once in a
    # python interpreter instance.
    init_global_data(conf_files, name)

    try:
        _setup_service(CONF.host, name)
    except exception.ServiceTooOld as exc:
        return error_application(exc, name)

    # This global init is safe because if we got here, we already successfully
    # set up the service and setting up the profile cannot fail.
    service.setup_profiler(name, CONF.host)

    conf = conf_files[0]

    return deploy.loadapp('config:%s' % conf, name=name)
Пример #46
0
def pytest_sessionstart():
    # setup resources before any test is executed
    pylonsapp = None
    pylons.test.pylonsapp = pylonsapp
    path = os.getcwd()
    sys.path.insert(0, path)
    pkg_resources.working_set.add_entry(path)
    config_file = py.test.config.inicfg.get("test_ini")
    pylonsapp = pylons.test.pylonsapp = loadapp('config:' + config_file,
                                                relative_to=path)

    # Setup the config and app_globals, only works if we can get
    # to the config object
    conf = getattr(pylonsapp, 'config')
    if conf:
        pylons.config._push_object(conf)

        if 'pylons.app_globals' in conf:
            pylons.app_globals._push_object(conf['pylons.app_globals'])

    # Initialize a translator for tests that utilize i18n
    translator = _get_translator(pylons.config.get('lang'))
    pylons.translator._push_object(translator)
Пример #47
0
def init_application(name):
    conf_files = _get_config_files()
    config.parse_args([], default_config_files=conf_files)

    logging.setup(CONF, "nova")
    try:
        _setup_service(CONF.host, name)
    except exception.ServiceTooOld as exc:
        return error_application(exc, name)

    service.setup_profiler(name, CONF.host)

    # dump conf at debug (log_options option comes from oslo.service)
    # FIXME(mriedem): This is gross but we don't have a public hook into
    # oslo.service to register these options, so we are doing it manually for
    # now; remove this when we have a hook method into oslo.service.
    CONF.register_opts(service_opts.service_opts)
    if CONF.log_options:
        CONF.log_opt_values(logging.getLogger(__name__), logging.DEBUG)

    conf = conf_files[0]

    return deploy.loadapp('config:%s' % conf, name=name)
Пример #48
0
def load_paste_app(app_name):
    """Builds and returns a WSGI app from a paste config file.

    :param app_name: Name of the application to load
    :raises RuntimeError when config file cannot be located or application
            cannot be loaded from config file
    """

    config_path = os.path.abspath(cfg.CONF.find_file(
        cfg.CONF.api_paste_config))
    LOG.info(_("Config paste file: %s"), config_path)

    try:
        app = deploy.loadapp("config:%s" % config_path, name=app_name)
    except (LookupError, ImportError):
        msg = (_("Unable to load %(app_name)s from "
                 "configuration file %(config_path)s.") % {
                     'app_name': app_name,
                     'config_path': config_path
                 })
        LOG.exception(msg)
        raise RuntimeError(msg)
    return app
Пример #49
0
    def start(self, key=None, backlog=128):
        """Run a WSGI server with the given application."""
        if self.socket is None:
            self.listen(key=key, backlog=backlog)

        try:
            kwargs = {
                'global_conf': {
                    'node_id': self.name,
                    'bus_id': self.bus_id,
                    'flags': json.dumps(self.flags)
                }
            }
            self.application = deploy.loadapp('config:%s' % self.app_conf,
                                              name='congress',
                                              **kwargs)
        except Exception:
            LOG.exception('Failed to Start %s server', self.name)
            raise exception.CongressException(
                'Failed to Start initializing %s server' % self.name)

        self.greenthread = self.pool.spawn(self._run, self.application,
                                           self.socket)
Пример #50
0
def main():
    # setup opts
    config.parse_args(args=sys.argv[1:])
    config.setup_logging()
    paste_conf = config.find_paste_config()

    # quick simple server for testing purposes or simple scenarios
    ip = CONF.get('bind_host', '0.0.0.0')
    port = CONF.get('bind_port', 9090)
    try:
        httpserver.serve(application=deploy.loadapp('config:%s' % paste_conf,
                                                    name='main'),
                         host=ip,
                         port=port)
        message = (_i18n._('Server listening on %(ip)s:%(port)s') % {
            'ip': ip,
            'port': port
        })
        _LOG.info(message)
        print(message)
    except KeyboardInterrupt:
        print(_i18n._("Thank You ! \nBye."))
        sys.exit(0)
Пример #51
0
def init_application():
    """Main entry point for initializing the Deckhand API service.

    Create routes for the v1.0 API and sets up logging.
    """
    config_files = _get_config_files()
    paste_file = config_files['paste']

    CONF([],
         project='deckhand',
         default_config_files=list(config_files.values()))

    setup_logging(CONF)

    policy.Enforcer(CONF)

    LOG.debug('Starting WSGI application using %s configuration file.',
              paste_file)

    db_api.setup_db(CONF.database.connection)

    app = deploy.loadapp('config:%s' % paste_file, name='deckhand_api')
    return app
Пример #52
0
def load_app(conf):
    global APPCONFIGS

    # Build the WSGI app
    cfg_path = conf.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = conf.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        LOG.debug("No api-paste configuration file found! Using default.")
        cfg_path = os.path.abspath(
            pkg_resources.resource_filename(__name__, "api-paste.ini"))

    config = dict(conf=conf)
    configkey = str(uuid.uuid4())
    APPCONFIGS[configkey] = config

    LOG.info("WSGI config used: %s", cfg_path)

    appname = "crane+basic"
    return deploy.loadapp("config:" + cfg_path,
                          name=appname,
                          global_conf={'configkey': configkey})
Пример #53
0
def load_paste_app(app_name=None):
    """Builds and returns a WSGI app from a paste config file.

    We assume the last config file specified in the supplied ConfigOpts
    object is the paste config file.

    :param app_name: name of the application to load

    :raises RuntimeError when config file cannot be located or application
            cannot be loaded from config file
    """
    if app_name is None:
        app_name = CONF.prog

    # append the deployment flavor to the application name,
    # in order to identify the appropriate paste pipeline
    app_name += _get_deployment_flavor()

    conf_file = _get_deployment_config_file()

    try:
        logger = logging.getLogger(__name__)
        logger.debug("Loading {app_name} from {conf_file}".format(
            conf_file=conf_file, app_name=app_name))

        app = deploy.loadapp("config:%s" % conf_file, name=app_name)

        return app
    except (LookupError, ImportError) as e:
        msg = _("Unable to load %(app_name)s from configuration file"
                " %(conf_file)s. \nGot: %(e)r") % {
                    'conf_file': conf_file,
                    'app_name': app_name,
                    'e': e
                }
        logger.error(msg)
        raise RuntimeError(msg)
Пример #54
0
class RedditTestCase(TestCase):
    """Base Test Case for tests that require the app environment to run.

    App startup does take time, so try to use unittest.TestCase directly when
    this isn't necessary as it'll save time.

    """
    if not _app_context:
        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        # this is basically what 'paster run' does (see r2/commands.py)
        test_response = test_app.get("/_test_vars")
        request_id = int(test_response.body)
        test_app.pre_request_hook = lambda self: \
            paste.registry.restorer.restoration_end()
        test_app.post_request_hook = lambda self: \
            paste.registry.restorer.restoration_begin(request_id)
        paste.registry.restorer.restoration_begin(request_id)

        _app_context = True

    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)

    def assert_same_dict(self, data, expected_data, prefix=None):
        prefix = prefix or []
        for k in set(data.keys() + expected_data.keys()):
            current_prefix = prefix + [k]
            want = expected_data.get(k)
            got = data.get(k)
            if isinstance(want, dict) and isinstance(got, dict):
                self.assert_same_dict(got, want, prefix=current_prefix)
            else:
                self.assertEqual(
                    got, want, "Mismatch for %s: %r != %r" %
                    (".".join(current_prefix), got, want))
Пример #55
0
class RedditTestCase(TestCase):
    """Base Test Case for tests that require the app environment to run.

    App startup does take time, so try to use unittest.TestCase directly when
    this isn't necessary as it'll save time.

    """
    if not _app_context:
        wsgiapp = loadapp('config:test.ini', relative_to=conf_dir)
        test_app = paste.fixture.TestApp(wsgiapp)

        # this is basically what 'paster run' does (see r2/commands.py)
        test_response = test_app.get("/_test_vars")
        request_id = int(test_response.body)
        test_app.pre_request_hook = lambda self: \
            paste.registry.restorer.restoration_end()
        test_app.post_request_hook = lambda self: \
            paste.registry.restorer.restoration_begin(request_id)
        paste.registry.restorer.restoration_begin(request_id)

        _app_context = True

    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)
Пример #56
0
def load_app(conf, indexer=None, storage=None,
             not_implemented_middleware=True):
    global APPCONFIGS

    # NOTE(sileht): We load config, storage and indexer,
    # so all
    if not storage:
        storage = gnocchi_storage.get_driver(conf)
    if not indexer:
        indexer = gnocchi_indexer.get_driver(conf)
        indexer.connect()

    # Build the WSGI app
    cfg_path = conf.api.paste_config
    if not os.path.isabs(cfg_path):
        cfg_path = conf.find_file(cfg_path)

    if cfg_path is None or not os.path.exists(cfg_path):
        LOG.debug("No api-paste configuration file found! Using default.")
        cfg_path = pkg_resources.resource_filename(__name__, "api-paste.ini")

    config = dict(conf=conf, indexer=indexer, storage=storage,
                  not_implemented_middleware=not_implemented_middleware)
    configkey = str(uuid.uuid4())
    APPCONFIGS[configkey] = config

    LOG.info("WSGI config used: %s", cfg_path)

    if conf.api.auth_mode == "noauth":
        warnings.warn("The `noauth' authentication mode is deprecated",
                      category=DeprecationWarning)

    appname = "gnocchi+" + conf.api.auth_mode
    app = deploy.loadapp("config:" + cfg_path, name=appname,
                         global_conf={'configkey': configkey})
    return cors.CORS(app, conf=conf)
Пример #57
0
def setUpModule():
    # Loading the application:
    conf_dir = config.here
    wsgiapp = loadapp('config:test.ini#main_without_authn',
                      relative_to=conf_dir)
    global app
    app = TestApp(wsgiapp)
    # Setting it up:
    test_file = path.join(conf_dir, 'test.ini')
    cmd = SetupCommand('setup-app')
    cmd.run([test_file])

    # Prepare authz test data
    subm_100 = model.Submission(
        id=100,
        filename=u'subm_100',
        source=u'subm_100',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc1').one(),
        language=model.Language.query.first())
    subm_101 = model.Submission(
        id=101,
        filename=u'subm_101',
        source=u'subm_101',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studentc2').one(),
        language=model.Language.query.first())
    subm_102 = model.Submission(
        id=102,
        filename=u'subm_102',
        source=u'subm_102',
        assignment=model.Assignment.query.filter_by(id=2).one(),
        user=model.User.query.filter_by(user_name='studente1').one(),
        language=model.Language.query.first())
    model.DBSession.add_all((subm_100, subm_101, subm_102))
    transaction.commit()
Пример #58
0
"""Sets server to wait for client requests."""
import os

from paste.deploy import loadapp
from waitress import serve
if __name__ == '__main__':
    port = int(os.environ.get("PORT", 5000))
    app = loadapp('config:production.ini', relative_to=".")

    serve(app, host='0.0.0.0', port=port)
Пример #59
0
 def loadapp(self, config, name='main'):
     return deploy.loadapp(self._paste_config(config), name=name)
Пример #60
0
 def load(self):
     return loadapp(self.cfgurl,
                    relative_to=self.relpath,
                    global_conf=self.gcfg)