Index: trunk/tools/editor_trends/utils/file_utils.py |
— | — | @@ -133,7 +133,7 @@ |
134 | 134 | return 'wb' |
135 | 135 | |
136 | 136 | |
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): |
138 | 138 | ''' |
139 | 139 | @data is a list which can contain other lists that will be written as a |
140 | 140 | single line to a textfile |
— | — | @@ -142,12 +142,14 @@ |
143 | 143 | The calling function is responsible for: |
144 | 144 | 1) closing the filehandle |
145 | 145 | ''' |
146 | | - lock = multiprocessing.Lock() |
| 146 | + |
| 147 | + |
147 | 148 | tab = False |
148 | 149 | wrote_newline = None |
149 | 150 | if recursive: |
150 | 151 | recursive = False |
151 | | - lock.acquire() |
| 152 | + if lock: |
| 153 | + lock.acquire() |
152 | 154 | for x, d in enumerate(data): |
153 | 155 | if tab: |
154 | 156 | fh.write('\t') |
— | — | @@ -168,7 +170,8 @@ |
169 | 171 | return True |
170 | 172 | if newline: |
171 | 173 | fh.write('\n') |
172 | | - lock.release() |
| 174 | + if lock: |
| 175 | + lock.release() |
173 | 176 | |
174 | 177 | def write_dict_to_csv(data, fh, keys, write_key=True, format='long'): |
175 | 178 | 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 @@ |
30 | 30 | def stop(self): |
31 | 31 | self.t1 = datetime.datetime.now() |
32 | 32 | |
33 | | - def elapsed(self): |
| 33 | + def elapsed(self, human=False): |
34 | 34 | 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 |
36 | 39 | |
37 | 40 | |
38 | 41 | def humanize_time_difference(seconds_elapsed): |
39 | | - """ |
| 42 | + ''' |
40 | 43 | Returns a humanized string representing time difference. |
41 | 44 | It will only output the first two time units, so days and |
42 | 45 | hours, or hours and minutes, except when there are only |
43 | 46 | seconds. |
44 | | - """ |
| 47 | + ''' |
45 | 48 | seconds_elapsed = int(seconds_elapsed) |
46 | 49 | 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)] |
48 | 52 | for time, unit in time_units: |
49 | 53 | dt = seconds_elapsed / unit |
50 | 54 | if dt > 0: |
51 | 55 | humanized_time[time] = dt |
52 | 56 | seconds_elapsed = seconds_elapsed - (unit * humanized_time[time]) |
53 | | - #humanized_time['seconds'] = seconds_elapsed |
54 | 57 | |
55 | 58 | x = 0 |
56 | 59 | if len(humanized_time) == 1: |
— | — | @@ -64,4 +67,5 @@ |
65 | 68 | obs.append((time, unit)) |
66 | 69 | x += 1 |
67 | 70 | 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]) |