Changeset 1469:48fa8d70e6ad in freeDiameter
- Timestamp:
- Mar 18, 2020, 9:40:01 AM (4 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/tools/csv_to_fd
r1464 r1469 7 7 Format of the CSV files is one of: 8 8 - Row per 3GPP AVP tables: 9 Name, Code, Section, DataType, Must, May, ShouldNot, MustNot [, ...]9 Name, Code, Section, DataType, Must, May, ShouldNot, MustNot [, extra] 10 10 - Name: 11 11 AVP Name. String, validated as ALPHA *(ALPHA / DIGIT / "-") … … 45 45 import re 46 46 import optparse 47 import os 47 48 import sys 48 49 … … 56 57 'shouldnot', 57 58 'mustnot', 58 'encrypt',59 59 ] 60 60 … … 89 89 _name_re = re.compile(r'^[a-zA-Z0-9][a-zA-Z0-9-\.]*$') 90 90 91 # Regex to validate flags: M, P, V, comma, space 92 _flags_re = re.compile(r'^[MPV, ]*$') 93 91 94 __slots__ = CSV_COLUMN_NAMES + [ 92 95 'filename', 'linenum', 'standard', 'vendor', ] 93 96 94 97 def __init__(self, name, code, section, datatype, 95 must, may, shouldnot, mustnot, e ncrypt,98 must, may, shouldnot, mustnot, extra_cells, 96 99 filename='', linenum=0, standard='', vendor=0): 97 100 # Members from CSV row … … 104 107 self.shouldnot = shouldnot 105 108 self.mustnot = mustnot 106 self.encrypt = encrypt107 109 # Members from file state 108 110 self.filename = filename … … 121 123 raise ValueError('Invalid AVP data type "{}"'.format( 122 124 self.datatype)) 123 # TODO: validate must, may, shouldnot, mustnot 125 for val, desc in [ 126 (self.must, 'Must'), 127 (self.may, 'May'), 128 (self.shouldnot, 'Should Not'), 129 (self.mustnot, 'Must Not'), 130 ]: 131 if not self._flags_re.match(val): 132 raise ValueError('Invalid AVP Flags {} "{}"'.format(desc, val)) 124 133 125 134 @property … … 217 226 218 227 def __init__(self): 228 self.filenames = [] 219 229 self.lines = [] 220 230 221 231 def next_file(self, filename): 222 print('/* CSV file: {} */'.format(filename))232 self.filenames.append(os.path.basename(filename)) 223 233 224 234 def avp(self, avp): … … 277 287 self.print_comment('') 278 288 self.print_comment('The following is created automatically with:') 279 self.print_comment(' csv_to_fd -p {}'.format(self.cls_name())) 289 self.print_comment(' csv_to_fd -p {} {}'.format( 290 self.cls_name(), ' '.join(self.filenames))) 280 291 self.print_comment('Changes will be lost during the next update.') 281 292 self.print_comment('Do not modify;' … … 412 423 avpproc.next_file(filename) 413 424 with open(filename, 'r') as csvfile: 414 csvdata = csv.DictReader(csvfile, CSV_COLUMN_NAMES) 425 csvdata = csv.DictReader(csvfile, CSV_COLUMN_NAMES, 426 restkey='extra_cells') 415 427 linenum = 0 416 428 standard = ''
Note: See TracChangeset
for help on using the changeset viewer.