http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82765
Revision: 82765
Author: diederik
Date: 2011-02-24 23:37:31 +0000 (Thu, 24 Feb 2011)
Log Message:
-----------
minor improvements
Modified Paths:
--------------
trunk/tools/editor_trends/utils/file_utils.py
trunk/tools/editor_trends/utils/timer.py
Modified: trunk/tools/editor_trends/utils/file_utils.py
===================================================================
--- trunk/tools/editor_trends/utils/file_utils.py 2011-02-24 23:37:03 UTC
(rev 82764)
+++ trunk/tools/editor_trends/utils/file_utils.py 2011-02-24 23:37:31 UTC
(rev 82765)
@@ -133,7 +133,7 @@
return 'wb'
-def write_list_to_csv(data, fh, recursive=False, newline=True, format='long'):
+def write_list_to_csv(data, fh, recursive=False, newline=True, format='long',
lock=None):
'''
@data is a list which can contain other lists that will be written as a
single line to a textfile
@@ -142,12 +142,14 @@
The calling function is responsible for:
1) closing the filehandle
'''
- lock = multiprocessing.Lock()
+
+
tab = False
wrote_newline = None
if recursive:
recursive = False
- lock.acquire()
+ if lock:
+ lock.acquire()
for x, d in enumerate(data):
if tab:
fh.write('\t')
@@ -168,7 +170,8 @@
return True
if newline:
fh.write('\n')
- lock.release()
+ if lock:
+ lock.release()
def write_dict_to_csv(data, fh, keys, write_key=True, format='long'):
assert format == 'long' or format == 'wide', 'Format should either be long
or wide.'
Modified: trunk/tools/editor_trends/utils/timer.py
===================================================================
--- trunk/tools/editor_trends/utils/timer.py 2011-02-24 23:37:03 UTC (rev
82764)
+++ trunk/tools/editor_trends/utils/timer.py 2011-02-24 23:37:31 UTC (rev
82765)
@@ -29,27 +29,30 @@
def stop(self):
self.t1 = datetime.datetime.now()
- def elapsed(self):
+ def elapsed(self, human=False):
self.stop()
- print 'Processing time: %s' % (self.t1 - self.t0)
+ seconds_elapsed = self.t1 - self.t0
+ if human:
+ seconds_elapsed = humanize_time_difference(seconds_elapsed)
+ print '\nProcessing time: %s' % seconds_elapsed
def humanize_time_difference(seconds_elapsed):
- """
+ '''
Returns a humanized string representing time difference.
It will only output the first two time units, so days and
hours, or hours and minutes, except when there are only
seconds.
- """
+ '''
seconds_elapsed = int(seconds_elapsed)
humanized_time = {}
- time_units = [('days', 86400), ('hours', 3600), ('minutes', 60),
('seconds', 1)]
+ time_units = [('days', 86400), ('hours', 3600),
+ ('minutes', 60), ('seconds', 1)]
for time, unit in time_units:
dt = seconds_elapsed / unit
if dt > 0:
humanized_time[time] = dt
seconds_elapsed = seconds_elapsed - (unit * humanized_time[time])
- #humanized_time['seconds'] = seconds_elapsed
x = 0
if len(humanized_time) == 1:
@@ -64,4 +67,5 @@
obs.append((time, unit))
x += 1
if x == 2:
- return '%s %s and %s %s' % (obs[0][1], obs[0][0],
obs[1][1], obs[1][0])
+ return '%s %s and %s %s' % (obs[0][1], obs[0][0],
+ obs[1][1], obs[1][0])
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs