diff options
author | Florent Le Coz <louiz@louiz.org> | 2011-11-16 02:09:55 +0100 |
---|---|---|
committer | Florent Le Coz <louiz@louiz.org> | 2011-11-16 02:09:55 +0100 |
commit | efeb0ad58e04104021897c401c73c6e5ff2831d0 (patch) | |
tree | 4162b0f24c2fc6632cc1d6ab0435ac3eb90430e9 /src/common.py | |
parent | d789a59f0c1d849e3074c890913882f09b048cd2 (diff) | |
parent | 034a2bde2c571645c7319f89ef63ccc0451bcb0e (diff) | |
download | poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.gz poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.bz2 poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.tar.xz poezio-efeb0ad58e04104021897c401c73c6e5ff2831d0.zip |
Merge branch 'master' of http://git.louiz.org/poezio
Diffstat (limited to 'src/common.py')
-rw-r--r-- | src/common.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common.py b/src/common.py index 35fd08da..fdad77a9 100644 --- a/src/common.py +++ b/src/common.py @@ -16,6 +16,7 @@ import mimetypes import hashlib import subprocess import time +import string import shlex from config import config @@ -191,3 +192,35 @@ def replace_key_with_bound(key): return config.get(key, key, 'bindings') else: return key + +def parse_str_to_secs(duration=''): + values = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400} + result = 0 + tmp = '0' + for char in duration: + if char in string.digits: + tmp += char + elif char in values: + tmp_i = int(tmp) + result += tmp_i * values[char] + tmp = '0' + else: + result += int(tmp) + if tmp != '0': + result += int(tmp) + return result + +def parse_secs_to_str(duration=0): + secs, mins, hours, days = 0, 0, 0, 0 + result = '' + secs = duration % 60 + mins = (duration % 3600) // 60 + hours = (duration % 86400) // 3600 + days = duration // 86400 + + result += '%sd' % days if days else '' + result += '%sh' % hours if hours else '' + result += '%sm' % mins if mins else '' + result += '%ss' % secs if secs else '' + return result + |