当前位置: 首页>>代码示例>>Python>>正文


Python registry.Registry类代码示例

本文整理汇总了Python中paste.registry.Registry的典型用法代码示例。如果您正苦于以下问题:Python Registry类的具体用法?Python Registry怎么用?Python Registry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Registry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_environment_and_database

def setup_environment_and_database(env_dir=None, enabled_plugins=''):
    global_config = {}
    env_dir = env_dir or '/invalid'
    app_instance_secret = secret.secret_string()
    app_config = {
        'plugins': enabled_plugins,
        'sqlalchemy.url': 'sqlite://',
        'layout_template': 'layout',
        'external_template': 'false',
        'image_dir': os.path.join(env_dir, 'images'),
        'media_dir': os.path.join(env_dir, 'media'),
        'beaker.session.secret': app_instance_secret,
        'sa_auth.cookie_secret': app_instance_secret,
    }
    pylons_config = load_environment(global_config, app_config)
    paste_registry = Registry()
    paste_registry.prepare()
    app_globals = pylons_config['pylons.app_globals']
    register_instance(paste_registry, 'app_globals', app_globals)

    pylons_config.update({
        'paste.registry': paste_registry,
        'pylons.pylons': pylons,
    })
    metadata.create_all(bind=DBSession.bind, checkfirst=True)
    return pylons_config
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:26,代码来源:support.py

示例2: HelloworldCommand

class HelloworldCommand(Command):
    '''
    A base class to use when the full Pylons environment should be loaded
    '''
    summary = __doc__.split("\n") [0]
    usage = __doc__
    group_name = "helloworld"
    
    def __init__(self, name):
        Command.__init__(self, name)
        self.parser = Command.standard_parser(verbose=False)
        self.parser.add_option('-c', '--config', dest='config', default='development.ini', help='Config file to use.')
        return

    def command(self):
        pass
    
    def _load_config(self):
        from paste.deploy import appconfig
        if not self.options.config:
            msg = 'No config file supplied'
            raise self.BadCommand(msg)
        self.filename = os.path.abspath(self.options.config)
        if not os.path.exists(self.filename):
            raise AssertionError('Config filename %r does not exist.' % self.filename)
        fileConfig (self.filename)
        conf = appconfig('config:' + self.filename)
        # We have now loaded the config. Now we can import helloworld for the first time.
        from helloworld.config.environment import load_environment
        load_environment (conf.global_conf, conf.local_conf)

        self.registry = Registry()
        self.registry.prepare()
        return
开发者ID:drmalex07,项目名称:pylons-helloworld,代码行数:34,代码来源:commands.py

示例3: main

def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('config', help = 'path of configuration file')
    parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity')

    args = parser.parse_args()
#    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)
    logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout)
    site_conf = appconfig('config:{}'.format(os.path.abspath(args.config)))
    load_environment(site_conf.global_conf, site_conf.local_conf)

    registry = Registry()
    registry.prepare()
    registry.register(pylons.translator, MockTranslator())

    plugins.load('synchronous_search')

    model.repo.new_revision()

    for package_extra in model.Session.query(model.PackageExtra).filter(
            model.PackageExtra.key == 'supplier_id',
            model.PackageExtra.package_id.in_(
                model.Session.query(model.Package.id).filter(model.Package.name.like('%-fork-%'))),
            ):
        model.Session.delete(package_extra)

    model.repo.commit_and_remove()

    return 0
开发者ID:etalab,项目名称:etalab-ckan-scripts,代码行数:29,代码来源:remove_supplier_from_forks.py

示例4: CkanCommand

class CkanCommand(paste.script.command.Command):
    parser = paste.script.command.Command.standard_parser(verbose=True)
    parser.add_option('-c', '--config', dest='config',
            default='development.ini', help='Config file to use.')
    parser.add_option('-f', '--file',
        action='store',
        dest='file_path',
        help="File to dump results to (if needed)")
    default_verbosity = 1
    group_name = 'ckan'

    def _load_config(self):
        from paste.deploy import appconfig
        from ckan.config.environment import load_environment
        if not self.options.config:
            msg = 'No config file supplied'
            raise self.BadCommand(msg)
        self.filename = os.path.abspath(self.options.config)
        if not os.path.exists(self.filename):
            raise AssertionError('Config filename %r does not exist.' % self.filename)
        fileConfig(self.filename)
        conf = appconfig('config:' + self.filename)
        load_environment(conf.global_conf, conf.local_conf)

        self.registry=Registry()
        self.registry.prepare()
        import pylons
        self.translator_obj = MockTranslator()
        self.registry.register(pylons.translator, self.translator_obj)

    def _setup_app(self):
        cmd = paste.script.appinstall.SetupCommand('setup-app') 
        cmd.run([self.filename]) 
开发者ID:ciudadanointeligente,项目名称:ckan,代码行数:33,代码来源:cli.py

示例5: main

def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('config', help = 'path of configuration file')
    parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity')

    args = parser.parse_args()
#    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)
    logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout)
    site_conf = appconfig('config:{}'.format(os.path.abspath(args.config)))
    load_environment(site_conf.global_conf, site_conf.local_conf)

    registry = Registry()
    registry.prepare()
    registry.register(pylons.translator, MockTranslator())

    plugins.load('synchronous_search')

    model.repo.new_revision()

    for package_extra in model.Session.query(model.PackageExtra).filter(
            model.PackageExtra.key == 'territorial_coverage_granularity',
            model.PackageExtra.value == 'france',
            ):
        package = package_extra.package
        if package.private or package.state != 'active':
            log.warning(u'Territorial coverage granularity of package {} must be manually corrected'.format(
                package.name))
            continue
        package_extra.value = 'pays'

    model.repo.commit_and_remove()

    return 0
开发者ID:etalab,项目名称:etalab-ckan-scripts,代码行数:33,代码来源:repair_territorial_coverage_granularity.py

示例6: register_translator

def register_translator():
    from paste.registry import Registry
    import pylons

    registry = Registry()
    registry.prepare()
    translator_obj = MockTranslator()
    registry.register(pylons.translator, translator_obj)
    log.info('Translator object was registered for the background job')
开发者ID:CI-WATER,项目名称:portal,代码行数:9,代码来源:helpers.py

示例7: main

def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('config', help = 'path of configuration file')
    parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity')

    args = parser.parse_args()
#    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)
    logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout)
    site_conf = appconfig('config:{}'.format(os.path.abspath(args.config)))
    load_environment(site_conf.global_conf, site_conf.local_conf)

    registry = Registry()
    registry.prepare()
    registry.register(pylons.translator, MockTranslator())

    plugins.load('synchronous_search')

#    model.repo.new_revision()
#    for resource in model.Session.query(model.Resource).filter(
#            model.Resource.url.like('%etalab2.fr%'),
#            ):
#        url = resource.url
#        if url.startswith('http://ckan.etalab2.fr/'):
#            resource.url = resource.url.replace('http://ckan.etalab2.fr/', 'http://www.data.gouv.fr/fr/')
#        elif url.startswith('http://ckan-hetic.etalab2.fr/'):
#            resource.url = resource.url.replace('http://ckan-hetic.etalab2.fr/', 'http://www.data.gouv.fr/fr/')
#        elif url.startswith('http://www.etalab2.fr/'):
#            resource.url = resource.url.replace('http://www.etalab2.fr/', 'http://www.data.gouv.fr/')
#        else:
#            print resource.url
#    model.repo.commit_and_remove()

#    model.repo.new_revision()
#    for resource in model.Session.query(model.Resource).filter(
#            model.Resource.url.like('%www.data.gouv.fr%'),
#            ):
#        if resource.url.startswith('http://www.data.gouv.fr/') and not resource.url.startswith('http://www.data.gouv.fr/var'):
#            resource.url = resource.url.replace('http://www.data.gouv.fr/', 'http://new.data.gouv.fr/')
#    model.repo.commit_and_remove()

    model.repo.new_revision()
    for resource in model.Session.query(model.Resource).filter(
            model.Resource.url.like('http://new.data.gouv.fr/%'),
            ):
        resource.url = resource.url.replace('http://new.data.gouv.fr/', 'https://www.data.gouv.fr/')
    model.repo.commit_and_remove()

    model.repo.new_revision()
    for resource in model.Session.query(model.Resource).filter(
            model.Resource.url.like('https://new.data.gouv.fr/%'),
            ):
        resource.url = resource.url.replace('https://new.data.gouv.fr/', 'https://www.data.gouv.fr/')
    model.repo.commit_and_remove()

    return 0
开发者ID:etalab,项目名称:etalab-ckan-scripts,代码行数:55,代码来源:migrate_etalab2_to_data_gouv_fr.py

示例8: _paste_registry

def _paste_registry(pylons_request):
    "Internal helper method to get a new registry."
    paste_registry = None
    is_request_registered = is_object_registered(pylons_request)
    if is_request_registered:
        paste_registry = pylons_request.environ.get('paste.registry')
    if paste_registry is None:
        paste_registry = Registry()
        paste_registry.prepare()
        if is_request_registered:
            pylons_request.environ['paste.registry'] = paste_registry
    return paste_registry
开发者ID:FelixSchwarz,项目名称:mediadrop-test-renames,代码行数:12,代码来源:support.py

示例9: register_translator

def register_translator():
    # Register a translator in this thread so that
    # the _() functions in logic layer can work
    from paste.registry import Registry
    from pylons import translator
    from ckan.lib.cli import MockTranslator
    global registry
    registry = Registry()
    registry.prepare()
    global translator_obj
    translator_obj = MockTranslator()
    registry.register(translator, translator_obj)
开发者ID:ckan,项目名称:ckanext-archiver,代码行数:12,代码来源:tasks.py

示例10: main

def main():
    parser = argparse.ArgumentParser(description = __doc__)
    parser.add_argument('config', help = 'path of configuration file')
    parser.add_argument('-t', '--territoria-url', help = 'Territoria URL', required = True)
    parser.add_argument('-v', '--verbose', action = 'store_true', help = 'increase output verbosity')

    args = parser.parse_args()
#    logging.basicConfig(level = logging.DEBUG if args.verbose else logging.WARNING, stream = sys.stdout)
    logging.basicConfig(level = logging.INFO if args.verbose else logging.WARNING, stream = sys.stdout)
    site_conf = appconfig('config:{}'.format(os.path.abspath(args.config)))
    load_environment(site_conf.global_conf, site_conf.local_conf)

    registry = Registry()
    registry.prepare()
    registry.register(pylons.translator, MockTranslator())

    plugins.load('synchronous_search')

    model.repo.new_revision()

    kind_code_name_by_kind_code = {}
    for package_extra in model.Session.query(model.PackageExtra).filter(
            model.PackageExtra.key == 'territorial_coverage',
            ):
        if package_extra.value == 'Coutry/FR':
            kind_code_name = 'Country/FR/FRANCE'
        elif package_extra.value == 'InternationalOrganization/EU':
            kind_code_name = 'InternationalOrganization/UE/UNION EUROPEENNE'
        elif package_extra.value.count('/') == 1:
            kind_code_name = kind_code_name_by_kind_code.get(package_extra.value)
            if kind_code_name is None:
                kind, code = package_extra.value.split('/')
                try:
                    response = urllib2.urlopen(urlparse.urljoin(args.territoria_url,
                        '/api/v1/territory?{}'.format(urllib.urlencode(dict(
                            code = code,
                            kind = kind,
                            ), doseq = True))))
                except urllib2.HTTPError, response:
                    print package_extra.value
                    raise
                response_dict = json.loads(response.read())
                main_postal_distribution = response_dict['data']['main_postal_distribution']
                kind_code_name_by_kind_code[package_extra.value] = kind_code_name = u'/'.join([kind, code,
                    main_postal_distribution])
                print kind_code_name
        else:
            continue
        package = package_extra.package
        if package.private or package.state != 'active':
            log.warning(u'Territorial coverage of package {} must be manually corrected'.format(package.name))
            continue
        package_extra.value = kind_code_name
开发者ID:etalab,项目名称:etalab-ckan-scripts,代码行数:53,代码来源:add_main_postal_distribution_to_territorial_coverage.py

示例11: load_config

def load_config(path):
    import paste.deploy
    conf = paste.deploy.appconfig('config:' + path)
    import ckan, pylons
    ckan.config.environment.load_environment(conf.global_conf,
            conf.local_conf)

    from ckan.lib.cli import MockTranslator    
    from paste.registry import Registry 
    registry=Registry() 
    registry.prepare()     
    translator_obj=MockTranslator() 
    registry.register(pylons.translator, translator_obj) 
开发者ID:ArunEG,项目名称:ckanext-dgu,代码行数:13,代码来源:theme-guesser.py

示例12: command

def command(dry_run=False):
    from ckan import model
    from ckanext.dgu.lib.resource_formats import match
    from running_stats import StatsList

    # Register a translator in this thread so that
    # the _() functions in logic layer can work
    from ckan.lib.cli import MockTranslator
    registry=Registry()
    registry.prepare()
    translator_obj=MockTranslator() 
    registry.register(translator, translator_obj) 

    if not dry_run:
        model.repo.new_revision()

    # Add canonised formats to map
    for format_ in res_type_map.keys():
        res_type_map[canonise(format_)] = res_type_map[format_]

    log.info('Tidying resource types')

    stats = StatsList()

    res_query = model.Session.query(model.Resource)
    log.info('Tidying formats. Resources=%i Canonised formats=%i',
             res_query.count(), len(set(res_type_map.values())))

    for res in res_query:
        canonised_fmt = canonise(res.format or '')
        if canonised_fmt in res_type_map:
            improved_fmt = res_type_map[canonised_fmt]
        else:
            improved_fmt = tidy(res.format)
        match_ = match(improved_fmt)
        if match_:
            improved_fmt = match_
        if (improved_fmt or '') != (res.format or ''):
            if not dry_run:
                res.format = improved_fmt
            stats.add(improved_fmt, res.format)
        else:
            stats.add('No change', res.format)

    if not dry_run:
        model.repo.commit_and_remove()

    log.info('Stats report: %r', stats.report())
    print stats.report()

    log.info('Warnings (%i): %r', len(warnings), warnings)
开发者ID:ArunEG,项目名称:ckanext-dgu,代码行数:51,代码来源:tidy_resource_types.py

示例13: load_config

def load_config(path):
    import paste.deploy
    from paste.registry import Registry
    from command import MockTranslator

    conf = paste.deploy.appconfig('config:' + os.path.abspath(path))

    import ckan
    ckan.config.environment.load_environment(conf.global_conf,
            conf.local_conf)

    registry=Registry()
    registry.prepare()
    translator_obj = MockTranslator()
    registry.register(pylons.translator, translator_obj)
开发者ID:ArunEG,项目名称:ckanext-dgu,代码行数:15,代码来源:publisher_info.py

示例14: register_translator

def register_translator():
    # https://github.com/ckan/ckanext-archiver/blob/master/ckanext/archiver/bin/common.py
    # If not set (in cli access), patch the a translator with a mock, so the
    # _() functions in logic layer don't cause failure.
    from paste.registry import Registry
    from pylons import translator
    from ckan.lib.cli import MockTranslator
    if 'registery' not in globals():
        global registry
        registry = Registry()
        registry.prepare()

    if 'translator_obj' not in globals():
        global translator_obj
        translator_obj = MockTranslator()
        registry.register(translator, translator_obj)
开发者ID:aptivate,项目名称:ckanext-syndicate,代码行数:16,代码来源:tasks.py

示例15: _register_translator

def _register_translator():
    """
    Register a translator in this thread.
    """
    global registry
    try:
        registry
    except NameError:
        registry = Registry()
    registry.prepare()
    global translator_obj
    try:
        translator_obj
    except NameError:
        translator_obj = MockTranslator()
    registry.register(translator, translator_obj)
开发者ID:vaquer,项目名称:ckanext-extractor,代码行数:16,代码来源:config.py


注:本文中的paste.registry.Registry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。