Fix pep8.. compliance
To be concordant with the coding styles fix pep8 compliance
This commit is contained in:
@@ -89,7 +89,6 @@ class MarkPagesBot( CurrentPageBot ): # sets 'current_page' on each treat()
|
|||||||
|
|
||||||
RedFamWorker.flush_db_cache()
|
RedFamWorker.flush_db_cache()
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def redfams(self):
|
def redfams(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -146,7 +146,8 @@ class DiscussionParserBot(
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Initiate RedPage object
|
# Initiate RedPage object
|
||||||
redpage = RedPage.session.query(RedPage).filter(RedPage.pageid == self.current_page.pageid ).one_or_none()
|
redpage = RedPage.session.query(RedPage).filter(
|
||||||
|
RedPage.pageid == self.current_page.pageid ).one_or_none()
|
||||||
|
|
||||||
if redpage:
|
if redpage:
|
||||||
redpage.update( self.current_page )
|
redpage.update( self.current_page )
|
||||||
|
|||||||
@@ -25,22 +25,27 @@
|
|||||||
Provides interface classes for communication of redundances bot with mysql-db
|
Provides interface classes for communication of redundances bot with mysql-db
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Prefere using oursql then MySQLdb
|
import atexit # noqa
|
||||||
try:
|
|
||||||
import oursql as mysqldb
|
|
||||||
except ImportError:
|
|
||||||
import MySQLdb as mysqldb
|
|
||||||
|
|
||||||
import atexit
|
import pywikibot # noqa
|
||||||
|
|
||||||
import pywikibot
|
|
||||||
from pywikibot import config
|
from pywikibot import config
|
||||||
|
|
||||||
import jogobot
|
import jogobot
|
||||||
|
|
||||||
|
from sqlalchemy import (
|
||||||
from sqlalchemy import create_engine
|
create_engine, Column, Integer, String, Text, DateTime, ForeignKey )
|
||||||
|
from sqlalchemy import text # noqa
|
||||||
from sqlalchemy.engine.url import URL
|
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",
|
url = URL( "mysql+oursql",
|
||||||
username=config.db_username,
|
username=config.db_username,
|
||||||
password=config.db_password,
|
password=config.db_password,
|
||||||
@@ -50,18 +55,6 @@ url = URL( "mysql+oursql",
|
|||||||
engine = create_engine(url, echo=True)
|
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 = sessionmaker(bind=engine)
|
||||||
session = Session()
|
session = Session()
|
||||||
|
|
||||||
@@ -70,20 +63,22 @@ family = "dewpbeta"
|
|||||||
|
|
||||||
class Mysql(object):
|
class Mysql(object):
|
||||||
session = session
|
session = session
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def _tableprefix(cls):
|
def _tableprefix(cls):
|
||||||
return family + "_"
|
return family + "_"
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def _tablesuffix(cls):
|
def _tablesuffix(cls):
|
||||||
return "s"
|
return "s"
|
||||||
|
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def __tablename__(cls):
|
def __tablename__(cls):
|
||||||
if has_inherited_table(cls):
|
if has_inherited_table(cls):
|
||||||
return None
|
return None
|
||||||
prefix = family + "_"
|
|
||||||
name = cls.__name__[len("Mysql"):].lower()
|
name = cls.__name__[len("Mysql"):].lower()
|
||||||
suffix = "s"
|
|
||||||
return cls._tableprefix + name + cls._tablesuffix
|
return cls._tableprefix + name + cls._tablesuffix
|
||||||
|
|
||||||
def changedp(self):
|
def changedp(self):
|
||||||
return self.session.is_modified(self)
|
return self.session.is_modified(self)
|
||||||
|
|
||||||
@@ -108,7 +103,7 @@ class MutableSet(MutableSet):
|
|||||||
|
|
||||||
@param item Item to add
|
@param item Item to add
|
||||||
"""
|
"""
|
||||||
if not item in self:
|
if item not in self:
|
||||||
super().add(item)
|
super().add(item)
|
||||||
|
|
||||||
def discard(self, item):
|
def discard(self, item):
|
||||||
@@ -187,8 +182,11 @@ class Status( types.TypeDecorator ):
|
|||||||
elif isinstance(value, String ) or value is None:
|
elif isinstance(value, String ) or value is None:
|
||||||
return value
|
return value
|
||||||
else:
|
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):
|
def process_result_value(self, value, dialect):
|
||||||
"""
|
"""
|
||||||
@@ -227,7 +225,8 @@ class MysqlRedFam( Mysql, Base ):
|
|||||||
Integer, ForeignKey( "dewpbeta_redpages.pageid" ), nullable=False )
|
Integer, ForeignKey( "dewpbeta_redpages.pageid" ), nullable=False )
|
||||||
beginning = Column( DateTime, nullable=False )
|
beginning = Column( DateTime, nullable=False )
|
||||||
ending = Column( DateTime, nullable=True )
|
ending = Column( DateTime, nullable=True )
|
||||||
_status = Column( 'status', MutableSet.as_mutable(Status(255)), nullable=True )
|
_status = Column( 'status', MutableSet.as_mutable(Status(255)),
|
||||||
|
nullable=True )
|
||||||
|
|
||||||
__article0_status = Column(
|
__article0_status = Column(
|
||||||
'article0_status', MutableSet.as_mutable(Status(64)), nullable=True )
|
'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 )
|
pageid = Column( Integer, unique=True, primary_key=True )
|
||||||
revid = Column( Integer, unique=True, nullable=False )
|
revid = Column( Integer, unique=True, nullable=False )
|
||||||
pagetitle = Column( String(255), 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(
|
redfams = relationship(
|
||||||
"MysqlRedFam", order_by=MysqlRedFam.famhash, back_populates="redpage",
|
"MysqlRedFam", order_by=MysqlRedFam.famhash, back_populates="redpage",
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import pywikibot # noqa
|
|||||||
from pywikibot.tools import deprecated # noqa
|
from pywikibot.tools import deprecated # noqa
|
||||||
|
|
||||||
import jogobot
|
import jogobot
|
||||||
from lib.mysqlred import MysqlRedFam
|
from lib.mysqlred import MysqlRedFam, text
|
||||||
|
|
||||||
|
|
||||||
class RedFam( MysqlRedFam ):
|
class RedFam( MysqlRedFam ):
|
||||||
@@ -60,8 +60,16 @@ class RedFam( MysqlRedFam ):
|
|||||||
# Having pywikibot.Site() is a good idea most of the time
|
# Having pywikibot.Site() is a good idea most of the time
|
||||||
self.site = pywikibot.Site()
|
self.site = pywikibot.Site()
|
||||||
|
|
||||||
super().__init__( articlesList=articlesList, beginning=beginning, ending=ending, redpageid=redpageid,
|
super().__init__(
|
||||||
famhash=famhash, heading=heading, status=status, articlesStatus=None )
|
articlesList=articlesList,
|
||||||
|
beginning=beginning,
|
||||||
|
ending=ending,
|
||||||
|
redpageid=redpageid,
|
||||||
|
famhash=famhash,
|
||||||
|
heading=heading,
|
||||||
|
status=status,
|
||||||
|
articlesStatus=None
|
||||||
|
)
|
||||||
|
|
||||||
def __repr__( self ):
|
def __repr__( self ):
|
||||||
"""
|
"""
|
||||||
@@ -228,23 +236,25 @@ class RedFamParser( RedFam ):
|
|||||||
if ending:
|
if ending:
|
||||||
ending = self.__datetime(ending)
|
ending = self.__datetime(ending)
|
||||||
|
|
||||||
|
super().__init__( articlesList,
|
||||||
super().__init__( articlesList, beginning, ending=ending, redpageid=redpage.page._pageid,
|
beginning,
|
||||||
famhash=famhash, heading=heading )
|
ending=ending,
|
||||||
|
redpageid=redpage.page._pageid,
|
||||||
|
famhash=famhash,
|
||||||
|
heading=heading )
|
||||||
|
|
||||||
# Check status changes
|
# Check status changes
|
||||||
self.check_status()
|
self.check_status()
|
||||||
|
|
||||||
self.session.add(self)
|
self.session.add(self)
|
||||||
|
|
||||||
|
|
||||||
def update( self, articlesList, heading, redpage, redpagearchive,
|
def update( self, articlesList, heading, redpage, redpagearchive,
|
||||||
beginning, ending=None ):
|
beginning, ending=None ):
|
||||||
|
|
||||||
self.articlesList = articlesList;
|
self.articlesList = articlesList
|
||||||
self.heading = heading;
|
self.heading = heading
|
||||||
self.redpage = redpage;
|
self.redpage = redpage
|
||||||
self.redpageid = redpage.pageid;
|
self.redpageid = redpage.pageid
|
||||||
|
|
||||||
self.add_beginning( beginning )
|
self.add_beginning( beginning )
|
||||||
|
|
||||||
@@ -271,8 +281,7 @@ class RedFamParser( RedFam ):
|
|||||||
heading = mwparser.parse( str( heading ) )
|
heading = mwparser.parse( str( heading ) )
|
||||||
|
|
||||||
# Save destinations of wikilinks in headings
|
# Save destinations of wikilinks in headings
|
||||||
return [ str( link.title ) for link
|
return [ str( link.title ) for link in heading.ifilter_wikilinks() ]
|
||||||
in heading.ifilter_wikilinks() ]
|
|
||||||
|
|
||||||
def add_beginning( self, beginning ):
|
def add_beginning( self, beginning ):
|
||||||
"""
|
"""
|
||||||
@@ -398,11 +407,13 @@ class RedFamParser( RedFam ):
|
|||||||
|
|
||||||
if redfam:
|
if redfam:
|
||||||
# Existing redfams need to be updated
|
# Existing redfams need to be updated
|
||||||
redfam.update( articlesList, str(heading), redpage, isarchive, beginning, ending )
|
redfam.update( articlesList, str(heading), redpage, isarchive,
|
||||||
|
beginning, ending )
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Create the RedFam object
|
# Create the RedFam object
|
||||||
redfam = RedFamParser( articlesList, str(heading), redpage, isarchive, beginning, ending )
|
redfam = RedFamParser( articlesList, str(heading),
|
||||||
|
redpage, isarchive, beginning, ending )
|
||||||
return redfam
|
return redfam
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -465,7 +476,8 @@ class RedFamWorker( RedFam ):
|
|||||||
# with wrong month abreviations in strptime
|
# with wrong month abreviations in strptime
|
||||||
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
|
||||||
|
|
||||||
def article_generator(self, filter_existing=None, filter_redirects=None,
|
def article_generator(self, # noqa
|
||||||
|
filter_existing=None, filter_redirects=None,
|
||||||
exclude_article_status=[],
|
exclude_article_status=[],
|
||||||
onlyinclude_article_status=[] ):
|
onlyinclude_article_status=[] ):
|
||||||
"""
|
"""
|
||||||
@@ -634,14 +646,12 @@ class RedFamWorker( RedFam ):
|
|||||||
Yield red_fams stored in db by given status which have an ending after
|
Yield red_fams stored in db by given status which have an ending after
|
||||||
given one
|
given one
|
||||||
"""
|
"""
|
||||||
from sqlalchemy import text
|
|
||||||
|
|
||||||
for redfam in RedFamWorker.session.query(RedFamWorker).filter(
|
for redfam in RedFamWorker.session.query(RedFamWorker).filter(
|
||||||
#~ RedFamWorker._status.like('archived'),
|
# NOT WORKING WITH OBJECT NOTATION
|
||||||
|
# RedFamWorker._status.like('archived'),
|
||||||
# RedFamWorker._status.like("%{0:s}%".format(status)),
|
# RedFamWorker._status.like("%{0:s}%".format(status)),
|
||||||
text("status LIKE '%archived%'"),
|
text("status LIKE '%archived%'"),
|
||||||
RedFamWorker.ending >= ending
|
RedFamWorker.ending >= ending ):
|
||||||
):
|
|
||||||
|
|
||||||
yield redfam
|
yield redfam
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ import mwparserfromhell as mwparser
|
|||||||
import jogobot # noqa
|
import jogobot # noqa
|
||||||
|
|
||||||
from lib.mysqlred import MysqlRedPage, relationship
|
from lib.mysqlred import MysqlRedPage, relationship
|
||||||
from lib.redfam import RedFam, RedFamParser
|
|
||||||
from sqlalchemy.orm.collections import attribute_mapped_collection
|
from sqlalchemy.orm.collections import attribute_mapped_collection
|
||||||
|
from lib.redfam import RedFamParser
|
||||||
|
|
||||||
|
|
||||||
class RedPage( MysqlRedPage ):
|
class RedPage( MysqlRedPage ):
|
||||||
|
|||||||
Reference in New Issue
Block a user