# HG changeset patch # User Jeff Hammel # Date 1428951840 25200 # Node ID 8a6ee9df8ae52f78c82df5d82d09a001c657855f # Parent 350e4298e11652364ef48c732d12e5f34fca5416 moving towards service restart diff -r 350e4298e116 -r 8a6ee9df8ae5 supervisoradmin/add.py --- a/supervisoradmin/add.py Mon Feb 09 13:11:09 2015 -0800 +++ b/supervisoradmin/add.py Mon Apr 13 12:04:00 2015 -0700 @@ -15,7 +15,7 @@ # module globals __all__ = ['main', 'SupervisorAdminParser'] -SUPERVISOR_CONF_DIR = '/etc/supervisor/conf.d' +SUPERVISOR_CONF = '/etc/supervisor/conf.d' template = """[program:{name}] command={command} @@ -27,6 +27,9 @@ user={user} """ +def basename(filename): + return os.path.splitext(os.path.basename(filename))[0] + class SupervisorAdminParser(argparse.ArgumentParser): """CLI option parser""" def __init__(self, **kwargs): @@ -39,6 +42,11 @@ help="name of program; by default taken from command") self.add_argument('-u', '--user', dest='user', default='ubuntu', help="run program as this user [DEFAULT: %(default)s]") + self.add_argument('-o', '--output', dest='output', + type=argparse.FileType('w'), + nargs='?', + const=sys.stdout, + help="output configuration and exit [DEFAULT: %(default)s]") self.options = None def parse_args(self, *args, **kw): @@ -63,7 +71,10 @@ parser.error("Please supply a command") # name - name = options.name or os.path.basename(command[0]) + name = options.name or basename(command[0]) + + # output configuration file + output = options.output or os.path.join(SUPERVISOR_CONF, '{}.conf'.format(name)) print (template.format(name=name, user=options.user, @@ -71,5 +82,3 @@ if __name__ == '__main__': main() - -