Пример #1
0
 def __init__(self, fileName=''):
     self.doc = minidom.Document()
     self.rootNode = XmlUtils.GetRoot(self.doc)
     self.name = ''
     self.fileName = ''  # 绝对路径
     self.dirName = ''  # 绝对路径
     self.baseName = ''  # 项目文件名
     # 用于判断是否重新生成 makefile,此标志为真时,必重新生成 makefile
     # FIXME: 如果此标志为真,但是此时关闭工作区,下次启动时不会重建 makefile
     self.isModified = False
     self.tranActive = False
     self.modifyTime = 0
     self.settings = None
     if fileName:
         try:
             self.doc = minidom.parse(fileName)
         except IOError:
             print 'Invalid fileName:', fileName
             raise IOError
         self.rootNode = XmlUtils.GetRoot(self.doc)
         self.name = XmlUtils.GetRoot(self.doc).getAttribute('Name')\
                 .encode('utf-8')
         self.fileName = os.path.abspath(fileName)  #绝对路径
         self.dirName, self.baseName = os.path.split(self.fileName)  #绝对路径
         self.modifyTime = Globals.GetFileModificationTime(fileName)
         self.settings = ProjectSettings(
             XmlUtils.FindFirstByTagName(self.rootNode, 'Settings'))
Пример #2
0
 def SetSettings(self, settings, autoSave=True):
     '''设置项目设置,并保存xml文件'''
     oldSettings = XmlUtils.FindFirstByTagName(XmlUtils.GetRoot(self.doc),
                                               'Settings')
     if oldSettings:
         oldSettings.parentNode.removeChild(oldSettings)
     XmlUtils.GetRoot(self.doc).appendChild(settings.ToXmlNode())
     if autoSave:
         self.DoSaveXmlFile()
     self.settings = settings
Пример #3
0
    def SetDependencies(self, deps, configuration):
        '''设置依赖

        deps: 依赖的项目名称列表
        configuration: 本依赖的名称'''
        # first try to locate the old node
        rootNode = XmlUtils.GetRoot(self.doc)
        for i in rootNode.childNodes:
            if i.nodeName == 'Dependencies' \
               and i.getAttribute('Name') == configuration:
                rootNode.removeChild(i)
                break

        # create new dependencies node
        node = self.doc.createElement('Dependencies')
        node.setAttribute('Name', configuration.decode('utf-8'))
        rootNode.appendChild(node)
        for i in deps:
            child = self.doc.createElement('Project')
            child.setAttribute('Name', i.decode('utf-8'))
            node.appendChild(child)

        # save changes
        self.DoSaveXmlFile()
        self.SetModified(True)
Пример #4
0
    def GetDependencies(self, configuration):
        '''返回依赖的项目的名称列表(构建顺序)'''
        result = []  # 依赖的项目名称列表
        # dependencies are located directly under the root level
        rootNode = XmlUtils.GetRoot(self.doc)
        if not rootNode:
            return result

        for i in rootNode.childNodes:
            if i.nodeName == 'Dependencies' \
               and i.getAttribute('Name') == configuration:
                # have found it
                for j in i.childNodes:
                    if j.nodeName == 'Project':
                        result.append(XmlUtils.ReadString(j, 'Name'))
                return result

        # if we are here, it means no match for the given configuration
        # return the default dependencies
        node = XmlUtils.FindFirstByTagName(rootNode, 'Dependencies')
        if node:
            for i in node.childNodes:
                if i.nodeName == 'Project':
                    result.append(XmlUtils.ReadString(i, 'Name'))
        return result
Пример #5
0
 def GetDescription(self):
     rootNode = XmlUtils.GetRoot(self.doc)
     if rootNode:
         node = XmlUtils.FindFirstByTagName(rootNode, 'Description')
         if node:
             return XmlUtils.GetNodeContent(node)
     return ''
Пример #6
0
 def SetGlobalSettings(self, globalSettings):
     settingsNode = XmlUtils.FindFirstByTagName(XmlUtils.GetRoot(self.doc),
                                                'Settings')
     oldSettings = XmlUtils.FindFirstByTagName(settingsNode,
                                               'GlobalSettings')
     if oldSettings:
         oldSettings.parentNode.removeChild(oldSettings)
     settingsNode.appendChild(globalSettings.ToXmlNode())
     self.DoSaveXmlFile()
     self.settings = ProjectSettings(settingsNode)
Пример #7
0
    def SetFiles(self, projectIns):
        '''copy files (and virtual directories) from src project to this project
        note that this call replaces the files that exists under this project'''
        # first remove all the virtual directories from this project
        # Remove virtual folders
        vdNode = XmlUtils.FindFirstByTagName(XmlUtils.GetRoot(self.doc),
                                             'VirtualDirectory')
        while vdNode:
            XmlUtils.GetRoot(self.doc).removeChild(vdNode)
            vdNode = XmlUtils.FindFirstByTagName(XmlUtils.GetRoot(self.doc),
                                                 'VirtualDirectory')

        # copy the virtual directories from the src project
        for i in XmlUtils.GetRoot(self.doc).childNodes:
            if i.nodeName == 'VirtualDirectory':
                # FIXME: deep?
                newNode = i.cloneNode(1)
                XmlUtils.GetRoot(self.doc).appendChild(newNode)

        self.DoSaveXmlFile()
Пример #8
0
    def __init__(self, fileName=''):
        self.doc = minidom.Document()
        self.rootNode = XmlUtils.GetRoot(self.doc)
        self.name = ''
        self.fileName = ''  # 绝对路径
        self.dirName = ''  # 绝对路径
        self.baseName = ''  # 项目文件名
        # 用于判断是否重新生成 makefile,此标志为真时,必重新生成 makefile
        # FIXME: 如果此标志为真,但是此时关闭工作区,下次启动时不会重建 makefile
        self.isModified = False
        self.tranActive = False
        self.modifyTime = 0
        self.settings = None

        self.version = 0

        if fileName:
            try:
                self.doc = minidom.parse(fileName)
            except IOError:
                print 'Invalid fileName:', fileName
                raise IOError
            self.rootNode = XmlUtils.GetRoot(self.doc)
            self.name = self.rootNode.getAttribute('Name').encode('utf-8')

            # 添加版本号
            if self.rootNode.hasAttribute('Version'):
                self.version = int(self.rootNode.getAttribute('Version'))

            # 绝对路径
            self.fileName = os.path.abspath(fileName)
            # NOTE: 还必须是真实路径
            self.fileName = os.path.realpath(self.fileName)
            self.dirName, self.baseName = os.path.split(self.fileName)  #绝对路径
            self.modifyTime = GetMTime(fileName)
            self.settings = ProjectSettings(
                XmlUtils.FindFirstByTagName(self.rootNode, 'Settings'))

            self._ConvertSettings()
            self._CleanupSettings()
Пример #9
0
 def GetAllFiles(self, absPath=False, projConfName=''):
     '''
     如果 projConfName 为空,返回结果会包含被忽略的文件,也就是全部文件
     如果 projConfName 非空,排除 projConfName 配置指定忽略的文件
     NOTE: 暂时只有在构建的时候才需要排除忽略的文件
     '''
     ignoredFiles = set()
     if projConfName:
         settings = self.GetSettings()
         bldConf = settings.GetBuildConfiguration(projConfName)
         if bldConf:
             ignoredFiles = bldConf.ignoredFiles.copy()
     if absPath:
         ds = DirSaver()
         os.chdir(self.dirName)
         files = self.GetFilesOfNode(XmlUtils.GetRoot(self.doc), True, '',
                                     ignoredFiles)
         #WSP_PATH_SEP + self.name)
     else:
         files = self.GetFilesOfNode(XmlUtils.GetRoot(self.doc), False, '',
                                     ignoredFiles)
         #WSP_PATH_SEP + self.name)
     return files
Пример #10
0
 def Save(self, fileName=''):
     self.tranActive = False
     if XmlUtils.GetRoot(self.doc):
         self.SetSettings(self.settings, False)
         self.DoSaveXmlFile(fileName)
Пример #11
0
 def GetProjectInternalType(self):
     return XmlUtils.GetRoot(self.doc).getAttribute('InternalType')
Пример #12
0
 def SetProjectInternalType(self, interType):
     XmlUtils.GetRoot(self.doc).setAttribute('InternalType',
                                             interType.decode('utf-8'))