ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/CMSSW/PhysicsTools/PythonAnalysis/python/cmscompleter.py
Revision: 1.1
Committed: Wed Mar 22 13:40:36 2006 UTC (19 years, 1 month ago) by hegner
Content type: text/x-python
Branch: MAIN
CVS Tags: CMSSW_1_3_6, CMSSW_1_3_1_HLT6, CMSSW_1_3_5, CMSSW_1_3_1_HLT5, CMSSW_1_3_1_HLT4, CMSSW_1_3_1_HLT3, CMSSW_1_3_4, CMSSW_1_3_3, CMSSW_1_3_2, CMSSW_1_2_6, CMSSW_1_2_5, CMSSW_1_3_1, CMSSW_1_2_4, CMSSW_1_3_0, CMSSW_1_3_0_pre7, CMSSW_1_3_0_pre6, CMSSW_1_2_0_4821, CMSSW_1_2_0_g4_82p01, CMSSW_1_3_0_pre5, V00-01-02, CMSSW_1_3_0_pre4, V00-01-01, CMSSW_1_2_3, CMSSW_1_3_0_pre3, CMSSW_1_2_0_g4_82, CMSSW_1_3_0_SLC4_pre2, CMSSW_1_3_0_pre2, CMSSW_1_2_2, CMSSW_1_2_1, CMSSW_1_3_0_SLC4_pre1, CMSSW_1_3_0_pre1, CMSSW_1_2_0_g4_81, CMSSW_1_2_0_SL4, CMSSW_1_2_0, CMSSW_1_2_0_pre9, CMSSW_1_2_0_pre8_g4_81, CMSSW_1_2_0_pre8, CMSSW_1_1_2, CMSSW_1_2_0_pre7, CMSSW_1_2_0_pre6, CMSSW_1_2_0_pre5, CMSSW_1_2_0_pre4, CMSSW_1_1_1, CMSSW_1_2_0_pre3, CMSSW_1_0_6, CMSSW_1_2_0_pre2, CMSSW_1_0_5, CMSSW_1_1_0, CMSSW_1_2_0_pre1, CMSSW_1_0_4, CMSSW_1_1_0_pre4, CMSSW_1_0_3, CMSSW_1_0_0_g4_81, CMSSW_1_1_0_pre3, CMSSW_1_0_2, CMSSW_1_0_1, CMSSW_1_1_0_pre2, CMSSW_1_0_0, CMSSW_1_0_0_pre5, CMSSW_1_1_0_pre1, CMSSW_0_8_4, CMSSW_1_0_0_pre4, CMSSW_1_0_0_pre3, CMSSW_0_9_2, CMSSW_0_8_3, CMSSW_1_0_0_pre2, CMSSW_0_9_0_pre2_g4_81, CMSSW_1_0_0_pre1, CMSSW_0_9_1, CMSSW_0_8_2, CMSSW_0_9_0, CMSSW_0_9_0_pre3, CMSSW_0_9_0_pre2, CMSSW_0_9_0_pre1, CMSSW_0_8_1, CMSSW_0_8_0, CMSSW_0_8_0_pre5, CMSSW_0_8_0_pre4, CMSSW_0_8_0_pre3, CMSSW_0_7_2, CMSSW_0_8_0_pre2, CMSSW_0_7_1, CMSSW_0_8_0_pre1, CMSSW_0_7_0, CMSSW_0_7_0_pre6, CMSSW_0_7_0_pre5, CMSSW_0_7_0_pre4, CMSSW_0_7_0_pre3, CMSSW_0_6_1, CMSSW_0_7_0_pre2, V00-00-04, CMSSW_0_7_0_pre1, CMSSW_0_6_0, CMSSW_0_6_0_pre7, CMSSW_0_6_0_pre6, CMSSW_0_6_0_pre5, CMSSW_0_6_0_pre4, CMSSW_0_6_0_pre3, CMSSW_0_6_0_pre2, V00-00-03, V00-00-02
Log Message:
New helper classes implemented

File Contents

# User Rev Content
1 hegner 1.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     # TODO: sometimes results are doubled. clean global_matches list!
9    
10     import readline
11     import rlcompleter
12     import __builtin__
13     import __main__
14    
15     __all__ = ["CMSCompleter"]
16    
17     class CMSCompleter(rlcompleter.Completer):
18     def __init__(self, namespace = None):
19    
20     print 'Preparing CMS tab completer tool...'
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     print 'Loading FWLite dictionary...'
36     import namespaceDict
37     self.cmsnamespace = namespaceDict.getNamespaceDict()
38     except:
39     print 'Could not load CMS namespace'
40    
41    
42     def global_matches(self, text):
43     """Compute matches when text is a simple name.
44    
45     Return a list of all keywords, built-in functions and names currently
46     defined in self.namespace and self.cmsnamespace that match.
47    
48     """
49     import keyword
50     matches = []
51     n = len(text)
52     for list in [keyword.kwlist,
53     __builtin__.__dict__,
54     self.cmsnamespace]:
55     for word in list:
56     if word[:n] == text and word != "__builtins__":
57     matches.append(word)
58     return matches
59    
60     # connect CMSCompleter with readline
61     readline.set_completer(CMSCompleter().complete)
62     readline.parse_and_bind('tab: complete')
63    
64