Fix bug caused by adding fam_hash to repr of RedFam class since it was not defined yet while output of warning caused by to many articles

This commit is contained in:
2015-09-17 19:57:53 +02:00
parent 53f53ddb8b
commit 8dc7fe678d

View File

@@ -97,7 +97,7 @@ class RedFam:
""" """
h = hashlib.sha1() h = hashlib.sha1()
h.update( str( self._articlesList ).encode('utf-8') ) h.update( str( self._articlesList[:8] ).encode('utf-8') )
if self._fam_hash and h.hexdigest() != self._fam_hash: if self._fam_hash and h.hexdigest() != self._fam_hash:
raise RedFamHashError( self._fam_hash, h.hexdigest() ) raise RedFamHashError( self._fam_hash, h.hexdigest() )
@@ -146,6 +146,7 @@ class RedFamParser( RedFam ):
# Set object attributes: # Set object attributes:
self._red_page_id = red_page_id self._red_page_id = red_page_id
self._red_page_archive = red_page_archive self._red_page_archive = red_page_archive
self._fam_hash = None
# Method self.add_beginning sets self._beginning directly # Method self.add_beginning sets self._beginning directly
self.add_beginning( beginning ) self.add_beginning( beginning )
@@ -165,6 +166,7 @@ class RedFamParser( RedFam ):
# Calculates the sha1 hash over self._articlesList to # Calculates the sha1 hash over self._articlesList to
# rediscover known redundance families # rediscover known redundance families
self.calc_fam_hash() self.calc_fam_hash()
# Open database connection, ask for data if existing, # Open database connection, ask for data if existing,
@@ -212,10 +214,12 @@ class RedFamParser( RedFam ):
# Catch sections with more then 8 articles, print error # Catch sections with more then 8 articles, print error
if len( self._articlesList ) > 8: if len( self._articlesList ) > 8:
pywikibot.output( "{datetime} \03{{lightred}}[WARNING] \ # For repression in output we need to know the fam hash
Maximum number of articles in red_fam exceeded, \ self.calc_fam_hash()
maximum number is 8, {number:d} were given\n\ pywikibot.output( "\
{repress}".format( {datetime} \03{{lightred}}[WARNING] \
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" ), datetime=datetime.now().strftime( "%Y-%m-%d %H:%M:%S" ),
number=len( self._articlesList ), repress=repr( self ) ) ) number=len( self._articlesList ), repress=repr( self ) ) )
@@ -409,7 +413,7 @@ class RedFamError( Exception ):
Output of error message Output of error message
""" """
return message return self.message
class RedFamHashError( RedFamError ): class RedFamHashError( RedFamError ):