|
@ -84,6 +84,12 @@ class RedFam( MysqlRedFam ): |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def calc_famhash(cls, articlesList ): |
|
|
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() |
|
|
h = hashlib.sha1() |
|
|
# Since articlesList attr of RedFam will have always 8 Members we |
|
|
# Since articlesList attr of RedFam will have always 8 Members we |
|
@ -95,22 +101,6 @@ class RedFam( MysqlRedFam ): |
|
|
|
|
|
|
|
|
return h.hexdigest() |
|
|
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 |
|
|
@classmethod |
|
|
def flush_db_cache( cls ): |
|
|
def flush_db_cache( cls ): |
|
|
""" |
|
|
""" |
|
@ -118,43 +108,6 @@ class RedFam( MysqlRedFam ): |
|
|
""" |
|
|
""" |
|
|
cls.session.commit() |
|
|
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 ): |
|
|
def article_add_status(self, status, index=None, title=None ): |
|
|
""" |
|
|
""" |
|
|
Adds a status specified by status, to article (identified by title |
|
|
Adds a status specified by status, to article (identified by title |
|
@ -267,7 +220,7 @@ class RedFamParser( RedFam ): |
|
|
famhash = type(self).calc_famhash(articlesList) |
|
|
famhash = type(self).calc_famhash(articlesList) |
|
|
|
|
|
|
|
|
# Set object attributes: |
|
|
# Set object attributes: |
|
|
self._redpagearchive = redpagearchive |
|
|
self.redpage = redpage |
|
|
|
|
|
|
|
|
# Parse Timestamps |
|
|
# Parse Timestamps |
|
|
beginning = self.__datetime(beginning) |
|
|
beginning = self.__datetime(beginning) |
|
@ -275,7 +228,7 @@ class RedFamParser( RedFam ): |
|
|
ending = self.__datetime(ending) |
|
|
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 ) |
|
|
famhash=famhash, heading=heading ) |
|
|
|
|
|
|
|
|
# Check status changes |
|
|
# Check status changes |
|
@ -294,7 +247,7 @@ class RedFamParser( RedFam ): |
|
|
|
|
|
|
|
|
self.add_beginning( beginning ) |
|
|
self.add_beginning( beginning ) |
|
|
|
|
|
|
|
|
if( ending ): |
|
|
if ending: |
|
|
self.add_ending( ending ) |
|
|
self.add_ending( ending ) |
|
|
|
|
|
|
|
|
self._redpagearchive = redpagearchive |
|
|
self._redpagearchive = redpagearchive |
|
@ -372,16 +325,16 @@ class RedFamParser( RedFam ): |
|
|
|
|
|
|
|
|
# No ending, discussion is running: |
|
|
# No ending, discussion is running: |
|
|
# Sometimes archived discussions also have no detectable ending |
|
|
# Sometimes archived discussions also have no detectable ending |
|
|
if not self.ending and not self._redpagearchive: |
|
|
if not self.ending and not self.redpage.archive: |
|
|
self.add_status("open") |
|
|
self.status.add("open") |
|
|
else: |
|
|
else: |
|
|
self.remove_status("open") |
|
|
self.status.remove("open") |
|
|
if not self._redpagearchive: |
|
|
if not self.redpage.archive: |
|
|
self.add_status("done") |
|
|
self.status.add("done") |
|
|
else: |
|
|
else: |
|
|
self.remove_status("done") |
|
|
self.status.remove("done") |
|
|
self.remove_status("open") |
|
|
self.status.remove("open") |
|
|
self.add_status("archived") |
|
|
self.status.add("archived") |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
|
def is_section_redfam_cb( cls, heading ): |
|
|
def is_section_redfam_cb( cls, heading ): |
|
@ -413,7 +366,7 @@ class RedFamParser( RedFam ): |
|
|
text = mwparser.parse( text ) |
|
|
text = mwparser.parse( text ) |
|
|
|
|
|
|
|
|
# Extract heading text |
|
|
# Extract heading text |
|
|
heading = next( text.ifilter_headings() ).title |
|
|
heading = next( text.ifilter_headings() ).title.strip() |
|
|
|
|
|
|
|
|
# Extract beginnig and maybe ending |
|
|
# Extract beginnig and maybe ending |
|
|
(beginning, ending) = RedFamParser.extract_dates( text, isarchive ) |
|
|
(beginning, ending) = RedFamParser.extract_dates( text, isarchive ) |
|
@ -448,7 +401,7 @@ class RedFamParser( RedFam ): |
|
|
|
|
|
|
|
|
else: |
|
|
else: |
|
|
# Create the RedFam object |
|
|
# 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 |
|
|
return redfam |
|
|
|
|
|
|
|
|
@classmethod |
|
|
@classmethod |
|
@ -593,13 +546,13 @@ class RedFamWorker( RedFam ): |
|
|
""" |
|
|
""" |
|
|
for article in self._articlesList: |
|
|
for article in self._articlesList: |
|
|
if self.article_has_status( "note_rej", title=article ): |
|
|
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 ): |
|
|
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 \ |
|
|
if not self.status.has( "sav_err" ) and \ |
|
|
not self.has_status( "note_rej" ): |
|
|
not self.status.has( "note_rej" ): |
|
|
self.add_status( "marked" ) |
|
|
self.status.add( "marked" ) |
|
|
|
|
|
|
|
|
self._mysql.data[ 'status' ] = self._raw_status() |
|
|
self._mysql.data[ 'status' ] = self._raw_status() |
|
|
index = 0 |
|
|
index = 0 |
|
|