r82765 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82764‎ | r82765 | r82766 >
Date:23:37, 24 February 2011
Author:diederik
Status:deferred
Tags:
Comment:
minor improvements
Modified paths:
  • /trunk/tools/editor_trends/utils/file_utils.py (modified) (history)
  • /trunk/tools/editor_trends/utils/timer.py (modified) (history)

Diff [purge]

Index: trunk/tools/editor_trends/utils/file_utils.py
@@ -133,7 +133,7 @@
134134 return 'wb'
135135
136136
137 -def write_list_to_csv(data, fh, recursive=False, newline=True, format='long'):
 137+def write_list_to_csv(data, fh, recursive=False, newline=True, format='long', lock=None):
138138 '''
139139 @data is a list which can contain other lists that will be written as a
140140 single line to a textfile
@@ -142,12 +142,14 @@
143143 The calling function is responsible for:
144144 1) closing the filehandle
145145 '''
146 - lock = multiprocessing.Lock()
 146+
 147+
147148 tab = False
148149 wrote_newline = None
149150 if recursive:
150151 recursive = False
151 - lock.acquire()
 152+ if lock:
 153+ lock.acquire()
152154 for x, d in enumerate(data):
153155 if tab:
154156 fh.write('\t')
@@ -168,7 +170,8 @@
169171 return True
170172 if newline:
171173 fh.write('\n')
172 - lock.release()
 174+ if lock:
 175+ lock.release()
173176
174177 def write_dict_to_csv(data, fh, keys, write_key=True, format='long'):
175178 assert format == 'long' or format == 'wide', 'Format should either be long or wide.'
Index: trunk/tools/editor_trends/utils/timer.py
@@ -29,27 +29,30 @@
3030 def stop(self):
3131 self.t1 = datetime.datetime.now()
3232
33 - def elapsed(self):
 33+ def elapsed(self, human=False):
3434 self.stop()
35 - print 'Processing time: %s' % (self.t1 - self.t0)
 35+ seconds_elapsed = self.t1 - self.t0
 36+ if human:
 37+ seconds_elapsed = humanize_time_difference(seconds_elapsed)
 38+ print '\nProcessing time: %s' % seconds_elapsed
3639
3740
3841 def humanize_time_difference(seconds_elapsed):
39 - """
 42+ '''
4043 Returns a humanized string representing time difference.
4144 It will only output the first two time units, so days and
4245 hours, or hours and minutes, except when there are only
4346 seconds.
44 - """
 47+ '''
4548 seconds_elapsed = int(seconds_elapsed)
4649 humanized_time = {}
47 - time_units = [('days', 86400), ('hours', 3600), ('minutes', 60), ('seconds', 1)]
 50+ time_units = [('days', 86400), ('hours', 3600),
 51+ ('minutes', 60), ('seconds', 1)]
4852 for time, unit in time_units:
4953 dt = seconds_elapsed / unit
5054 if dt > 0:
5155 humanized_time[time] = dt
5256 seconds_elapsed = seconds_elapsed - (unit * humanized_time[time])
53 - #humanized_time['seconds'] = seconds_elapsed
5457
5558 x = 0
5659 if len(humanized_time) == 1:
@@ -64,4 +67,5 @@
6568 obs.append((time, unit))
6669 x += 1
6770 if x == 2:
68 - return '%s %s and %s %s' % (obs[0][1], obs[0][0], obs[1][1], obs[1][0])
 71+ return '%s %s and %s %s' % (obs[0][1], obs[0][0],
 72+ obs[1][1], obs[1][0])

Status & tagging log