r86628 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r86627‎ | r86628 | r86629 >
Date:16:10, 21 April 2011
Author:diederik
Status:deferred
Tags:
Comment:
Implemented pylint suggestions
Modified paths:
  • /trunk/tools/editor_trends/analyses/analyzer.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/inventory.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/json_encoders.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/ppi_editor_productivity.py (modified) (history)
  • /trunk/tools/editor_trends/analyses/plugins/taxonomy_list_makers.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/analyses/plugins/taxonomy_list_makers.py
@@ -66,7 +66,7 @@
6767
6868 def preload(rts):
6969 collection = '%s%s_articles_raw' % (rts.language.code, rts.project.name)
70 - db = storage.Database(rts.storage, rts.dbname, collection)
 70+ db = storage.init_database(rts.storage, rts.dbname, collection)
7171 data = {}
7272 cursor = db.find('category', 'List')
7373 for c in cursor:
Index: trunk/tools/editor_trends/analyses/plugins/ppi_editor_productivity.py
@@ -26,7 +26,6 @@
2727
2828 edits = editor['character_count']
2929 username = editor['username']
30 -
3130 try:
3231 added = edits['2010']['11']['0']['added']
3332 except KeyError:
Index: trunk/tools/editor_trends/analyses/json_encoders.py
@@ -13,7 +13,7 @@
1414 '''
1515
1616 __author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
17 -__author__email = 'dvanliere at gmail dot com'
 17+__email__ = 'dvanliere at gmail dot com'
1818 __date__ = '2011-01-27'
1919 __version__ = '0.1'
2020
Index: trunk/tools/editor_trends/analyses/inventory.py
@@ -13,14 +13,13 @@
1414 '''
1515
1616 __author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
17 -__author__email = 'dvanliere at gmail dot com'
 17+__email__ = 'dvanliere at gmail dot com'
1818 __date__ = '2011-02-11'
1919 __version__ = '0.1'
2020
2121
2222 import os
2323 import sys
24 -import types
2524
2625 def available_analyses(caller='manage'):
2726 '''
@@ -30,24 +29,17 @@
3130 ignore: a list of functions that should never be called from manage.py,
3231 they are not valid entry points.
3332 '''
34 - assert caller == 'django' or caller == 'manage'
35 - ignore = ['__init__']
36 - charts = {}
 33+ assert caller == 'webpy' or caller == 'manage'
3734
3835 fn = os.path.realpath(__file__)
3936 pos = fn.rfind(os.sep)
4037 loc = fn[:pos]
41 - path = os.path.join(loc , 'plugins')
 38+ path = os.path.join(loc, 'plugins')
4239 modules = import_libs(path)
4340
44 -# for module_name, module in modules.iteritems():
45 -# func = getattr(module, module_name)
46 -# plugin = module()
47 -# if isinstance(plugin, types.FunctionType) and plugin.func_name not in ignore:
48 -# charts[plugin.func_name] = plugin
4941 if caller == 'manage':
5042 return modules
51 - elif caller == 'django':
 43+ elif caller == 'webpy':
5244 django_functions = []
5345 for module in modules:
5446 fancy_name = module.replace('_', ' ').title()
@@ -62,9 +54,9 @@
6355 '''
6456 plugins = {}
6557 sys.path.append(path)
66 - for f in os.listdir(os.path.abspath(path)):
67 - module_name, ext = os.path.splitext(f)
68 - if ext == '.py':
 58+ for filename in os.listdir(os.path.abspath(path)):
 59+ module_name, ext = os.path.splitext(filename)
 60+ if ext == '.py' and module_name != '__init__':
6961 module = __import__(module_name)
7062 plugins[module_name] = module
7163
Index: trunk/tools/editor_trends/analyses/analyzer.py
@@ -74,9 +74,9 @@
7575
7676
7777 def write_output(ds, rts, stopwatch):
78 - ds.create_filename()
 78+ filename = ds.create_filename()
7979 print 'Storing dataset: %s' % os.path.join(rts.dataset_location,
80 - ds.filename)
 80+ filename)
8181 ds.write(format='csv')
8282 print 'Serializing dataset to %s_%s' % (rts.dbname, 'charts')
8383 #log.log_to_mongo(rts, 'chart', 'storing', stopwatch, event='start')
@@ -97,15 +97,15 @@
9898
9999 feedback(func, rts)
100100
101 - obs = dict()
102101 tasks = JoinableQueue()
103102 result = JoinableQueue()
104103
105104 mgr = Manager()
106105 lock = mgr.RLock()
 106+ obs = dict()
107107 obs_proxy = mgr.dict(obs)
108108
109 - db = storage.Database(rts.storage, rts.dbname, rts.editors_dataset)
 109+ db = storage.init_database(rts.storage, rts.dbname, rts.editors_dataset)
110110 editors = db.retrieve_distinct_keys('editor')
111111 min_year, max_year = determine_project_year_range(db, 'new_wikipedian')
112112
@@ -118,11 +118,12 @@
119119 var = dataset.Variable('count', time_unit, lock, obs_proxy, **kwargs)
120120
121121 try:
122 - print 'Preloading data...'
 122+ print 'Determinging whether plugin requires preloaded data...'
123123 preloader = getattr(plugin, 'preload')
124124 data = preloader(rts)
 125+ print 'Finished preloading data...'
125126 except Exception, error:
126 - print error
 127+ print Exception, error
127128 data = None
128129 finally:
129130 print 'Finished preloading data.'
@@ -131,7 +132,7 @@
132133 for editor in editors:
133134 tasks.put(analytics.Task(plugin, editor))
134135
135 - consumers = [analytics.Analyzer(rts, tasks, result, var, data) for
 136+ analyzers = [analytics.Analyzer(rts, tasks, result, var, data) for
136137 x in xrange(rts.number_of_processes)]
137138
138139
@@ -139,12 +140,11 @@
140141 tasks.put(None)
141142
142143 pbar = progressbar.ProgressBar(maxval=len(editors)).start()
143 - for w in consumers:
144 - w.start()
 144+ for analyzer in analyzers:
 145+ analyzer.start()
145146
146147
147148 ppills = rts.number_of_processes
148 - vars = []
149149 while True:
150150 while ppills > 0:
151151 try: