示例#1
0
 def FindScriptFilename(self, level = 0):
     """
     Find the filename of the source code that is (directly or indirectly) calling this function.
     level - 0: Find filename of the script calling FindScriptFilename (default),
             1: Find filename of the script calling the function that calls FindScriptFilename,
             x: Find filename of the script calling FindScriptFilename indirectly through x+1 function calls
     """
     return csnProject.FindFilename(1+level)
示例#2
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)
示例#3
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
示例#4
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
示例#5
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
示例#7
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)
示例#8
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
示例#9
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)
示例#10
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)))