Example #1
0
File: wsgi.py Project: hjalves/ines
    def start_applications(self, debug=False):
        settings = get_appsettings(self.config_path)
        not_found_application = settings.local_conf.pop(
            'not_found_application',
            settings.global_conf.get('not_found_application'))
        if not_found_application:
            not_found_application = loadapp(
                not_found_application,
                global_conf=settings.global_conf)
        else:
            not_found_application = not_found_api_application(
                settings.global_conf, **settings.local_conf)
        self.not_found_application = not_found_application

        self.validate_config_seconds = maybe_integer(
            settings.local_conf.pop('validate_config_seconds', None))

        for path, app_name in settings.local_conf.items():
            path = parse_path_expression(path)
            self[path] = get_app(self.config_path, app_name)

            if debug:
                print (
                    'Application %s reloaded on pid %s'
                    % (app_name, getpid()))
Example #2
0
def test_app():
    global _app
    _app = loadapp('config:sample.ini',
                   **dict(global_conf={},
                          relative_to=resource_filename(req, 'docs')
                          )
                   )
    return _app
Example #3
0
def setup(tc):
    global app
    doc_path = pkg_resources.resource_filename(dist, 'docs')
    gc = dict(data_path='psid:tests')
    app2 = loadapp('config:psid-conf.ini',
                   name='test',
                   **dict(global_conf=gc, relative_to=doc_path))
    
    app = TestApp(app2)
    teardown()
Example #4
0
def setup(tc):
    global app
    doc_path = pkg_resources.resource_filename(dist, 'docs')
    gc = dict(data_path='psid:tests')
    app2 = loadapp('config:psid-conf.ini',
                   name='test',
                   **dict(global_conf=gc, relative_to=doc_path))

    app = TestApp(app2)
    teardown()
Example #5
0
def webtest_app(request):
    relative_to = None
    if "webtest" in request.keywords:
        inifile = request.keywords["webtest"].args[0]
        relative_to = os.path.dirname(request.module.__file__)
    else:
        inifile = request.config.inifile
        inifile = os.path.abspath(os.path.normpath(inifile))
    app = loadwsgi.loadapp(
        "config:" + inifile,
        relative_to=relative_to)
    return webtest.TestApp(app)
 def start_server(self, env=None):
     """ Start the server instance.
     """
     print('\n==================================================================================')
     print("Starting wsgiref pyramid test server on host %s port %s" % (self.hostname, self.port))
     wsgi_app = loadapp('config:' + self.working_config)
     self.server = make_server(self.hostname, self.port, wsgi_app)
     worker = threading.Thread(target=self.server.serve_forever)
     worker.daemon = True
     worker.start()
     self.wait_for_go()
     print("Server now awake")
     print('==================================================================================')
 def start_server(self, env=None):
     """ Start the server instance.
     """
     print('\n==================================================================================')
     print("Starting wsgiref pyramid test server on host %s port %s" % (self.hostname, self.port))
     wsgi_app = loadapp('config:' + self.working_config)
     self.server = make_server(self.hostname, self.port, wsgi_app)
     worker = threading.Thread(target=self.server.serve_forever)
     worker.daemon = True
     worker.start()
     self.wait_for_go()
     print("Server now awake")
     print('==================================================================================')
Example #8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('config')
    parser.add_argument('--reload', action="store_true")

    args = parser.parse_args()
    if args.reload:
        if os.environ.get('PYTHON_RELOADER_SHOULD_RUN'):
            monitor.install_monitor()
            print('subprocess')
        else:
            return restart_with_reloader()
    app = loadwsgi.loadapp("config:" + args.config, relative_to=os.getcwd())
    server = loadwsgi.loadserver("config:" + args.config, relative_to=os.getcwd())
    server(app)
Example #9
0
def paste_deploy_app(paste_config_file, app_name, conf):
    """Load a WSGI app from a PasteDeploy configuration.

    Use deploy.loadapp() to load the app from the PasteDeploy configuration,
    ensuring that the supplied ConfigOpts object is passed to the app and
    filter constructors.

    :param paste_config_file: a PasteDeploy config file
    :param app_name: the name of the app/pipeline to load from the file
    :param conf: a ConfigOpts object to supply to the app and its filters
    :returns: the WSGI app
    """
    setup_paste_factories(conf)
    try:
        return loadwsgi.loadapp("config:%s" % paste_config_file, name=app_name)
    finally:
        teardown_paste_factories()
Example #10
0
def paste_deploy_app(paste_config_file, app_name, conf):
    """Load a WSGI app from a PasteDeploy configuration.

    Use deploy.loadapp() to load the app from the PasteDeploy configuration,
    ensuring that the supplied ConfigOpts object is passed to the app and
    filter constructors.

    :param paste_config_file: a PasteDeploy config file
    :param app_name: the name of the app/pipeline to load from the file
    :param conf: a ConfigOpts object to supply to the app and its filters
    :returns: the WSGI app
    """
    setup_paste_factories(conf)
    try:
        return loadwsgi.loadapp("config:%s" % paste_config_file, name=app_name)
    finally:
        teardown_paste_factories()
Example #11
0
 def command(self):
     # Load config file.
     app_spec = 'config:{0}'.format(self.args[0])
     base = os.getcwd()
     app = loadapp(app_spec, name='main', relative_to=base, global_conf={})
     # Read settings.
     settings = app.registry.settings
     cache = settings['fanscribed.cache']
     snippet_cache = settings['fanscribed.snippet_cache']
     # Make sure paths exist.
     if not os.path.isdir(cache):
         print 'Cache path {0} does not exist'.format(cache)
         return 1
     if not os.path.isdir(snippet_cache):
         print 'Snippet cache path {0} does not exist'.format(snippet_cache)
         return 1
     # Go through all of the files in the content cache and delete ones
     # not accessed within the threshold.
     print 'Content cache',
     oldest_allowed = time.time() - CONTENT_CACHE_THRESHOLD_SECONDS
     unlinked_count = 0
     filenames = os.listdir(cache)
     for filename in filenames:
         full_path = os.path.join(cache, filename)
         atime = os.stat(full_path).st_atime
         if atime < oldest_allowed:
             os.unlink(full_path)
             unlinked_count += 1
     print 'Unlinked: {0}, Remaining: {1}'.format(unlinked_count, len(filenames) - unlinked_count)
     # Go through all of the files in the snippet cache and delete ones
     # not accessed within the threshold.
     print 'Snippet cache',
     oldest_allowed = time.time() - SNIPPET_CACHE_THRESHOLD_SECONDS
     unlinked_count = 0
     filenames = os.listdir(snippet_cache)
     for filename in filenames:
         full_path = os.path.join(snippet_cache, filename)
         atime = os.stat(full_path).st_atime
         if atime < oldest_allowed:
             os.unlink(full_path)
             unlinked_count += 1
     print 'Unlinked: {0}, Remaining: {1}'.format(unlinked_count, len(filenames) - unlinked_count)
Example #12
0
    def start_applications(self, debug=False):
        settings = get_appsettings(self.config_path)
        not_found_application = settings.local_conf.pop(
            'not_found_application',
            settings.global_conf.get('not_found_application'))
        if not_found_application:
            not_found_application = loadapp(not_found_application,
                                            global_conf=settings.global_conf)
        else:
            not_found_application = not_found_api_application(
                settings.global_conf, **settings.local_conf)
        self.not_found_application = not_found_application

        self.validate_config_seconds = maybe_integer(
            settings.local_conf.pop('validate_config_seconds', None))

        for path, app_name in settings.local_conf.items():
            path = parse_path_expression(path)
            self[path] = get_app(self.config_path, app_name)

            if debug:
                print('Application %s reloaded on pid %s' %
                      (app_name, getpid()))
Example #13
0
def create_app(d):
    path = d.write('ftest.ini', config)
    app = loadapp("config:" + path)
    return webtest.TestApp(app)
Example #14
0
import sys

from paste.deploy.loadwsgi import loadapp

loadapp('config:' + sys.argv[1])
Example #15
0
 def __init__(self, app=None, source_location=None):
     if not app.startswith("config:") and not app.startswith("egg:"):
         app = "config:%s" % app
     self.app_string = app
     self.app = loadwsgi.loadapp(app)
     self.source_location = source_location
Example #16
0
 def __init__(self, app=None, source_location=None):
     if not app.startswith("config:") and not app.startswith("egg:"):
         app = "config:%s" % app
     self.app_string = app
     self.app = loadwsgi.loadapp(app)
     self.source_location = source_location
 def setUpClass(cls):
     cls.app = cls.AppClass(
         loadapp(cls.relative_uri, relative_to=cls.relative_to))
     cls.couchdb_server = cls.app.app.registry.couchdb_server
     cls.db = cls.app.app.registry.db
Example #18
0
 def command(self):
     # Load config file.
     app_spec = 'config:{0}'.format(self.args[0])
     base = os.getcwd()
     app = loadapp(app_spec, name='main', relative_to=base, global_conf={})
     # Read settings.
     settings = app.registry.settings
     audio_path = settings['fanscribed.audio']
     repos_path = settings['fanscribed.repos']
     templates_path = settings['fanscribed.repo_templates']
     snippet_seconds = int(settings['fanscribed.snippet_seconds'])
     # Make sure paths exist.
     if not os.path.isdir(templates_path):
         print 'Repo templates path {0} does not exist'.format(templates_path)
         return 1
     template_names = os.listdir(templates_path)
     if not template_names:
         print 'No templates exist in repo templates path {0}'.format(templates_path)
         return 1
     # Ask for a unique site name.
     is_valid_host_name = False
     host_name = None
     repo_path = None
     while not is_valid_host_name:
         host_name = self.challenge('Host name of new transcript')
         repo_path = os.path.join(repos_path, host_name)
         is_valid_host_name = not os.path.exists(repo_path)
         if not is_valid_host_name:
             print '{0} already exists'.format(repo_path)
     # Ask for audio URL.
     audio_url = self.challenge('Audio URL')
     # Ask for the template.
     print 'Available templates: {0}'.format(', '.join(template_names))
     is_valid_template = False
     variables_txt_path = None
     template_path = None
     while not is_valid_template:
         template_name = self.challenge('Template for new transcript')
         template_path = os.path.join(templates_path, template_name)
         variables_txt_path = os.path.join(template_path, 'variables.txt')
         is_valid_template = os.path.isfile(variables_txt_path)
         if not is_valid_template:
             print '{0} is not a valid template'.format(template_name)
     # Ask for all the variables in the template.
     variables = {}
     with open(variables_txt_path, 'rU') as f:
         for line in f.readlines():
             line = line.strip()
             parts = line.split(';', 1)
             if len(parts) != 2:
                 # Not a valid variable definition.
                 continue
             name, description = (part.strip() for part in parts)
             value = self.challenge(description)
             variables[name] = value
     # Download the audio.
     full_audio_file = os.path.join(audio_path, '{0}.mp3'.format(host_name))
     if not os.path.exists(full_audio_file) or self.ask('File exists, re-download?'):
         print 'Downloading {0} to {1} (please be patient)'.format(audio_url, full_audio_file)
         urllib.urlretrieve(audio_url, full_audio_file)
     else:
         print 'File already exists, and you wanted to keep it as-is.'
     # Get information about the audio.
     print 'Inspecting MP3 file for total time.'
     try:
         mp3_duration_ms = mp3.duration(full_audio_file)
     except IOError:
         print 'Could not determine duration of MP3 file!'
         return 1
     else:
         print 'MP3 file is {0}ms long'.format(mp3_duration_ms)
     # Prepare the repository.
     print 'Preparing repository.'
     repo = git.Repo.init(repo_path)
     print 'Writing transcription.json file.'
     transcription_json_path = os.path.join(template_path, 'transcription.json')
     if os.path.isfile(transcription_json_path):
         with open(transcription_json_path, 'rU') as f:
             transcription_json = f.read() % variables
     else:
         transcription_json = '{}'
     transcription_json = json.loads(transcription_json)
     transcription_json['audio_url'] = audio_url
     transcription_json['bytes_total'] = os.stat(full_audio_file).st_size
     transcription_json['duration'] = mp3_duration_ms
     transcription_json_output_path = os.path.join(repo_path, 'transcription.json')
     with open(transcription_json_output_path, 'wb') as f:
         json.dump(transcription_json, f, indent=4)
     repo.index.add(['transcription.json'])
     print 'Writing remaining_reviews.json and remaining_snippets.json'
     snippet_ms = snippet_seconds * 1000
     remaining_snippets = range(0, mp3_duration_ms, snippet_ms)
     remaining_reviews = remaining_snippets[:-1]
     remaining_snippets_output_path = os.path.join(repo_path, 'remaining_snippets.json')
     with open(remaining_snippets_output_path, 'wb') as f:
         json.dump(remaining_snippets, f, indent=4)
     repo.index.add(['remaining_snippets.json'])
     remaining_reviews_output_path = os.path.join(repo_path, 'remaining_reviews.json')
     with open(remaining_reviews_output_path, 'wb') as f:
         json.dump(remaining_reviews, f, indent=4)
     repo.index.add(['remaining_reviews.json'])
     print 'Writing additional template files:'
     for template_filename in os.listdir(template_path):
         if template_filename in {'transcription.json', 'variables.txt'}:
             # Skip special files.
             continue
         template_source = os.path.join(template_path, template_filename)
         if os.path.isdir(template_source):
             # Skip directories.
             continue
         print ' - {0}'.format(template_filename)
         with open(template_source, 'rb') as f:
             template_content = f.read() % variables
         template_dest = os.path.join(repo_path, template_filename)
         with open(template_dest, 'wb') as f:
             f.write(template_content)
         repo.index.add([template_filename])
     print 'Initial commit, using your globally configured name and email.'
     repo.index.commit('Initial commit.')
     print 'Done!'
def loadwsgiapp(uri, **kwargs):
    if os.environ.get("SINGLE_APP", False):
        global wsgiapp
        wsgiapp = wsgiapp or loadapp(uri, **kwargs)
        return wsgiapp
    return loadapp(uri, **kwargs)
Example #20
0
def app_factory(config):
    return loadwsgi.loadapp(
        config['config_url'],
        relative_to=config['relative_to'],
        global_conf=config['global_conf'])
Example #21
0
def app_factory(config):
    return loadwsgi.loadapp(config['config_url'],
                            relative_to=config['relative_to'],
                            global_conf=config['global_conf'])
Example #22
0
def app_factory(global_conf, virtualenv=None, config=None, **kw):

    assert virtualenv is not None

    site.addsitedir(virtualenv)
    return loadapp(config)