Clean up PEP8 styleguide compatibility with flake8

This commit is contained in:
2015-09-13 11:53:47 +02:00
parent cafe08dd7f
commit 74b2dc727c
4 changed files with 205 additions and 142 deletions

View File

@@ -2,25 +2,25 @@
# -*- coding: utf-8 -*-
#
# mysqlred.py
#
#
# Copyright 2015 GOLDERWEB Jonathan Golder <jonathan@golderweb.de>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
#
#
"""
Provides interface classes for communication of redundances bot with mysql-db
"""
@@ -33,6 +33,7 @@ except ImportError:
from pywikibot import config
class MysqlRed:
"""
Basic interface class, containing opening of connection
@@ -40,12 +41,13 @@ class MysqlRed:
Specific querys should be defined in descendant classes per data type
"""
#Save mysqldb-connection as class attribute to use only one in descendant classes
# Save mysqldb-connection as class attribute to use only one
# in descendant classes
connection = False
db_hostname=config.db_hostname
db_username=config.db_username
db_password=config.db_password
db_name=config.db_username + '__bot'
db_hostname = config.db_hostname
db_username = config.db_username
db_password = config.db_password
db_name = config.db_username + '__bot'
def __init__( self ):
"""
@@ -55,9 +57,13 @@ class MysqlRed:
"""
# Connect to mysqldb only once
if( type( self ).connection == False ):
if not type( self ).connection:
type( self ).connection = mysqldb.connect( host=type( self ).db_hostname, user=type( self ).db_username, passwd=type( self ).db_password, db=type( self ).db_name )
type( self ).connection = mysqldb.connect(
host=type( self ).db_hostname,
user=type( self ).db_username,
passwd=type( self ).db_password,
db=type( self ).db_name )
def __del__( self ):
"""
@@ -66,10 +72,11 @@ class MysqlRed:
type( self ).connection.close()
class MysqlRedPage( MysqlRed ):
"""
MySQL-db Interface for handling querys for RedPages
"""
"""
MySQL-db Interface for handling querys for RedPages
"""
def __init__( self, page_id ):
"""
@@ -78,7 +85,7 @@ class MysqlRedPage( MysqlRed ):
super().__init__( )
self.__page_id = int( page_id );
self.__page_id = int( page_id )
self.data = self.get_page()
@@ -91,13 +98,14 @@ class MysqlRedPage( MysqlRed ):
@param int page_id MediaWiki page_id for page to retrieve
@returns tuple Tuple with data for given page_id otherwise if none found
bool FALSE
@returns tuple Tuple with data for given page_id
bool FALSE if none found
"""
cursor = type( self ).connection.cursor(mysqldb.DictCursor)
cursor.execute( 'SELECT * FROM `red_pages` WHERE `page_id` = ?;', ( self.__page_id, ) )
cursor.execute( 'SELECT * FROM `red_pages` WHERE `page_id` = ?;',
( self.__page_id, ) )
res = cursor.fetchone()
if res:
@@ -109,9 +117,9 @@ class MysqlRedPage( MysqlRed ):
"""
Inserts a red page row in MySQL-Database for given page_id
@param int rev_id MediaWiki current rev_id for page to update
@param str page_title MediaWiki new page_title for page to update
@param int status Page parsing status (0 - not (successfully) parsed; 1 - successfully parsed; 2 - successfully parsed archive)
@param int rev_id MediaWiki current rev_id
@param str page_title MediaWiki new page_title
@param int status Page parsing status
"""
cursor = type( self ).connection.cursor()
@@ -121,8 +129,10 @@ class MysqlRedPage( MysqlRed ):
if not rev_id:
rev_id = self.data[ 'rev_id' ]
query = 'INSERT INTO `red_pages` ( page_id, page_title, rev_id, status ) VALUES ( ?, ?, ?, ? );'
data = ( self.__page_id, str( page_title ), int( rev_id ), int( status ) )
query = 'INSERT INTO `red_pages` \
( page_id, page_title, rev_id, status ) \
VALUES ( ?, ?, ?, ? );'
data = ( self.__page_id, page_title, rev_id, status )
cursor.execute( query, data)
@@ -134,9 +144,9 @@ class MysqlRedPage( MysqlRed ):
"""
Updates the red page row in MySQL-Database for given page_id
@param int rev_id MediaWiki current rev_id for page to update
@param str page_title MediaWiki new page_title for page to update
@param int status Page parsing status (0 - not (successfully) parsed; 1 - successfully parsed)
@param int rev_id MediaWiki current rev_id
@param str page_title MediaWiki new page_title
@param int status Page parsing status
"""
cursor = type( self ).connection.cursor()
@@ -146,17 +156,20 @@ class MysqlRedPage( MysqlRed ):
if not rev_id:
rev_id = self.data[ 'rev_id' ]
query = 'UPDATE `red_pages` SET `page_title` = ?, `rev_id` = ?, `status`= ? WHERE `page_id` = ?;'
data = ( str( page_title ), int( rev_id ), int( status ), self.__page_id )
query = 'UPDATE `red_pages` \
SET `page_title` = ?, `rev_id` = ?, `status`= ? \
WHERE `page_id` = ?;'
data = ( page_title, rev_id, status, self.__page_id )
cursor.execute( query, data)
type( self ).connection.commit()
class MysqlRedFam( MysqlRed ):
"""
MySQL-db Interface for handling querys for RedFams
"""
MySQL-db Interface for handling querys for RedFams
"""
def __init__( self, fam_hash ):
"""
@@ -176,13 +189,14 @@ class MysqlRedFam( MysqlRed ):
"""
Retrieves a red family row from MySQL-Database for given fam_hash
@returns dict Dictionairy with data for given fam hash otherwise if none found
bool FALSE
@returns dict Dictionairy with data for given fam hash
False if none found
"""
cursor = type( self ).connection.cursor(mysqldb.DictCursor)
cursor = type( self ).connection.cursor( mysqldb.DictCursor )
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;', ( self.__fam_hash, ) )
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;',
( self.__fam_hash, ) )
res = cursor.fetchone()
if res:
@@ -190,12 +204,18 @@ class MysqlRedFam( MysqlRed ):
else:
return False
def add_fam( self, articlesList, heading, red_page_id, beginning, ending=None, status=0 ):
def add_fam( self, articlesList, heading, red_page_id,
beginning, ending=None, status=0 ):
cursor = type( self ).connection.cursor()
query = 'INSERT INTO `red_families` ( fam_hash, red_page_id, beginning, ending, status, heading, article0, article1, article2, article3, article4, article5, article6, article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
data = [ str( self.__fam_hash ), red_page_id, beginning, ending, status, heading ]
query = 'INSERT INTO `red_families` \
( fam_hash, red_page_id, beginning, ending, status, heading, \
article0, article1, article2, article3, \
article4, article5, article6, article7 ) \
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
data = [ self.__fam_hash, red_page_id, beginning, ending,
status, heading ]
for article in articlesList:
data.append( str( article ) )
@@ -215,16 +235,19 @@ class MysqlRedFam( MysqlRed ):
"""
Updates the red fam row in MySQL-Database for given fam_hash
@param int red_page_id MediaWiki page_id which contains red_fam
@param datetime beginning Timestamp of beginning of redundance discussion
qparam datetime ending Timestamp of ending of redundance discussion
@param int status red_fam status (0 - discussion is running; 1 - discussion over; 2 - discussion archived)
@param int red_page_id MediaWiki page_id
@param datetime beginning Timestamp of beginning
qparam datetime ending Timestamp of ending of
@param int status red_fam status
"""
cursor = type( self ).connection.cursor()
query = 'UPDATE `red_families` SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, `ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
data = ( int(red_page_id ), str( heading ), beginning, ending, int( status ), self.__fam_hash )
query = 'UPDATE `red_families` \
SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, \
`ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
data = ( red_page_id, heading, beginning,
ending, status, self.__fam_hash )
cursor.execute( query, data)

184
redfam.py
View File

@@ -2,64 +2,54 @@
# -*- coding: utf-8 -*-
#
# redfam.py
#
#
# Copyright 2015 GOLDERWEB Jonathan Golder <jonathan@golderweb.de>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
#
#
"""
Provides classes for working with RedFams
"""
import hashlib
import re
import locale
import re
from datetime import datetime
import pywikibot
from mysqlred import MysqlRedFam
class RedFam:
"""
Basic class for RedFams, containing the basic data structure
"""
def __init__( self, fam_hash=None, articlesList=None, red_page_id=None, beginning=None, ending=None, status=0 ):
def __init__( self, fam_hash=None, articlesList=None, red_page_id=None,
beginning=None, ending=None, status=0 ):
"""
Generates a new RedFam object
@param articlesList list List of articles of redundance family
@param beginning datetime Beginning date of redundance diskussion
@param ending datetime Ending date of redundance diskussion
@param articlesList list List of articles
@param beginning datetime Beginning date
@param ending datetime Ending date
"""
#if( beginning ):
# self.add_beginning( beginning )
# self._beginning = None
#if( ending ):
# self.add_ending( ending )
#else:
# self._ending = None
#self._status = status # __TODO__ STATUS CODE
#self._handle_db()
pass
def __repr__( self ):
@@ -73,13 +63,16 @@ class RedFam:
else:
ending = ""
__repr = "RedFam( " + repr( self._articlesList ) + beginning + ending + ", status=" + repr( self._status ) + " )"
__repr = "RedFam( " + repr( self._articlesList ) + beginning +\
ending + ", status=" + repr( self._status ) + " )"
return __repr
class RedFamParser( RedFam ):
"""
Provides an interface to RedFam for adding/updating redundance families while parsig redundance pages
Provides an interface to RedFam for adding/updating redundance families
while parsig redundance pages
"""
# Define the timestamp format
@@ -89,26 +82,29 @@ class RedFamParser( RedFam ):
__sectionhead_pat = re.compile( r"^(=+)(.*\[\[.+\]\].*\[\[.+\]\].*)\1" )
# Define timestamp re.pattern
__timestamp_pat = re.compile( r"(\d{2}:\d{2}), (\d{1,2}). (Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez).? (\d{4})" )
__timestamp_pat = re.compile( r"(\d{2}:\d{2}), (\d{1,2}). (Jan|Feb|Mär|Apr|Mai|Jun|Jul|Aug|Sep|Okt|Nov|Dez).? (\d{4})" ) # noqa
# Textpattern for recognisation of done-notices
__done_notice = ":<small>Archivierung dieses Abschnittes wurde gewünscht von:"
__done_notice = ":<small>Archivierung dieses Abschnittes \
wurde gewünscht von:"
__done_notice2 = "{{Erledigt|"
def __init__( self, heading, red_page_id, red_page_archive, beginning, ending=None ):
def __init__( self, heading, red_page_id, red_page_archive,
beginning, ending=None ):
"""
Creates a RedFam object based on data collected while parsing red_pages combined with possibly former known data from db
Creates a RedFam object based on data collected while parsing red_pages
combined with possibly former known data from db
@param red_fam_heading string String with wikitext heading of redundance section
@param red_page_id int MediaWiki page_id of red_page containing red_fam
@param red_page_archive bool Is red_page an archive
@param beginning datetime Timestamp of beginning of redundance discussion
string Timestamp of beginning of redundance discussion as srftime parseable string
@param ending datetime Timestamp of ending of redundance discussion
string Timestamp of ending of redundance discussion as srftime parseable string
@param red_fam_heading str Wikitext heading of section
@param red_page_id int MediaWiki page_id
@param red_page_archive bool Is red_page an archive
@param beginning datetime Timestamp of beginning
str as strptime parseable string
@param ending datetime Timestamp of ending
str strptime parseable string
"""
## Set object attributes:
# Set object attributes:
self._red_page_id = red_page_id
self._red_page_archive = red_page_archive
@@ -119,18 +115,21 @@ class RedFamParser( RedFam ):
if( ending ):
self.add_ending( ending )
else:
#If no ending was provided set to None
# If no ending was provided set to None
self._ending = None
self._status = None
# Parse the provided heading of redundance section to set self._articlesList
# Parse the provided heading of redundance section
# to set self._articlesList
self.heading_parser( heading )
# Calculates the sha1 hash over self._articlesList to rediscover known redundance families
# Calculates the sha1 hash over self._articlesList to
# rediscover known redundance families
self.fam_hash()
# Open database connection, ask for data if existing, otherwise create entry
# Open database connection, ask for data if existing,
# otherwise create entry
self.__handle_db()
# Check status changes
@@ -148,7 +147,9 @@ class RedFamParser( RedFam ):
self.__mysql = MysqlRedFam( self._fam_hash )
if not self.__mysql.data:
self.__mysql.add_fam( self._articlesList, self._heading, self._red_page_id, self._beginning, self._ending )
self.__mysql.add_fam( self._articlesList, self._heading,
self._red_page_id, self._beginning,
self._ending )
def heading_parser( self, heading ):
"""
@@ -165,12 +166,20 @@ class RedFamParser( RedFam ):
else:
raise ValueError( "Heading is not valid" )
# We get the pages in first [0] element iterating over wikilink_pat.findall( line )
self._articlesList = [ link[0] for link in wikilink_pat.findall( self._heading ) ]
# We get the pages in first [0] element iterating over
# wikilink_pat.findall( line )
self._articlesList = [ link[0] for link
in wikilink_pat.findall( self._heading ) ]
# Catch sections with more then 8 articles, print error
if len( self._articlesList ) > 8:
pywikibot.output( "{datetime} \03{{lightred}}[WARNING] Maximum number of articles in red_fam exceeded, maximum number is 8, {number:d} were given\n{repress}".format( datetime=datetime.now().strftime("%Y-%m-%d %H:%M:%S (%Z)"), number=len( self._articlesList ), repress=repr( self ) ) )
pywikibot.output( "{datetime} \03{{lightred}}[WARNING] \
Maximum number of articles in red_fam exceeded, \
maximum number is 8, {number:d} were given\n\
{repress}".format(
datetime=datetime.now().strftime( "%Y-%m-%d %H:%M:%S" ),
number=len( self._articlesList ), repress=repr( self ) ) )
self._articlesList = self._articlesList[:8]
def fam_hash( self ):
@@ -178,58 +187,61 @@ class RedFamParser( RedFam ):
Calculates the SHA-1 hash for the articlesList of redundance family.
Since we don't need security SHA-1 is just fine.
@returns str String with the hexadecimal hash digest
@returns str String with the hexadecimal hash digest
"""
h = hashlib.sha1()
h.update( str( self._articlesList ).encode('utf-8') )
self._fam_hash= h.hexdigest()
self._fam_hash = h.hexdigest()
def add_beginning( self, beginning ):
"""
Adds the beginning date of a redundance diskussion to the object and sets changed to True
Adds the beginning date of a redundance diskussion to the object
@param datetime datetime Beginning date of redundance diskussion
@param datetime datetime Beginning date
"""
self._beginning = self.__datetime( beginning )
def add_ending( self, ending ):
"""
Adds the ending date of a redundance diskussion to the object. Also sets the status to __TODO__ STATUS NUMBER and changed to True
Adds the ending date of a redundance diskussion to the object.
@param datetime datetime Ending date of redundance diskussion
@param datetime datetime Ending date
"""
self._ending = self.__datetime( ending )
def __datetime( self, timestamp ):
"""
Decides wether given timestamp is a parseable string or a datetime object and returns a datetime object in both cases
Decides wether given timestamp is a parseable string or a
datetime object and returns a datetime object in both cases
@param datetime timestamp Datetime object
str timestamp Parseable string with timestamp in format __timestamp_format
str timestamp Parseable string with timestamp
@returns datetime Datetime object
"""
# Make sure locale is set to 'de_DE.UTF-8' to prevent problems with wrong month abreviations in strptime
# Make sure locale is set to 'de_DE.UTF-8' to prevent problems
# with wrong month abreviations in strptime
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
if( isinstance( timestamp, datetime ) ):
return timestamp
else:
result = datetime.strptime( timestamp, type( self ).__timestamp_format )
result = datetime.strptime( timestamp,
type( self ).__timestamp_format )
return result
def status( self ):
"""
Handles detection of correct status
There are three possible stati:
- 0 Discussion is running --> no ending, page is not an archive
- 1 Discussion is over --> ending present, page is not an archive
- 2 Discussion is archived --> ending (normaly) present, page is an archive
- 0 Discussion running --> no ending, page is not an archive
- 1 Discussion over --> ending present, page is not an archive
- 2 Discussion archived --> ending (normaly) present, page is archive
- 3 and greater status was set by worker script, do not change it
"""
@@ -247,22 +259,28 @@ class RedFamParser( RedFam ):
self._status = 2
else:
self._status = self.__mysql.data[ 'status' ]
def changed( self ):
"""
Checks wether anything has changed and maybe triggers db update
"""
# On archived red_fams do not delete possibly existing ending
if not self._ending and self._status > 1 and self.__mysql.data[ 'ending' ]:
self._ending = self.__mysql.data[ 'ending' ]
if( not self._ending and self._status > 1
and self.__mysql.data[ 'ending' ] ):
self._ending = self.__mysql.data[ 'ending' ]
# Since status change means something has changed, update database
if( self._status != self.__mysql.data[ 'status' ] or self._beginning != self.__mysql.data[ 'beginning' ] or self._ending != self.__mysql.data[ 'ending' ] or self._red_page_id != self.__mysql.data[ 'red_page_id' ] or self._heading != self.__mysql.data[ 'heading' ]):
self.__mysql.update_fam( self._red_page_id, self._heading, self._beginning, self._ending, self._status )
if( self._status != self.__mysql.data[ 'status' ] or
self._beginning != self.__mysql.data[ 'beginning' ] or
self._ending != self.__mysql.data[ 'ending' ] or
self._red_page_id != self.__mysql.data[ 'red_page_id' ] or
self._heading != self.__mysql.data[ 'heading' ]):
self.__mysql.update_fam( self._red_page_id, self._heading,
self._beginning, self._ending,
self._status )
@classmethod
def is_sectionheading( cls, line ):
@@ -271,7 +289,7 @@ class RedFamParser( RedFam ):
@param str line String to check
@returns bool Returns True if it is a section heading, otherwise false
@returns bool Returns True if it is a section heading
"""
if cls.__sectionhead_pat.search( line ):
@@ -291,8 +309,10 @@ class RedFamParser( RedFam ):
match = cls.__timestamp_pat.search( line )
if match:
# Since some timestamps are broken we need to reconstruct them by regex match groups
result = match.group(1) + ", " + match.group(2) + ". " + match.group(3) + ". " + match.group(4)
# Since some timestamps are broken we need to reconstruct them
# by regex match groups
result = match.group(1) + ", " + match.group(2) + ". " +\
match.group(3) + ". " + match.group(4)
return result
else:
return None
@@ -301,16 +321,18 @@ class RedFamParser( RedFam ):
def is_ending( cls, line ):
"""
Returns the timestamp of done notice ( if one ), otherwise None
@param str line String to search in
@param str line String to search in
@returns str Timestamp, otherwise None
@returns str Timestamp, otherwise None
"""
if ( cls.__done_notice in line ) or ( cls.__done_notice2 in line ):
match = cls.__timestamp_pat.search( line )
if match:
# Since some timestamps are broken we need to reconstruct them by regex match groups
result = match.group(1) + ", " + match.group(2) + ". " + match.group(3) + ". " + match.group(4)
# Since some timestamps are broken we need to reconstruct them
# by regex match groups
result = match.group(1) + ", " + match.group(2) + ". " +\
match.group(3) + ". " + match.group(4)
return result
return None
@@ -325,14 +347,18 @@ class RedFamParser( RedFam ):
matches = cls.__timestamp_pat.findall( line )
if matches:
# Since some timestamps are broken we need to reconstruct them by regex match groups
result = matches[-1][0] + ", " + matches[-1][1] + ". " + matches[-1][2] + ". " + matches[-1][3]
# Since some timestamps are broken we need to reconstruct them
# by regex match groups
result = matches[-1][0] + ", " + matches[-1][1] + ". " +\
matches[-1][2] + ". " + matches[-1][3]
return result
else:
return None
return None
class RedFamWorker( RedFam ):
"""
Handles working with redundance families stored in database where discussion is finished
Handles working with redundance families stored in database
where discussion is finished
"""
pass

View File

@@ -2,34 +2,35 @@
# -*- coding: utf-8 -*-
#
# redpage.py
#
#
# Copyright 2015 GOLDERWEB Jonathan Golder <jonathan@golderweb.de>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
#
"""
Provides a class for handling redundance discussion pages and archives
"""
import pywikibot
import pywikibot # noqa
from mysqlred import MysqlRedPage
from redfam import RedFamParser
class RedPage:
"""
Class for handling redundance discussion pages and archives
@@ -39,7 +40,7 @@ class RedPage:
"""
Generate a new RedPage object based on the given pywikibot page object
@param page page Pywikibot/MediaWiki page object for page to work on
@param page page Pywikibot/MediaWiki page object for page
"""
# Safe the pywikibot page object
@@ -72,7 +73,10 @@ class RedPage:
Check wether the page was changed since last run
"""
if( self.__mysql.data != { 'page_id': self.page._pageid, 'rev_id': self.page._revid, 'page_title': self.page.title(), 'status': self.__mysql.data[ 'status' ] } ):
if( self.__mysql.data != { 'page_id': self.page._pageid,
'rev_id': self.page._revid,
'page_title': self.page.title(),
'status': self.__mysql.data[ 'status' ] } ):
self._changed = True
else:
self._changed = False
@@ -82,10 +86,13 @@ class RedPage:
Detects wether current page is an archive of discussions
"""
if self._archive or ( u"/Archiv" in self.page.title() ) or ( "{{Archiv}}" in self.page.text ) or ( "{{Archiv|" in self.page.text ):
return True
if( self._archive or ( u"/Archiv" in self.page.title() ) or
( "{{Archiv}}" in self.page.text ) or
( "{{Archiv|" in self.page.text ) ):
return True
else:
return False
return False
def parse( self ):
"""
@@ -108,7 +115,7 @@ class RedPage:
# Iterate over the lines of the page
for line in text_lines:
# Check wether we have an "Redundance-Family"-Section heading (Level 3)
# Check wether we have an "Redundance-Family"-Section heading
if RedFamParser.is_sectionheading( line ):
# Save line number for last detected Redundance-Family
@@ -120,16 +127,18 @@ class RedPage:
beginning = None
ending = None
# Check wether we are currently in an "Redundance-Family"-Section Body
# Check wether we are currently in an "Redundance-Family"-Section
if i > last_fam and last_fam > 0:
# Check if we have alredy recognized the beginning date of the discussion (in former iteration) or if we have a done-notice
# Check if we have alredy recognized the beginning date of the
# discussion (in former iteration) or if we have a done-notice
if not beginning:
beginning = RedFamParser.is_beginning( line )
elif not ending:
ending = RedFamParser.is_ending( line )
# Detect end of red_fam section (next line is new sectionheading) or end of file
# Detect end of red_fam section (next line is new sectionheading)
# or end of file
# Prevent from running out of index
if i < (length - 1):
test = RedFamParser.is_sectionheading( text_lines[ i + 1 ] )
@@ -140,7 +149,8 @@ class RedPage:
# Create the red_fam object
if( fam_heading and beginning ):
#Maybe we can find a ending by feed if we have None yet (No done notice on archive pages)
# Maybe we can find a ending by feed if we have None yet
# (No done notice on archive pages)
if not ending and self.is_archive():
j = i
while (j > last_fam) and not ending:
@@ -148,7 +158,9 @@ class RedPage:
ending = RedFamParser.is_ending2( text_lines[ j ] )
# Create the RedFam object
red_fam = RedFamParser( fam_heading, self.page._pageid, self.is_archive(), beginning, ending )
red_fam = RedFamParser( fam_heading, self.page._pageid,
self.is_archive(), beginning,
ending )
# Increment line counter
i += 1

2
tox.ini Normal file
View File

@@ -0,0 +1,2 @@
[flake8]
ignore = E129,E201,E202,W293