comparison contrib/tools/csv_to_fd @ 1464:1404de313b85

csv_to_fd: consistent comparison order
author Luke Mewburn <luke@mewburn.net>
date Tue, 10 Mar 2020 09:33:41 +1100
parents 8f6c77f24b1a
children 48fa8d70e6ad
comparison
equal deleted inserted replaced
1463:8f6c77f24b1a 1464:1404de313b85
91 __slots__ = CSV_COLUMN_NAMES + [ 91 __slots__ = CSV_COLUMN_NAMES + [
92 'filename', 'linenum', 'standard', 'vendor', ] 92 'filename', 'linenum', 'standard', 'vendor', ]
93 93
94 def __init__(self, name, code, section, datatype, 94 def __init__(self, name, code, section, datatype,
95 must, may, shouldnot, mustnot, encrypt, 95 must, may, shouldnot, mustnot, encrypt,
96 filename=None, linenum=0, standard=None, vendor=0): 96 filename='', linenum=0, standard='', vendor=0):
97 # Members from CSV row 97 # Members from CSV row
98 self.name = name 98 self.name = name
99 self.code = int(code) 99 self.code = int(code)
100 self.section = section 100 self.section = section
101 self.datatype = datatype 101 self.datatype = datatype
221 def next_file(self, filename): 221 def next_file(self, filename):
222 print('/* CSV file: {} */'.format(filename)) 222 print('/* CSV file: {} */'.format(filename))
223 223
224 def avp(self, avp): 224 def avp(self, avp):
225 comment = '{name}, {datatype}, code {code}'.format(**vars(avp)) 225 comment = '{name}, {datatype}, code {code}'.format(**vars(avp))
226 if '' != avp.section: 226 if avp.section != '':
227 comment += ', section {}'.format(avp.section) 227 comment += ', section {}'.format(avp.section)
228 self.add_comment(comment) 228 self.add_comment(comment)
229 self.add('\t{') 229 self.add('\t{')
230 self.add('\t\tstruct dict_avp_data data = {') 230 self.add('\t\tstruct dict_avp_data data = {')
231 # TODO: remove comments? 231 # TODO: remove comments?
239 # TODO: add trailing comma? 239 # TODO: add trailing comma?
240 self.add('\t\t\tAVP_TYPE_{}\t/* base type of data */'.format( 240 self.add('\t\t\tAVP_TYPE_{}\t/* base type of data */'.format(
241 DERIVED_TO_BASE.get(avp.datatype, avp.datatype).upper())) 241 DERIVED_TO_BASE.get(avp.datatype, avp.datatype).upper()))
242 self.add('\t\t};') 242 self.add('\t\t};')
243 avp_type = 'NULL' 243 avp_type = 'NULL'
244 if 'Enumerated' == avp.datatype: 244 if avp.datatype == 'Enumerated':
245 self.add('\t\tstruct dict_object\t*type;') 245 self.add('\t\tstruct dict_object\t*type;')
246 vendor_prefix = '' 246 vendor_prefix = ''
247 if avp.vendor != 0: 247 if avp.vendor != 0:
248 vendor_prefix = '{}/'.format(VENDOR_TO_NAME[avp.vendor]) 248 vendor_prefix = '{}/'.format(VENDOR_TO_NAME[avp.vendor])
249 self.add( 249 self.add(
260 # TODO: remove ; on scope brace 260 # TODO: remove ; on scope brace
261 self.add('\t};') 261 self.add('\t};')
262 self.add('') 262 self.add('')
263 263
264 def comment(self, comment, filename, linenum): 264 def comment(self, comment, filename, linenum):
265 if '' == comment: 265 if comment == '':
266 self.add('') 266 self.add('')
267 elif '=' == comment: 267 elif comment == '=':
268 self.add_header() 268 self.add_header()
269 elif comment.startswith(' '): 269 elif comment.startswith(' '):
270 self.add_comment(comment[1:]) 270 self.add_comment(comment[1:])
271 else: 271 else:
272 raise ValueError('Unsupported comment "{}"'.format(comment)) 272 raise ValueError('Unsupported comment "{}"'.format(comment))
426 elif row['name'].startswith('@'): 426 elif row['name'].startswith('@'):
427 parameter = row['name'][1:] 427 parameter = row['name'][1:]
428 value = row['code'] 428 value = row['code']
429 if False: 429 if False:
430 pass 430 pass
431 elif 'standard' == parameter: 431 elif parameter == 'standard':
432 standard = value 432 standard = value
433 elif 'vendor' == parameter: 433 elif parameter == 'vendor':
434 vendor = int(value) 434 vendor = int(value)
435 else: 435 else:
436 raise ValueError('Unknown parameter "{}"'.format( 436 raise ValueError('Unknown parameter "{}"'.format(
437 parameter)) 437 parameter))
438 else: 438 else:
457 457
458 # Generate result 458 # Generate result
459 avpproc.generate() 459 avpproc.generate()
460 460
461 461
462 if '__main__' == __name__: 462 if __name__ == '__main__':
463 main() 463 main()
464 464
465 # vim: set et sw=4 sts=4 : 465 # vim: set et sw=4 sts=4 :
"Welcome to our mercurial repository"