def parsed_files(path, file_types): """ Generator of parsed DB files. Args: path: the path to load DBs from file_types: a list of file extensions that are expected Yields: parsed db files """ for db in _load_files(path, file_types): try: yield parse_db(db) except (ValueError, LookupError) as e: raise ValueError( "Failed to parse DB '{}'. Exception was: {}".format( db.directory, e))
def check(self): print "\n** CHECKING", self.file, "**" records = parse_db(self.file) grouper = Grouper() #Check for consistancy in whether PV macros are followed by colons colon = None for r in records.keys(): if colon is None: n = self.remove_macro(r, False) colon = n.startswith(':') else: n = self.remove_macro(r, False) if n.startswith(':') != colon: if colon: self.errors.append("FORMAT ERROR: " + r + " should have a colon after the macro") else: self.errors.append("FORMAT ERROR: " + r + " should not have a colon after the macro") groups = grouper.group_records(records) if self.debug: for s in groups.keys(): print s, groups[s].RB, groups[s].SP, groups[s].SP_RBV for s in groups.keys(): self.check_case(groups[s]) self.check_chars(groups[s]) self.check_candidates(groups[s], records) for w in self.warnings: print w for e in self.errors: print e print "** WARNING COUNT =", len(self.warnings), "**" print "** ERROR COUNT =", len(self.errors), "**"
) if not ma1 is None: recordGroups[s].SP = name elif not ma2 is None: recordGroups[s].SP_RBV = name elif s == name: recordGroups[s].RB = name # ~ ma3 = re.search("^" + re.escape(s) + "[_:](RBV|RB|READBACK|READ)$", name) # ~ if ma1 != None or ma2 != None or ma3 != None: # ~ recordGroups[s].append(name) # ~ elif s == name: # ~ recordGroups[s].append(name) if debug: print "GROUPS:" for s in recordGroups.keys(): print s, recordGroups[s].RB, recordGroups[s].SP, recordGroups[s].SP_RBV return recordGroups if __name__ == "__main__": # Simple test from db_parser import parse_db testfile = "./generate_sim_records_tests/test_db.db" r = parse_db(testfile) g = Grouper() g.group_records(r, True)
fout.write(' field(SDIS, "' + dis_record_name +'")\n') fout.write(line) fin.close() if insert_sims: new_records = generate_sim_records(records, sim_record_name, dis_record_name) #If no new records, don't write anything if new_records.strip() != "": fout.write("\n### SIMULATION RECORDS ###\n\n") fout.write(new_records) fout.close() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('file', nargs=1, type=str, help='The base file for adding records to') parser.add_argument('-o', '--output', nargs=1, default=[], help='The name of the output file') args = parser.parse_args() file = args.file[0] if len(args.output) == 1: out = args.output[0] else: f = os.path.split(file) out = "sim_" + f[-1] r = parse_db(file ) generate_modifed_db(file, out, r)
def parse_files(self): """ Method that stores all the records from all found files and returns a list of them """ return [parse_db(db) for db in self.dbs]