CMS 3D CMS Logo

cmscompleter.py
Go to the documentation of this file.
1 """Word completion for CMS Software.
2 Based on rlcompleter from Python 2.4.1. Included additional namespace for not loaded modules
3 Please read license in your lcg external python version
4 
5 benedikt.hegner@cern.ch
6 
7 """
8 from __future__ import absolute_import
9 from __future__ import print_function
10 # TODO: sometimes results are doubled. clean global_matches list!
11 
12 import readline
13 import rlcompleter
14 from six import builtins
15 import __main__
16 
17 __all__ = ["CMSCompleter"]
18 
19 class CMSCompleter(rlcompleter.Completer):
20  def __init__(self, namespace = None):
21 
22  if namespace and not isinstance(namespace, dict):
23  raise TypeError('namespace must be a dictionary')
24 
25  # Don't bind to namespace quite yet, but flag whether the user wants a
26  # specific namespace or to use __main__.__dict__. This will allow us
27  # to bind to __main__.__dict__ at completion time, not now.
28  if namespace is None:
29  self.use_main_ns = 1
30  else:
31  self.use_main_ns = 0
32  self.namespace = namespace
33  try:
34  # loading cms namespace
35  from . import namespaceDict
36  self.cmsnamespace = namespaceDict.getNamespaceDict()
37  except:
38  print('Could not load CMS namespace')
39 
40 
41  def global_matches(self, text):
42  """Compute matches when text is a simple name.
43 
44  Return a list of all keywords, built-in functions and names currently
45  defined in self.namespace and self.cmsnamespace that match.
46 
47  """
48  import keyword
49  matches = []
50  n = len(text)
51  for list in [keyword.kwlist,
52  builtins.__dict__,
53  self.cmsnamespace]:
54  for word in list:
55  if word[:n] == text and word != "__builtins__":
56  matches.append(word)
57  return matches
58 
59 # connect CMSCompleter with readline
60 readline.set_completer(CMSCompleter().complete)
61 readline.parse_and_bind('tab: complete')
62 
63 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def __init__(self, namespace=None)
Definition: cmscompleter.py:20