Browse Source

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
develop
Jonathan Golder 8 years ago
parent
commit
0af7eb11d6
  1. 23
      redfam.py
  2. 33
      redpage.py

23
redfam.py

@ -325,6 +325,7 @@ class RedFamParser( RedFam ):
self._status ) self._status )
@classmethod @classmethod
@deprecated
def is_sectionheading( cls, line ): def is_sectionheading( cls, line ):
""" """
Checks wether given line is a red_fam section heading Checks wether given line is a red_fam section heading
@ -339,6 +340,28 @@ class RedFamParser( RedFam ):
else: else:
return False 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 @classmethod
def extract_dates( cls, text, isarchive=False ): def extract_dates( cls, text, isarchive=False ):
""" """

33
redpage.py

@ -28,8 +28,9 @@ Provides a class for handling redundance discussion pages and archives
import pywikibot # noqa import pywikibot # noqa
import mwparserfromhell as mwparser import mwparserfromhell as mwparser
import jogobot
from mysqlred import MysqlRedPage from mysqlred import MysqlRedPage
from redfam import RedFamParser
class RedPage: class RedPage:
@ -53,10 +54,6 @@ class RedPage:
self.is_page_changed() self.is_page_changed()
self._parsed = None self._parsed = None
if( self._changed or self.__mysql.data[ 'status' ] == 0 ):
self.parse()
self.__update_db()
def __handle_db( self ): def __handle_db( self ):
""" """
@ -95,6 +92,16 @@ class RedPage:
else: else:
return False 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 ): def parse( self ):
""" """
Handles the parsing process Handles the parsing process
@ -109,27 +116,17 @@ class RedPage:
# include_lead = if true include first section (intro) # include_lead = if true include first section (intro)
# include_heading = if true include heading # include_heading = if true include heading
fams = self.wikicode.get_sections( fams = self.wikicode.get_sections(
matches=RedFamParser.is_sectionheading, matches=jogobot.config["redundances"]["section_heading_regex"],
include_lead=False, include_headings=True ) include_lead=False, include_headings=True )
# Iterate over RedFam # Iterate over RedFam
for fam in fams: for fam in fams:
# Extract heading text yield fam
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 )
else: else:
RedFamParser.flush_db_cache()
self._parsed = True self._parsed = True
self.__update_db()
def __update_db( self ): def __update_db( self ):
""" """

Loading…
Cancel
Save