r91126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91125‎ | r91126 | r91127 >
Date:22:23, 29 June 2011
Author:rfaulk
Status:deferred
Tags:
Comment:
Built connection for enwiki slave into VandalRevertLoader
Enabled query specification via args
Modified paths:
  • /trunk/tools/wsor/scripts/classes/WSORSlaveDataLoader.py (modified) (history)
  • /trunk/tools/wsor/scripts/vandal_revert.py (modified) (history)

Diff [purge]

Index: trunk/tools/wsor/scripts/vandal_revert.py
@@ -42,17 +42,19 @@
4343 """
4444 def main(args):
4545
46 - #print args.test
47 -
4846 """ Configure the logger """
4947 LOGGING_STREAM = sys.stderr
5048 logging.basicConfig(level=logging.DEBUG, stream=LOGGING_STREAM, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%b-%d %H:%M:%S')
5149
52 - vl = VandalLoader()
 50+ """ Create a DataLoader object and execute """
 51+ vl = VandalLoader(args.query)
5352 data = vl.run_query()
5453
55 - print data
 54+ """ PROCESS the data -- !! TODO - add data reporting here to build results !! """
 55+ # print data
5656
 57+ vl.close_db()
 58+
5759 return 0
5860
5961
Index: trunk/tools/wsor/scripts/classes/WSORSlaveDataLoader.py
@@ -43,6 +43,7 @@
4444 """ Establish connection """
4545 try:
4646 self._db_ = MySQLdb.connect(host=settings.__db_server__, user=settings.__user__, db=settings.__db__, port=settings.__db_port__, passwd=settings.__pass__)
 47+ self._db_enwiki_ = MySQLdb.connect(host=settings.__db_server__, user=settings.__user__, db=settings.__db_enwikislave__, port=settings.__db_port__, passwd=settings.__pass__)
4748 logging.info('Successfully connected.\n')
4849 except:
4950 logging.DEBUG('Could not establish a connection to %s @ %s : %s' % (settings.__user__, settings.__db_server__, settings.__db__))
@@ -50,28 +51,48 @@
5152
5253 """ Create cursor """
5354 self._cur_ = self._db_.cursor()
 55+ self._cur_enwiki_ = self._db_enwiki_.cursor()
5456
5557
 58+ def close_db(self):
 59+
 60+ self._cur_.close()
 61+ self._db_.close()
 62+
 63+ self._cur_enwiki_.close()
 64+ self._db_enwiki_.close()
5665
5766
5867 """
59 - Inherits DataLoader
 68+ Inherits WSORSlaveDataLoader
6069
61 - DataLoader class for the WSOR MySQL Slave
 70+ DataLoader class for vandal reversion related queries
6271
6372 """
6473 class VandalLoader(WSORSlaveDataLoader):
6574
66 - _query_test_ = 'select count(*) from revert_20110115'
67 - _query_vandal_count_ = 'select revision_id, username, user_id, sum(is_vandalism) from reverted_20110115 group by 1,2,3'
68 - _query_total_reverts_ = 'select revision_id, username, user_id, sum(is_vandalism) from reverted_20110115'
6975
70 - def __init__(self):
 76+ def __init__(self, query_key):
7177
7278 DataLoader.__init__(self)
7379 logging.info('Creating VadalLoader')
7480
 81+ """
 82+ DEFINE SQL queries
 83+ """
 84+ self._query_names_['query_test'] = 'select count(*) from revert_20110115'
 85+ self._query_names_['query_vandal_count'] = 'select revision_id, username, user_id, sum(is_vandalism) from reverted_20110115 group by 1,2,3'
 86+ self._query_names_['query_total_reverts'] = 'select revision_id, username, user_id, sum(is_vandalism) from reverted_20110115'
7587
 88+ """
 89+ ASSIGN query
 90+ """
 91+ try:
 92+ _sql_ = self._query_names_[query_key]
 93+ except KeyError:
 94+ logging.debug('Query does not exist\n')
 95+
 96+
7697 """
7798 Main execution body and data handling for the loader object
7899 """
@@ -82,7 +103,7 @@
83104 self.init_db()
84105
85106 try:
86 - self._cur_.execute(self._query_test_)
 107+ self._cur_.execute(self._query_names_['query_test'])
87108
88109 """ GET THE COLUMN NAMES FROM THE QUERY RESULTS """
89110 self._col_names_ = list()

Status & tagging log