2015-07-10 23:23:20 +00:00
|
|
|
#!/usr/bin/python
|
2016-04-12 22:52:16 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2016-10-28 22:21:41 +00:00
|
|
|
# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs
|
2016-04-12 22:52:16 +00:00
|
|
|
# Copyright (C) 2012-2014 Bastian Kleineidam
|
2017-05-14 22:54:02 +00:00
|
|
|
# Copyright (C) 2015-2017 Tobias Gruetzmacher
|
2016-04-12 22:52:16 +00:00
|
|
|
'''update languages.py from pycountry'''
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
2015-07-10 23:23:20 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import codecs
|
|
|
|
|
|
|
|
basepath = os.path.dirname(os.path.dirname(__file__))
|
2016-04-16 11:14:12 +00:00
|
|
|
sys.path.insert(0, basepath)
|
2015-07-10 23:23:20 +00:00
|
|
|
|
2016-04-16 11:14:12 +00:00
|
|
|
from dosagelib.scraper import get_scrapers # noqa
|
2016-04-12 22:52:16 +00:00
|
|
|
|
2015-07-10 23:23:20 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Update language information in dosagelib/languages.py."""
|
|
|
|
fn = os.path.join(basepath, 'dosagelib', 'languages.py')
|
|
|
|
encoding = 'utf-8'
|
|
|
|
with codecs.open(fn, 'w', encoding) as f:
|
|
|
|
f.write('# -*- coding: %s -*-%s' % (encoding, os.linesep))
|
|
|
|
f.write('# ISO 693-1 language codes from pycountry%s' % os.linesep)
|
|
|
|
f.write('# This file is automatically generated, DO NOT EDIT!%s' % os.linesep)
|
2017-05-14 22:54:02 +00:00
|
|
|
f.write('from __future__ import absolute_import, division, print_function%s' % os.linesep)
|
2015-07-10 23:23:20 +00:00
|
|
|
lang = get_used_languages()
|
|
|
|
write_languages(f, lang)
|
|
|
|
|
|
|
|
|
|
|
|
def get_used_languages():
|
|
|
|
lang = {}
|
2016-04-16 11:14:12 +00:00
|
|
|
for scraperobj in get_scrapers():
|
|
|
|
l = scraperobj.lang
|
2015-07-10 23:23:20 +00:00
|
|
|
if l not in lang:
|
2016-04-16 11:14:12 +00:00
|
|
|
lang[l] = scraperobj.language()
|
2015-07-10 23:23:20 +00:00
|
|
|
return lang
|
|
|
|
|
2016-04-12 22:52:16 +00:00
|
|
|
|
2015-07-10 23:23:20 +00:00
|
|
|
def write_languages(f, l):
|
|
|
|
"""Write language information."""
|
|
|
|
f.write("Languages = {%s" % os.linesep)
|
|
|
|
for lang in sorted(l):
|
|
|
|
f.write(" %r: %r,%s" % (lang, l[lang], os.linesep))
|
|
|
|
f.write("}%s" % os.linesep)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|