According to memory this is a port of a shell script called pants that allows one to "start," "stop," "restart," and find the "status" of one's pants (the program itself). I am not sure what the silliness is about but must have found the idea interesting to rewrite in Python. This is committed for archival to be run under Python 2.5 or later versions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | # THIS IS A PORT OF ANOTHER PROGRAM
import sys, os
p, a = (sys.argv + [None])[:2]
def echo(string, newline=False):
sys.stdout.write(string + (newline and '\n' or ''))
def start():
echo("Putting on pants ...", True)
if os.stat(p).st_mode == 33206:
echo("one leg at a time.")
os.chmod(p, 256)
else:
echo("Looks like we've still got some old pants on. They'll do.")
def stop(newline=False):
echo("Taking off pants ...", newline)
os.chmod(p, 128)
def restart():
echo("Time for a change of pants.", True)
stop(True)
start()
def status():
if os.stat(p).st_mode == 33060:
echo("Pants are on.")
else:
echo("We're not wearing any pants.")
if a in ('start', 'stop', 'restart', 'status'):
globals()[a]()
else:
echo("Usage: %s {start|stop|restart|status}" % os.path.basename(p))
|
Documentation for usage is automatically printed as needed.