Remove old status API
Now we use the methods of status object directly
This commit is contained in:
@@ -84,6 +84,12 @@ class RedFam( MysqlRedFam ):
|
||||
|
||||
@classmethod
|
||||
def calc_famhash(cls, articlesList ):
|
||||
"""
|
||||
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
|
||||
"""
|
||||
|
||||
h = hashlib.sha1()
|
||||
# Since articlesList attr of RedFam will have always 8 Members we
|
||||
@@ -95,22 +101,6 @@ class RedFam( MysqlRedFam ):
|
||||
|
||||
return h.hexdigest()
|
||||
|
||||
def c_famhash( self ):
|
||||
"""
|
||||
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
|
||||
"""
|
||||
print( type( self ) )
|
||||
|
||||
if self.famhash and type(self).calc_famhash(self.articlesList) != self.famhash:
|
||||
raise RedFamHashError( self.famhash, h.hexdigest() )
|
||||
elif self.famhash:
|
||||
return
|
||||
else:
|
||||
self.famhash = type(self).calc_famhash(self.articlesList)
|
||||
|
||||
@classmethod
|
||||
def flush_db_cache( cls ):
|
||||
"""
|
||||
@@ -118,43 +108,6 @@ class RedFam( MysqlRedFam ):
|
||||
"""
|
||||
cls.session.commit()
|
||||
|
||||
def add_status(self, status):
|
||||
"""
|
||||
Adds a status specified by status, to status set
|
||||
|
||||
@param status Statusstring to add
|
||||
@type status str
|
||||
"""
|
||||
self.status.add(status)
|
||||
|
||||
def remove_status(self, status, weak=True):
|
||||
"""
|
||||
Removes a status, specified by status from set. If weak is set to
|
||||
False it will throw a KeyError when trying to remove a status not set.
|
||||
|
||||
@param status Statusstring to add
|
||||
@type status str
|
||||
@param weak Change behavior on missing status
|
||||
@type bool
|
||||
"""
|
||||
if weak:
|
||||
self.status.discard(status)
|
||||
else:
|
||||
self.status.remove(status)
|
||||
|
||||
def has_status(self, status):
|
||||
"""
|
||||
Returns True, if redfam has given status
|
||||
|
||||
@param status Statusstring to check
|
||||
@type status str
|
||||
@returns True if status is present else False
|
||||
"""
|
||||
if status in self.status:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def article_add_status(self, status, index=None, title=None ):
|
||||
"""
|
||||
Adds a status specified by status, to article (identified by title
|
||||
@@ -267,7 +220,7 @@ class RedFamParser( RedFam ):
|
||||
famhash = type(self).calc_famhash(articlesList)
|
||||
|
||||
# Set object attributes:
|
||||
self._redpagearchive = redpagearchive
|
||||
self.redpage = redpage
|
||||
|
||||
# Parse Timestamps
|
||||
beginning = self.__datetime(beginning)
|
||||
@@ -275,7 +228,7 @@ class RedFamParser( RedFam ):
|
||||
ending = self.__datetime(ending)
|
||||
|
||||
|
||||
super().__init__( articlesList, beginning, ending=ending, redpageid=redpage._pageid,
|
||||
super().__init__( articlesList, beginning, ending=ending, redpageid=redpage.page._pageid,
|
||||
famhash=famhash, heading=heading )
|
||||
|
||||
# Check status changes
|
||||
@@ -294,7 +247,7 @@ class RedFamParser( RedFam ):
|
||||
|
||||
self.add_beginning( beginning )
|
||||
|
||||
if( ending ):
|
||||
if ending:
|
||||
self.add_ending( ending )
|
||||
|
||||
self._redpagearchive = redpagearchive
|
||||
@@ -372,16 +325,16 @@ class RedFamParser( RedFam ):
|
||||
|
||||
# No ending, discussion is running:
|
||||
# Sometimes archived discussions also have no detectable ending
|
||||
if not self.ending and not self._redpagearchive:
|
||||
self.add_status("open")
|
||||
if not self.ending and not self.redpage.archive:
|
||||
self.status.add("open")
|
||||
else:
|
||||
self.remove_status("open")
|
||||
if not self._redpagearchive:
|
||||
self.add_status("done")
|
||||
self.status.remove("open")
|
||||
if not self.redpage.archive:
|
||||
self.status.add("done")
|
||||
else:
|
||||
self.remove_status("done")
|
||||
self.remove_status("open")
|
||||
self.add_status("archived")
|
||||
self.status.remove("done")
|
||||
self.status.remove("open")
|
||||
self.status.add("archived")
|
||||
|
||||
@classmethod
|
||||
def is_section_redfam_cb( cls, heading ):
|
||||
@@ -413,7 +366,7 @@ class RedFamParser( RedFam ):
|
||||
text = mwparser.parse( text )
|
||||
|
||||
# Extract heading text
|
||||
heading = next( text.ifilter_headings() ).title
|
||||
heading = next( text.ifilter_headings() ).title.strip()
|
||||
|
||||
# Extract beginnig and maybe ending
|
||||
(beginning, ending) = RedFamParser.extract_dates( text, isarchive )
|
||||
@@ -448,7 +401,7 @@ class RedFamParser( RedFam ):
|
||||
|
||||
else:
|
||||
# Create the RedFam object
|
||||
redfam = RedFamParser( articlesList, str(heading).strip(), redpage.page, isarchive, beginning, ending )
|
||||
redfam = RedFamParser( articlesList, str(heading), redpage, isarchive, beginning, ending )
|
||||
return redfam
|
||||
|
||||
@classmethod
|
||||
@@ -593,13 +546,13 @@ class RedFamWorker( RedFam ):
|
||||
"""
|
||||
for article in self._articlesList:
|
||||
if self.article_has_status( "note_rej", title=article ):
|
||||
self.add_status( "note_rej" )
|
||||
self.status.add( "note_rej" )
|
||||
if self.article_has_status( "sav_err", title=article ):
|
||||
self.add_status( "sav_err" )
|
||||
self.status.add( "sav_err" )
|
||||
|
||||
if not self.has_status( "sav_err" ) and \
|
||||
not self.has_status( "note_rej" ):
|
||||
self.add_status( "marked" )
|
||||
if not self.status.has( "sav_err" ) and \
|
||||
not self.status.has( "note_rej" ):
|
||||
self.status.add( "marked" )
|
||||
|
||||
self._mysql.data[ 'status' ] = self._raw_status()
|
||||
index = 0
|
||||
|
||||
@@ -86,25 +86,25 @@ class RedPage( MysqlRedPage ):
|
||||
|
||||
@property
|
||||
def archive(self):
|
||||
return self.has_status("archived")
|
||||
self.is_archive()
|
||||
return self.status.has("archive")
|
||||
|
||||
def is_archive( self ):
|
||||
"""
|
||||
Detects wether current page is an archive of discussions
|
||||
"""
|
||||
if( self.archive or ( u"/Archiv" in self.page.title() ) or
|
||||
if( ( u"/Archiv" in self.page.title() ) or
|
||||
( "{{Archiv}}" in self.page.text ) or
|
||||
( "{{Archiv|" in self.page.text ) ):
|
||||
self.status.add("archive")
|
||||
else:
|
||||
self.status.discard("archive")
|
||||
return False
|
||||
|
||||
def is_parsing_needed( self ):
|
||||
"""
|
||||
Decides wether current RedPage needs to be parsed or not
|
||||
"""
|
||||
return self.changedp() or not self.has_status("parsed")
|
||||
return self.changedp() or not self.status.has("parsed")
|
||||
|
||||
def parse( self ):
|
||||
"""
|
||||
@@ -138,40 +138,3 @@ class RedPage( MysqlRedPage ):
|
||||
Calls flush method of Mysql Interface class
|
||||
"""
|
||||
cls.session.commit()
|
||||
|
||||
def add_status(self, status):
|
||||
"""
|
||||
Adds a status specified by status, to status set
|
||||
|
||||
@param status Statusstring to add
|
||||
@type status str
|
||||
"""
|
||||
self.status.add(status)
|
||||
|
||||
def remove_status(self, status, weak=True):
|
||||
"""
|
||||
Removes a status, specified by status from set. If weak is set to
|
||||
False it will throw a KeyError when trying to remove a status not set.
|
||||
|
||||
@param status Statusstring to add
|
||||
@type status str
|
||||
@param weak Change behavior on missing status
|
||||
@type bool
|
||||
"""
|
||||
if weak:
|
||||
self.status.discard(status)
|
||||
else:
|
||||
self.status.remove(status)
|
||||
|
||||
def has_status(self, status):
|
||||
"""
|
||||
Returns True, if redfam has given status
|
||||
|
||||
@param status Statusstring to check
|
||||
@type status str
|
||||
@returns True if status is present else False
|
||||
"""
|
||||
if status in self.status:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user