def _yaml_include(loader, node): filename = self._locate(node.value) if not filename: msg = "Failed to locate included file '{}'".format(node.value) self.errs.append(msg) return None file_dict[filename] = 1 with utils.open_file(filename) as inputfile: return yaml.load(inputfile, Loader)
def read_report_csv(filepath, rmindex=True): rows = [] try: with utils.open_file(filepath) as fd: for row in csv.reader(fd): if row[0] != '#': if rmindex: row.pop(0) rows.append(row) except Exception: #print("failed to open {} to read".format(filepath)) pass return rows
def init_file(self, filename, paths=[]): self._init_paths(filename, paths) file_path = self._locate(filename) if not file_path: self.errs.append("File {} not found".format(filename)) return None fh = utils.open_file(file_path) if not fh: self.errs.append("Failed to open {}".format(filename)) return None try: text0 = fh.read() fh.close() self.all_files = self.init_content(text0) self.all_files[file_path] = 1 return file_path except Exception as e: self.errs.append(e) raise (e)