Revision: 887
http://assorted.svn.sourceforge.net/assorted/?rev=887&view=rev
Author: yangzhang
Date: 2008-07-13 11:47:55 -0700 (Sun, 13 Jul 2008)
Log Message:
-----------
added countdown
Added Paths:
-----------
shell-tools/trunk/src/countdown.py
Added: shell-tools/trunk/src/countdown.py
===================================================================
--- shell-tools/trunk/src/countdown.py (rev 0)
+++ shell-tools/trunk/src/countdown.py 2008-07-13 18:47:55 UTC (rev 887)
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+from commons.startup import command_name, run_main
+from time import sleep, time
+from sys import stdout
+
+def main( argv ):
+ start = time()
+
+ try:
+ arg = argv[1]
+ if False: pass
+ elif arg[-1] == 's': mult = 1
+ elif arg[-1] == 'm': mult = 60
+ elif arg[-1] == 'h': mult = 3600
+ elif arg[-1].isdigit(): mult = 1
+ else: raise Exception()
+ if arg[-1].isalpha(): arg = arg[:-1]
+ except: raise Exception( '%s <time>[h|m|s]' % command_name() )
+
+ t = int(arg) * mult
+ end = start + t
+ try:
+ while True:
+ now = time()
+ elap, rem = now - start, end - now
+ if now >= end: break
+ print '\r%dm%ds elapsed, %dm%ds remaining' % (elap/60, elap%60, rem/60, rem%60),
+ stdout.flush()
+ sleep(1)
+ except:
+ print
+
+run_main(handle_exceptions = True)
Property changes on: shell-tools/trunk/src/countdown.py
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|