示例#1
0
    def DeletePycFiles(self):
        """
        Tries to delete all pyc files from _projectPath, _rootFolders and thirdPartyFolders.
        However, __init__.pyc files are not removed.
        """
        # determine list of folders to search for pyc files
        folderList = []
        if self.context:
            folderList.extend(self.context.GetThirdPartyFolders())
            folderList.extend(self.context.GetRootFolders())

        # remove pyc files
        while len(folderList) > 0:
            newFolders = []
            for folder in folderList:
                pycFiles = [
                    csnUtility.NormalizePath(x)
                    for x in glob.glob("%s/*.pyc" % folder)
                ]
                for pycFile in pycFiles:
                    if not os.path.basename(pycFile) == "__init__.pyc":
                        os.remove(pycFile)

                newFolders.extend([
                    csnUtility.NormalizePath(os.path.dirname(x))
                    for x in glob.glob("%s/*/__init__.py" % folder)
                ])
            folderList = list(newFolders)
示例#2
0
    def ResolvePathsOfFilesToInstall(self, _skipCVS=1):
        """ 
        This function replaces relative paths and wildcards in self.filesToInstall with absolute paths without wildcards.
        Any folder is replaced by a complete list of the files in that folder.
        _skipCVS - If true, folders called CVS and .svn are automatically skipped. 
        """
        excludedFolderList = ("CVS", ".svn")
        for project in self.project.GetProjects(_recursive=1,
                                                _includeSelf=True):
            project.installManager.filesToInstallResolved = dict()
            for mode in ("Debug", "Release"):
                filesToInstall = dict()
                for location in project.installManager.filesToInstall[
                        mode].keys():
                    for dllPattern in project.installManager.filesToInstall[
                            mode][location]:
                        for tpfolder in self.project.context.GetThirdPartyBuildFolders(
                        ):
                            tpfolder += "/" + self.project.context.GetCompiler(
                            ).GetThirdPartySubFolder()
                            path = csnUtility.NormalizePath(dllPattern)
                            if not os.path.isabs(path):
                                path = "%s/%s" % (tpfolder, path)
                            for file in glob.glob(path):
                                if (os.path.basename(file)
                                        in excludedFolderList
                                    ) and _skipCVS and os.path.isdir(file):
                                    continue
                                if os.path.isdir(file):
                                    for folderFile in GlobDirectoryWalker.Walker(
                                            file, ["*"], excludedFolderList):
                                        if not os.path.isdir(folderFile):
                                            normalizedLocation = location + "/" + csnUtility.RemovePrefixFromPath(
                                                os.path.dirname(folderFile),
                                                file)
                                            normalizedLocation = csnUtility.NormalizePath(
                                                normalizedLocation)
                                            if not filesToInstall.has_key(
                                                    normalizedLocation):
                                                filesToInstall[
                                                    normalizedLocation] = []
                                            filesToInstall[
                                                normalizedLocation].append(
                                                    csnUtility.NormalizePath(
                                                        folderFile))
                                else:
                                    normalizedLocation = csnUtility.NormalizePath(
                                        location)
                                    if not filesToInstall.has_key(
                                            normalizedLocation):
                                        filesToInstall[normalizedLocation] = []
                                    filesToInstall[normalizedLocation].append(
                                        csnUtility.NormalizePath(file))

                project.installManager.filesToInstallResolved[
                    mode] = filesToInstall
示例#3
0
    def testNormalizePath(self):
        """ csnUtilityTests: test NormalizePath function. """
        refString = "c:/hallo"

        self.assertEqual(csnUtility.NormalizePath(""), ".")
        self.assertEqual(csnUtility.NormalizePath("."), ".")
        testString1 = "c:/hallo"
        self.assertEqual(csnUtility.NormalizePath(testString1), refString)
        testString2 = "c:\\hallo"
        self.assertEqual(csnUtility.NormalizePath(testString2), refString)
示例#4
0
 def FindAdditionalRootFolders(self):
     ''' Look for folders with the rootFolder.csnake file. '''
     result = []
     folder = csnUtility.NormalizePath(
         os.path.dirname(self.context.GetCsnakeFile()))
     previousFolder = ""
     while folder != previousFolder:
         if os.path.exists(
                 "%s/rootFolder.csnake" %
                 folder) and not folder in self.context.GetRootFolders():
             result.append(folder)
         previousFolder = folder
         folder = csnUtility.NormalizePath(os.path.split(folder)[0])
     return result
示例#5
0
    def Do(self, _project):
        # create folder if it does not exist
        if not os.path.exists(_project.context.GetKdevelopProjectFolder()):
            os.makedirs(_project.context.GetKdevelopProjectFolder())

        kdevelopProjectFolder = csnUtility.NormalizePath(
            _project.context.GetKdevelopProjectFolder())

        if not os.path.exists(self.__GetKDevelopProjectFilename(_project)):
            return

        # Postprocess "*.kdevelop.filelist" file (KDevelop filelist)

        f = open(self.__GetFilelistFilename(_project), 'w')
        for project in _project.dependenciesManager.ProjectsToUse():
            for source in project.GetSources():
                fileListItem = csnUtility.RemovePrefixFromPath(
                    source, kdevelopProjectFolder)
                fileListItem = csnUtility.NormalizePath(fileListItem)
                f.write(fileListItem + "/n")
        f.close()

        csnUtility.ReplaceDestinationFileIfDifferent(
            self.__GetFilelistFilename(_project),
            self.__GetFilelistFilename(_project, kdevelopProjectFolder))

        # Postprocess "*.kdevelop" file (KDevelop project)

        f = open(self.__GetKDevelopProjectFilename(_project), 'r')
        kdevelopProjectText = f.read()
        f.close()

        searchText = "<projectdirectory>%s" % _project.GetBuildFolder()
        replaceText = "<projectdirectory>%s" % kdevelopProjectFolder
        kdevelopProjectText = kdevelopProjectText.replace(
            searchText, replaceText)

        searchText = "<filelistdirectory>%s" % _project.GetBuildFolder()
        replaceText = "<filelistdirectory>%s" % kdevelopProjectFolder
        kdevelopProjectText = kdevelopProjectText.replace(
            searchText, replaceText)

        if csnUtility.FileToString(
                self.__GetKDevelopProjectFilename(
                    _project, kdevelopProjectFolder)) != kdevelopProjectText:
            f = open(
                self.__GetKDevelopProjectFilename(_project,
                                                  kdevelopProjectFolder), 'w')
            f.write(kdevelopProjectText)
            f.close()
示例#6
0
    def __init__(self,
                 name,
                 type,
                 sourceRootFolder=None,
                 categories=None,
                 context=None):
        # name
        self.name = name
        # type: dll, exe, tp
        self.type = type
        # source root folder
        if sourceRootFolder is None:
            sourceRootFolder = csnUtility.NormalizePath(
                os.path.dirname(FindFilename(1)))
        # categories: ~name
        self.categories = categories
        if self.categories is None:
            self.categories = []
        # context
        self.context = context

        # managers
        self.pathsManager = csnProjectPaths.Manager(self, sourceRootFolder)
        self.dependenciesManager = csnDependencies.Manager(self)
        self.installManager = csnInstall.Manager(self)
示例#7
0
def CilabModuleProject(_name, _type, _sourceRootFolder=None):
    if _sourceRootFolder is None:
        filename = csnProject.FindFilename(1)
        dirname = os.path.dirname(filename)
        _sourceRootFolder = csnUtility.NormalizePath(dirname,
                                                     _correctCase=False)
    return StandardModuleProject(_name=_name,
                                 _type=_type,
                                 _sourceRootFolder=_sourceRootFolder)
示例#8
0
    def __init__(self,
                 _name,
                 _type,
                 _sourceRootFolder=None,
                 _categories=None,
                 _context=None):
        """
        _type -- Type of the project, should be \"executable\", \"library\", \"dll\" or \"third party\".
        _name -- Name of the project, e.g. \"SampleApp\".
        _sourceRootFolder -- Folder used for locating source files for this project. If None, then the folder name is derived from 
        the call stack. For example, if this class' constructor is called in a file d:/users/me/csnMyProject.py, then d:/users/me 
        will be set as the source root folder.
        """
        if _sourceRootFolder is None:
            _sourceRootFolder = csnUtility.NormalizePath(
                os.path.dirname(FindFilename(1)))
        VeryGenericProject.__init__(self, _name, _type, _sourceRootFolder,
                                    _categories, _context)

        # TODO: Remove this code as soon as possible. This process should be done exclusively in the subclass for third parties.
        self.thirdPartyIndex = -1
        count = 0
        for folder in self.context.GetThirdPartyFolders():
            if csnUtility.IsSameFileOrDirectory(
                    folder, os.path.dirname(_sourceRootFolder)):
                self.thirdPartyIndex = count
                break
            count += 1
        if self.thirdPartyIndex < 0 and self.type == "third party":
            raise Exception(
                "Could not find any thirdparty folder for this project.")

        self.rules = dict()
        self.customCommands = []
        self.__compileManager = csnCompile.Manager(self)
        self.__compileManagerUpdates = list()
        self.installSubFolder = ""
        self.testsManager = csnTests.Manager(self)
        self.properties = []
        self.__postCMakeTasks = []
        self.listCmakeInsertBeforeTarget = list()
        self.listCmakeInsertAfterTarget = list()
        self.listCmakeInsertBeginning = list()

        for flag in globalCurrentContext.GetCompiler().GetCompileFlags():
            self.__compileManager.private.definitions.append(flag)

        # Function called before "ADD_LIBARRY"
        self.CMakeInsertBeforeTarget = new.instancemethod(
            SetCMakeInsertBeforeTarget, self)
        # Function called after "ADD_LIBARRY"
        self.CMakeInsertAfterTarget = new.instancemethod(
            SetCMakeInsertAfterTarget, self)
        # Function called at the beginning of the CMakeList
        self.CMakeInsertBeginning = new.instancemethod(SetCMakeInsertBeginning,
                                                       self)
示例#9
0
def GimiasPluginProject(_name, _sourceRootFolder=None):
    """
    This class is used to build a plugin coming from the CilabApps/Plugins folder. Use AddWidgetModules to add widget
    modules to the plugin.

    """
    if _sourceRootFolder is None:
        _sourceRootFolder = csnUtility.NormalizePath(
            os.path.dirname(csnProject.FindFilename(1)))
    pluginName = "GIMIAS%s" % _name
    project = csnProject.Project(_name,
                                 _type="dll",
                                 _sourceRootFolder=_sourceRootFolder,
                                 _categories=[pluginName])
    project.applicationsProject = None
    project.installSubFolder = "plugins/%s/lib" % _name
    project.AddIncludeFolders(["."])
    project.AddWidgetModules = new.instancemethod(
        _AddWidgetModulesMemberFunction, project)
    project.context.SetSuperSubCategory("Plugins", pluginName)

    # Windows debug
    installFolder = "%s/debug" % project.installSubFolder
    project.installManager.AddFilesToInstall(project.Glob("plugin.xml"),
                                             installFolder,
                                             _debugOnly=1,
                                             _WIN32=1)
    installFolder = installFolder + "/Filters/"
    project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"),
                                             installFolder,
                                             _debugOnly=1,
                                             _WIN32=1)

    # Windows release
    installFolder = "%s/release" % project.installSubFolder
    project.installManager.AddFilesToInstall(project.Glob("plugin.xml"),
                                             installFolder,
                                             _releaseOnly=1,
                                             _WIN32=1)
    installFolder = installFolder + "/Filters/"
    project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"),
                                             installFolder,
                                             _releaseOnly=1,
                                             _WIN32=1)

    # Linux
    project.installManager.AddFilesToInstall(project.Glob("plugin.xml"),
                                             project.installSubFolder,
                                             _NOT_WIN32=1)

    installFolder = project.installSubFolder + "/Filters"
    project.installManager.AddFilesToInstall(project.Glob("Filters/*.xml"),
                                             installFolder,
                                             _NOT_WIN32=1)

    return project
示例#10
0
def StandardModuleProject(_name, _type, _sourceRootFolder=None):
    if _sourceRootFolder is None:
        _sourceRootFolder = csnUtility.NormalizePath(
            os.path.dirname(csnProject.FindFilename(1)))

    project = csnProject.Project(_name, _type, _sourceRootFolder)
    project.applicationsProject = None
    project.AddLibraryModules = new.instancemethod(
        _AddLibraryModulesMemberFunction, project)
    project.AddApplications = new.instancemethod(
        _AddApplicationsMemberFunction, project)
    return project
示例#11
0
    def AddTests(self,
                 listOfTests,
                 _cxxTestProject,
                 _enableWxWidgets=0,
                 _dependencies=None,
                 _pch=""):
        """
        _cxxTestProject -- May be the cxxTest project instance, or a function returning a cxxTest project instance.
        listOfTests -- List of source files containing cxx test classes.
        """
        cxxTestProject = csnProject.ToProject(_cxxTestProject)

        if self.testProject is None:
            self.__CreateTestProject(cxxTestProject, _enableWxWidgets)

        for test in listOfTests:
            absPathToTest = self.testProject.pathsManager.PrependRootFolderToRelativePath(
                test)
            self.testProject.AddSources([absPathToTest], _checkExists=0)

        wxRunnerArg = None
        if _enableWxWidgets:
            wxRunnerArg = "--template \"%s\"" % (csnUtility.GetRootOfCSnake() +
                                                 "/resources/wxRunner.tpl")
        else:
            wxRunnerArg = "--template \"%s\"" % (
                csnUtility.GetRootOfCSnake() + "/resources/%s" %
                self.testProject.context.GetTestRunnerTemplate())

        pythonScript = "%s/CxxTest/cxxtestgen.py" % cxxTestProject.GetSourceRootFolder(
        )
        command = "\"%s\" \"%s\" %s --have-eh --error-printer -o \"%s\" " % (
            csnUtility.NormalizePath(self.testProject.context.GetPythonPath()),
            pythonScript, wxRunnerArg, self.testRunnerSourceFile)
        depends = []
        for source in self.testProject.GetSources():
            if os.path.splitext(source)[1] in (".h", ".hpp"):
                depends.append('"%s"' % source)
                command += ' "%s"' % source
        self.testProject.AddRule("Create test runner",
                                 self.testRunnerSourceFile, command, depends)
        self.testProject.AddCMakeInsertAfterTarget(CustomCMakeLinesTest,
                                                   self.testProject)
        self.holdingProject.AddCMakeInsertBeginning(
            CustomCMakeLinesTestHoldingProject, self.holdingProject)
        self.testProject.AddLibraries(["DelayImp"], _WIN32=1)

        if not _dependencies is None:
            self.testProject.AddProjects(_dependencies)

        if (_pch != ""):
            self.testProject.SetPrecompiledHeader(_pch)
示例#12
0
 def CreateThirdPartyProject(self, name, sourceRootFolder = None):
     """
     Creates a new third party project (project that has its source in one of the third party source folders
     and that is compiled using a custom "CMakeLists.txt" file rather than CSnake files. The CSnake project returned
     by this function can then be used to point dependent projects to the config- and use-file of this third party
     project, so other projects are able to use the libraries.
     """
     if sourceRootFolder is None:
         filename = csnProject.FindFilename(1)
         dirname = os.path.dirname(filename)
         sourceRootFolder = csnUtility.NormalizePath(dirname, _correctCase = False)
     project = ThirdPartyProject(name, csnProject.globalCurrentContext, sourceRootFolder)
     return self.__thirdPartyProjectConstructor(project, self.__version)
 def __init__(self, _name, _type, _sourceRootFolder=None, _categories=None):
     if _sourceRootFolder is None:
         filename = csnProject.FindFilename(1)
         dirname = os.path.dirname(filename)
         _sourceRootFolder = csnUtility.NormalizePath(dirname,
                                                      _correctCase=False)
     GenericProject.__init__(self,
                             _name=_name,
                             _type=_type,
                             _sourceRootFolder=_sourceRootFolder,
                             _categories=_categories,
                             _context=csnProject.globalCurrentContext)
     self.applicationsProject = None
示例#14
0
 def CreateStandardModuleProject(self, name, projectType, sourceRootFolder = None, categories = None, showInProjectTree = False):
     """
     Creates a compiled project (see "CreateCompiledProject") with the additional modules "AddApplications" and "AddLibraryModules".
     """
     if sourceRootFolder is None:
         filename = csnProject.FindFilename(1)
         dirname = os.path.dirname(filename)
         sourceRootFolder = csnUtility.NormalizePath(dirname, _correctCase = False)
     if categories:
         showInProjectTree = True
     project = StandardModuleProject(name, projectType, sourceRootFolder, [name] if showInProjectTree else None)
     if categories:
         superCategory = " / ".join(categories)
         project.context.SetSuperSubCategory(superCategory, name)
     return self.__standardModuleProjectConstructor(project, self.__version)
示例#15
0
    def __FindPath(self, _path):
        """ 
        Tries to locate _path as an absolute path or as a path relative to self.sourceRootFolder. 
        Returns an absolute path, containing only forward slashes.
        Throws IOError if path was not found.
        """
        path = os.path.normpath(_path)
        if not os.path.isabs(path):
            path = os.path.abspath("%s/%s" %
                                   (self.project.GetSourceRootFolder(), path))
        if not os.path.exists(path):
            raise IOError, "Path file not found %s (tried %s)" % (_path, path)

        path = csnUtility.NormalizePath(path)
        return path
示例#16
0
    def __init__(self, name, context, sourceRootFolder=None):
        if sourceRootFolder is None:
            sourceRootFolder = csnUtility.NormalizePath(
                os.path.dirname(FindFilename(1)))
        VeryGenericProject.__init__(self, name, "third party",
                                    sourceRootFolder, None, context)

        # Get the thirdPartyBuildFolder index
        self.thirdPartyIndex = -1
        count = 0
        for folder in self.context.GetThirdPartyFolders():
            if csnUtility.IsSameFileOrDirectory(
                    folder, os.path.dirname(sourceRootFolder)):
                self.thirdPartyIndex = count
                break
            count += 1
        if self.thirdPartyIndex < 0:
            raise Exception(
                "Could not find any thirdparty folder for this project.")
示例#17
0
def CommandLinePlugin(_name, _holderProject=None):
    """ Create a command line plugin project. """
    _sourceRootFolder = csnUtility.NormalizePath(
        os.path.dirname(csnProject.FindFilename(1)))

    # command line lib
    projectLibName = "%sLib" % _name
    projectLib = csnProject.Project(projectLibName, "dll", _sourceRootFolder)
    #project = CilabModuleProject(projectName, "dll", _sourceRootFolder)
    projectLib.AddDefinitions(["-Dmain=ModuleEntryPoint"], _private=1)
    projectLib.installSubFolder = "commandLinePlugins"
    projectLib.CMakeInsertBeforeTarget = new.instancemethod(
        CreateCMakeCLPPre, projectLib)
    projectLib.CMakeInsertAfterTarget = new.instancemethod(
        CreateCMakeCLPPost, projectLib)

    # command line executable
    projectAppName = _name
    projectApp = csnBuild.Project(projectAppName, "executable",
                                  _sourceRootFolder)
    projectApp.AddProjects([projectLib])
    projectApp.installSubFolder = "commandLinePlugins"
    # wrapper for shared libraries
    wrapperSourceFile = None
    for thirdParty in csnProject.globalCurrentContext.GetThirdPartyFolders():
        currentWrapperSourceFile = u'%s/SLICER/Slicer3/Applications/CLI/Templates/CommandLineSharedLibraryWrapper.cxx' % thirdParty
        if os.path.isfile(currentWrapperSourceFile):
            wrapperSourceFile = currentWrapperSourceFile
    if wrapperSourceFile is None:
        raise Exception(
            "Could not find Slicer template in your thirdParty folders.")
    projectApp.AddSources([wrapperSourceFile])

    # force the creation of the application project
    projectLib.AddProjects([projectApp], _dependency=0)

    if not (_holderProject is None):
        _holderProject.AddProjects([projectLib])

    return projectLib
示例#18
0
 def CreateCompiledProject(self, name, projectType, sourceRootFolder = None, categories = None, showInProjectTree = False):
     """
     Creates a compiled project.
     name - Project name
     projectType - Type of the project: Can be "executable", "library" or "dll".
     sourceRootFolder - The main folder of the library (many subsequent operations take subdirectory parameters relative
                        to this directory); if None, the location of the CSnake file calling this function is used.
     categories - Hierarchy of categories for the project tree of the "Select Projects" tab
     showInProjectTree - If True, the project will be shown in the project tree of the "Select Projects" tab (if there
                         is a connection between the selected instance and this project) and can be deselected (if the
                         selected instance doesn't depend on this project). If False, the project is always compiled, if
                         there is a connection between the selected instance and this project.
     """
     if sourceRootFolder is None:
         filename = csnProject.FindFilename(1)
         dirname = os.path.dirname(filename)
         sourceRootFolder = csnUtility.NormalizePath(dirname, _correctCase = False)
     if categories:
         showInProjectTree = True
     project = GenericProject(name, projectType, sourceRootFolder, [name] if showInProjectTree else None, _context=csnProject.globalCurrentContext)
     if categories:
         superCategory = " / ".join(categories)
         project.context.SetSuperSubCategory(superCategory, name)
     return self.__genericProjectConstructor(project, self.__version)
示例#19
0
def Executable(_name, _sourceRootFolder=None, _categories=None):
    if _sourceRootFolder is None:
        _sourceRootFolder = csnUtility.NormalizePath(
            os.path.dirname(FindFilename(1)))
    return Project(_name, "executable", _sourceRootFolder, _categories)
示例#20
0
def Project(_name, _type, _sourceRootFolder=None, _categories=None):
    if _sourceRootFolder is None:
        _sourceRootFolder = csnUtility.NormalizePath(
            os.path.dirname(FindFilename(1)))
    return globalCurrentContext.CreateProject(_name, _type, _sourceRootFolder,
                                              _categories)
示例#21
0
import csnProject
import csnUtility

import os.path
import inspect

import csnVisualStudio2003
import csnVisualStudio2005
import csnVisualStudio2008
if csnBuild.version < 2.22:
    import csnVisualStudio2008x64


# Used to configure gimias
def CreateGIMIAS():

    gimias = csnCilab.CilabModuleProject("Gimias", "executable")
    gimias.AddSources(gimias.Glob("GUI/MainApp/src/*.h"), _checkExists=1)
    gimias.AddSources(gimias.Glob("GUI/MainApp/src/*.cxx"), _checkExists=1)
    gimias.SetPrecompiledHeader("GUI/MainApp/gmMainAppPCH.h")
    gimias.AddIncludeFolders([gimias.GetBuildFolder()])

    return gimias


commandLinePlugins = csnProject.Project(
    "CommandLinePlugins",
    "container",
    csnUtility.NormalizePath(os.path.dirname(inspect.stack()[1][1])),
    _categories=["GIMIASCommandLinePlugins"])
示例#22
0
 def FindSourceRootFolder(self, level = 0):
     """
     Find the folder containing the CSnake file that is (directly or indirectly) calling this function.
     level - see function FindScriptFilename
     """
     return csnUtility.NormalizePath(os.path.dirname(csnProject.FindFilename(1+level)))
示例#23
0
 def GetControlValue(self):
     controlValue = self.control.GetValue()
     if controlValue != "" and FilenameLabel() in self.labels:
         controlValue = csnUtility.NormalizePath(controlValue)
     return controlValue