Fix pep8.. compliance

To be concordant with the coding styles fix pep8 compliance
This commit is contained in:
2017-03-08 18:38:15 +01:00
parent 9ba7d2e517
commit e16925197c
5 changed files with 70 additions and 60 deletions

View File

@@ -25,22 +25,27 @@
Provides interface classes for communication of redundances bot with mysql-db
"""
# Prefere using oursql then MySQLdb
try:
import oursql as mysqldb
except ImportError:
import MySQLdb as mysqldb
import atexit # noqa
import atexit
import pywikibot
import pywikibot # noqa
from pywikibot import config
import jogobot
from sqlalchemy import create_engine
from sqlalchemy import (
create_engine, Column, Integer, String, Text, DateTime, ForeignKey )
from sqlalchemy import text # noqa
from sqlalchemy.engine.url import URL
from sqlalchemy.ext.declarative import (
declarative_base, declared_attr, has_inherited_table )
from sqlalchemy.ext.mutable import MutableComposite, MutableSet
from sqlalchemy.orm import sessionmaker, relationship, composite
from sqlalchemy.orm.collections import attribute_mapped_collection
import sqlalchemy.types as types
Base = declarative_base()
url = URL( "mysql+oursql",
username=config.db_username,
password=config.db_password,
@@ -50,18 +55,6 @@ url = URL( "mysql+oursql",
engine = create_engine(url, echo=True)
from sqlalchemy.ext.declarative import (
declarative_base, declared_attr, has_inherited_table )
Base = declarative_base()
from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import sessionmaker, relationship, composite
from sqlalchemy.ext.mutable import MutableComposite, MutableSet
from sqlalchemy.orm.collections import attribute_mapped_collection
import sqlalchemy.types as types
Session = sessionmaker(bind=engine)
session = Session()
@@ -70,20 +63,22 @@ family = "dewpbeta"
class Mysql(object):
session = session
@declared_attr
def _tableprefix(cls):
return family + "_"
@declared_attr
def _tablesuffix(cls):
return "s"
@declared_attr
def __tablename__(cls):
if has_inherited_table(cls):
return None
prefix = family + "_"
name = cls.__name__[len("Mysql"):].lower()
suffix = "s"
return cls._tableprefix + name + cls._tablesuffix
def changedp(self):
return self.session.is_modified(self)
@@ -108,7 +103,7 @@ class MutableSet(MutableSet):
@param item Item to add
"""
if not item in self:
if item not in self:
super().add(item)
def discard(self, item):
@@ -187,8 +182,11 @@ class Status( types.TypeDecorator ):
elif isinstance(value, String ) or value is None:
return value
else:
raise ProgrammingError
raise TypeError(
"Value should be an instance of one of {0:s},".format(
str( [type(MutableSet()), type(String()), type(None)] ) ) +
"given value was an instance of {1:s}".format(
str(type(value))) )
def process_result_value(self, value, dialect):
"""
@@ -226,8 +224,9 @@ class MysqlRedFam( Mysql, Base ):
redpageid = Column(
Integer, ForeignKey( "dewpbeta_redpages.pageid" ), nullable=False )
beginning = Column( DateTime, nullable=False )
ending = Column( DateTime, nullable=True )
_status = Column( 'status', MutableSet.as_mutable(Status(255)), nullable=True )
ending = Column( DateTime, nullable=True )
_status = Column( 'status', MutableSet.as_mutable(Status(255)),
nullable=True )
__article0_status = Column(
'article0_status', MutableSet.as_mutable(Status(64)), nullable=True )
@@ -296,7 +295,8 @@ class MysqlRedPage( Mysql, Base ):
pageid = Column( Integer, unique=True, primary_key=True )
revid = Column( Integer, unique=True, nullable=False )
pagetitle = Column( String(255), nullable=False )
__status = Column( 'status', MutableSet.as_mutable(Status(255)), nullable=True )
__status = Column( 'status', MutableSet.as_mutable(Status(255)),
nullable=True )
redfams = relationship(
"MysqlRedFam", order_by=MysqlRedFam.famhash, back_populates="redpage",