Some minor style fixes.

This commit is contained in:
Tobias Gruetzmacher 2017-05-15 00:54:02 +02:00
parent b8484cde50
commit 8b90aa5cfb
18 changed files with 71 additions and 40 deletions

View file

@ -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'

View file

@ -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"

View file

@ -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

View file

@ -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)

View file

@ -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',
}

View file

@ -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

View file

@ -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/'

View file

@ -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'),

View file

@ -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

View file

@ -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__)

View file

@ -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()

View file

@ -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)

View file

@ -167,5 +167,6 @@ class SmackJeevesUpdater(ComicListUpdater):
opt += ", endOfLife=True"
return u"cls('%s', %s)," % (name, opt)
if __name__ == '__main__':
SmackJeevesUpdater(__file__).run()

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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", [
('<img src="%s">', ValuePrefix+'foo', True),
('<img src="%s">', ValuePrefix + 'foo', True),
('< img src = "%s" >', ValuePrefix, True),
('<img class="prev" src="%s">', ValuePrefix+'...', True),
('<img class="prev" src="%s">', ValuePrefix + '...', True),
('<img origsrc="%s">', ValuePrefix, False),
('<Img src="%s">', ValuePrefix, True),
('<img SrC="%s">', ValuePrefix, True),