From: <de...@us...> - 2004-01-07 01:48:33
|
Update of /cvsroot/pymerase/smw/smw/scw/Project In directory sc8-pr-cvs1:/tmp/cvs-serv32238/smw/scw/Project Added Files: SfiManager.py __init__.py python.iml Log Message: Imported version of SMW downloaded on 2003 Apr 14 --- NEW FILE: SfiManager.py --- #!/usr/bin/env python2 """ The Project layer is the fisrt layer in the SCW project. It can create and delete a project. Rename and load/save projects. """ __layer__ = 'Project' from smw.metamodel import UML14 as metamodel from smw.transform.uml2py.uml2py import isNameValid from smw import io import os.path import sys import smw.Configuration class SfiManager: # N = 0 def __init__(self): """ Constructor for a new SfiManager. """ # self.__class__.N += 1 # if self.__class__.N > 1: # raise 'More than one instance exists.' # self.setUp() config=smw.Configuration.Configuration() ppObj=config.getParameter("install_path") pp=ppObj.currentValue if os.path.isfile(pp+"/scw/python.iml"): #pythonUMLModel=io.loadModel(pp+"/smw/scw/python.iml") #self._pythonUMLPackage=pythonUMLModel.ownedElement[0] self.setUp() else: print "You must run the 'smw/scw/make' in command first" sys.exit() def pythonPackage(self): """returns the python package""" return self._pythonUMLPackage def projects(self): """returns a dictonary containing the project (more use when the editor supports several projects)""" return self._projects def setUp(self): """just clears the attributes,used when starting a new project""" self._projects={} self._currentProject=None self._pythonUMLPackage=None def __del__(self): print 'instance of %s.SfiManager deleted' % __layer__ def newProject(self, projectName = None): """ Adds a new project to the 'projects' -dictionary. The new project is assigned as current project. Returns the new Project. """ if not projectName: projectName = self.createUniqueName() if not isinstance(projectName, str): return if len(self._projects)!=0: return if isNameValid(projectName): if self._projects.has_key(projectName): return self._projects[projectName] = metamodel.Model() self._projects[projectName].name=projectName self._currentProject=self._projects[projectName] config=smw.Configuration.Configuration() ppObj=config.getParameter("install_path") pp=ppObj.currentValue pythonUMLModel=io.loadModel(pp+"/scw/python.iml") self._pythonUMLPackage=pythonUMLModel.ownedElement[0] self._pythonUMLPackage.name="python2_2" # THIS HAS TO BE CHANGED self._currentProject.ownedElement.append(self._pythonUMLPackage) return self._projects[projectName] else: return def createUniqueName(self): """ Creates a unique name for a project and returns it. """ defName = "Project" x = 1 while self._projects.has_key(defName + str(x)): x = x + 1 return defName + str(x) def deleteProject(self, arg): """ Deletes the specified project from the dictionary if it exists. -arg can be either the name of the project or the project itself Returns the deleted project. """ if isinstance(arg,str): if not self._projects.has_key(arg): return None else: uModel = self._projects[arg] del self._projects[arg] elif isinstance(arg,metamodel.Model): if not self._projects.has_key(arg.name): return None else: uModel=arg del self._projects[arg.name] # if needed to delete project (Current) without arguments add it here else: return if len(self._projects.keys())<1: self._currentProject=None else: firstKey=(self._projects.keys())[0] self.focusOnProject(firstKey) return uModel def renameProject(self, oldName, newName): """ Renames the project with the name 'oldName' to 'newName' and returns the new name of the project. Returns none if either one of the parameters is invalid. """ if isNameValid(newName): if not self._projects.has_key(oldName): return elif self._projects.has_key(newName): return else: value=self._projects[oldName] del self._projects[oldName] self._projects[newName]=value self._projects[newName].name=newName return newName else: return def currentProject(self): """ Returns the current project. """ return self._currentProject def focusOnProject(self,project): """ Assigns the project given as parameter to current project and returns the current project if the parameter is an existing project. """ if isinstance(project,str): if self._projects.has_key(project): self._currentProject=self._projects[project] # THIS HAS TO BE CHANGED!!!!!!!!! #self.pythonPackage().namespace=self.currentProject return self.currentProject() else: return elif isinstance(project,metamodel.Model): if self._projects.has_key(project.name): self._currentProject=project # THIS HAS TO BE CHANGED!!!!!!!!!!!!!!!!! #self.pythonPackage().namespace=self.currentProject return self.currentProject() else: return else: return def loadProject(self, fname): """ Loads the project from the file named 'fname'. After loading the current element is the project itself. Returns the loaded project if the loading succeeded """ if self.currentProject(): self._projects={} if not isinstance(fname, str): return if not os.path.isfile(fname): return uModel = io.loadModel(fname) # model was loaded and the name does not exist in the dictionary. if uModel and not self._projects.has_key(uModel.name): self._projects[uModel.name] = uModel self._currentProject = uModel foundPP=0 for x in range(len(uModel.ownedElement)): e=uModel.ownedElement[x] if (e.oclIsKindOf(metamodel.Package) and e.name=="python2_2"): foundPP=1 if not foundPP: config=smw.Configuration.Configuration() ppObj=config.getParameter("install_path") pp=ppObj.currentValue pythonUMLModel=io.loadModel(pp+"/scw/python.iml") self._pythonUMLPackage=pythonUMLModel.ownedElement[0] self._pythonUMLPackage.name="python2_2" self._currentProject.ownedElement.append(self._pythonUMLPackage) return uModel return def saveProject(self): """ saves the currentProject and returns the name. """ if not self.currentProject(): return fname = self.currentProject().name + ".iml" savedModel=io.saveModel(fname, self.currentProject()) if savedModel: return self.currentProject().name else: print "Saving unsuccesful!" return def saveProjectAs(self, fname): """ Saves the project with the given name and returns the name. """ if not self.currentProject(): return savedModel=io.saveModel(fname, self.currentProject()) if savedModel: return fname[0:len(fname)-4] else: print "Saving unsuccesfull!" return --- NEW FILE: __init__.py --- from SfiManager import * --- NEW FILE: python.iml --- (ismw.metamodel.UML14 Model p1 (dp2 S'isAbstract' p3 I0 sS'isSpecification' p4 I0 sS'__uniqueID__' p5 S'i3af6dbe0141dc49e413e120e4051be18' p6 sS'isRoot' p7 I0 sS'visibility' p8 [...27200 lines suppressed...] I0 sg5 S'if1f5e220f72663332016cb25e518e381' p4846 sg17 g4825 sg41 I0 sg4 I0 sg7 I0 sg8 I0 sg10 S'PyZipFile' p4847 sg9 I0 sbasbsbasbsbasbsb. |