From 979174a5685ae810327f98b04a8cf522c504f15c Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 14:11:31 +0200 Subject: [PATCH] integrate parser Signed-off-by: Nico Schottelius --- bin/cdist | 86 +++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 50 deletions(-) diff --git a/bin/cdist b/bin/cdist index 72e95e29..a9b400ca 100755 --- a/bin/cdist +++ b/bin/cdist @@ -20,13 +20,13 @@ # # -import sys -import subprocess # execute stuff -import os -import tempfile -import shutil +import argparse import logging - +import os +import subprocess +import shutil +import sys +import tempfile # Given paths from installation BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) @@ -37,6 +37,7 @@ MANIFEST_DIR = os.path.join(CONF_DIR, "manifest") REMOTE_BASE_DIR = "/var/lib/cdist" REMOTE_CONF_DIR = os.path.join(REMOTE_BASE_DIR, "conf") REMOTE_GLOBAL_EXPLORER_DIR = os.path.join(REMOTE_CONF_DIR, "explorer") +VERSION = "2.0.0" #class Context(object): @@ -64,7 +65,6 @@ log = logging.getLogger() class Cdist: """Cdist main class to hold arbitrary data""" - version="2.0.0" def __init__(self, hostname, initial_manifest=False): self.hostname = hostname @@ -195,47 +195,33 @@ class Cdist: if __name__ == "__main__": hostname=sys.argv[1] - for host in sys.argv[1:]: - c = Cdist(host) - c.deploy_to() - print(c.list_global_explorers()) - c.cleanup() + parser = argparse.ArgumentParser(description='cdist ' + VERSION) + parser.add_argument('host', nargs='+', help='one or more hosts to operate on') + parser.add_argument('-d', '--debug', help='set log level to debug', + action='store_true') + parser.add_argument('-i', '--initial-manifest', + help='path to a cdist manifest or - to read from stdin', + dest='manifest', required=True) + parser.add_argument('-p', '--parallel', + help='operate on multiple hosts in parallel', + action='store_true', dest='parallel') + parser.add_argument('-s', '--sequential', + help='operate on multiple hosts sequentially', + action='store_false', dest='parallel') + + args = parser.parse_args(sys.argv[1:]) + if args.debug: + logging.root.setLevel(logging.DEBUG) + + try: + print(args) + import cdist + sys.exit(cdist.main(args)) - -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import logging -# TODO: configure logging based on config and/or user given arguments -logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s') -log = logging.getLogger() - -import argparse -import sys - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Some helpfull blabla') - parser.add_argument('host', nargs='+', help='one or more hosts to operate on') - parser.add_argument('-i', '--initial-manifest', - help='path to a cdist manifest or - to read from stdin', - dest='manifest', required=True) - parser.add_argument('-p', '--parallel', - help='operate on multiple hosts in parallel', - action='store_true', dest='parallel') - parser.add_argument('-s', '--sequential', - help='operate on multiple hosts sequentially', - action='store_false', dest='parallel') - parser.add_argument('-d', '--debug', help='set log level to debug', - action='store_true') - - args = parser.parse_args(sys.argv[1:]) - if args.debug: - logging.root.setLevel(logging.DEBUG) - log.debug('Look ma, now whe\'re showing debug messages') - - try: - print(args) - #import cdist - #sys.exit(cdist.main(args)) - except KeyboardInterrupt: - sys.exit(0) + for host in sys.argv[1:]: + c = Cdist(host) + c.deploy_to() + print(c.list_global_explorers()) + c.cleanup() + except KeyboardInterrupt: + sys.exit(0)