metanohi-misc-subsites/subsites/lunchuman/manage

50 lines
1.1 KiB
Plaintext
Raw Normal View History

2012-02-28 11:37:03 +01:00
#!/usr/bin/env python3
import sys
import os
import pickle
_absfile = os.path.abspath(__file__)
_filedir = os.path.dirname(_absfile)
dfile = os.path.join(_filedir, '.dynamicsettings')
def write(data):
with open(dfile, 'wb') as f:
pickle.dump(data, f)
def touch(fname):
if os.path.exists(fname):
return os.utime(fname, None)
else:
with open(path, 'w'):
pass
def _traverse(xs):
for x in xs:
pass
def act(d):
try:
d[sys.argv[1]]()
except (IndexError, KeyError):
print('unknown command', file=sys.stderr)
print_help()
def print_help():
print('''
Run one of:
stop
start
restart
''')
if __name__ == '__main__':
act({
'stop': lambda: write({'status': 'stop'}),
'start': lambda: write({'status': 'running'}),
'restart': lambda: _traverse(
f() for f in (lambda: write({'status': 'running'}),
lambda: touch(dfile))),
'help': print_help, '-h': print_help, '--help': print_help
})