Ejemplo n.º 1
0
    def testDownload2(self):
        from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump

        with patch.multiple(
            'clld.web.adapters.download',
            GzipFile=MagicMock(),
            ZipFile=MagicMock(),
            path=Mock(return_value=Mock(
                dirname=Mock(return_value=Mock(exists=Mock(return_value=False))))),
        ):
            dl = CsvDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            dl.create(self.env['request'], filename='name.n3', verbose=False)
            dl = N3Dump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            dl = RdfXmlDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
Ejemplo n.º 2
0
    def testDownload2(self):
        from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump
        from clld.web.adapters.cldf import CldfDownload

        tmp = mktemp()

        class Path(MagicMock, UnicodeMixin):
            @property
            def stem(self):
                return 'a'

            @property
            def parent(self):
                return Mock(exists=Mock(return_value=False))

            def open(self, mode):
                return open(tmp, mode)

        with patch.multiple(
                'clld.web.adapters.cldf',
                ZipFile=MagicMock(),
                Path=MagicMock(return_value=Path()),
                move=Mock(),
                remove=Mock(),
        ):
            with patch(
                    'clld.web.adapters.download.Path',
                    new=MagicMock(return_value=Path()),
            ):
                dl = CldfDownload(Dataset, 'clld')
                dl.create(self.env['request'], verbose=False)

        with patch.multiple(
                'clld.web.adapters.download',
                ZipFile=MagicMock(),
                Path=MagicMock(return_value=Path()),
                move=Mock(),
                remove=Mock(),
        ):
            dl = CsvDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            dl.create(self.env['request'], filename='name.n3', verbose=False)
            dl = N3Dump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            if os.path.exists(tmp):
                os.remove(tmp)
            else:  # pragma: no cover
                raise ValueError
            dl = RdfXmlDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)

        with closing(gzip.open(tmp, 'rb')) as fp:
            assert et.fromstring(fp.read())

        if os.path.exists(tmp):
            os.remove(tmp)
        else:  # pragma: no cover
            raise ValueError
Ejemplo n.º 3
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings['route_patterns'] = {
        'walss': '/wals',
        'wals': '/wals/{id:[^/\.]+}'
    }
    config = Configurator(settings=settings)
    config.include('clldmpg')
    config.registry.registerUtility(ApicsCtxFactoryQuery(), ICtxFactoryQuery)
    config.registry.registerUtility(ApicsMapMarker(), IMapMarker)
    config.registry.registerUtility(frequency_marker, IFrequencyMarker)
    config.registry.registerUtility(link_attrs, ILinkAttrs)
    config.register_menu(
        ('dataset', partial(menu_item, 'dataset', label='Home')),
        ('contributions', partial(menu_item, 'contributions')),
        ('parameters', partial(menu_item, 'parameters')),
        ('apics_wals', lambda ctx, rq:
         (rq.route_url('walss'), u'WALS\u2013APiCS')),
        ('surveys', partial(menu_item, 'surveys')),
        ('sentences', partial(menu_item, 'sentences')),
        ('sources', partial(menu_item, 'sources')),
        ('contributors', partial(menu_item, 'contributors')),
    )
    config.register_adapter(
        {
            "base": Representation,
            "mimetype": 'application/vnd.clld.chapter+html',
            "send_mimetype": "text/html",
            "extension": 'chapter.html',
            "template": 'parameter/chapter_html.mako',
        },
        IParameter,
        name="application/vnd.clld.chapter+html")

    config.register_download(
        CsvDump(common.Language, 'apics', description="Languages as CSV"))
    config.register_download(
        N3Dump(common.Language, 'apics', description="Languages as RDF"))
    config.register_download(
        Download(common.Source,
                 'apics',
                 ext='bib',
                 description="Sources as BibTeX"))

    config.register_resource('wals', Wals, IWals, with_index=True)
    config.register_resource('survey', Survey, ISurvey, with_index=True)

    config.register_adapters([
        (ISurvey, Representation, 'application/vnd.clld.md+xml', 'md.html',
         'md_html.mako', {
             'rel': 'describedby'
         })
    ])

    return config.make_wsgi_app()
Ejemplo n.º 4
0
    def test_Download2(self):
        from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump

        out = self.tmp_path('dl')
        dl = CsvDump(Language, 'clld')
        dl.create(self.env['request'], verbose=False, outfile=out)
        self.assertTrue(out.exists())
        dl.create(self.env['request'], filename=out, verbose=False, outfile=out)
        dl = N3Dump(Language, 'clld')
        self.assertEqual(dl.abspath(self.env['request']).name, 'dataset-language.n3.gz')
        dl.create(self.env['request'], verbose=False, outfile=out)
        dl = RdfXmlDump(Language, 'clld')
        dl.create(self.env['request'], verbose=False, outfile=out)

        with closing(gzip.open(out.as_posix(), 'rb')) as fp:
            assert et.fromstring(fp.read())
Ejemplo n.º 5
0
    def testDownload2(self):
        from clld.web.adapters.download import CsvDump, N3Dump, RdfXmlDump

        with patch.multiple(
                'clld.web.adapters.download',
                GzipFile=MagicMock(),
                ZipFile=MagicMock(),
                path=Mock(return_value=Mock(dirname=Mock(return_value=Mock(
                    exists=Mock(return_value=False))))),
        ):
            dl = CsvDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            dl.create(self.env['request'], filename='name.n3', verbose=False)
            dl = N3Dump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
            dl = RdfXmlDump(Language, 'clld')
            dl.create(self.env['request'], verbose=False)
Ejemplo n.º 6
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    lc = path(glottolog3.__file__).dirname().joinpath('static',
                                                      'legacy_codes.json')
    with open(lc) as fp:
        settings['legacy_codes'] = load(fp)

    settings.update(CFG)
    settings['navbar.inverse'] = True
    settings['route_patterns'] = {
        'languages': '/glottolog',
        'language': '/resource/languoid/id/{id:[^/\.]+}',
        'source': '/resource/reference/id/{id:[^/\.]+}',
        'sources': '/langdoc',
        #'provider': '/langdoc/langdocinformation#provider-{id}',
        'providers': '/langdoc/langdocinformation',
    }
    settings['sitemaps'] = ['language', 'source']
    config = get_configurator('glottolog3',
                              (GLCtxFactoryQuery(), ICtxFactoryQuery),
                              settings=settings,
                              routes=[
                                  ('languoid.xhtml',
                                   '/resource/languoid/id/{id:[^/\.]+}.xhtml'),
                                  ('reference.xhtml',
                                   '/resource/reference/id/{id:[^/\.]+}.xhtml')
                              ])
    config.register_menu(
        ('dataset', partial(menu_item, 'dataset', label='Home')),
        ('languages', partial(menu_item, 'languages', label='Languoids')),
        ('sources', partial(menu_item, 'sources', label='Langdoc')),
    )
    config.register_resource('provider',
                             models.Provider,
                             IProvider,
                             with_index=True)
    config.register_adapter(adapters.Redirect, IProvider)
    config.register_adapter(adapters.Bigmap, ILanguage)
    config.register_adapter(
        adapter_factory('provider/index_html.mako', base=Index), IProvider)
    config.register_datatable('providers', datatables.Providers)

    config.add_view(views.redirect_languoid_xhtml, route_name='languoid.xhtml')
    config.add_view(views.redirect_reference_xhtml,
                    route_name='reference.xhtml')

    config.add_route_and_view('glottolog.meta',
                              '/glottolog/glottologinformation',
                              views.glottologmeta,
                              renderer='glottologmeta.mako')

    config.add_route_and_view('glottolog.families',
                              '/glottolog/family',
                              views.families,
                              renderer='families.mako')

    config.add_route_and_view('glottolog.iso',
                              '/resource/languoid/iso/{id:[^/\.]+}', views.iso)

    config.add_route_and_view('glottolog.languages',
                              '/glottolog/language',
                              views.languages,
                              renderer='languages.mako')

    config.add_route_and_view('glottolog.childnodes',
                              '/db/getchildlects',
                              views.childnodes,
                              renderer='json')

    config.add_route_and_view('langdoc.complexquery',
                              '/langdoc/complexquery',
                              views.langdoccomplexquery,
                              renderer='langdoccomplexquery.mako')

    for name in 'credits glossary cite downloads errata contact'.split():
        pp = '/' if name == 'credits' else '/meta/'
        config.add_route_and_view('home.' + name,
                                  pp + name,
                                  getattr(views, name),
                                  renderer=name + '.mako')

    config.register_map('language', maps.LanguoidMap)
    config.register_datatable('languages', datatables.Families)
    config.register_datatable('sources', datatables.Refs)

    config.register_download(
        CsvDump(Language, 'glottolog3', description="Languoids as CSV"))
    config.register_download(
        N3Dump(Language, 'glottolog3', description="Languoids as RDF"))
    config.register_download(
        Download(Source,
                 'glottolog3',
                 ext='bib',
                 description="References as BibTeX"))
    config.register_download(
        N3Dump(Source, 'glottolog3', description="References as RDF"))
    return config.make_wsgi_app()