def index(): project = Project.find() onlyfiles = [f for f in project.model_dir().iterdir() if f.is_file()] path = project.model_dir() dashboardsParser = M5oCollectionParser(path, M5oCollectionParserTypes.Dashboard) reportsParser = M5oCollectionParser(path, M5oCollectionParserTypes.Report) reportsFiles = reportsParser.parse() dashboardFiles = dashboardsParser.parse() sortedM5oFiles = { "dashboards": {"label": "Dashboards", "items": dashboardFiles}, "documents": {"label": "Documents", "items": []}, "topics": {"label": "Topics", "items": []}, "reports": {"label": "Reports", "items": reportsFiles}, "tables": {"label": "Tables", "items": []}, } onlydocs = project.model_dir().parent.glob("*.md") for d in onlydocs: file_dict = MeltanoAnalysisFileParser.fill_base_m5o_dict( d.relative_to(project.root), str(d.name) ) sortedM5oFiles["documents"]["items"].append(file_dict) for f in onlyfiles: filename, ext = os.path.splitext(f) if ext != ".m5o": continue # filename splittext twice occurs due to current *.type.extension convention (two dots) filename = filename.lower() filename, ext = os.path.splitext(filename) file_dict = MeltanoAnalysisFileParser.fill_base_m5o_dict( f.relative_to(project.root), filename ) if ext == ".topic": sortedM5oFiles["topics"]["items"].append(file_dict) if ext == ".table": sortedM5oFiles["tables"]["items"].append(file_dict) m5o_parser = MeltanoAnalysisFileParser(project) for package in m5o_parser.packages(): package_files = MeltanoAnalysisFileParser.package_files(package) sortedM5oFiles["topics"]["items"] += package_files["topics"]["items"] sortedM5oFiles["tables"]["items"] += package_files["tables"]["items"] if not len(sortedM5oFiles["topics"]["items"]): return jsonify( { "result": False, "errors": [{"message": "Missing topic file(s)", "file_name": "*"}], "files": [], } ) return jsonify(sortedM5oFiles)
def get_dashboards(self): project = Project.find() dashboardsParser = M5oCollectionParser( project.analyze_dir("dashboards"), M5oCollectionParserTypes.Dashboard) return dashboardsParser.parse()
def get_package_records(self, *args): records_parser = M5oCollectionParser( self.packages_dir.joinpath(*args), self.record_type ) return records_parser.parse()
def get_reports(self): project = Project.find() reportsParser = M5oCollectionParser(project.analyze_dir("reports"), M5oCollectionParserTypes.Report) return reportsParser.parse()