File indexing completed on 2024-11-25 02:29:52
0001 """Word completion for CMS Software.
0002 Based on rlcompleter from Python 2.4.1. Included additional namespace for not loaded modules
0003 Please read license in your lcg external python version
0004
0005 benedikt.hegner@cern.ch
0006
0007 """
0008
0009
0010 import readline
0011 import rlcompleter
0012 import builtins
0013 import __main__
0014
0015 __all__ = ["CMSCompleter"]
0016
0017 class CMSCompleter(rlcompleter.Completer):
0018 def __init__(self, namespace = None):
0019
0020 if namespace and not isinstance(namespace, dict):
0021 raise TypeError('namespace must be a dictionary')
0022
0023
0024
0025
0026 if namespace is None:
0027 self.use_main_ns = 1
0028 else:
0029 self.use_main_ns = 0
0030 self.namespace = namespace
0031 try:
0032
0033 from . import namespaceDict
0034 self.cmsnamespace = namespaceDict.getNamespaceDict()
0035 except:
0036 print('Could not load CMS namespace')
0037
0038
0039 def global_matches(self, text):
0040 """Compute matches when text is a simple name.
0041
0042 Return a list of all keywords, built-in functions and names currently
0043 defined in self.namespace and self.cmsnamespace that match.
0044
0045 """
0046 import keyword
0047 matches = []
0048 n = len(text)
0049 for list in [keyword.kwlist,
0050 builtins.__dict__,
0051 self.cmsnamespace]:
0052 for word in list:
0053 if word[:n] == text and word != "__builtins__":
0054 matches.append(word)
0055 return matches
0056
0057
0058 readline.set_completer(CMSCompleter().complete)
0059 readline.parse_and_bind('tab: complete')
0060
0061