diff --git a/dosagelib/__init__.py b/dosagelib/__init__.py index 6f22614f7..0b3ee2948 100644 --- a/dosagelib/__init__.py +++ b/dosagelib/__init__.py @@ -15,8 +15,6 @@ Comic modules for each comic are located in L{dosagelib.plugins}. """ from __future__ import absolute_import, division, print_function -import sys -import os from pbr.version import VersionInfo AppName = u'dosage' diff --git a/dosagelib/cmd.py b/dosagelib/cmd.py index 500b2f836..14d77098b 100644 --- a/dosagelib/cmd.py +++ b/dosagelib/cmd.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function @@ -22,6 +22,7 @@ class ArgumentParser(argparse.ArgumentParser): with out.pager(): out.info(self.format_help()) + Examples = """\ EXAMPLES List available comics: @@ -293,6 +294,7 @@ def do_column_list(scrapers): del names[:names_per_line] return num, disabled + TAG_ADULT = "adult" TAG_LANG = "lang" TAG_DISABLED = "dis" diff --git a/dosagelib/configuration.py b/dosagelib/configuration.py index 1fa15de44..defaafe36 100644 --- a/dosagelib/configuration.py +++ b/dosagelib/configuration.py @@ -1,11 +1,12 @@ # -*- coding: utf-8 -*- # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher """ Define basic configuration data like version or application name. """ -from __future__ import print_function +from __future__ import absolute_import, division, print_function + from . import AppName, AppVersion App = AppName + u' ' + AppVersion @@ -18,7 +19,7 @@ UserAgent = u"Mozilla/5.0 (compatible; %s/%s; +%s)" % (AppName, AppVersion, Url) Copyright = u"""Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs Copyright (C) 2012-2014 Bastian Kleineidam -Copyright (C) 2015-2016 Tobias Gruetzmacher +Copyright (C) 2015-2017 Tobias Gruetzmacher """ Freeware = AppName + u""" comes with ABSOLUTELY NO WARRANTY! This is free software, and you are welcome to redistribute it diff --git a/dosagelib/events.py b/dosagelib/events.py index 71d4a8f46..43a6e1ff7 100644 --- a/dosagelib/events.py +++ b/dosagelib/events.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function @@ -310,6 +310,7 @@ def addHandlerClass(clazz): raise ValueError("%s must be subclassed from %s" % (clazz, EventHandler)) _handler_classes[clazz.name] = clazz + addHandlerClass(HtmlEventHandler) addHandlerClass(RSSEventHandler) addHandlerClass(JSONEventHandler) diff --git a/dosagelib/languages.py b/dosagelib/languages.py index 12321677e..a31d1b459 100644 --- a/dosagelib/languages.py +++ b/dosagelib/languages.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- # ISO 693-1 language codes from pycountry # This file is automatically generated, DO NOT EDIT! +from __future__ import absolute_import, division, print_function Languages = { - 'de': u'German', - 'en': u'English', - 'es': u'Spanish; Castilian', - 'fi': u'Finnish', - 'fr': u'French', - 'it': u'Italian', - 'ja': u'Japanese', - 'pt': u'Portuguese', + 'de': 'German', + 'en': 'English', + 'es': 'Spanish; Castilian', + 'fi': 'Finnish', + 'fr': 'French', + 'it': 'Italian', + 'ja': 'Japanese', + 'pt': 'Portuguese', } diff --git a/dosagelib/plugins/q.py b/dosagelib/plugins/q.py index cf7299cd4..8f9bf7f98 100644 --- a/dosagelib/plugins/q.py +++ b/dosagelib/plugins/q.py @@ -1,6 +1,9 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam +# Copyright (C) 2015-2017 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function from re import compile, escape from ..scraper import _BasicScraper diff --git a/dosagelib/plugins/x.py b/dosagelib/plugins/x.py index e53930605..4e8faf22d 100644 --- a/dosagelib/plugins/x.py +++ b/dosagelib/plugins/x.py @@ -1,13 +1,14 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function from ..scraper import _ParserScraper from ..helpers import bounceStarter + class Xkcd(_ParserScraper): name = 'xkcd' url = 'http://xkcd.com/' diff --git a/dosagelib/rss.py b/dosagelib/rss.py index a68882fb0..d4cff6dbc 100644 --- a/dosagelib/rss.py +++ b/dosagelib/rss.py @@ -1,12 +1,17 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs -# TODO: Not sure if this RSS output is "valid", should be though. -# Might also be nice categorise Comics under one Item +# Copyright (C) 2015-2017 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function import xml.dom.minidom import time from .configuration import App +# TODO: Not sure if this RSS output is "valid", should be though. +# Might also be nice categorise Comics under one Item + + class Feed(object): """Write an RSS feed with comic strip images.""" @@ -62,10 +67,13 @@ def parseFeed(filename, yesterday): """Parse an RSS feed and filter only entries that are newer than yesterday.""" dom = xml.dom.minidom.parse(filename) - getText = lambda node, tag: node.getElementsByTagName(tag)[0].childNodes[0].data - getNode = lambda tag: dom.getElementsByTagName(tag) + def getText(node, tag): + node.getElementsByTagName(tag)[0].childNodes[0].data - content = getNode('channel')[0] # Only one channel node + def getNode(tag): + dom.getElementsByTagName(tag) + + content = getNode('channel')[0] # Only one channel node feedTitle = getText(content, 'title') feedLink = getText(content, 'link') @@ -75,7 +83,7 @@ def parseFeed(filename, yesterday): for item in getNode('item'): itemDate = time.strptime(getText(item, 'pubDate'), '%a, %d %b %Y %H:%M:%S GMT') - if (itemDate > yesterday): # If newer than yesterday + if (itemDate > yesterday): # If newer than yesterday feed.addItem(getText(item, 'title'), getText(item, 'link'), getText(item, 'description'), diff --git a/dosagelib/singleton.py b/dosagelib/singleton.py index b53cb8ddd..b985497ae 100644 --- a/dosagelib/singleton.py +++ b/dosagelib/singleton.py @@ -1,9 +1,11 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # Copied from: https://github.com/pycontribs/tendo # License: PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 # Author: Sorin Sbarnea # Changes: changed logging and formatting +from __future__ import absolute_import, division, print_function + import sys import os import errno @@ -49,7 +51,7 @@ class SingleInstance(object): self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) except OSError: type, e, tb = sys.exc_info() - if e.errno == errno.EACCES: # EACCES == 13 + if e.errno == errno.EACCES: # EACCES == 13 self.exit(exit_code) raise else: # non Windows diff --git a/dosagelib/updater.py b/dosagelib/updater.py index 37586aafb..ce2392b9b 100644 --- a/dosagelib/updater.py +++ b/dosagelib/updater.py @@ -1,7 +1,10 @@ -# -*- coding: iso-8859-1 -*- -""" -Function to check for updates. -""" +# -*- coding: utf-8 -*- +# Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs +# Copyright (C) 2012-2014 Bastian Kleineidam +# Copyright (C) 2015-2017 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function + import os import dosagelib from dosagelib import configuration @@ -9,10 +12,10 @@ from .util import urlopen from distutils.version import StrictVersion import requests - UPDATE_URL = "https://api.github.com/repos/webcomics/dosage/releases/latest" -def check_update (): + +def check_update(): """Return the following values: (False, errmsg) - online version could not be determined (True, None) - user has newest version @@ -33,7 +36,7 @@ def check_update (): return True, (version, None) -def get_online_version (): +def get_online_version(): """Download update info and parse it.""" session = requests.session() page = urlopen(UPDATE_URL, session).json() @@ -47,6 +50,6 @@ def get_online_version (): return version, url -def is_newer_version (version): +def is_newer_version(version): """Check if given version is newer than current version.""" return StrictVersion(version) > StrictVersion(dosagelib.__version__) diff --git a/scripts/creators.py b/scripts/creators.py index 333dd599d..cbc889c05 100755 --- a/scripts/creators.py +++ b/scripts/creators.py @@ -40,5 +40,6 @@ class CreatorsUpdater(ComicListUpdater): langopt = ", 'es'" if name.lower().endswith('spanish') else '' return u"cls('%s', '%s'%s)," % (name, path, langopt) + if __name__ == '__main__': CreatorsUpdater(__file__).run() diff --git a/scripts/mklanguages.py b/scripts/mklanguages.py index d7c9afe03..1e818ef0c 100755 --- a/scripts/mklanguages.py +++ b/scripts/mklanguages.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher '''update languages.py from pycountry''' from __future__ import absolute_import, division, print_function @@ -24,6 +24,7 @@ def main(): 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) + f.write('from __future__ import absolute_import, division, print_function%s' % os.linesep) lang = get_used_languages() write_languages(f, lang) diff --git a/scripts/smackjeeves.py b/scripts/smackjeeves.py index 0fcd8f3f5..bbbf91d3a 100755 --- a/scripts/smackjeeves.py +++ b/scripts/smackjeeves.py @@ -167,5 +167,6 @@ class SmackJeevesUpdater(ComicListUpdater): opt += ", endOfLife=True" return u"cls('%s', %s)," % (name, opt) + if __name__ == '__main__': SmackJeevesUpdater(__file__).run() diff --git a/tests/__init__.py b/tests/__init__.py index b5047bb27..4b02005d9 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Copyright (C) 2013-2014 Bastian Kleineidam -# Copyright (C) 2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function import os import subprocess diff --git a/tests/test_comicnames.py b/tests/test_comicnames.py index ae37db31b..55bc4a70a 100644 --- a/tests/test_comicnames.py +++ b/tests/test_comicnames.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2015-2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher from __future__ import absolute_import, division, print_function diff --git a/tests/test_scraper.py b/tests/test_scraper.py index 8ac335544..0dd7d4a32 100644 --- a/tests/test_scraper.py +++ b/tests/test_scraper.py @@ -2,6 +2,8 @@ # Copyright (C) 2013-2014 Bastian Kleineidam # Copyright (C) 2015-2016 Tobias Gruetzmacher +from __future__ import absolute_import, division, print_function + import pytest from dosagelib import scraper diff --git a/tests/test_singletoninstance.py b/tests/test_singletoninstance.py index 1ca808916..0544a6ee5 100644 --- a/tests/test_singletoninstance.py +++ b/tests/test_singletoninstance.py @@ -4,6 +4,8 @@ # Author: Sorin Sbarnea # Changes: changed logging and formatting +from __future__ import absolute_import, division, print_function + from dosagelib import singleton from multiprocessing import Process diff --git a/tests/test_util.py b/tests/test_util.py index ae9e65897..8089e3c31 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- # Copyright (C) 2004-2008 Tristan Seligmann and Jonathan Jacobs # Copyright (C) 2012-2014 Bastian Kleineidam -# Copyright (C) 2016 Tobias Gruetzmacher +# Copyright (C) 2015-2017 Tobias Gruetzmacher + +from __future__ import absolute_import, division, print_function import pytest import re @@ -30,9 +32,9 @@ class TestRegex(object): ValuePrefix = '/bla/' @pytest.mark.parametrize("tag,value,domatch", [ - ('', ValuePrefix+'foo', True), + ('', ValuePrefix + 'foo', True), ('< img src = "%s" >', ValuePrefix, True), - ('', ValuePrefix+'...', True), + ('', ValuePrefix + '...', True), ('', ValuePrefix, False), ('', ValuePrefix, True), ('', ValuePrefix, True),