2017-11-26 18:26:44 +00:00
|
|
|
#!/usr/bin/python3
|
2020-04-18 11:45:44 +00:00
|
|
|
# SPDX-License-Identifier: MIT
|
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
|
2018-05-22 22:54:40 +00:00
|
|
|
# Copyright (C) 2015-2018 Tobias Gruetzmacher
|
2016-04-12 22:52:16 +00:00
|
|
|
'''update languages.py from pycountry'''
|
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')
|
2020-04-18 11:45:44 +00:00
|
|
|
with codecs.open(fn, 'w', 'utf-8') as f:
|
|
|
|
f.write('# SPDX-License-Identifier: MIT\n')
|
|
|
|
f.write('# ISO 693-1 language codes from pycountry\n')
|
|
|
|
f.write('# This file is automatically generated, DO NOT EDIT!\n')
|
2015-07-10 23:23:20 +00:00
|
|
|
lang = get_used_languages()
|
|
|
|
write_languages(f, lang)
|
|
|
|
|
|
|
|
|
|
|
|
def get_used_languages():
|
2018-05-22 22:54:40 +00:00
|
|
|
languages = {}
|
2016-04-16 11:14:12 +00:00
|
|
|
for scraperobj in get_scrapers():
|
2018-05-22 22:54:40 +00:00
|
|
|
lang = scraperobj.lang
|
|
|
|
if lang not in languages:
|
|
|
|
languages[lang] = scraperobj.language()
|
|
|
|
return languages
|
2015-07-10 23:23:20 +00:00
|
|
|
|
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()
|