Changeset 695 for branches/0.4/parse_ganglia.py
- Timestamp:
- 03/21/13 12:31:54 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/parse_ganglia.py
r693 r695 1 1 #!/usr/bin/env python 2 2 3 import shlex, sys 3 import shlex, sys, pprint 4 4 from glob import glob 5 5 … … 9 9 10 10 self.conf_lijst = [ ] 11 self.conf_dict = { } 11 12 self.filename = filename 12 13 self.file_pointer = file( filename, 'r' ) … … 15 16 16 17 self.parse() 18 17 19 18 20 def __del__( self ): … … 43 45 44 46 t = 'bogus' 45 c = False46 i = False47 c = False 48 i = False 47 49 48 50 while t != self.lexx.eof: … … 50 52 t = self.lexx.get_token() 51 53 52 if t == '/*': 53 c = True 54 print 'comment start' 55 print 'skipping: %s' %t 56 continue 57 58 if t == '*/': 59 c = False 60 print 'skipping: %s' %t 61 print 'comment end' 62 continue 54 if len( t ) >= 2: 55 56 if len( t ) >= 4: 57 58 if t[:2] == '/*' and t[-2:] == '*/': 59 60 print 'comment line' 61 print 'skipping: %s' %t 62 continue 63 64 if t == '/*' or t[:2] == '/*': 65 c = True 66 print 'comment start' 67 print 'skipping: %s' %t 68 continue 69 70 if t == '*/' or t[-2:] == '*/': 71 c = False 72 print 'skipping: %s' %t 73 print 'comment end' 74 continue 63 75 64 76 if c: … … 100 112 return self.conf_lijst 101 113 114 def confListToDict( self, parent_list=None ): 115 116 new_dict = { } 117 count = 0 118 skip = 0 119 120 if not parent_list: 121 parent_list = self.conf_lijst 122 123 print 'entering confListToDict(): (parent) list size %s' %len(parent_list) 124 125 for n, c in enumerate( parent_list ): 126 127 count = count + 1 128 129 print 'CL: n %d c %s' %(n, c) 130 131 if skip > 0: 132 133 #print '- skipped' 134 skip = skip - 1 135 continue 136 137 if (n+1) <= (len( parent_list )-1): 138 139 if parent_list[(n+1)] == '{': 140 141 if not new_dict.has_key( c ): 142 new_dict[ c ] = [ ] 143 144 (temp_new_dict, skip) = self.confListToDict( parent_list[(n+2):] ) 145 new_dict[ c ].append( temp_new_dict ) 146 147 if parent_list[(n+1)] == '=' and (n+2) <= (len( parent_list )-1): 148 149 if not new_dict.has_key( c ): 150 new_dict[ c ] = [ ] 151 152 new_dict[ c ].append( parent_list[ (n+2) ] ) 153 154 skip = 2 155 156 if parent_list[n] == '}': 157 158 #print 'parent_list = %s' %parent_list 159 print 'leaving confListToDict(): new dict = %s' %new_dict 160 return (new_dict, count) 161 162 def getConfDict( self ): 163 164 return self.conf_dict 165 166 def makeConfDict( self ): 167 168 new_dict = { } 169 skip = 0 170 171 print 'entering makeConfDict()' 172 173 for n, c in enumerate( self.conf_lijst ): 174 175 print 'M: n %d c %s' %(n, c) 176 177 if skip > 0: 178 179 print '- skipped' 180 skip = skip - 1 181 continue 182 183 if (n+1) <= (len( self.conf_lijst )-1): 184 185 if self.conf_lijst[(n+1)] == '{': 186 187 if not new_dict.has_key( c ): 188 new_dict[ c ] = [ ] 189 190 ( temp_new_dict, skip ) = self.confListToDict( self.conf_lijst[(n+2):] ) 191 new_dict[ c ].append( temp_new_dict ) 192 193 if self.conf_lijst[(n+1)] == '=' and (n+2) <= (len( self.conf_lijst )-1): 194 195 if not new_dict.has_key( c ): 196 new_dict[ c ] = [ ] 197 198 new_dict[ c ].append( self.conf_lijst[ (n+2) ] ) 199 200 skip = 2 201 202 self.conf_dict = new_dict 203 print 'leaving makeConfDict(): conf dict size %d' %len( self.conf_dict ) 204 102 205 GMOND_LOCATION = '/etc/ganglia/gmond.conf' 103 206 104 207 g = GangliaConfigParser( GMOND_LOCATION ) 105 208 106 print g.getConfLijst() 209 pprint.pprint( g.getConfLijst(), width=1 ) 210 211 g.makeConfDict() 212 213 pprint.pprint( g.getConfDict(), width=1 ) 107 214 108 215 print 'exiting..'
Note: See TracChangeset
for help on using the changeset viewer.