aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVG <vg@devys.org>2017-05-09 18:48:44 +0200
committerVG <vg@devys.org>2017-05-09 18:48:44 +0200
commit0cbddfab73b55bdfad07991663a56c84fea026e3 (patch)
treed789a9ffdb99901e243f84155487f8a836b73ce2
parentcb73d949f755759d20a31415ebe9218f4f66c66f (diff)
downloadscripts-0cbddfab73b55bdfad07991663a56c84fea026e3.tar.gz
scripts-0cbddfab73b55bdfad07991663a56c84fea026e3.tar.bz2
scripts-0cbddfab73b55bdfad07991663a56c84fea026e3.zip
fix pylint3 reported errors
-rwxr-xr-xscripts/fancy-sleep69
1 files changed, 42 insertions, 27 deletions
diff --git a/scripts/fancy-sleep b/scripts/fancy-sleep
index 76cb04c..76e24b0 100755
--- a/scripts/fancy-sleep
+++ b/scripts/fancy-sleep
@@ -24,83 +24,80 @@ import re
import docopt
-_determine_delta_pattern = None
-
-
# to avoid accidental trailing spaces removal, use another character and
# replace.
-numbers = [i.replace('.', ' ') for i in (
-"""\
+NUMBERS = [i.replace('.', ' ') for i in (
+ """\
██████
██ ██
██ ██
██ ██
██████
""",
-"""\
+ """\
██
██
██
██
██
""",
-"""\
+ """\
██████
██
██████
██....
██████
""",
-"""\
+ """\
██████
██
██████
██
██████
""",
-"""\
+ """\
██ ██
██ ██
██████
██
██
""",
-"""\
+ """\
██████
██....
██████
██
██████
""",
-"""\
+ """\
██████
██....
██████
██ ██
██████
""",
-"""\
+ """\
██████
██
██
██
██
""",
-"""\
+ """\
██████
██ ██
██████
██ ██
██████
""",
-"""\
+ """\
██████
██ ██
██████
██
██████
""",
-"""\
+ """\
.
██.
.
@@ -111,14 +108,15 @@ numbers = [i.replace('.', ' ') for i in (
def print_translated(string):
+ 'print 09:30 style time to big:numbers'
translated = []
for character in string:
index = 0
- if '0' <= character and character <= '9':
+ if character >= '0' and character <= '9':
index = ord(character) - ord('0')
elif character == ':':
index = 10
- translated.append(numbers[index])
+ translated.append(NUMBERS[index])
display_lines = ['', '', '', '', '', '']
for index in range(5):
for number in translated:
@@ -128,6 +126,7 @@ def print_translated(string):
def determine_delta(elements,
time_pattern=re.compile(r'^(\d+)([dhms]?)$')):
+ 'return a cumulative datetime.timedelta from elements list of strings'
default = datetime.datetime.strptime('0', '%S')
timedelta = datetime.timedelta()
for element in elements:
@@ -162,18 +161,30 @@ def determine_delta(elements,
def determine_delta_tests():
- assert(determine_delta('11'.split()) == datetime.timedelta(seconds=11))
- assert(determine_delta('11s'.split()) == datetime.timedelta(seconds=11))
- assert(determine_delta('11h 47m'.split()) == datetime.timedelta(hours=11, minutes=47))
- assert(determine_delta('11h 47'.split()) == datetime.timedelta(hours=11, seconds=47))
- assert(determine_delta('11h 47m 09'.split()) == datetime.timedelta(hours=11, minutes=47, seconds=9))
- assert(determine_delta('09:53'.split()) == datetime.timedelta(hours=9, minutes=53))
- assert(determine_delta('8:2 9'.split()) == datetime.timedelta(hours=8, minutes=2, seconds=9))
- assert(determine_delta('8d 5:32 6s'.split()) == datetime.timedelta(days=8, hours=5, minutes=32, seconds=6))
+ 'test determine_delta function'
+ assert determine_delta('11'.split()) \
+ == datetime.timedelta(seconds=11)
+ assert determine_delta('11s'.split()) \
+ == datetime.timedelta(seconds=11)
+ assert determine_delta('11h 47m'.split()) \
+ == datetime.timedelta(hours=11, minutes=47)
+ assert determine_delta('11h 47'.split()) \
+ == datetime.timedelta(hours=11, seconds=47)
+ assert determine_delta('11h 47m 09'.split()) \
+ == datetime.timedelta(hours=11, minutes=47, seconds=9)
+ assert determine_delta('09:53'.split()) \
+ == datetime.timedelta(hours=9, minutes=53)
+ assert determine_delta('8:2 9'.split()) \
+ == datetime.timedelta(hours=8, minutes=2, seconds=9)
+ assert determine_delta('8d 5:32 6s'.split()) \
+ == datetime.timedelta(days=8, hours=5, minutes=32, seconds=6)
+
+
-if __name__ == '__main__':
- 'run fancy-sleep code: args parsing, display and sleeping logic'
+
+def main():
+ 'function called only when script invoked directly on command line'
# FIXME: can be done automatically with nose for example ?
determine_delta_tests()
@@ -217,3 +228,7 @@ if __name__ == '__main__':
time.sleep(target_time.timestamp() - time.time())
except KeyboardInterrupt:
sys.exit(130)
+
+
+if __name__ == '__main__':
+ main()