Exemplo n.º 1
0
    def testDownload_url(self):
        from clld.web.adapters.download import Download

        with patch.multiple(
                'clld.web.adapters.download',
                download_asset_spec=Mock(
                    return_value='clld:web/static/images/favicon.ico')):
            dl = Download(Source, 'clld', ext='bib')
            assert dl.url(self.env['request'])
Exemplo n.º 2
0
    def test_Download_url(self):
        from clld.web.adapters.download import Download

        with patch.multiple(
                'clld.web.adapters.download',
                download_asset_spec=Mock(
                    return_value='clld:web/static/images/favicon.ico')):
            dl = Download(Source, 'clld', ext='bib')
            assert dl.url(self.env['request'])
Exemplo n.º 3
0
 def create(self, req, filename=None, verbose=True):  # pragma: no cover
     meanings = [(p.name, p.id)
                 for p in DBSession.query(Parameter).order_by(Parameter.pk)]
     tmp = mkdtemp()
     path = os.path.join(tmp, 'asjp.tab')
     with UnicodeWriter(f=path, delimiter=binary_type("\t")) as writer:
         writer.writerow([f[0] for f in self.fields] + [m[0] for m in meanings])
         for lang in DBSession.query(Doculect).order_by(Doculect.pk).options(
                 joinedload_all(Language.valuesets, ValueSet.values),
                 joinedload_all(Language.valuesets, ValueSet.parameter)
         ).limit(10000):
             row = [f[1](lang) for f in self.fields]
             vss = {vs.parameter.id: vs for vs in lang.valuesets}
             row.extend([Doculect.format_words(vss.get(m[1])) for m in meanings])
             writer.writerow(row)
     Download.create(self, req, filename=path)
     rmtree(tmp)
Exemplo n.º 4
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()
Exemplo n.º 5
0
 def create(self, req, filename=None, verbose=True):  # pragma: no cover
     meanings = [(p.name, p.id)
                 for p in DBSession.query(Parameter).order_by(Parameter.pk)]
     tmp = mkdtemp()
     path = os.path.join(tmp, 'asjp.tab')
     with UnicodeWriter(f=path, delimiter=binary_type("\t")) as writer:
         writer.writerow([f[0]
                          for f in self.fields] + [m[0] for m in meanings])
         for lang in DBSession.query(Doculect).order_by(
                 Doculect.pk).options(
                     joinedload_all(Language.valuesets, ValueSet.values),
                     joinedload_all(Language.valuesets,
                                    ValueSet.parameter)).limit(10000):
             row = [f[1](lang) for f in self.fields]
             vss = {vs.parameter.id: vs for vs in lang.valuesets}
             row.extend(
                 [Doculect.format_words(vss.get(m[1])) for m in meanings])
             writer.writerow(row)
     Download.create(self, req, filename=path)
     rmtree(tmp)
Exemplo n.º 6
0
 def asset_spec(self, req):
     return '.'.join(Download.asset_spec(self, req).split('.')[:-1])
Exemplo n.º 7
0
    def test_Download(self):
        from clld.web.adapters.download import Download

        dl = Download(Source, 'clld', ext='x')
        assert dl.asset_spec(Mock()).startswith('clld:')

        class TestDownload(Download):
            _path = mktemp()

            def asset_spec(self, req):
                return self._path

        dl = TestDownload(Source, 'clld', ext='bib')
        abspath = dl.abspath(self.env['request'])
        assert not abspath.exists()
        dl.create(self.env['request'], verbose=False)
        dl.size(self.env['request'])
        dl.label(self.env['request'])
        assert abspath.exists()
        os.remove(abspath.as_posix())

        dl = TestDownload(Source, 'clld', ext='rdf')
        dl.create(self.env['request'], verbose=False)
        os.remove(dl.abspath(self.env['request']).as_posix())
Exemplo n.º 8
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    settings.update(CFG)
    settings['navbar.inverse'] = True
    settings['route_patterns'] = {
        'languages': '/glottolog/language',
        '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 = Configurator(settings=settings)
    #
    # Note: The following routes must be registered before including the clld web app,
    # because they are special cases of a more general route pattern registered there.
    #
    config.add_route('languoid.xhtml',
                     '/resource/languoid/id/{id:[^/\.]+}.xhtml')
    config.add_route('reference.xhtml',
                     '/resource/reference/id/{id:[^/\.]+}.xhtml')

    config.include('clldmpg')
    config.add_route_and_view(
        'robots', '/robots.txt',
        lambda req: Response('Sitemap: {0}\nUser-agent: *\nDisallow: /files/\n'
                             .format(req.route_url('sitemapindex')),
                             content_type='text/plain'))
    config.registry.registerUtility(GLCtxFactoryQuery(), ICtxFactoryQuery)
    config.register_menu(
        #('dataset', partial(menu_item, 'dataset', label='Home')),
        ('languages', partial(menu_item, 'languages', label='Languages')),
        ('families', partial(menu_item, 'glottolog.families',
                             label='Families')),
        ('search',
         partial(menu_item, 'glottolog.languages', label='Language Search')),
        ('sources', partial(menu_item, 'sources', label='References')),
        ('query',
         partial(menu_item, 'langdoc.complexquery', label='Reference Search')),
        ('about', partial(menu_item, 'about', label='About')),
    )
    config.register_resource('provider',
                             models.Provider,
                             IProvider,
                             with_index=True)
    config.register_adapter(
        adapter_factory('provider/index_html.mako', base=Index), IProvider)
    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('news',
                              '/news',
                              views.news,
                              renderer='news.mako')
    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',
                              views.languages,
                              renderer='language/search_html.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 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_download(
        adapters.LanguoidCsvDump(models.Languoid,
                                 'glottolog3',
                                 description="Languoids as CSV"))
    config.register_download(
        adapters.LanguoidN3Dump(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"))

    config.add_route('langdocstatus', '/langdoc/status')
    config.add_route('langdocstatus.browser', '/langdoc/status/browser')
    config.add_route('langdocstatus.languages',
                     '/langdoc/status/languages-{ed:[0-9]}-{sdt:[0-9]}')
    config.scan('glottolog3.langdocstatus')
    config.register_datatable('providers', Providers)
    return config.make_wsgi_app()
Exemplo n.º 9
0
    def test_Download(self):
        from clld.web.adapters.download import Download

        dl = Download(Source, 'clld', ext='x')
        assert dl.asset_spec(Mock()).startswith('clld:')

        class TestDownload(Download):
            _path = mktemp()

            def asset_spec(self, req):
                return self._path

        dl = TestDownload(Source, 'clld', ext='bib')
        abspath = dl.abspath(self.env['request'])
        assert not abspath.exists()
        dl.create(self.env['request'], verbose=False)
        dl.size(self.env['request'])
        dl.label(self.env['request'])
        assert abspath.exists()
        os.remove(abspath.as_posix())

        dl = TestDownload(Source, 'clld', ext='rdf')
        dl.create(self.env['request'], verbose=False)
        os.remove(dl.abspath(self.env['request']).as_posix())
Exemplo n.º 10
0
def main(global_config, **settings):
    """return a Pyramid WSGI application."""
    settings['route_patterns'] = {
        'languages': '/languoid',
        'language': '/languoid/lect/wals_code_{id:[^/\.]+}',
        'source': '/refdb/record/{id:[^/\.]+}',
        'sources': '/refdb',
        'familys': '/languoid/family',
        'family': '/languoid/family/{id:[^/\.]+}',
        'genus': '/languoid/genus/{id:[^/\.]+}',
        'parameters': '/feature',
        'parameter': '/feature/{id:[^/\.]+}',
        'sentences': '/example',
        'sentence': '/example/{id:[^/\.]+}',
        'contributions': '/chapter',
        'contribution': '/chapter/{id:[^/\.]+}',
        'countrys': '/country',
        'country': '/country/{id:[^/\.]+}',
        'contributors': '/author',
        'contributor': '/author/{id:[^/\.]+}',
        'legal': '/about/legal',
        'olac': '/languoid/oai',
        'credits': '/about/credits',
    }
    filename_pattern = re.compile('(?P<spec>(c|d|s|f|t)[0-9a-f]{3})\.png')
    icons = []
    for p in sorted(Path(__file__).parent.joinpath('static',
                                                   'icons').iterdir(),
                    key=lambda p: p.name):
        m = filename_pattern.match(p.name)
        if m:
            icons.append(WalsIcon(m.group('spec')))

    config = Configurator(**dict(settings=settings))
    config.include('clldmpg')
    for utility, interface in [
        (WalsCtxFactoryQuery(), ICtxFactoryQuery),
        (map_marker, IMapMarker),
        (Blog(settings), IBlog),
        (icons, IIconList),
    ]:
        config.registry.registerUtility(utility, interface)

    config.register_resource('family', Family, IFamily, with_index=True)
    config.register_resource('genus', Genus, IGenus, with_index=True)
    config.register_resource('country', Country, ICountry)

    config.add_route('sample_alt',
                     '/languoid/samples/{count}.{ext}',
                     factory=sample_factory)
    config.add_route('sample',
                     '/languoid/samples/{count}',
                     factory=sample_factory)

    for spec in [
            dict(template='parameter/detail_tab.mako',
                 mimetype='application/vnd.clld.tab',
                 send_mimetype="text/plain",
                 extension='tab',
                 name='tab-separated values'),
            dict(template='parameter/detail_xml.mako',
                 mimetype='application/vnd.clld.xml',
                 send_mimetype="application/xml",
                 extension='xml',
                 name='WALS XML',
                 __doc__="Custom XML format."),
            dict(template='parameter/detail_georss.mako',
                 mimetype='application/vnd.clld.georss+xml',
                 send_mimetype="application/rdf+xml",
                 extension='georss',
                 name="GeoRSS",
                 __doc__="RSS with location information "
                 "(http://en.wikipedia.org/wiki/GeoRSS)."),
            dict(template='parameter/detail_kml.mako',
                 mimetype='application/vnd.google-earth.kml+xml',
                 send_mimetype="application/xml",
                 extension='kml',
                 name='KML',
                 __doc__="Keyhole Markup Language"),
    ]:
        config.register_adapter(spec, IParameter)

    config.add_route('feature_info', '/feature-info/{id}')
    config.add_route('genealogy', '/languoid/genealogy')

    config.add_301('/index', lambda req: req.route_url('dataset'))
    config.add_301(
        '/.{ext}',
        lambda req: req.route_url('dataset_alt', ext=req.matchdict['ext']))
    config.add_301(
        '/example/{fid}/all',
        lambda req: req.route_url('parameter', id=req.matchdict['fid']))
    config.add_301(
        '/example/all/wals_code_{lid}',
        lambda req: req.route_url('sentences',
                                  _query=dict(language=req.matchdict['lid'])))

    # we redirect legacy urls for datapoints because they could not be expressed
    # with a single id.
    def datapoint(req):
        data = {k: v for k, v in req.matchdict.items()}
        if data['fid'][-1] not in ascii_uppercase:
            data['fid'] += 'A'
        return req.route_url('valueset',
                             id='%(fid)s-%(lid)s' % data,
                             _query=req.query_params)

    config.add_301('/datapoint/{fid}/wals_code_{lid}',
                   datapoint,
                   name='datapoint')

    # we redirect legacy urls for feature combinations because they could not be expressed
    # with a single id.
    def combined(req):
        return req.route_url('combination',
                             id='%(id1)s_%(id2)s' % req.matchdict,
                             _query=req.query_params)

    config.add_301('/feature/combined/{id1}/{id2}', combined, name='combined')

    config.add_301(
        "/feature/description/{id:[0-9]+}",
        lambda req: req.route_url('contribution', id=req.matchdict['id']))

    config.add_301(
        "/languoid/by_geography",
        lambda req: req.route_url('country', id=req.params.get('country')))

    config.add_301(
        "/wals-2011-{fid}",
        lambda req: req.route_url('parameter', id=req.matchdict.get('fid')))

    config.add_301('/languoid/lect', lambda req: req.route_url('languages'))
    config.add_301('/languoid/family', lambda req: req.route_url('languages'))
    config.add_301('/languoid/genus', lambda req: req.route_url('languages'))
    config.add_301('/supplement/1',
                   lambda req: req.route_url('contribution', id='s1'))
    config.add_301('/supplement/3',
                   lambda req: req.route_url('contribution', id='s1'))
    config.add_301('/supplement/5',
                   lambda req: req.route_url('contribution', id='s5'))
    config.add_301('/supplement/6',
                   lambda req: req.route_url('contribution', id='s6'))
    config.add_301('/supplement/7',
                   lambda req: req.route_url('contribution', id='s7'))
    config.add_301('/supplement/8',
                   lambda req: req.route_url('contribution', id='s8'))
    config.add_301('/supplement/9',
                   lambda req: req.route_url('contribution', id='s9'))

    for pattern in [
            '/refdb/', '/refdb/record', '/refdb/record/', '/refdb/search'
    ]:
        config.add_301(pattern, lambda req: req.route_url('sources'))

    config.add_410('/languoid/osd.{ext}')
    config.add_410("/experimental/{id}")

    config.add_route('olac.source', '/refdb_oai')
    config.add_route('languoids', '/languoids')
    config.add_route('blog_feed', '/blog')

    config.register_download(
        Matrix(Language, 'wals3', description="Feature values CSV"))
    config.register_download(
        Download(Source, 'wals3', ext='bib', description="Sources as BibTeX"))

    return config.make_wsgi_app()
Exemplo n.º 11
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()
Exemplo n.º 12
0
 def asset_spec(self, req):
     return '.'.join(Download.asset_spec(self, req).split('.')[:-1])