Clean up PEP8 styleguide compatibility with flake8

This commit is contained in:
2015-09-13 11:53:47 +02:00
parent cafe08dd7f
commit 74b2dc727c
4 changed files with 205 additions and 142 deletions

View File

@@ -2,25 +2,25 @@
# -*- coding: utf-8 -*-
#
# mysqlred.py
#
#
# Copyright 2015 GOLDERWEB Jonathan Golder <jonathan@golderweb.de>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
#
#
"""
Provides interface classes for communication of redundances bot with mysql-db
"""
@@ -33,6 +33,7 @@ except ImportError:
from pywikibot import config
class MysqlRed:
"""
Basic interface class, containing opening of connection
@@ -40,12 +41,13 @@ class MysqlRed:
Specific querys should be defined in descendant classes per data type
"""
#Save mysqldb-connection as class attribute to use only one in descendant classes
# Save mysqldb-connection as class attribute to use only one
# in descendant classes
connection = False
db_hostname=config.db_hostname
db_username=config.db_username
db_password=config.db_password
db_name=config.db_username + '__bot'
db_hostname = config.db_hostname
db_username = config.db_username
db_password = config.db_password
db_name = config.db_username + '__bot'
def __init__( self ):
"""
@@ -55,9 +57,13 @@ class MysqlRed:
"""
# Connect to mysqldb only once
if( type( self ).connection == False ):
if not type( self ).connection:
type( self ).connection = mysqldb.connect( host=type( self ).db_hostname, user=type( self ).db_username, passwd=type( self ).db_password, db=type( self ).db_name )
type( self ).connection = mysqldb.connect(
host=type( self ).db_hostname,
user=type( self ).db_username,
passwd=type( self ).db_password,
db=type( self ).db_name )
def __del__( self ):
"""
@@ -66,10 +72,11 @@ class MysqlRed:
type( self ).connection.close()
class MysqlRedPage( MysqlRed ):
"""
MySQL-db Interface for handling querys for RedPages
"""
"""
MySQL-db Interface for handling querys for RedPages
"""
def __init__( self, page_id ):
"""
@@ -78,7 +85,7 @@ class MysqlRedPage( MysqlRed ):
super().__init__( )
self.__page_id = int( page_id );
self.__page_id = int( page_id )
self.data = self.get_page()
@@ -91,13 +98,14 @@ class MysqlRedPage( MysqlRed ):
@param int page_id MediaWiki page_id for page to retrieve
@returns tuple Tuple with data for given page_id otherwise if none found
bool FALSE
@returns tuple Tuple with data for given page_id
bool FALSE if none found
"""
cursor = type( self ).connection.cursor(mysqldb.DictCursor)
cursor.execute( 'SELECT * FROM `red_pages` WHERE `page_id` = ?;', ( self.__page_id, ) )
cursor.execute( 'SELECT * FROM `red_pages` WHERE `page_id` = ?;',
( self.__page_id, ) )
res = cursor.fetchone()
if res:
@@ -109,9 +117,9 @@ class MysqlRedPage( MysqlRed ):
"""
Inserts a red page row in MySQL-Database for given page_id
@param int rev_id MediaWiki current rev_id for page to update
@param str page_title MediaWiki new page_title for page to update
@param int status Page parsing status (0 - not (successfully) parsed; 1 - successfully parsed; 2 - successfully parsed archive)
@param int rev_id MediaWiki current rev_id
@param str page_title MediaWiki new page_title
@param int status Page parsing status
"""
cursor = type( self ).connection.cursor()
@@ -121,8 +129,10 @@ class MysqlRedPage( MysqlRed ):
if not rev_id:
rev_id = self.data[ 'rev_id' ]
query = 'INSERT INTO `red_pages` ( page_id, page_title, rev_id, status ) VALUES ( ?, ?, ?, ? );'
data = ( self.__page_id, str( page_title ), int( rev_id ), int( status ) )
query = 'INSERT INTO `red_pages` \
( page_id, page_title, rev_id, status ) \
VALUES ( ?, ?, ?, ? );'
data = ( self.__page_id, page_title, rev_id, status )
cursor.execute( query, data)
@@ -134,9 +144,9 @@ class MysqlRedPage( MysqlRed ):
"""
Updates the red page row in MySQL-Database for given page_id
@param int rev_id MediaWiki current rev_id for page to update
@param str page_title MediaWiki new page_title for page to update
@param int status Page parsing status (0 - not (successfully) parsed; 1 - successfully parsed)
@param int rev_id MediaWiki current rev_id
@param str page_title MediaWiki new page_title
@param int status Page parsing status
"""
cursor = type( self ).connection.cursor()
@@ -146,17 +156,20 @@ class MysqlRedPage( MysqlRed ):
if not rev_id:
rev_id = self.data[ 'rev_id' ]
query = 'UPDATE `red_pages` SET `page_title` = ?, `rev_id` = ?, `status`= ? WHERE `page_id` = ?;'
data = ( str( page_title ), int( rev_id ), int( status ), self.__page_id )
query = 'UPDATE `red_pages` \
SET `page_title` = ?, `rev_id` = ?, `status`= ? \
WHERE `page_id` = ?;'
data = ( page_title, rev_id, status, self.__page_id )
cursor.execute( query, data)
type( self ).connection.commit()
class MysqlRedFam( MysqlRed ):
"""
MySQL-db Interface for handling querys for RedFams
"""
MySQL-db Interface for handling querys for RedFams
"""
def __init__( self, fam_hash ):
"""
@@ -176,13 +189,14 @@ class MysqlRedFam( MysqlRed ):
"""
Retrieves a red family row from MySQL-Database for given fam_hash
@returns dict Dictionairy with data for given fam hash otherwise if none found
bool FALSE
@returns dict Dictionairy with data for given fam hash
False if none found
"""
cursor = type( self ).connection.cursor(mysqldb.DictCursor)
cursor = type( self ).connection.cursor( mysqldb.DictCursor )
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;', ( self.__fam_hash, ) )
cursor.execute( 'SELECT * FROM `red_families` WHERE `fam_hash` = ?;',
( self.__fam_hash, ) )
res = cursor.fetchone()
if res:
@@ -190,12 +204,18 @@ class MysqlRedFam( MysqlRed ):
else:
return False
def add_fam( self, articlesList, heading, red_page_id, beginning, ending=None, status=0 ):
def add_fam( self, articlesList, heading, red_page_id,
beginning, ending=None, status=0 ):
cursor = type( self ).connection.cursor()
query = 'INSERT INTO `red_families` ( fam_hash, red_page_id, beginning, ending, status, heading, article0, article1, article2, article3, article4, article5, article6, article7 ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
data = [ str( self.__fam_hash ), red_page_id, beginning, ending, status, heading ]
query = 'INSERT INTO `red_families` \
( fam_hash, red_page_id, beginning, ending, status, heading, \
article0, article1, article2, article3, \
article4, article5, article6, article7 ) \
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? );'
data = [ self.__fam_hash, red_page_id, beginning, ending,
status, heading ]
for article in articlesList:
data.append( str( article ) )
@@ -215,16 +235,19 @@ class MysqlRedFam( MysqlRed ):
"""
Updates the red fam row in MySQL-Database for given fam_hash
@param int red_page_id MediaWiki page_id which contains red_fam
@param datetime beginning Timestamp of beginning of redundance discussion
qparam datetime ending Timestamp of ending of redundance discussion
@param int status red_fam status (0 - discussion is running; 1 - discussion over; 2 - discussion archived)
@param int red_page_id MediaWiki page_id
@param datetime beginning Timestamp of beginning
qparam datetime ending Timestamp of ending of
@param int status red_fam status
"""
cursor = type( self ).connection.cursor()
query = 'UPDATE `red_families` SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, `ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
data = ( int(red_page_id ), str( heading ), beginning, ending, int( status ), self.__fam_hash )
query = 'UPDATE `red_families` \
SET `red_page_id` = ?, `heading` = ?, `beginning` = ?, \
`ending` = ?, `status`= ? WHERE `fam_hash` = ?;'
data = ( red_page_id, heading, beginning,
ending, status, self.__fam_hash )
cursor.execute( query, data)