Example #1
0
 def __init__(self, field_num, field):
     """Loop constructor
     If a word occurs before "OCCURS x TIMES", that word is
     used for the name of model, otherwise the name is determined
     from the base model name followed by and underscore and the
     line number at which the loop starts.
     
     Setup whether it is fixed loop or wheter it depends on another value
     
     :type field_num: list 
     :param field_num: line from copybook2csv split at ','   
     
     :type field: Field object
     :param field:   
     
     """
     self.counter = 0
     self.start_line_num = field_num
     loop_str = field.name.split()
     if loop_str[0] == 'OCCURS':
         loop_name = self.model_name
         self.name = '%s_%d' % (loop_name, field_num)
         self.num_times = loop_str[1]
     else:
         self.name, self.num_times = loop_str[0], loop_str[2]
     if self.num_times.isdigit():
         self.num_times = int(self.num_times)
         self.depends_on_field_name = False
     else:
         self.num_times = self.num_times.strip('"').strip("'")
         self.depends_on_field_name = names.legal_db_name(self.num_times)
         self.num_times = 0
Example #2
0
 def __init__(self, line):
     """Field constructor
     :type line: list 
     :param line: line from copybook2csv split at ','
          
     """
     self.value = None
     self.indents = line[0].count('\t')
     field = [ i.lstrip() for i in line ]
     if len(field) == 1:
         # it's a loop not a field, i.e. <name> OCCURS x TIMES
         self.name = field[0]
     else:
         # standard field definition
         name, self.type, length, decimal_pos = field
         self.name = names.legal_db_name(name)
         self.length = int(length) 
         self.decimal_pos = int(decimal_pos)
Example #3
0
def get_base_model_name(filename):
    """Generates the name of the base model/table from the filename"""
    model_name = os.path.basename(filename)
    model_name = os.path.splitext(filename)
    model_name = names.legal_db_name(model_name[0]).title()
    return model_name