예제 #1
0
    def __init__(self, request):
        self.request = request
        self.language = request.locale_name
        self.settings = request.registry.settings
        es_host = self.settings.get('es.host', 'http://localhost:9200')
        self.es_settings = {'urls': [es_host]}

        repo_dir = self.settings.get('unicore.repos_dir', 'repos')
        repo_names = config_list(self.settings['unicore.content_repos'])
        self.all_repo_paths = map(
            lambda repo_name: os.path.join(repo_dir, repo_name), repo_names)
        self.all_index_prefixes = map(
            lambda repo_path_or_name: parse_repo_name(repo_path_or_name),
            repo_names)

        search_config = {
            'in_': self.all_repo_paths,
            'index_prefixes': self.all_index_prefixes
        }
        self.all_categories = SM(Category,
                                 **search_config).es(**self.es_settings)
        self.all_pages = SM(Page, **search_config).es(**self.es_settings)
        self.all_localisations = SM(Localisation,
                                    **search_config).es(**self.es_settings)
        self.available_languages = config_list(
            self.settings.get('available_languages', ''))
        self.featured_languages = config_list(
            self.settings.get('featured_languages', ''))
        self.display_languages = list(
            set(self.featured_languages) - set([self.language]))
예제 #2
0
    def __init__(self, request):
        self.request = request
        self.language = request.locale_name
        self.settings = request.registry.settings
        es_host = self.settings.get('es.host', 'http://localhost:9200')
        self.es_settings = {
            'urls': [es_host]
        }

        repo_dir = self.settings.get('unicore.repos_dir', 'repos')
        repo_names = config_list(self.settings['unicore.content_repos'])
        self.all_repo_paths = map(
            lambda repo_name: os.path.join(repo_dir, repo_name),
            repo_names)
        self.all_index_prefixes = map(
            lambda repo_path_or_name: parse_repo_name(repo_path_or_name),
            repo_names)

        search_config = {
            'in_': self.all_repo_paths,
            'index_prefixes': self.all_index_prefixes
        }
        self.all_categories = SM(Category, **search_config).es(
            **self.es_settings)
        self.all_pages = SM(Page, **search_config).es(**self.es_settings)
        self.all_localisations = SM(Localisation, **search_config).es(
            **self.es_settings)
        self.available_languages = config_list(
            self.settings.get('available_languages', ''))
        self.featured_languages = config_list(
            self.settings.get('featured_languages', ''))
        self.display_languages = list(
            set(self.featured_languages) - set([self.language]))
예제 #3
0
    def run(self, ini_config, ini_section, locales):
        if not locales:
            cp = ConfigParser()
            cp.read(ini_config)
            locales = config_list(cp.get(ini_section, 'available_languages'))

        package_name = run_setup('setup.py', stop_after='init').get_name()
        locale_dir = os.path.join(package_name, 'locale')
        pot_filename = os.path.join(locale_dir, 'messages.pot')

        # delete existing .mo files
        for filename in glob.glob(
                os.path.join(locale_dir, '*/LC_MESSAGES/*.mo')):
            os.remove(filename)

        # generate new .pot file
        run_setup('setup.py', ['extract_messages', '-o', pot_filename])

        # initialize new locales' .po files
        for locale in locales:
            po_filename = os.path.join(locale_dir,
                                       '%s/LC_MESSAGES/messages.po' % locale)
            if os.path.exists(po_filename):
                continue
            run_setup('setup.py', [
                'init_catalog', '-i', pot_filename, '-d', locale_dir, '-l',
                locale
            ])

        # update and compile .po files
        run_setup('setup.py',
                  ['update_catalog', '-i', pot_filename, '-d', locale_dir])
        run_setup('setup.py', ['compile_catalog', '-d', locale_dir])
예제 #4
0
    def run(self, ini_config, ini_section, locales):
        if not locales:
            cp = ConfigParser()
            cp.read(ini_config)
            locales = config_list(cp.get(ini_section, 'available_languages'))

        package_name = run_setup('setup.py', stop_after='init').get_name()
        locale_dir = os.path.join(package_name, 'locale')
        pot_filename = os.path.join(locale_dir, 'messages.pot')

        # delete existing .mo files
        for filename in glob.glob(
                os.path.join(locale_dir, '*/LC_MESSAGES/*.mo')):
            os.remove(filename)

        # generate new .pot file
        run_setup('setup.py', [
            'extract_messages', '-o', pot_filename])

        # initialize new locales' .po files
        for locale in locales:
            po_filename = os.path.join(
                locale_dir, '%s/LC_MESSAGES/messages.po' % locale)
            if os.path.exists(po_filename):
                continue
            run_setup('setup.py', [
                'init_catalog', '-i', pot_filename, '-d', locale_dir,
                '-l', locale])

        # update and compile .po files
        run_setup('setup.py', [
            'update_catalog', '-i', pot_filename, '-d', locale_dir])
        run_setup('setup.py', [
            'compile_catalog', '-d', locale_dir])
예제 #5
0
    def run(self, config, verbose, clobber, repo_dir, repo_url,
            ini_config, ini_section, update_config, repo_name):
        config_file, config_data = config
        repo_name = repo_name or parse_repo_name(repo_url)
        workdir, _ = self.clone_repo(repo_name=repo_name,
                                     repo_url=repo_url,
                                     repo_dir=repo_dir,
                                     clobber=clobber,
                                     verbose=verbose)
        self.bootstrap(
            workdir,
            config_data.get('models', {}).items(),
            clobber=clobber,
            verbose=verbose)

        if not update_config:
            return

        repositories = config_data.setdefault('repositories', {})

        if repo_name not in repositories:
            repositories[repo_name] = repo_url

            with open(config_file, 'w') as fp:
                yaml.safe_dump(config_data,
                               stream=fp, default_flow_style=False)
            self.emit('Added %s to the %s config file.' % (
                repo_name, config_file))

        config_key = 'unicore.content_repos'

        cp = ConfigParser()
        cp.read(ini_config)
        if not cp.has_section(ini_section):
            cp.add_section(ini_section)

        existing_repo_names = (cp.get(ini_section, config_key)
                               if cp.has_option(ini_section, config_key)
                               else '')
        existing_repo_names = config_list(existing_repo_names)

        if repo_name not in existing_repo_names:
            cp.set(ini_section, config_key,
                   '\n'.join(chain(existing_repo_names, [repo_name])))
            with open(ini_config, 'w') as fp:
                cp.write(fp)
            self.emit(
                'Updated unicore.content_repos in %s.' % (ini_config,))
예제 #6
0
    def run(self, config, verbose, clobber, repo_dir, repo_url,
            ini_config, ini_section, update_config, repo_name, repo_host):
        repo_name = repo_name or parse_repo_name(repo_url)
        if repo_host:
            repo_location = self.import_remote(
                config, verbose, clobber, repo_host, repo_url, repo_name)
        else:
            repo_location = self.import_local(
                config, verbose, clobber, repo_dir, repo_url, repo_name)

        if not update_config:
            return

        config_file, config_data = config
        repositories = config_data.setdefault('repositories', {})

        if repo_name not in repositories:
            repositories[repo_name] = repo_url

            with open(config_file, 'w') as fp:
                yaml.safe_dump(config_data,
                               stream=fp, default_flow_style=False)
            self.emit('Added %s to the %s config file.' % (
                repo_name, config_file))

        config_key = 'unicore.content_repo_urls'

        cp = ConfigParser()
        cp.read(ini_config)
        if not cp.has_section(ini_section):
            cp.add_section(ini_section)

        existing_repos = (cp.get(ini_section, config_key)
                          if cp.has_option(ini_section, config_key)
                          else '')
        existing_repos = config_list(existing_repos)

        if repo_location not in existing_repos:
            cp.set(ini_section, config_key,
                   '\n'.join(chain(existing_repos, [repo_location])))
            with open(ini_config, 'w') as fp:
                cp.write(fp)
            self.emit(
                'Updated unicore.content_repo_urls in %s.' % (ini_config,))
예제 #7
0
    def run(self, config, verbose, clobber, repo_dir, repo_url, ini_config,
            ini_section, update_config, repo_name, repo_host):
        repo_name = repo_name or parse_repo_name(repo_url)
        if repo_host:
            repo_location = self.import_remote(config, verbose, clobber,
                                               repo_host, repo_url, repo_name)
        else:
            repo_location = self.import_local(config, verbose, clobber,
                                              repo_dir, repo_url, repo_name)

        if not update_config:
            return

        config_file, config_data = config
        repositories = config_data.setdefault('repositories', {})

        if repo_name not in repositories:
            repositories[repo_name] = repo_url

            with open(config_file, 'w') as fp:
                yaml.safe_dump(config_data,
                               stream=fp,
                               default_flow_style=False)
            self.emit('Added %s to the %s config file.' %
                      (repo_name, config_file))

        config_key = 'unicore.content_repo_urls'

        cp = ConfigParser()
        cp.read(ini_config)
        if not cp.has_section(ini_section):
            cp.add_section(ini_section)

        existing_repos = (cp.get(ini_section, config_key) if cp.has_option(
            ini_section, config_key) else '')
        existing_repos = config_list(existing_repos)

        if repo_location not in existing_repos:
            cp.set(ini_section, config_key,
                   '\n'.join(chain(existing_repos, [repo_location])))
            with open(ini_config, 'w') as fp:
                cp.write(fp)
            self.emit('Updated unicore.content_repo_urls in %s.' %
                      (ini_config, ))
예제 #8
0
 def test_config_list(self):
     self.assertEqual(['1', '2', '3'], config_list('1\n2\n3'))
     self.assertEqual(['1', '2', '3'], config_list('1\n2\n3\n'))
     self.assertEqual([], config_list(''))
예제 #9
0
 def test_config_list(self):
     self.assertEqual(['1', '2', '3'], config_list('1\n2\n3'))
     self.assertEqual(['1', '2', '3'], config_list('1\n2\n3\n'))
     self.assertEqual([], config_list(''))