From 86b31dc12b8938655535320417831b647e62ee57 Mon Sep 17 00:00:00 2001 From: Tobias Gruetzmacher Date: Tue, 21 Apr 2015 21:56:54 +0200 Subject: [PATCH] Depend on pycountry directly. --- dosage | 5 +- dosagelib/languages.py | 189 ----------------------------------------- dosagelib/util.py | 6 -- requirements.txt | 1 + scripts/mklanguages.py | 29 ------- setup.py | 1 + 6 files changed, 5 insertions(+), 226 deletions(-) delete mode 100644 dosagelib/languages.py delete mode 100755 scripts/mklanguages.py diff --git a/dosage b/dosage index a4485c941..5a0cd5612 100755 --- a/dosage +++ b/dosage @@ -15,9 +15,10 @@ import os import argparse import pydoc from io import StringIO +import pycountry from dosagelib import events, configuration, singleton, director from dosagelib.output import out -from dosagelib.util import internal_error, strlimit, getLangName +from dosagelib.util import internal_error, strlimit from dosagelib.ansicolor import get_columns @@ -151,7 +152,7 @@ def displayComicHelp(scraperobj): try: out.info(u"URL: " + scraperobj.url) if scraperobj.lang: - out.info(u"Language: " + getLangName(scraperobj.lang)) + out.info(u"Language: " + pycountry.languages.get(alpha2 = scraperobj.lang).name) if scraperobj.help: for line in scraperobj.help.splitlines(): out.info(line) diff --git a/dosagelib/languages.py b/dosagelib/languages.py deleted file mode 100644 index 81173588a..000000000 --- a/dosagelib/languages.py +++ /dev/null @@ -1,189 +0,0 @@ -# -*- coding: utf-8 -*- -# ISO 693-1 language codes from pycountry -Iso2Language = { - u'aa': u'Afar', - u'ab': u'Abkhazian', - u'af': u'Afrikaans', - u'ak': u'Akan', - u'sq': u'Albanian', - u'am': u'Amharic', - u'ar': u'Arabic', - u'an': u'Aragonese', - u'hy': u'Armenian', - u'as': u'Assamese', - u'av': u'Avaric', - u'ae': u'Avestan', - u'ay': u'Aymara', - u'az': u'Azerbaijani', - u'ba': u'Bashkir', - u'bm': u'Bambara', - u'eu': u'Basque', - u'be': u'Belarusian', - u'bn': u'Bengali', - u'bh': u'Bihari languages', - u'bi': u'Bislama', - u'bs': u'Bosnian', - u'br': u'Breton', - u'bg': u'Bulgarian', - u'my': u'Burmese', - u'ca': u'Catalan; Valencian', - u'ch': u'Chamorro', - u'ce': u'Chechen', - u'zh': u'Chinese', - u'cu': u'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', - u'cv': u'Chuvash', - u'kw': u'Cornish', - u'co': u'Corsican', - u'cr': u'Cree', - u'cs': u'Czech', - u'da': u'Danish', - u'dv': u'Divehi; Dhivehi; Maldivian', - u'nl': u'Dutch; Flemish', - u'dz': u'Dzongkha', - u'en': u'English', - u'eo': u'Esperanto', - u'et': u'Estonian', - u'ee': u'Ewe', - u'fo': u'Faroese', - u'fj': u'Fijian', - u'fi': u'Finnish', - u'fr': u'French', - u'fy': u'Western Frisian', - u'ff': u'Fulah', - u'ka': u'Georgian', - u'de': u'German', - u'gd': u'Gaelic; Scottish Gaelic', - u'ga': u'Irish', - u'gl': u'Galician', - u'gv': u'Manx', - u'el': u'Greek, Modern (1453-)', - u'gn': u'Guarani', - u'gu': u'Gujarati', - u'ht': u'Haitian; Haitian Creole', - u'ha': u'Hausa', - u'he': u'Hebrew', - u'hz': u'Herero', - u'hi': u'Hindi', - u'ho': u'Hiri Motu', - u'hr': u'Croatian', - u'hu': u'Hungarian', - u'ig': u'Igbo', - u'is': u'Icelandic', - u'io': u'Ido', - u'ii': u'Sichuan Yi; Nuosu', - u'iu': u'Inuktitut', - u'ie': u'Interlingue; Occidental', - u'ia': u'Interlingua (International Auxiliary Language Association)', - u'id': u'Indonesian', - u'ik': u'Inupiaq', - u'it': u'Italian', - u'jv': u'Javanese', - u'ja': u'Japanese', - u'kl': u'Kalaallisut; Greenlandic', - u'kn': u'Kannada', - u'ks': u'Kashmiri', - u'kr': u'Kanuri', - u'kk': u'Kazakh', - u'km': u'Central Khmer', - u'ki': u'Kikuyu; Gikuyu', - u'rw': u'Kinyarwanda', - u'ky': u'Kirghiz; Kyrgyz', - u'kv': u'Komi', - u'kg': u'Kongo', - u'ko': u'Korean', - u'kj': u'Kuanyama; Kwanyama', - u'ku': u'Kurdish', - u'lo': u'Lao', - u'la': u'Latin', - u'lv': u'Latvian', - u'li': u'Limburgan; Limburger; Limburgish', - u'ln': u'Lingala', - u'lt': u'Lithuanian', - u'lb': u'Luxembourgish; Letzeburgesch', - u'lu': u'Luba-Katanga', - u'lg': u'Ganda', - u'mk': u'Macedonian', - u'mh': u'Marshallese', - u'ml': u'Malayalam', - u'mi': u'Maori', - u'mr': u'Marathi', - u'ms': u'Malay', - u'mg': u'Malagasy', - u'mt': u'Maltese', - u'mo': u'Moldavian; Moldovan', - u'mn': u'Mongolian', - u'na': u'Nauru', - u'nv': u'Navajo; Navaho', - u'nr': u'Ndebele, South; South Ndebele', - u'nd': u'Ndebele, North; North Ndebele', - u'ng': u'Ndonga', - u'ne': u'Nepali', - u'nn': u'Norwegian Nynorsk; Nynorsk, Norwegian', - u'nb': u'Bokm\xe5l, Norwegian; Norwegian Bokm\xe5l', - u'no': u'Norwegian', - u'ny': u'Chichewa; Chewa; Nyanja', - u'oc': u'Occitan (post 1500)', - u'oj': u'Ojibwa', - u'or': u'Oriya', - u'om': u'Oromo', - u'os': u'Ossetian; Ossetic', - u'pa': u'Panjabi; Punjabi', - u'fa': u'Persian', - u'pi': u'Pali', - u'pl': u'Polish', - u'pt': u'Portuguese', - u'ps': u'Pushto; Pashto', - u'qu': u'Quechua', - u'rm': u'Romansh', - u'ro': u'Romanian', - u'rn': u'Rundi', - u'ru': u'Russian', - u'sg': u'Sango', - u'sa': u'Sanskrit', - u'si': u'Sinhala; Sinhalese', - u'sk': u'Slovak', - u'sl': u'Slovenian', - u'se': u'Northern Sami', - u'sm': u'Samoan', - u'sn': u'Shona', - u'sd': u'Sindhi', - u'so': u'Somali', - u'st': u'Sotho, Southern', - u'es': u'Spanish; Castilian', - u'sc': u'Sardinian', - u'sr': u'Serbian', - u'ss': u'Swati', - u'su': u'Sundanese', - u'sw': u'Swahili', - u'sv': u'Swedish', - u'ty': u'Tahitian', - u'ta': u'Tamil', - u'tt': u'Tatar', - u'te': u'Telugu', - u'tg': u'Tajik', - u'tl': u'Tagalog', - u'th': u'Thai', - u'bo': u'Tibetan', - u'ti': u'Tigrinya', - u'to': u'Tonga (Tonga Islands)', - u'tn': u'Tswana', - u'ts': u'Tsonga', - u'tk': u'Turkmen', - u'tr': u'Turkish', - u'tw': u'Twi', - u'ug': u'Uighur; Uyghur', - u'uk': u'Ukrainian', - u'ur': u'Urdu', - u'uz': u'Uzbek', - u've': u'Venda', - u'vi': u'Vietnamese', - u'vo': u'Volap\xfck', - u'cy': u'Welsh', - u'wa': u'Walloon', - u'wo': u'Wolof', - u'xh': u'Xhosa', - u'yi': u'Yiddish', - u'yo': u'Yoruba', - u'za': u'Zhuang; Chuang', - u'zu': u'Zulu', -} diff --git a/dosagelib/util.py b/dosagelib/util.py index b16cc07d1..f6f93bd10 100644 --- a/dosagelib/util.py +++ b/dosagelib/util.py @@ -30,7 +30,6 @@ except ImportError: from .decorators import memoized from .output import out from .configuration import UserAgent, AppName, App, SupportUrl -from .languages import Iso2Language # Maximum content size for HTML pages MaxContentBytes = 1024 * 1024 * 2 # 2 MB @@ -564,11 +563,6 @@ def strlimit (s, length=72): return "%s..." % s[:length] -def getLangName(code): - """Get name of language specified by ISO 693-1 code.""" - return Iso2Language[code] - - def writeFile(filename, content, encoding=None): """Write content to given filename. Checks for zero-sized files. If encoding is given writes to a codec.open() file.""" diff --git a/requirements.txt b/requirements.txt index b86af7c1b..588709337 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ # required: requests +pycountry # optional: argcomplete lxml diff --git a/scripts/mklanguages.py b/scripts/mklanguages.py deleted file mode 100755 index 1fd676c18..000000000 --- a/scripts/mklanguages.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python -# update languages.py from pycountry -import os -import codecs -import pycountry - -basepath = os.path.dirname(os.path.dirname(__file__)) - -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) - write_languages(f) - - -def write_languages(f): - """Write language information.""" - f.write("Iso2Language = {%s" % os.linesep) - for language in pycountry.languages: - if hasattr(language, 'alpha2'): - f.write(" %r: %r,%s" % (language.alpha2, language.name, os.linesep)) - f.write("}%s" % os.linesep) - - -if __name__ == '__main__': - main() diff --git a/setup.py b/setup.py index e81dde29c..d567e2933 100644 --- a/setup.py +++ b/setup.py @@ -457,6 +457,7 @@ args = dict( ), install_requires = ( 'requests', + 'pycountry', ) )