public inbox for cluster-cvs@sourceware.org help / color / mirror / Atom feed
From: "Marek Grác" <marx@fedoraproject.org> To: cluster-cvs-relay@redhat.com Subject: cluster: RHEL55 - fencing: #519670 - Support long options from command line Date: Fri, 28 Aug 2009 16:13:00 -0000 [thread overview] Message-ID: <20090828161251.08C23120285@lists.fedorahosted.org> (raw) Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=d4de56c4c8f6d91a98fbb80e9eed8aebc4a8edf9 Commit: d4de56c4c8f6d91a98fbb80e9eed8aebc4a8edf9 Parent: 66767ee1c9e6d2d9f4cba0b4b5c1fd212222838d Author: Marek 'marx' Grac <mgrac@redhat.com> AuthorDate: Fri Aug 28 17:28:34 2009 +0200 Committer: Marek 'marx' Grac <mgrac@redhat.com> CommitterDate: Fri Aug 28 17:28:34 2009 +0200 fencing: #519670 - Support long options from command line --- fence/agents/lib/fencing.py.py | 82 +++++++++++++++++++++++++++++----------- 1 files changed, 60 insertions(+), 22 deletions(-) diff --git a/fence/agents/lib/fencing.py.py b/fence/agents/lib/fencing.py.py index 809c2e2..f449037 100644 --- a/fence/agents/lib/fencing.py.py +++ b/fence/agents/lib/fencing.py.py @@ -39,23 +39,27 @@ SSL_PATH = "/usr/lib/fence/telnet_ssl" all_opt = { "help" : { "getopt" : "h", - "help" : "-h Display this help and exit", + "longopt" : "help", + "help" : "-h, --help Display this help and exit", "order" : 54 }, "version" : { "getopt" : "V", - "help" : "-V Output version information and exit", + "longopt" : "version", + "help" : "-V, --version Output version information and exit", "order" : 53 }, "quiet" : { "getopt" : "q", - "help" : "-q Quiet mode", + "help" : "", "order" : 50 }, "verbose" : { "getopt" : "v", - "help" : "-v Verbose mode", + "longopt" : "verbose", + "help" : "-v, --verbose Verbose mode", "order" : 51 }, "debug" : { "getopt" : "D:", - "help" : "-D <debugfile> Debugging to output file", + "longopt" : "debug-file", + "help" : "-D, --debug-file=<debugfile> Debugging to output file", "order" : 52 }, "agent" : { "getopt" : "", @@ -63,15 +67,18 @@ all_opt = { "order" : 1 }, "action" : { "getopt" : "o:", - "help" : "-o <action> Action: status, reboot (default), off or on", + "longopt" : "action", + "help" : "-o, --action=<action> Action: status, reboot (default), off or on", "order" : 1 }, "ipaddr" : { "getopt" : "a:", - "help" : "-a <ip> IP address or hostname of fencing device", + "longopt" : "ip", + "help" : "-a, --ip=<ip> IP address or hostname of fencing device", "order" : 1 }, "login" : { "getopt" : "l:", - "help" : "-l <name> Login name", + "longopt" : "username", + "help" : "-l, --username=<name> Login name", "order" : 1 }, "no_login" : { "getopt" : "", @@ -83,23 +90,28 @@ all_opt = { "order" : 1 }, "passwd" : { "getopt" : "p:", - "help" : "-p <password> Login password or passphrase", + "longopt" : "password", + "help" : "-p, --password=<password> Login password or passphrase", "order" : 1 }, "passwd_script" : { "getopt" : "S:", - "help" : "-S <script> Script to run to retrieve password", + "longopt" : "password-script=", + "help" : "-S, --password-script=<script> Script to run to retrieve password", "order" : 1 }, "identity_file" : { "getopt" : "k:", - "help" : "-k <filename> Identity file (private key) for ssh ", + "longopt" : "identity-file", + "help" : "-k, --identity-file=<filename> Identity file (private key) for ssh ", "order" : 1 }, "module_name" : { "getopt" : "m:", - "help" : "-m <module> DRAC/MC module name", + "longopt" : "module-name", + "help" : "-m, --module-name=<module> DRAC/MC module name", "order" : 1 }, "drac_version" : { "getopt" : "d:", - "help" : "-d <version> Force DRAC version to use", + "longopt" : "drac-version", + "help" : "-d, --drac-version=<version> Force DRAC version to use", "order" : 1 }, "hmc_version" : { "getopt" : "H:", @@ -108,35 +120,42 @@ all_opt = { "order" : 1 }, "ribcl" : { "getopt" : "r:", - "help" : "-r <version> Force ribcl version to use", + "longopt" : "ribcl-version", + "help" : "-r, --ribcl-version=<version> Force ribcl version to use", "order" : 1 }, "cmd_prompt" : { "getopt" : "c:", - "help" : "-c <prompt> Force command prompt", + "longopt" : "command-prompt", + "help" : "-c, --command-prompt=<prompt> Force command prompt", "order" : 1 }, "secure" : { "getopt" : "x", - "help" : "-x Use ssh connection", + "longopt" : "ssh", + "help" : "-x, --ssh Use ssh connection", "order" : 1 }, "ssl" : { "getopt" : "z", - "help" : "-z Use ssl connection", + "longopt" : "ssl", + "help" : "-z, --ssl Use ssl connection", "order" : 1 }, "port" : { "getopt" : "n:", - "help" : "-n <id> Physical plug number on device or name of virtual machine", + "longopt" : "plug", + "help" : "-n, --plug=<id> Physical plug number on device or\n" + + " name of virtual machine", "order" : 1 }, "switch" : { "getopt" : "s:", - "help" : "-s <id> Physical switch number on device", + "longopt" : "switch", + "help" : "-s, --switch=<id> Physical switch number on device", "order" : 1 }, "partition" : { "getopt" : "n:", - "help" : "-n <id> Name of the partition", + "help" : "-n <id> Name of the partition", "order" : 1 }, "managed" : { "getopt" : "s:", - "help" : "-s <id> Name of the managed system", + "help" : "-s <id> Name of the managed system", "order" : 1 }, "test" : { "getopt" : "T", @@ -259,21 +278,40 @@ def process_input(avail_opt): ## Prepare list of options for getopt ##### getopt_string = "" + longopt_list = [ ] for k in avail_opt: if all_opt.has_key(k): getopt_string += all_opt[k]["getopt"] else: fail_usage("Parse error: unknown option '"+k+"'") + if all_opt.has_key(k) and all_opt[k].has_key("longopt"): + if all_opt[k]["getopt"].endswith(":"): + longopt_list.append(all_opt[k]["longopt"] + "=") + else: + longopt_list.append(all_opt[k]["longopt"]) + ## ## Read options from command line or standard input ##### if len(sys.argv) > 1: try: - opt, args = getopt.gnu_getopt(sys.argv[1:], getopt_string) + opt, args = getopt.gnu_getopt(sys.argv[1:], getopt_string, longopt_list) except getopt.GetoptError, error: fail_usage("Parse error: " + error.msg) + ## Transform longopt to short one which are used in fencing agents + ##### + old_opt = opt + opt = { } + for o in dict(old_opt).keys(): + if o.startswith("--"): + for x in all_opt.keys(): + if all_opt[x].has_key("longopt") and "--" + all_opt[x]["longopt"] == o: + opt["-" + all_opt[x]["getopt"].rstrip(":")] = dict(old_opt)[o] + else: + opt[o] = dict(old_opt)[o] + ## Compatibility Layer ##### z = dict(opt)
reply other threads:[~2009-08-28 16:13 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20090828161251.08C23120285@lists.fedorahosted.org \ --to=marx@fedoraproject.org \ --cc=cluster-cvs-relay@redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).