- Timestamp:
- 03/21/13 12:56:12 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.4/parse_ganglia.py
r695 r696 17 17 self.parse() 18 18 19 20 19 def __del__( self ): 20 21 """ 22 Cleanup: close file descriptor 23 """ 21 24 22 25 self.file_pointer.close() … … 44 47 def parse( self ): 45 48 49 """ 50 Parse self.filename using shlex scanning. 51 - Removes /* comments */ 52 - Traverses (recursively) through all include () statements 53 - Stores complete valid config tokens in self.conf_list 54 55 i.e.: 56 ['globals', 57 '{', 58 'daemonize', 59 '=', 60 'yes', 61 'setuid', 62 '=', 63 'yes', 64 'user', 65 '=', 66 'ganglia', 67 'debug_level', 68 '=', 69 '0', 70 <etc> ] 71 """ 72 46 73 t = 'bogus' 47 74 c = False … … 58 85 if t[:2] == '/*' and t[-2:] == '*/': 59 86 60 print 'comment line'61 print 'skipping: %s' %t87 #print 'comment line' 88 #print 'skipping: %s' %t 62 89 continue 63 90 64 91 if t == '/*' or t[:2] == '/*': 65 92 c = True 66 print 'comment start'67 print 'skipping: %s' %t93 #print 'comment start' 94 #print 'skipping: %s' %t 68 95 continue 69 96 70 97 if t == '*/' or t[-2:] == '*/': 71 98 c = False 72 print 'skipping: %s' %t73 print 'comment end'99 #print 'skipping: %s' %t 100 #print 'comment end' 74 101 continue 75 102 76 103 if c: 77 print 'skipping: %s' %t104 #print 'skipping: %s' %t 78 105 continue 79 106 80 107 if t == 'include': 81 108 i = True 82 print 'include start'83 print 'skipping: %s' %t109 #print 'include start' 110 #print 'skipping: %s' %t 84 111 continue 85 112 86 113 if i: 87 114 88 print 'include start: %s' %t115 #print 'include start: %s' %t 89 116 90 117 t2 = self.removeQuotes( t ) … … 93 120 for in_file in glob( self.removeQuotes(t2) ): 94 121 95 print 'including file: %s' %in_file122 #print 'including file: %s' %in_file 96 123 parse_infile = GangliaConfigParser( in_file ) 97 124 … … 101 128 102 129 i = False 103 print 'include end'104 print 'skipping: %s' %t105 continue 106 107 print 'keep: %s' %t130 #print 'include end' 131 #print 'skipping: %s' %t 132 continue 133 134 #print 'keep: %s' %t 108 135 self.conf_lijst.append( t ) 109 136 … … 113 140 114 141 def confListToDict( self, parent_list=None ): 142 143 """ 144 Recursively traverses a conf_list and creates dictionary from it 145 """ 115 146 116 147 new_dict = { } … … 121 152 parent_list = self.conf_lijst 122 153 123 print 'entering confListToDict(): (parent) list size %s' %len(parent_list)154 #print 'entering confListToDict(): (parent) list size %s' %len(parent_list) 124 155 125 156 for n, c in enumerate( parent_list ): … … 127 158 count = count + 1 128 159 129 print 'CL: n %d c %s' %(n, c)160 #print 'CL: n %d c %s' %(n, c) 130 161 131 162 if skip > 0: … … 156 187 if parent_list[n] == '}': 157 188 158 #print 'parent_list = %s' %parent_list 159 print 'leaving confListToDict(): new dict = %s' %new_dict 189 #print 'leaving confListToDict(): new dict = %s' %new_dict 160 190 return (new_dict, count) 161 191 … … 165 195 166 196 def makeConfDict( self ): 197 198 """ 199 Walks through self.conf_list and creates a dictionary based upon config values 200 201 i.e.: 202 'tcp_accept_channel': [{'acl': [{'access': [{'action': ['"allow"'], 203 'ip': ['"127.0.0.1"'], 204 'mask': ['32']}]}], 205 'port': ['8649']}], 206 'udp_recv_channel': [{'port': ['8649']}], 207 'udp_send_channel': [{'host': ['145.101.32.3'], 208 'port': ['8649']}, 209 {'host': ['145.101.32.207'], 210 'port': ['8649']}]} 211 """ 167 212 168 213 new_dict = { } 169 214 skip = 0 170 215 171 print 'entering makeConfDict()'216 #print 'entering makeConfDict()' 172 217 173 218 for n, c in enumerate( self.conf_lijst ): 174 219 175 print 'M: n %d c %s' %(n, c)220 #print 'M: n %d c %s' %(n, c) 176 221 177 222 if skip > 0: 178 223 179 print '- skipped'224 #print '- skipped' 180 225 skip = skip - 1 181 226 continue … … 201 246 202 247 self.conf_dict = new_dict 203 print 'leaving makeConfDict(): conf dict size %d' %len( self.conf_dict )248 #print 'leaving makeConfDict(): conf dict size %d' %len( self.conf_dict ) 204 249 205 250 GMOND_LOCATION = '/etc/ganglia/gmond.conf'
Note: See TracChangeset
for help on using the changeset viewer.