Some cleanups
Remove old commented out code from manual mysql solution
This commit is contained in:
180
lib/redfam.py
180
lib/redfam.py
@@ -35,8 +35,7 @@ import pywikibot # noqa
|
||||
from pywikibot.tools import deprecated # noqa
|
||||
|
||||
import jogobot
|
||||
#~ from lib.mysqlred import Column, Integer, String, Text, DateTime, ForeignKey, ColumnList, Status
|
||||
from lib.mysqlred import MysqlRedFam, MutableSet, ColumnList #, Mysql, Base, relationship, composite,
|
||||
from lib.mysqlred import MysqlRedFam
|
||||
|
||||
|
||||
class RedFam( MysqlRedFam ):
|
||||
@@ -45,7 +44,7 @@ class RedFam( MysqlRedFam ):
|
||||
"""
|
||||
|
||||
def __init__( self, articlesList, beginning, ending=None, redpageid=None,
|
||||
status=MutableSet(), famhash=None, heading=None ):
|
||||
status=None, famhash=None, heading=None ):
|
||||
"""
|
||||
Generates a new RedFam object
|
||||
|
||||
@@ -61,34 +60,9 @@ class RedFam( MysqlRedFam ):
|
||||
# Having pywikibot.Site() is a good idea most of the time
|
||||
self.site = pywikibot.Site()
|
||||
|
||||
# Database interface
|
||||
#self._mysql = MysqlRedFam( famhash )
|
||||
|
||||
# Initial attribute values
|
||||
#~ self.articlesList = articlesList
|
||||
#~ self.beginning = beginning
|
||||
#~ self.ending = ending
|
||||
#~ self.redpageid = redpageid
|
||||
#~ # self._status = set()
|
||||
#~ # self._status = self._parse_status(status)
|
||||
#~ self.famhash = famhash
|
||||
#~ self.heading = heading
|
||||
#self.status = status
|
||||
|
||||
#articlesStatus = ColumnList([ MutableSet() for x in range(0,8) ])
|
||||
|
||||
#~ # Calculates the sha1 hash over self._articlesList to
|
||||
#~ # rediscover known redundance families
|
||||
#~ self.calc_famhash()
|
||||
|
||||
#~ if not status:
|
||||
#~ status = MutableSet()
|
||||
|
||||
super().__init__( articlesList=articlesList, beginning=beginning, ending=ending, redpageid=redpageid,
|
||||
famhash=famhash, heading=heading, status=status, articlesStatus=None )
|
||||
|
||||
#super().__init__()
|
||||
|
||||
def __repr__( self ):
|
||||
"""
|
||||
Returns repression str of RedFam object
|
||||
@@ -137,35 +111,12 @@ class RedFam( MysqlRedFam ):
|
||||
else:
|
||||
self.famhash = type(self).calc_famhash(self.articlesList)
|
||||
|
||||
#~ def changed( self ):
|
||||
#~ """
|
||||
#~ Checks wether anything has changed and maybe triggers db update
|
||||
#~ """
|
||||
|
||||
#~ # On archived redfams do not delete possibly existing ending
|
||||
#~ if( not self.ending and "archived" in self._status and
|
||||
#~ self._mysql.data[ 'ending' ] ):
|
||||
|
||||
#~ self._ending = self._mysql.data[ 'ending' ]
|
||||
|
||||
#~ # Since status change means something has changed, update database
|
||||
#~ if( self._raw_status != self._mysql.data[ 'status' ] or
|
||||
#~ self._beginning != self._mysql.data[ 'beginning' ] or
|
||||
#~ self._ending != self._mysql.data[ 'ending' ] or
|
||||
#~ self._red_page_id != self._mysql.data[ 'redpageid' ] or
|
||||
#~ self._heading != self._mysql.data[ 'heading' ]):
|
||||
|
||||
#~ self._mysql.update_fam( self._redpageid, self._heading,
|
||||
#~ self._beginning, self._ending,
|
||||
#~ self._raw_status() )
|
||||
|
||||
@classmethod
|
||||
def flush_db_cache( cls ):
|
||||
"""
|
||||
Calls flush method of Mysql Interface class
|
||||
"""
|
||||
cls.session.commit()
|
||||
#~ MysqlRedFam.flush()
|
||||
|
||||
def add_status(self, status):
|
||||
"""
|
||||
@@ -204,24 +155,6 @@ class RedFam( MysqlRedFam ):
|
||||
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 )
|
||||
|
||||
def article_add_status(self, status, index=None, title=None ):
|
||||
"""
|
||||
Adds a status specified by status, to article (identified by title
|
||||
@@ -292,46 +225,6 @@ class RedFam( MysqlRedFam ):
|
||||
else:
|
||||
raise IndexError( "No index given or wrong format!")
|
||||
|
||||
def _article_parse_status(self, raw_status, index=None, title=None ):
|
||||
"""
|
||||
Sets status based on comma separated list to articles (identified by
|
||||
title or index in articlesList) status set
|
||||
|
||||
@param status Statusstring to set
|
||||
@type status str
|
||||
@param index Add to article with index in articlesList
|
||||
@type index int
|
||||
@param title Add to article with title in articlesList
|
||||
@type title str
|
||||
"""
|
||||
if title and not index:
|
||||
index = self._articlesList.index( title )
|
||||
|
||||
if isinstance( index, int ) and index < len(self._articlesList):
|
||||
self._article_status[index] = set( raw_status.strip().split(","))
|
||||
else:
|
||||
raise IndexError( "No index given or wrong format!")
|
||||
|
||||
def _article_raw_status( self, index=None, title=None ):
|
||||
"""
|
||||
Returns status as commaseparated string (to save in DB) of article
|
||||
(identified by title or index in articlesList) status set
|
||||
|
||||
@param index Get from article with index in articlesList
|
||||
@type index int
|
||||
@param title Get from article with title in articlesList
|
||||
@type title str
|
||||
@returns Raw status string
|
||||
@rtype str
|
||||
"""
|
||||
if title and not index:
|
||||
index = self._articlesList.index( title )
|
||||
|
||||
if isinstance( index, int ) and index < len(self._articlesList):
|
||||
return ",".join( self._article_status[index] )
|
||||
else:
|
||||
raise IndexError( "No index given or wrong format!")
|
||||
|
||||
|
||||
class RedFamParser( RedFam ):
|
||||
"""
|
||||
@@ -369,54 +262,14 @@ class RedFamParser( RedFam ):
|
||||
str strptime parseable string
|
||||
"""
|
||||
|
||||
# Parse the provided heading of redundance section
|
||||
# to set self._articlesList
|
||||
#~ self.heading = str(heading)
|
||||
#~ self.articlesList = articlesList
|
||||
|
||||
#~ # Catch sections with more then 8 articles, print error
|
||||
#~ if len( self.articlesList ) > 8:
|
||||
#~ # For repression in output we need to know the fam hash
|
||||
#~ self.calc_famhash()
|
||||
|
||||
#~ jogobot.output(
|
||||
#~ ( "\03{{lightred}}" +
|
||||
#~ "Maximum number of articles in red_fam exceeded, " +
|
||||
#~ "maximum number is 8, {number:d} were given \n {repress}"
|
||||
#~ ).format( datetime=datetime.now().strftime(
|
||||
#~ "%Y-%m-%d %H:%M:%S" ), number=len( self._articlesList ),
|
||||
#~ repress=repr( self ) ),
|
||||
#~ "WARNING" )
|
||||
|
||||
#~ # Only save the first 8 articles
|
||||
#~ # self.articlesList = self.articlesList[:8]
|
||||
|
||||
# Calculates the sha1 hash over self._articlesList to
|
||||
# rediscover known redundance families
|
||||
famhash = type(self).calc_famhash(articlesList)
|
||||
|
||||
#~ obj = self.session.query(RedFamParser).filter(RedFamParser.famhash == self.famhash ).one_or_none()
|
||||
#~ if obj:
|
||||
#~ self = obj
|
||||
|
||||
|
||||
# Set object attributes:
|
||||
#~ self.redpageid = redpage._pageid
|
||||
self._redpagearchive = redpagearchive
|
||||
# self.famhash = None
|
||||
|
||||
# Method self.add_beginning sets self._beginning directly
|
||||
#~ self.add_beginning( beginning )
|
||||
|
||||
#~ # Method self.add_ending sets self._ending directly
|
||||
#~ if( ending ):
|
||||
#~ self.add_ending( ending )
|
||||
#~ else:
|
||||
#~ # If no ending was provided set to None
|
||||
#~ self.ending = None
|
||||
|
||||
#~ self.status = MutableSet()
|
||||
|
||||
# Parse Timestamps
|
||||
beginning = self.__datetime(beginning)
|
||||
if ending:
|
||||
ending = self.__datetime(ending)
|
||||
@@ -429,31 +282,8 @@ class RedFamParser( RedFam ):
|
||||
self.check_status()
|
||||
|
||||
self.session.add(self)
|
||||
# Open database connection, ask for data if existing,
|
||||
# otherwise create entry
|
||||
# self.__handle_db()
|
||||
|
||||
|
||||
|
||||
# Triggers db update if anything changed
|
||||
# self.changed()
|
||||
|
||||
|
||||
|
||||
#~ def __handle_db( self ):
|
||||
#~ """
|
||||
#~ Handles opening of db connection
|
||||
#~ """
|
||||
|
||||
#~ # We need a connection to our mysqldb
|
||||
#~ self._mysql = MysqlRedFam( )
|
||||
#~ self._mysql.get_fam( self._famhash )
|
||||
|
||||
#~ if not self._mysql.data:
|
||||
#~ self._mysql.add_fam( self._articlesList, self._heading,
|
||||
#~ self._redpageid, self._beginning,
|
||||
#~ self._ending )
|
||||
|
||||
def update( self, articlesList, heading, redpage, redpagearchive,
|
||||
beginning, ending=None):
|
||||
|
||||
@@ -490,8 +320,6 @@ class RedFamParser( RedFam ):
|
||||
return [ str( link.title ) for link
|
||||
in heading.ifilter_wikilinks() ]
|
||||
|
||||
|
||||
|
||||
def add_beginning( self, beginning ):
|
||||
"""
|
||||
Adds the beginning date of a redundance diskussion to the object
|
||||
@@ -780,8 +608,6 @@ class RedFamWorker( RedFam ):
|
||||
self._article_raw_status( index=index )
|
||||
index += 1
|
||||
|
||||
print( repr(self) )
|
||||
|
||||
def get_disc_link( self ):
|
||||
"""
|
||||
Constructs and returns the link to Redundancy discussion
|
||||
|
||||
Reference in New Issue
Block a user