Apply changes to data structure
See related ticket Related Task: [https://fs.golderweb.de/index.php?do=details&task_id=94 FS#94]
This commit is contained in:
@@ -49,6 +49,8 @@ class RedPage:
|
||||
@type pageid int
|
||||
"""
|
||||
|
||||
self._status = set()
|
||||
|
||||
# Safe the pywikibot page object
|
||||
self.page = page
|
||||
self.pageid = pageid
|
||||
@@ -71,7 +73,7 @@ class RedPage:
|
||||
elif self.pageid:
|
||||
self.__mysql = MysqlRedPage( self.pageid )
|
||||
self.page = pywikibot.Page( pywikibot.Site(),
|
||||
self.__mysql.data['page_title'] )
|
||||
self.__mysql.data['pagetitle'] )
|
||||
self.page.exists()
|
||||
else:
|
||||
raise ValueError( "Page NOR pagid provided!" )
|
||||
@@ -84,9 +86,9 @@ 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(),
|
||||
if( self.__mysql.data != { 'pageid': self.page._pageid,
|
||||
'revid': self.page._revid,
|
||||
'pagetitle': self.page.title(),
|
||||
'status': self.__mysql.data[ 'status' ] } ):
|
||||
self._changed = True
|
||||
else:
|
||||
@@ -110,7 +112,7 @@ class RedPage:
|
||||
Decides wether current RedPage needs to be parsed or not
|
||||
"""
|
||||
|
||||
if( self._changed or self.__mysql.data[ 'status' ] == 0 ):
|
||||
if( self._changed or self.__mysql.data[ 'status' ] == "" ):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
@@ -146,14 +148,16 @@ class RedPage:
|
||||
Updates the page meta data in mysql db
|
||||
"""
|
||||
if( self._parsed or not self._changed ):
|
||||
status = 1
|
||||
self.add_status( "open" )
|
||||
|
||||
if( self.is_archive() ):
|
||||
status = 2
|
||||
self.remove_status( "open" )
|
||||
self.add_status( "archived" )
|
||||
else:
|
||||
status = 0
|
||||
self._status = set()
|
||||
|
||||
self.__mysql.update_page( self.page._revid, self.page.title(), status )
|
||||
self.__mysql.update_page( self.page._revid, self.page.title(),
|
||||
self._raw_status() )
|
||||
|
||||
@classmethod
|
||||
def flush_db_cache( cls ):
|
||||
@@ -161,3 +165,58 @@ class RedPage:
|
||||
Calls flush method of Mysql Interface class
|
||||
"""
|
||||
MysqlRedPage.flush()
|
||||
|
||||
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 _parse_status(self, raw_status ):
|
||||
"""
|
||||
Sets status based on comma separated list
|
||||
|
||||
@param raw_status Commaseparated string of stati (from DB)
|
||||
@type raw_status str
|
||||
"""
|
||||
self._status = set( raw_status.strip().split(","))
|
||||
|
||||
def _raw_status( self ):
|
||||
"""
|
||||
Returns status as commaseparated string (to save in DB)
|
||||
|
||||
@returns Raw status string
|
||||
@rtype str
|
||||
"""
|
||||
return ",".join( self._status )
|
||||
|
||||
Reference in New Issue
Block a user