Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.apo.nmsu.edu/Telescopes/TCC/html/help_8py_source.html
Дата изменения: Tue Sep 15 02:25:37 2015
Дата индексирования: Sun Apr 10 00:17:38 2016
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п п п п п п п п п п п
lsst.tcc: python/tcc/cmd/help.py Source File
lsst.tcc  1.2.2-3-g89ecb63
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
help.py
Go to the documentation of this file.
1 from __future__ import division, absolute_import
2 
3 from RO.StringUtil import quoteStr
4 from RO.Alg import MatchList
5 from twistedActor import CommandError
6 
7 __all = ["help"]
8 
9 _CmdMatchList = None
10 
11 def getCmdMatchList(cmdParser):
12  """Return an RO.Alg.MatchList with all command names
13 
14  Uses an internal cache, so only computes once
15  """
16  global _CmdMatchList
17  if _CmdMatchList is None:
18  cmdNameList = cmdParser.cmdDefDict.keys()
19  _CmdMatchList = MatchList(
20  valueList = cmdNameList,
21  abbrevOK = True,
22  ignoreCase = True,
23  )
24  return _CmdMatchList
25 
26 def getSubCmdMatchList(cmdDef):
27  """Return a sub command matchList and dict of sub-command name: sub-command definition
28  """
29  try:
30  subCmdList = cmdDef.subCmdList
31  except AttributeError:
32  raise CommandError("The command %r has no sub-commands" % (cmdDef.name,))
33  subCmdDict = dict((subcmd.subCommandName.lower(), subcmd) for subcmd in subCmdList)
34  return MatchList(
35  valueList = subCmdDict.keys(),
36  abbrevOK = True,
37  ignoreCase = True,
38  ), subCmdDict
39 
40 def help(tccActor, cmd):
41  """Print help
42 
43  Use help cmdName for full info on the specified command
44  Use help/full for full info on all commands
45  """
46  cmdName = None
47  subCmdName = None
48  subCmdDef = None
49  if cmd.parsedCmd.paramDict['command'].valueList:
50  cmdName = cmd.parsedCmd.paramDict['command'].valueList[0]
51  cmdMatchList = getCmdMatchList(tccActor.cmdParser)
52  try:
53  fullCmdName = cmdMatchList.getUniqueMatch(cmdName)
54  except ValueError as e:
55  raise CommandError(e)
56  cmdDef = tccActor.cmdParser.cmdDefDict[fullCmdName]
57  if cmd.parsedCmd.paramDict['subcommand'].valueList:
58  subCmdName = cmd.parsedCmd.paramDict['subcommand'].valueList[0]
59  subCmdMatchList, subCmdDict = getSubCmdMatchList(cmdDef)
60 
61  # discover the index in subCommandList for which to print help
62  try:
63  fullSubCmdName = subCmdMatchList.getUniqueMatch(subCmdName)
64  except ValueError as e:
65  raise CommandError(e)
66  else:
67  subCmdDef = subCmdDict[fullSubCmdName]
68  if cmdName is not None:
69  # print full help for one command
70  if subCmdDef is not None:
71  dataList = subCmdDef.getFullHelp()
72  else:
73  dataList = cmdDef.getFullHelp()
74  for outStr in dataList:
75  for line in outStr.split("\n"):
76  tccActor.writeToOneUser("i", "Text=%s" % (quoteStr(line),), cmd=cmd)
77  return
78 
79  # print help for all commands
80  cmdList = sorted(tccActor.cmdParser.cmdDefDict.keys())
81  isFull = cmd.parsedCmd.qualDict["full"].boolValue
82  if isFull:
83  # print full help for all commands
84  for cmdName in cmdList:
85  cmdDef = tccActor.cmdParser.cmdDefDict[cmdName]
86  dataList = cmdDef.getFullHelp()
87  for outStr in dataList:
88  # split on newlines
89  for line in outStr.split("\n"):
90  tccActor.writeToOneUser("i", "Text=%s" % (quoteStr(line),), cmd=cmd)
91  tccActor.writeToOneUser("i", "", cmd=cmd)
92  else:
93  # print brief help for all commands
94  for cmdName in cmdList:
95  cmdDef = tccActor.cmdParser.cmdDefDict[cmdName]
96  dataList = cmdDef.getBriefHelp()
97  for outStr in dataList:
98  for line in outStr.split("\n"):
99  tccActor.writeToOneUser("i", "Text=%s" % (quoteStr(line),), cmd=cmd)
100  tccActor.writeToOneUser("i", "", cmd=cmd)
def getCmdMatchList
Definition: help.py:11
def getSubCmdMatchList
Definition: help.py:26
def help
Definition: help.py:40