Skip to content

Commit

Permalink
Use optparse.OptionParser for my two command line configuration optio…
Browse files Browse the repository at this point in the history
…ns; prints better help/usage.
  • Loading branch information
TimothyFitz committed Jul 12, 2012
1 parent d78d260 commit 9668874
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions zdd/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import signal
import os
import time
from optparse import OptionParser
from ConfigParser import SafeConfigParser, Error as ConfigParserError

SERVICE_PREFIX = "service:"
Expand Down Expand Up @@ -198,9 +199,6 @@ def deploy(config_file):
print "Starting new", service.name
service.start()


nginx = Nginx(config)

# Wait for new services to spin up, and save their pids
replacements = {}
for service in services:
Expand All @@ -212,9 +210,9 @@ def deploy(config_file):
print "%s succesfully started, process %s listening on port %s." % (service.name, rs.pid, rs.port)

replacements[service.name] = str(rs.port)

write_int_file(service.current_pid_filename, rs.pid)

nginx = Nginx(config)
nginx.render_config(replacements)
nginx.reconfig()

Expand All @@ -230,21 +228,35 @@ def deploy(config_file):
print "Stopping previous instance of %s, process %s." % (service.name, service.previous_pid)
service.stop(service.previous_pid)


def cli_deploy(argv):
def usage():
print >> sys.stderr, "Usage: deploy.py [config file]"
sys.exit(1)

if len(argv) == 1:
conf_file = settings.DEFAULT_CONF_FILE
elif len(argv) == 2:
conf_file = argv[1]
else:
usage()

if not os.path.exists(conf_file):
print >> sys.stderr, "%s not found." % conf_file
usage()

deploy(conf_file)
parser = OptionParser()

parser.add_option(
"-c",
"--conf",
dest="deploy_conf",
help="FILENAME of zdd configuration. [default %default]",
default="deploy.conf",
metavar="FILENAME",
)

parser.add_option(
"-v",
"--verbose",
dest="verbose",
action="store_true",
default=False,
help="Enable verbose logging of the actions zdd takes.",
)

options, args = parser.parse_args(argv)

settings.VERBOSE = options.verbose

if not os.path.exists(options.deploy_conf):
print "ERROR: Unable to read zdd configuration file: %s" % options.deploy_conf
print
parser.print_help()
parser.exit()

deploy(options.deploy_conf)

0 comments on commit 9668874

Please sign in to comment.