From: Thierry Parmentelat Date: Wed, 22 May 2013 13:42:26 +0000 (+0200) Subject: cosmetic changes here and there X-Git-Tag: sfa-2.1-26~10^2~18 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9ab83d66336252a2a394444ea8cf6cad81b15082;p=sfa.git cosmetic changes here and there --- diff --git a/sfa/client/sfi.py b/sfa/client/sfi.py index 5c106308..af219b3e 100644 --- a/sfa/client/sfi.py +++ b/sfa/client/sfi.py @@ -236,6 +236,7 @@ def register_command (args_string, example): def wrap(m): name=getattr(m,'__name__') doc=getattr(m,'__doc__',"-- missing doc --") + doc=doc.strip(" \t\n") commands_list.append(name) commands_dict[name]=(doc, args_string, example) @wraps(m) @@ -272,7 +273,9 @@ class Sfi: self.authority = None self.logger = sfi_logger self.logger.enable_console() + self.command=None + ### suitable if no reasonable command has been provided def print_commands_help (self, options): verbose=getattr(options,'verbose') format3="%18s %-15s %s" @@ -286,11 +289,23 @@ class Sfi: for (command, (doc, args_string, example)) in commands_dict.iteritems(): if verbose: print line - doc=doc.strip(" \t\n") doc=doc.replace("\n","\n"+35*' ') print format3%(command,args_string,doc) if verbose: self.create_command_parser(command).print_help() + + ### now if a known command was found we can be more verbose on that one + def print_help (self): + print "==================== Generic sfi usage" + self.sfi_parser.print_help() + (doc,_,example)=commands_dict[self.command] + print "\n==================== Purpose of %s"%self.command + print doc + print "\n==================== Specific usage for %s"%self.command + self.command_parser.print_help() + if example: + print "\n==================== %s example"%self.command + print example def create_command_parser(self, command): if command not in commands_dict: @@ -306,7 +321,7 @@ class Sfi: parser = OptionParser(add_help_option=False, usage="sfi [sfi_options] %s [cmd_options] %s" % (command, args_string)) - parser.add_option ("-h","--help",dest='command_help',action='store_true',default=False, + parser.add_option ("-h","--help",dest='help',action='store_true',default=False, help="Summary of one command usage") if command in ("add", "update"): @@ -440,23 +455,13 @@ use this if you mean an authority instead""") parser.add_option("-t", "--timeout", dest="timeout", default=None, help="Amout of time to wait before timing out the request") parser.add_option("-h", "--help", - action="store_true", dest="commands_help", default=False, + action="store_true", dest="help", default=False, help="one page summary on commands & exit") parser.disable_interspersed_args() return parser - def print_help (self): - print "==================== Generic sfi usage" - self.sfi_parser.print_help() - print "\n==================== Specific usage for %s"%self.command - self.command_parser.print_help() - (_,__,example)=commands_dict[self.command] - if example: - print "\n==================== %s example"%self.command - print example - # # Main: parse arguments and dispatch to command # @@ -470,7 +475,7 @@ use this if you mean an authority instead""") def main(self): self.sfi_parser = self.create_parser() (options, args) = self.sfi_parser.parse_args() - if options.commands_help: + if options.help: self.print_commands_help(options) sys.exit(1) self.options = options @@ -493,6 +498,9 @@ use this if you mean an authority instead""") self.command=command self.command_parser = self.create_command_parser(command) (command_options, command_args) = self.command_parser.parse_args(args[1:]) + if command_options.help: + self.print_help() + sys.exit(1) self.command_options = command_options self.read_config ()