2014-05-04 17:26:43 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vi:si:et:sw=4:sts=4:ts=4
|
2014-08-09 21:39:10 +00:00
|
|
|
from __future__ import division, print_function
|
2014-05-04 17:26:43 +00:00
|
|
|
|
|
|
|
import sys
|
|
|
|
|
2014-08-09 17:06:53 +00:00
|
|
|
import api
|
|
|
|
import commands
|
2014-05-04 17:26:43 +00:00
|
|
|
import server
|
|
|
|
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == 'server':
|
|
|
|
server.run()
|
|
|
|
else:
|
2014-08-09 17:06:53 +00:00
|
|
|
names = [c[8:] for c in dir(commands) if c.startswith('command_')]
|
|
|
|
command = sys.argv[1] if len(sys.argv) > 1 else None
|
|
|
|
if command and command in names:
|
|
|
|
getattr(commands, "command_%s"%command)(sys.argv[1:])
|
|
|
|
else:
|
2014-08-09 21:39:10 +00:00
|
|
|
print("usage: ctl [action]")
|
2014-08-09 17:06:53 +00:00
|
|
|
indent = max([len(command) for command in names]) + 4
|
|
|
|
for command in sorted(names):
|
|
|
|
space = ' ' * (indent - len(command))
|
|
|
|
info = getattr(commands, "command_%s"%command).__doc__.split('\n')
|
|
|
|
info = [' %s%s' % (' ' * indent, i.strip()) for i in info]
|
|
|
|
info = '\n'.join(info).strip()
|
2014-08-09 21:39:10 +00:00
|
|
|
print(" %s%s%s" % (command, space, info))
|
2014-08-09 17:06:53 +00:00
|
|
|
sys.exit(1)
|