Index: trunk/tools/editor_trends/utils/timer.py |
— | — | @@ -0,0 +1,66 @@ |
| 2 | +#!/usr/bin/python
|
| 3 | +# -*- coding: utf-8 -*-
|
| 4 | +'''
|
| 5 | +Copyright (C) 2010 by Diederik van Liere (dvanliere@gmail.com)
|
| 6 | +This program is free software; you can redistribute it and/or
|
| 7 | +modify it under the terms of the GNU General Public License version 2
|
| 8 | +as published by the Free Software Foundation.
|
| 9 | +This program is distributed in the hope that it will be useful,
|
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
| 12 | +See the GNU General Public License for more details, at
|
| 13 | +http://www.fsf.org/licenses/gpl.html
|
| 14 | +'''
|
| 15 | +
|
| 16 | +__author__ = '''\n'''.join(['Diederik van Liere (dvanliere@gmail.com)', ])
|
| 17 | +__author__email = 'dvanliere at gmail dot com'
|
| 18 | +__date__ = '2011-01-14'
|
| 19 | +__version__ = '0.1'
|
| 20 | +
|
| 21 | +import datetime
|
| 22 | +
|
| 23 | +class Timer(object):
|
| 24 | + def __init__(self):
|
| 25 | + self.t0 = datetime.datetime.now()
|
| 26 | +
|
| 27 | + def __str__(self):
|
| 28 | + return 'Timer started: %s' % self.t0
|
| 29 | +
|
| 30 | + def stop(self):
|
| 31 | + self.t1 = datetime.datetime.now()
|
| 32 | +
|
| 33 | + def elapsed(self):
|
| 34 | + self.stop()
|
| 35 | + print 'Processing time: %s' % (self.t1 - self.t0)
|
| 36 | +
|
| 37 | +def humanize_time_difference(seconds_elapsed):
|
| 38 | + """
|
| 39 | + Returns a humanized string representing time difference.
|
| 40 | + It will only output the first two time units, so days and
|
| 41 | + hours, or hours and minutes, except when there are only
|
| 42 | + seconds.
|
| 43 | + """
|
| 44 | + seconds_elapsed = int(seconds_elapsed)
|
| 45 | + humanized_time = {}
|
| 46 | + time_units = [('days', 86400), ('hours', 3600), ('minutes', 60), ('seconds', 1)]
|
| 47 | + for time, unit in time_units:
|
| 48 | + dt = seconds_elapsed / unit
|
| 49 | + if dt > 0:
|
| 50 | + humanized_time[time] = dt
|
| 51 | + seconds_elapsed = seconds_elapsed - (unit * humanized_time[time])
|
| 52 | + #humanized_time['seconds'] = seconds_elapsed
|
| 53 | +
|
| 54 | + x = 0
|
| 55 | + if len(humanized_time) == 1:
|
| 56 | + return '%s %s' % (humanized_time['seconds'], 'seconds')
|
| 57 | + else:
|
| 58 | + obs = []
|
| 59 | + for time, unit in time_units:
|
| 60 | + if time in humanized_time:
|
| 61 | + unit = humanized_time.get(time, None)
|
| 62 | + if humanized_time[time] == 1:
|
| 63 | + time = time[:-1]
|
| 64 | + obs.append((time, unit))
|
| 65 | + x += 1
|
| 66 | + if x == 2:
|
| 67 | + return '%s %s and %s %s' % (obs[0][1], obs[0][0], obs[1][1], obs[1][0])
|
Index: trunk/tools/editor_trends/utils/utils.py |
— | — | @@ -451,39 +451,6 @@ |
452 | 452 | pbar.update(pbar.currval + x) |
453 | 453 | |
454 | 454 | |
455 | | -def humanize_time_difference(seconds_elapsed): |
456 | | - """ |
457 | | - Returns a humanized string representing time difference. |
458 | | - It will only output the first two time units, so days and |
459 | | - hours, or hours and minutes, except when there are only |
460 | | - seconds. |
461 | | - """ |
462 | | - seconds_elapsed = int(seconds_elapsed) |
463 | | - humanized_time = {} |
464 | | - time_units = [('days', 86400), ('hours', 3600), ('minutes', 60), ('seconds', 1)] |
465 | | - for time, unit in time_units: |
466 | | - dt = seconds_elapsed / unit |
467 | | - if dt > 0: |
468 | | - humanized_time[time] = dt |
469 | | - seconds_elapsed = seconds_elapsed - (unit * humanized_time[time]) |
470 | | - #humanized_time['seconds'] = seconds_elapsed |
471 | | - |
472 | | - x = 0 |
473 | | - if len(humanized_time) == 1: |
474 | | - return '%s %s' % (humanized_time['seconds'], 'seconds') |
475 | | - else: |
476 | | - obs = [] |
477 | | - for time, unit in time_units: |
478 | | - if time in humanized_time: |
479 | | - unit = humanized_time.get(time, None) |
480 | | - if humanized_time[time] == 1: |
481 | | - time = time[:-1] |
482 | | - obs.append((time, unit)) |
483 | | - x += 1 |
484 | | - if x == 2: |
485 | | - return '%s %s and %s %s' % (obs[0][1], obs[0][0], obs[1][1], obs[1][0]) |
486 | | - |
487 | | - |
488 | 455 | if __name__ == '__main__': |
489 | 456 | tool = settings.determine_ziptool() |
490 | 457 | path = settings.detect_installed_program(tool) |