def CreateModuleVariable(self, variableName, variableDescription, variableType, variableMode, value=None): self.__ValidateArgs() # Validating Variable Type if variableMode == "Internal": raise err.Conflict( "A Variable with the mode '{0}' is not support by Modules !". format(variableMode)) return None # Setting Value if variableMode != "Static": value = None jsonContent = self.OpenModule() # Validating Uniquness if variableName in jsonContent["ModuleVariables"]: raise err.Conflict( "A Module Variable with the name '{0}' already exists !". format(variableName)) return None else: jsonContent = self.OpenSchema() jsonContent["Modules"][ self.moduleName]["ModuleVariables"][variableName] = ( js.VariableJSON(variableName, variableDescription, variableType, variableMode, value)) fl.Write(self.schemaMetaData, js.Dump(jsonContent), True) return "Variable '{0}' created successfully !".format(variableName)
def CreateProjectVariable(self, variableName, variableDescription, variableType, variableMode, value=None): self.__ValidateArgs() # Validating Variable Type if variableMode != "Static" and variableMode != "Runtime": raise err.Conflict( "A Variable with the mode '{0}' is not support by Projects !". format(variableMode)) return None # Setting Value if variableMode != "Static": value = None jsonContent = self.OpenProject() # Validating Uniquness if variableName in jsonContent["ProjectVariables"]: raise err.Conflict( "A Project Variable with the name '{0}' already exists !". format(variableName)) return None else: jsonContent["ProjectVariables"][variableName] = (js.VariableJSON( variableName, variableDescription, variableType, variableMode, value)) fl.Write(self.projectMetaData, js.Dump(jsonContent), True) return "Variable '{0}' created successfully !".format(variableName)
def CreateModule(self, moduleDescription, group, data): self.__ValidateArgs() # Validating Path try: if self.OpenModule() is not None: raise err.Conflict( "A Module with the name '{0}' already exists !".format( self.moduleName)) except err.Conflict as ex: if "Unable to find a Project" in str(ex): return None if "Unable to find a Schema" in str(ex): return None if "already exists" in str(ex): raise err.Conflict( "A Module with the name '{0}' already exists !".format( self.moduleName)) return None # Checking Group Count groupCount = int(self.GetGroupCount()) if group > groupCount: raise err.Conflict( "Group number '{0}' is greater than the allowed number of '{1}' !" .format(group, groupCount)) return None # Creating Directory & File try: jsonContent = js.Load(fl.Read(self.schemaMetaData)) jsonContent["Modules"][self.moduleName] = js.ModuleJSON( self.moduleName, moduleDescription, group) fl.Write(self.schemaMetaData, js.Dump(jsonContent), True) fl.Write(self.modulePath, data, True) return "Module '{0}' created successfully !".format( self.moduleName) except WindowsError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) except OSError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) if os.path.exists(self.schemaPath): os.removedirs(self.schemaPath) return None
def OpenTemplate(self): self.ValidateArgs() # Opening Template templates = self.GetTemplateList() if self.templateName in templates: return fl.Read(self.templateMetaData) else: raise err.Conflict( "Unable to find a Template with the name '{0}'".format( self.templateName)) return None
def SetEnvironmentPath(self, envPath): if os.path.exists(envPath): self.envDIR=envPath else: raise err.Conflict("The path '{0}' not found !".format(envPath)) os.makedirs(ProjectPath) metaFile=open(os.path.join(ProjectPath, ".metadata"),"w+") metaFile.write(json.dumps({'ProjectName': projectName, 'ProjectDescription': projectDescription,'Schemas':[]}, sort_keys=True, indent=4, separators=(',', ': '))) metaFile.close() self.curProject=ProjectPath return "Project '{0}' created successfully !".format(projectName)
def OpenProject(self): self.__ValidateArgs() # Opening Project try: projectData = fl.Read(self.projectMetaData) return js.Load(projectData) except IOError: raise err.Conflict( "Unable to find a Project with the name '{0}'".format( self.projectName)) return None
def OpenSchema(self): self.__ValidateArgs() schemas = self.GetSchemaList() # Opening Schema if self.schemaName in schemas: return js.Load(fl.Read(self.schemaMetaData)) else: raise err.Conflict( "Unable to find a Schema with the name '{0}'".format( self.schemaName)) return None
def OpenModule(self): self.__ValidateArgs() # Opening Module modules = self.GetModuleList() if self.moduleName in modules: return js.Load(fl.Read( self.schemaMetaData))["Modules"][self.moduleName] else: raise err.Conflict( "Unable to find a Module with the name '{0}'".format( self.moduleName)) return None
def CreateSchema(self, schemaDescription, groupCount): self.__ValidateArgs() try: if self.OpenSchema() is not None: raise err.Conflict( "A Schema with the name '{0}' already exists !".format( self.schemaName)) except err.Conflict as ex: if "Unable to find a Project" in str(ex): return None if "already exists" in str(ex): raise err.Conflict( "A Schema with the name '{0}' already exists !".format( self.schemaName)) return None # Creating Directory & File try: os.makedirs(self.schemaPath) jsonContent = js.Load(fl.Read(self.projectMetaData)) jsonContent["Schemas"].append(self.schemaName) fl.Write(self.projectMetaData, js.Dump(jsonContent), True) # Creating Schema Metadata jsonContent = js.SchemaJSON(self.schemaName, schemaDescription, groupCount) fl.Write(self.schemaMetaData, js.Dump(jsonContent), True) return "Schema '{0}' created successfully !".format( self.schemaName) except WindowsError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) except OSError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) if os.path.exists(self.schemaPath): os.removedirs(self.schemaPath) return None
def CreateTemplate(self, templateDescription): self.ValidateArgs() # Validating Templates try: if self.OpenTemplate() is not None: raise err.Conflict( "A Template with the name '{0}' already exists !".format( self.templateName)) return None except err.Conflict as ex: if "Unable to find a Project" in str(ex): return None if "Unable to find a Schema" in str(ex): return None if "already exists" in str(ex): raise err.Conflict( "A Template with the name '{0}' already exists !".format( self.templateName)) return None # Creating Template try: jsonContent = js.Load(fl.Read(self.schemaMetaData)) jsonContent["Templates"].append(self.templateName) fl.Write(self.schemaMetaData, js.Dump(jsonContent), True) fl.Write(self.templateMetaData, "", True) return "Template '{0}' created successfully !".format( self.templateName) except WindowsError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) except OSError: raise err.Conflict( "There are errors in the metadata file. Synchronize the data to fix them !" ) if os.path.exists(self.templateMetaData): os.remove(self.templateMetaData) return None
def CreateProject(self, projectDescription): self.__ValidateArgs() # Creating Directory & File try: os.makedirs(self.projectPath) fl.Write( self.projectMetaData, js.ProjectJSON(self.projectName, projectDescription, asJSON=True)) return "Project '{0}' created successfully !".format( self.projectName) except WindowsError or OSError: raise err.Conflict( "A Project with the name '{0}' already exists !".format( self.projectName)) return None
def AddModules(self, moduleKey, moduleName): self.ValidateArgs() # Validating Module Key if js.GetJSON(self.GetTemplateModules(), "ModuleKey", moduleKey): raise err.Conflict( "A Module with the key '{0}' already exists !".format( moduleKey)) return None # Adding Modules to Template jsonContent = js.Load(fl.Read(self.projectMetaData)) index = js.GetJSONIndex( jsonContent["Schemas"][self.schemaIndex]["Templates"], "TemplateName", self.templateName) jsonContent["Schemas"][self.schemaIndex]["Templates"][int( index[0])]["Modules"].append( js.TemplateModuleJSON(moduleKey, moduleName)) fl.Write(self.projectMetaData, js.Dump(jsonContent), True) return "Module '{0}' added successfully !".format(moduleName)
def ValidateArgs(self): if self.moduleName == None: raise err.Conflict("Template arguments are missing !") return None
def __ValidateArgs(self): if self.projectName == None: raise err.Conflict("Project arguments are missing !") return None
def __ValidateArgs(self): if self.schemaName == None: raise err.Conflict("Schema arguments are missing !") return None