"Fossies" - the Fresh Open Source Software Archive

Member "unicore-ucc-8.0.2/extras/bash-completion/ucc_bash_completion_create.py" (18 May 2020, 1763 Bytes) of package /linux/misc/unicore-ucc-8.0.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "ucc_bash_completion_create.py" see the Fossies "Dox" file reference documentation.

    1 #!/usr/bin/env python
    2 
    3 from __future__ import with_statement
    4 from subprocess import Popen, PIPE, STDOUT
    5 
    6 TEMPLATE = "ucc_bash_completion.template"
    7 OUTPUT = "ucc_bash_completion.sh"
    8 UCC_CMD = "ucc"
    9 
   10 ######################################################################
   11 
   12 def find_commands():
   13     commands = []
   14     print "Running UCC to get the list of commands ... "
   15     p = Popen([UCC_CMD], stdout=PIPE, stderr=STDOUT)
   16     p.wait()
   17     for line in p.stdout.readlines():
   18         if not line.startswith(" "):
   19             continue
   20         else:
   21             commands.append(line.split()[0])
   22 
   23     return commands
   24 
   25 
   26 def find_options(command):
   27     options = []
   28     print "Getting options for %s" % command
   29     p = Popen([UCC_CMD, command, "-h"], stdout=PIPE, stderr=STDOUT)
   30     p.wait()
   31     for line in p.stdout.readlines():
   32         if not line.startswith(" -"):
   33             continue
   34         else:
   35             s = line.split()[0]
   36             options.append(s.split(",")[1])
   37 
   38     return options
   39 
   40 
   41 ######################################################################
   42 
   43 with open(TEMPLATE) as f:
   44     output = f.read()
   45     
   46 commands = sorted(find_commands())
   47 global_opts = find_options("system-info")
   48 case_body = ""
   49 
   50 
   51 for command in commands:
   52     if command == "wsrf":
   53         continue # This is a special case, it's in the template
   54 
   55     opts = find_options(command)
   56     opts = set(opts) - set(global_opts)
   57     s = '    %s)\n    opts="$global_opts %s"\n    ;;\n' % (command,
   58                                                            " ".join(opts))
   59     case_body += s
   60 
   61 
   62 output = output % {"commands": " ".join(commands),
   63                    "global_opts": " ".join(global_opts),
   64                    "case_body": case_body}
   65 
   66 
   67 with open(OUTPUT, "w") as f:
   68     f.write(output)