📄 projecteditor.py
字号:
finally:
try:
f.close()
except: pass
return stagedir
def _FixWsdlAgFiles(self, stagedir):
"""For each wsdlag file in the stagedir: if referenced artifact (wsdl or code file) is a known product file (such as securityservice.wsdl), make sure patch to it is parameterized with special env var. We do not want to copy those files. For user artifacts, ensure the file lives in root of stagedir. This should be the case if it is part of project (since staging has run). If it is not at root of stagedir, copy it. Then update path in wsdlag."""
files = os.listdir(stagedir)
for f in files:
if (f.endswith(WsdlAgEditor.WsdlAgDocument.WSDL_AG_EXT)):
wsdlagpath = os.path.join(stagedir, f)
fileObject = None
modified = False
try:
fileObject = open(wsdlagpath)
serviceref = WsdlAgEditor.load(fileObject)
# referenced wsdl
if (hasattr(serviceref, WsdlAgModel.WSDL_FILE_ATTR)):
modified = (modified |
self._UpdateServiceRefPathAttr(
stagedir, serviceref,
WsdlAgModel.WSDL_FILE_ATTR))
# referenced code file
if (hasattr(serviceref, WsdlAgModel.LOCAL_SERVICE_ELEMENT)):
lse = getattr(serviceref,
WsdlAgModel.LOCAL_SERVICE_ELEMENT)
if (hasattr(lse, WsdlAgModel.LOCAL_SERVICE_FILE_ATTR)):
modified = (modified |
self._UpdateServiceRefPathAttr(
stagedir, lse,
WsdlAgModel.LOCAL_SERVICE_FILE_ATTR))
finally:
try:
fileObject.close()
except:
pass
# no need to save the file if we did not change anything
if not modified: continue
# write the wsdlag file
fileObject = open(wsdlagpath)
try:
serviceref = WsdlAgEditor.save(fileObject, serviceref)
finally:
try:
fileObject.close()
except:
pass
def _UpdateServiceRefPathAttr(self, stagedir, serviceref, attrName):
"""Returns True if serviceref path has been updated, False otherwise."""
filePath = getattr(serviceref, attrName)
if (filePath == None):
return False
filePath = filePath.strip()
if (len(filePath) == 0):
return False
# if filePath starts with one of the AG systems vars, we don't
# have to do anything
if (fileutils.startsWithAgSystemVar(filePath)):
return False
# remove any known env var refs (we'll put them back a little below)
# we remove them here so that paths that do not have env vars also
# get parameterized correctly below
filePath = fileutils.expandKnownAGVars(filePath)
# make sure we have forward slashes. this is a workaround, which
# would not be necessary if we only write paths with forward slashes
# into our files
filePath = filePath.replace("\\", "/")
filePath = os.path.abspath(filePath)
if (not os.path.exists(filePath)):
# Wrong place to validate that referenced file exists, so just
# give up
return False
# If the referenced file is in stagedir already, there's nothing to do
if (fileutils.hasAncestorDir(filePath, stagedir)):
return False
# The path points outside of stagedir.
# Check if we already have the referenced wsdl file at root, should be
# the case if the referenced wsdl is part of project.
# Copy it if we don't have it, unless it lives in one of the known
# product directories - in which case we parameterize the known path
# with one of our AG system vars
relPath = os.path.basename(filePath)
stagePath = os.path.join(stagedir, relPath)
if (not os.path.exists(stagePath)):
pFilePath = fileutils.parameterizePathWithAGSystemVar(filePath)
if pFilePath == filePath: # no parameterization happened, copy
fileutils.copyFile(filePath, stagePath)
setattr(serviceref, attrName, relPath)
else:
setattr(serviceref, attrName, pFilePath.replace("\\", "/"))
else:
setattr(serviceref, attrName, relPath)
return True
def _SetSchemaTargetDataSource(self, projectFiles, dsmapping):
"""Update schema's default data source, if necessary."""
for projectFile in projectFiles:
if (projectFile.type == basedocmgr.FILE_TYPE_SCHEMA):
name = os.path.basename(projectFile.filePath)
if (dsmapping.has_key(name)):
schema = xmlutils.load(projectFile.filePath)
defaultName = schema.getDefaultDataSourceName()
if (defaultName != dsmapping[name]):
schema.setDefaultDataSourceName(dsmapping[name])
xmlutils.save(projectFile.filePath, schema)
def _StageFiles(self, fileDict):
"""Copy files to staging directory, update filePath attr of project's ProjectFile instances."""
# fileDict: ProjectFile instance -> dest path (string)
for fileRef, fileDest in fileDict.items():
fileutils.copyFile(fileRef.filePath, fileDest)
fileRef.filePath = fileDest
def _ValidateFilePaths(self, projectdir, stagedir):
"""If paths validate, returns a dict mapping ProjectFile to destination path. Destination path is the path the file needs to be copied to for staging. If paths don't validate, throws an IOError.
With our current slightly simplistic staging algorithm, staging will not work iff the project has files outside of the projectdir with names (filename without path) that:
- match filenames of files living at the root of the project.
- are same as those of any other file that lives outside of the projectdir.
We have this limitation because we move any file that lives outside of the project dir into the root of the stagedir (== copied project dir). We could make this smarter by either giving files unique names if we detect a collistion, or by creating some directory structure instead of putting all files from outside of the projectdir into the root of the stagedir (== copied projectdir)."""
# ProjectFile instance -> dest path (string)
rtn = {}
projectRootFiles = sets.Set() # live at project root
foreignFiles = sets.Set() # live outside of project
fileRefsToDeploy = self.GetFileRefs()
for fileRef in fileRefsToDeploy:
relPath = fileutils.getRelativePath(fileRef.filePath, projectdir)
filename = os.path.basename(fileRef.filePath)
if not relPath: # file lives outside of project dir...
# do we have another file with the same name already?
if filename in foreignFiles:
raise IOError("More than one file with name \"%s\" lives outside of the project. These files need to have unique names" % filename)
foreignFiles.add(filename)
fileDest = os.path.join(stagedir, filename)
else:
# file lives somewhere within the project dir
fileDest = os.path.join(stagedir, relPath)
if not os.path.dirname(relPath):
projectRootFiles.add(filename)
rtn[fileRef] = fileDest
# make sure we won't collide with a file that lives at root of
# projectdir when moving files into project
for filename in foreignFiles:
if filename in projectRootFiles:
raise IOError("File outside of project, \"%s\", cannot have same name as file at project root" % filename)
return rtn
def RenameFolder(self, oldFolderPath, newFolderPath):
for file in self.GetModel()._files:
if file.logicalFolder == oldFolderPath:
file.logicalFolder = newFolderPath
self.UpdateAllViews(hint = ("rename folder", self, oldFolderPath, newFolderPath))
self.Modify(True)
return True
def GetSchemas(self):
"""Returns list of schema models (activegrid.model.schema.schema) for all schemas in this project."""
rtn = []
resourceFactory = self._GetResourceFactory()
for projectFile in self.GetModel().projectFiles:
if (projectFile.type == basedocmgr.FILE_TYPE_SCHEMA):
schema = resourceFactory.getModel(projectFile)
if (schema != None):
rtn.append(schema)
return rtn
def GetFiles(self):
return self.GetModel().filePaths
def GetFileRefs(self):
return self.GetModel().findAllRefs()
def SetFileRefs(self, fileRefs):
return self.GetModel().setRefs(fileRefs)
def IsFileInProject(self, filename):
return self.GetModel().FindFile(filename)
def GetAppInfo(self):
return self.GetModel().GetAppInfo()
def GetAppDocMgr(self):
return self.GetModel()
def GetProjectName(self):
return os.path.splitext(os.path.basename(self.GetFilename()))[0]
def GetDeploymentFilepath(self, pre17=False):
if (pre17):
name = self.GetProjectName() + PRE_17_TMP_DPL_NAME
else:
name = self.GetProjectName() + _17_TMP_DPL_NAME
return os.path.join(self.GetModel().homeDir, name)
def _GetResourceFactory(self, preview=False, deployFilepath=None):
return IDEResourceFactory(
openDocs=wx.GetApp().GetDocumentManager().GetDocuments(),
dataSourceService=wx.GetApp().GetService(DataModelEditor.DataSourceService),
projectDir=os.path.dirname(self.GetFilename()),
preview=preview,
deployFilepath=deployFilepath)
def GenerateDeployment(self, deployFilepath=None, preview=False):
if ACTIVEGRID_BASE_IDE:
return
if not deployFilepath:
deployFilepath = self.GetDeploymentFilepath()
d = DeploymentGeneration.DeploymentGenerator(
self.GetModel(), self._GetResourceFactory(preview,
deployFilepath))
dpl = d.getDeployment(deployFilepath)
if preview:
dpl.initialize() # used in preview only
# REVIEW 07-Apr-06 stoens@activegrid.com -- Check if there's a
# tmp dpl file with pre 17 name, if so, delete it, so user doesn't end
# up with unused file in project dir. We should probably remove this
# check after 1.7 goes out.
fileutils.remove(self.GetDeploymentFilepath(pre17=True))
deploymentlib.saveThroughCache(dpl.fileName, dpl)
return deployFilepath
def AddNameSpaces(self, filePaths):
""" Add any new wsdl and schema namespaces to bpel files """
""" Add any new schema namespaces to wsdl files """
if ACTIVEGRID_BASE_IDE:
return
processRefs = self.GetAppDocMgr().findRefsByFileType(basedocmgr.FILE_TYPE_PROCESS) # bpel
schemaRefs = self.GetAppDocMgr().findRefsByFileType(basedocmgr.FILE_TYPE_SCHEMA) # xsd
serviceRefs = self.GetAppDocMgr().allServiceRefs # wsdl
# update bpel files
if processRefs and (serviceRefs or schemaRefs):
for processRef in processRefs:
processDoc = processRef.ideDocument
process = processDoc.GetModel()
if processDoc and process:
modified = False
# add wsdl namespaces to bpel file
for serviceRef in serviceRefs:
wsdl = serviceRef.document
if (wsdl
and (wsdl.fileName in filePaths
or serviceRef.filePath in filePaths)):
wsdlLongNS = wsdl.targetNamespace
wsdlShortNS = self.GetAppDocMgr().findShortNS(wsdlLongNS)
if not wsdlShortNS:
wsdlShortNS = xmlutils.genShortNS(process, wsdlLongNS)
xmlutils.addNSAttribute(process, wsdlShortNS, wsdlLongNS)
modified = True
# add schema namespaces to bpel file
for schemaRef in schemaRefs:
schema = schemaRef.document
if schema and schema.fileName in filePaths:
schemaLongNS = schema.targetNamespace
schemaShortNS = self.GetAppDocMgr().findShortNS(schemaLongNS)
if not schemaShortNS:
schemaShortNS = xmlutils.genShortNS(process, schemaLongNS)
xmlutils.addNSAttribute(process, schemaShortNS, schemaLongNS)
modified = True
if modified:
processDoc.OnSaveDocument(processDoc.GetFilename())
# update wsdl files
if serviceRefs and schemaRefs:
for serviceRef in serviceRefs:
wsdl = serviceRef.document
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -