102 lines
3.1 KiB
Python
102 lines
3.1 KiB
Python
import os
|
|
import sys
|
|
import os.path
|
|
import json
|
|
import yaml
|
|
from os import path
|
|
from typing import List
|
|
from Project import Project
|
|
from context.Context import Context
|
|
import coloredlogs, logging
|
|
from yaspin import yaspin
|
|
from Options import Options
|
|
|
|
|
|
class ProjectList:
|
|
|
|
__projectList=[]
|
|
|
|
logger = logging.getLogger("yamo")
|
|
|
|
#def execProject(self, projectName):
|
|
|
|
#def printReport(self):
|
|
# for i in self.__projectList:
|
|
# print(i.getErrors())
|
|
def getProjectList(self):
|
|
return self.__projectList
|
|
|
|
def execProject(self, projectName):
|
|
self.logger.info("Start Processing "+ projectName)
|
|
project = [x for x in self.__projectList if x.name == projectName]
|
|
|
|
if len(project) > 0:
|
|
project[0].execRestCalls()
|
|
else:
|
|
self.logger.warning("Could not find project "+projectName)
|
|
|
|
self.logger.info("End Processing "+ projectName)
|
|
|
|
def execAll(self):
|
|
for p in self.__projectList:
|
|
|
|
#with yaspin(text=p.name, color="yellow", side="right") as sp:
|
|
self.logger.info("== Start Projet "+ p.name+" ==")
|
|
p.execRestCalls()
|
|
self.logger.info("== Finished Projet "+ p.name+" ==")
|
|
#success = True if p.hasErrors else False
|
|
#sp.text = p.name
|
|
#if success:
|
|
# sp.ok("[SUCCESS] ")
|
|
#else:
|
|
# sp.fail("[FAILED]")
|
|
|
|
#if not success
|
|
|
|
|
|
self.logger.debug("Finished Processing ProjectList")
|
|
|
|
|
|
def exec(self):
|
|
|
|
self.logger.debug("Start Processing ProjectList")
|
|
|
|
if Options.getInstance().project:
|
|
self.execProject(Options.getInstance().project)
|
|
else:
|
|
self.execAll()
|
|
|
|
|
|
|
|
def __buildProjectList(self, projects_root_path):
|
|
context = Context.getInstance()
|
|
""" READ THE PROJECT PATH """
|
|
project_dirs: List[str] = os.listdir(projects_root_path)
|
|
|
|
for project in project_dirs:
|
|
|
|
if path.isdir(projects_root_path+"/"+project):
|
|
restCalls = []
|
|
rest_calls: List[str] = os.listdir(projects_root_path+"/"+project)
|
|
|
|
if len(rest_calls) == 0:
|
|
self.logger.warning("Project: " + project+ " has no configuration")
|
|
|
|
for restPath in rest_calls:
|
|
#execConfig=self.readExecutionConfig(projects_root_path+"/"+project+"/"+restPath+"/"+restPath+".yaml")
|
|
restC=context.restFactory.getRest(restPath, projects_root_path+"/"+project)
|
|
|
|
if restC is None:
|
|
self.logger.warning("Project: " + project+ " - RestPath: "+restPath+ " is unknown or missing missing "+ restPath+".yaml file, will be ignored")
|
|
|
|
if restC:
|
|
restCalls.append(restC)
|
|
|
|
if len(restCalls) > 0:
|
|
self.__projectList.append(Project(project,restCalls))
|
|
|
|
def __init__(self,projects_root_path):
|
|
self.__buildProjectList(projects_root_path)
|
|
#if len(self.__projectList) < 1:
|
|
# print("WARNING: no project folders found in: ", projects_root_path)
|
|
|