Index: trunk/tools/wsor/scripts/vandal_revert.py |
— | — | @@ -42,17 +42,19 @@ |
43 | 43 | """ |
44 | 44 | def main(args): |
45 | 45 | |
46 | | - #print args.test |
47 | | - |
48 | 46 | """ Configure the logger """ |
49 | 47 | LOGGING_STREAM = sys.stderr |
50 | 48 | logging.basicConfig(level=logging.DEBUG, stream=LOGGING_STREAM, format='%(asctime)s %(levelname)-8s %(message)s', datefmt='%b-%d %H:%M:%S') |
51 | 49 | |
52 | | - vl = VandalLoader() |
| 50 | + """ Create a DataLoader object and execute """ |
| 51 | + vl = VandalLoader(args.query) |
53 | 52 | data = vl.run_query() |
54 | 53 | |
55 | | - print data |
| 54 | + """ PROCESS the data -- !! TODO - add data reporting here to build results !! """ |
| 55 | + # print data |
56 | 56 | |
| 57 | + vl.close_db() |
| 58 | + |
57 | 59 | return 0 |
58 | 60 | |
59 | 61 | |
Index: trunk/tools/wsor/scripts/classes/WSORSlaveDataLoader.py |
— | — | @@ -43,6 +43,7 @@ |
44 | 44 | """ Establish connection """ |
45 | 45 | try: |
46 | 46 | 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__) |
47 | 48 | logging.info('Successfully connected.\n') |
48 | 49 | except: |
49 | 50 | logging.DEBUG('Could not establish a connection to %s @ %s : %s' % (settings.__user__, settings.__db_server__, settings.__db__)) |
— | — | @@ -50,28 +51,48 @@ |
51 | 52 | |
52 | 53 | """ Create cursor """ |
53 | 54 | self._cur_ = self._db_.cursor() |
| 55 | + self._cur_enwiki_ = self._db_enwiki_.cursor() |
54 | 56 | |
55 | 57 | |
| 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() |
56 | 65 | |
57 | 66 | |
58 | 67 | """ |
59 | | - Inherits DataLoader |
| 68 | + Inherits WSORSlaveDataLoader |
60 | 69 | |
61 | | - DataLoader class for the WSOR MySQL Slave |
| 70 | + DataLoader class for vandal reversion related queries |
62 | 71 | |
63 | 72 | """ |
64 | 73 | class VandalLoader(WSORSlaveDataLoader): |
65 | 74 | |
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' |
69 | 75 | |
70 | | - def __init__(self): |
| 76 | + def __init__(self, query_key): |
71 | 77 | |
72 | 78 | DataLoader.__init__(self) |
73 | 79 | logging.info('Creating VadalLoader') |
74 | 80 | |
| 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' |
75 | 87 | |
| 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 | + |
76 | 97 | """ |
77 | 98 | Main execution body and data handling for the loader object |
78 | 99 | """ |
— | — | @@ -82,7 +103,7 @@ |
83 | 104 | self.init_db() |
84 | 105 | |
85 | 106 | try: |
86 | | - self._cur_.execute(self._query_test_) |
| 107 | + self._cur_.execute(self._query_names_['query_test']) |
87 | 108 | |
88 | 109 | """ GET THE COLUMN NAMES FROM THE QUERY RESULTS """ |
89 | 110 | self._col_names_ = list() |