Move parsing of redfams from RedPageParser to RedFamParser.parser so RedPageParse won't do anything with redfams

except for returning a generator of text-sections
This commit is contained in:
2016-03-03 20:41:14 +01:00
parent 7422307985
commit 0af7eb11d6
2 changed files with 38 additions and 18 deletions

View File

@@ -325,6 +325,7 @@ class RedFamParser( RedFam ):
self._status )
@classmethod
@deprecated
def is_sectionheading( cls, line ):
"""
Checks wether given line is a red_fam section heading
@@ -339,6 +340,28 @@ class RedFamParser( RedFam ):
else:
return False
@classmethod
def parser( cls, text, pageid, isarchive=False ):
"""
Handles parsing of redfam section
@param text Text of RedFam-Section
@type text wikicode or mwparser-parseable
"""
# Parse heading with mwparse if needed
if not isinstance( text, mwparser.wikicode.Wikicode ):
text = mwparser.parse( text )
# Extract heading text
heading = next( text.ifilter_headings() ).title
# Extract beginnig and maybe ending
(beginning, ending) = RedFamParser.extract_dates( text, isarchive )
# Create the RedFam object
RedFamParser( heading, pageid, isarchive, beginning, ending )
@classmethod
def extract_dates( cls, text, isarchive=False ):
"""

View File

@@ -28,8 +28,9 @@ Provides a class for handling redundance discussion pages and archives
import pywikibot # noqa
import mwparserfromhell as mwparser
import jogobot
from mysqlred import MysqlRedPage
from redfam import RedFamParser
class RedPage:
@@ -53,10 +54,6 @@ class RedPage:
self.is_page_changed()
self._parsed = None
if( self._changed or self.__mysql.data[ 'status' ] == 0 ):
self.parse()
self.__update_db()
def __handle_db( self ):
"""
@@ -95,6 +92,16 @@ class RedPage:
else:
return False
def is_parsing_needed( self ):
"""
Decides wether current RedPage needs to be parsed or not
"""
if( self._changed or self.__mysql.data[ 'status' ] == 0 ):
return True
else:
return False
def parse( self ):
"""
Handles the parsing process
@@ -109,27 +116,17 @@ class RedPage:
# include_lead = if true include first section (intro)
# include_heading = if true include heading
fams = self.wikicode.get_sections(
matches=RedFamParser.is_sectionheading,
matches=jogobot.config["redundances"]["section_heading_regex"],
include_lead=False, include_headings=True )
# Iterate over RedFam
for fam in fams:
# Extract heading text
heading = next( fam.ifilter_headings() ).title
# Extract beginnig and maybe ending
(beginning, ending) = RedFamParser.extract_dates( fam,
self.is_archive()
)
# Create the RedFam object
RedFamParser( heading, self.page._pageid,
self.is_archive(), beginning, ending )
yield fam
else:
RedFamParser.flush_db_cache()
self._parsed = True
self.__update_db()
def __update_db( self ):
"""