コード例 #1
0
ファイル: WinSCP.py プロジェクト: hjkuijf/communitymodules
def _procFinished(proc):
  global _processes  
  
  MLABFileManager.remove(_processes[proc])
  del _processes[proc]
  
  if len(_processes) == 0:
    ctx.field("transferring").value = 0
    ctx.field("finished").touch()
コード例 #2
0
def _procFinished(proc):
  global _processes  
  
  MLABFileManager.remove(_processes[proc])
  del _processes[proc]
  
  if len(_processes) == 0:
    ctx.field("transferring").value = 0
    ctx.field("finished").touch()
コード例 #3
0
 def save(self,filename=""):
   if not self._excel:
     return
   
   if self._options['commas']:
     self._excel = self._excel.replace(".",",")
 
   if not filename:
     filename = ctx.type() + "-" + datetime.date.today().strftime("%Y-%m-%d")
   file = MLABFileDialog.getSaveFileName(MLABFileManager.getHomeDir() + "/" + filename + ".csv","Excel files (*.csv)","Save file")
   if file:
     MLABFileManager.writeStringToFile(file,self._excel)
コード例 #4
0
def filenameChanged(field=None):
  filename = ctx.expandFilename(ctx.field("filename").stringValue())
  if MLABFileManager.exists(filename):
    if MLABFileManager.isDir(filename):
      MLAB.logWarning("LocalAnalyzeLoad.filename - File is a directory (" + filename + ")")
    else:
      ctx.field("AnalyzeHeader.filename").setStringValue(filename)
  else:
    if not filename == "":
      MLAB.logWarning("LocalAnalyzeLoad.filename - File does not exist (" + filename + ")")
    ctx.field("AnalyzeHeader.filename").setStringValue("")
    
  parseFile(filename)
コード例 #5
0
def DataPathChanged():
    print("DataPath changed")
    exp = ctx.field("DataPath").stringValue()
    if MLABFileManager.exists(ctx.expandFilename(exp)):
        updateData()
    else:
        fileDialog()
コード例 #6
0
def selectPresentation(field=None):
    presentation = ctx.field("presentation").stringValue()
    header = ""
    footer = ""
    module = ""
    style = ""

    if presentation:
        config = MLABFileManager.readStringFromFile(
            _presentations[presentation] + "config").split("\n")
        for line in config:
            parts = line.split("=")
            if not len(parts) == 2: continue

            tag = parts[0].strip()
            value = parts[1].strip()

            if tag == "HEADER":
                header = value
            elif tag == "FOOTER":
                footer = value
            elif tag == "STYLE":
                if _styles.has_key(value):
                    style = value
            elif tag == "MODULE":
                module = value

    ctx.field("header").setStringValue(header)
    ctx.field("footer").setStringValue(footer)
    ctx.field("module").setStringValue(module)
    ctx.field("style").setStringValue(style)

    selectStyle()
コード例 #7
0
ファイル: WinSCP.py プロジェクト: hjkuijf/communitymodules
def upload(field=None):
  sources = ctx.field("sources").stringValue().split("\n")
  target = ctx.field("target").stringValue()
  
  if not sources or not target:
    return
    
  if not target[-1] == "/":
    target += "/"    
  
  winsources = []
  for source in sources:
    winsources.append(MLABFileManager.nativePath(source))
    
  script  = _getScript()    
  commands = ctx.field("preCommand").stringValue().split(";")
  for command in commands:
    if command:
      script += command + "\n"
  script += "put \"" + "\" \"".join(winsources) + "\" \"" + target + "\"\n"
  commands = ctx.field("postCommand").stringValue().split(";")
  for command in commands:
    if command:
      script += command + "\n"
  script += "close\nexit\n"
    
  _executeScript(script)
コード例 #8
0
def AtlasPathChanged():
    print("atlaspath changed")
    exp = ctx.field("AtlasPath").stringValue()
    if MLABFileManager.exists(ctx.expandFilename(exp)):
        updateAtlas()
    else:
        fileDialog()
コード例 #9
0
def updateAtlas(newWeek=None):

    if MLABFileManager.exists(ctx.expandFilename(
            ctx.field("AtlasPath").value)):
        for file in os.listdir(ctx.expandFilename(
                ctx.field("AtlasPath").value)):
            if file.endswith(".nii.gz"):
                if not "parc" in file and not "LogicalMask" in file:
                    if "STA%i" % ctx.field("currentWeek").value in file:
                        print(
                            os.path.join(
                                ctx.expandFilename(
                                    ctx.field("AtlasPath").value), file))
                        ctx.field(
                            "itkImageFileReader.fileName").setStringValue(
                                os.path.join(
                                    ctx.expandFilename(
                                        ctx.field("AtlasPath").value), file))
                if "LogicalMask" in file:
                    if "STA%i" % ctx.field("currentWeek").value in file:
                        ctx.field(
                            "itkImageFileReaderMask.fileName").setStringValue(
                                os.path.join(
                                    ctx.expandFilename(
                                        ctx.field("AtlasPath").value), file))
    else:
        AtlasPathChanged()
コード例 #10
0
def upload(field=None):
  sources = ctx.field("sources").stringValue().split("\n")
  target = ctx.field("target").stringValue()
  
  if not sources or not target:
    return
    
  if not target[-1] == "/":
    target += "/"    
  
  winsources = []
  for source in sources:
    winsources.append(MLABFileManager.nativePath(source))
    
  script  = _getScript()    
  commands = ctx.field("preCommand").stringValue().split(";")
  for command in commands:
    if command:
      script += command + "\n"
  script += "put \"" + "\" \"".join(winsources) + "\" \"" + target + "\"\n"
  commands = ctx.field("postCommand").stringValue().split(";")
  for command in commands:
    if command:
      script += command + "\n"
  script += "close\nexit\n"
    
  _executeScript(script)
コード例 #11
0
def selectPresentation(field=None):
  presentation = ctx.field("presentation").stringValue()
  header = ""
  footer = ""
  module = ""
  style = ""
  
  if presentation:
    config = MLABFileManager.readStringFromFile(_presentations[presentation] + "config").split("\n")
    for line in config:
      parts = line.split("=")
      if not len(parts) == 2: continue
        
      tag = parts[0].strip()
      value = parts[1].strip()
      
      if tag == "HEADER":
        header = value
      elif tag == "FOOTER":
        footer = value
      elif tag == "STYLE":
        if _styles.has_key(value):
          style = value
      elif tag == "MODULE":
        module = value    
  
  ctx.field("header").setStringValue(header)
  ctx.field("footer").setStringValue(footer)
  ctx.field("module").setStringValue(module)
  ctx.field("style").setStringValue(style)
  
  selectStyle()
コード例 #12
0
def filenameChanged(field=None):
    filename = ctx.expandFilename(ctx.field("filename").stringValue())
    if MLABFileManager.exists(filename):
        if MLABFileManager.isDir(filename):
            MLAB.logWarning(
                "LocalAnalyzeLoad.filename - File is a directory (" +
                filename + ")")
        else:
            ctx.field("AnalyzeHeader.filename").setStringValue(filename)
    else:
        if not filename == "":
            MLAB.logWarning(
                "LocalAnalyzeLoad.filename - File does not exist (" +
                filename + ")")
        ctx.field("AnalyzeHeader.filename").setStringValue("")

    parseFile(filename)
コード例 #13
0
def initialize(field=None):
    global _styles
    _styles = {}

    cb = ctx.control("styles")
    cb.clearItems()
    cb.insertItem("")

    stylePath = ctx.localPath() + "/Styles/"

    contents = MLABFileManager.contentOfDirectory(stylePath)
    for file in contents:
        if MLABFileManager.isDir(stylePath + file):
            if MLABFileManager.exists(stylePath + file + "/style") and \
               MLABFileManager.exists(stylePath + file + "/tags") and \
               MLABFileManager.exists(stylePath + file + "/template") and \
               MLABFileManager.exists(stylePath + file + "/style.png"):

                cb.insertItem(file)
                _styles[file] = stylePath + file + "/"

    if _styles:
        cb.setCurrentItem(0)
        ctx.field("style").setStringValue(cb.currentText())
        selectStyle()

    global _presentations
    _presentations = {}

    cb = ctx.control("presentations")
    cb.clearItems()
    cb.insertItem("")

    presentationsPath = ctx.localPath() + "/Presentations/"
    contents = MLABFileManager.contentOfDirectory(presentationsPath)
    for file in contents:
        if MLABFileManager.isDir(presentationsPath + file):
            if MLABFileManager.exists(presentationsPath + file + "/config") and \
               MLABFileManager.exists(presentationsPath + file + "/slides"):

                cb.insertItem(file)
                _presentations[file] = presentationsPath + file + "/"
コード例 #14
0
def initialize(field=None):  
  global _styles
  _styles = {}
  
  cb = ctx.control("styles")
  cb.clearItems()
  cb.insertItem("")
  
  stylePath = ctx.localPath() + "/Styles/"
  
  contents = MLABFileManager.contentOfDirectory(stylePath)
  for file in contents:
    if MLABFileManager.isDir(stylePath + file):
      if MLABFileManager.exists(stylePath + file + "/style") and \
         MLABFileManager.exists(stylePath + file + "/tags") and \
         MLABFileManager.exists(stylePath + file + "/template") and \
         MLABFileManager.exists(stylePath + file + "/style.png"):
         
        cb.insertItem(file)
        _styles[file] = stylePath + file + "/"
        
  if _styles:
    cb.setCurrentItem(0)
    ctx.field("style").setStringValue(cb.currentText())
    selectStyle()
    
  global _presentations
  _presentations = {}
  
  cb = ctx.control("presentations")
  cb.clearItems()
  cb.insertItem("")
  
  presentationsPath = ctx.localPath() + "/Presentations/"
  contents = MLABFileManager.contentOfDirectory(presentationsPath)
  for file in contents:
    if MLABFileManager.isDir(presentationsPath + file):
      if MLABFileManager.exists(presentationsPath + file + "/config") and \
         MLABFileManager.exists(presentationsPath + file + "/slides"):
         
        cb.insertItem(file)        
        _presentations[file] = presentationsPath + file + "/"
コード例 #15
0
def _executeScript(script):
  tmp = MLABFileManager.getTmpDir()
  if not tmp[-1] == "/":
    tmp += "/"
  now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  
  file = MLABFileManager.getUniqueFilename(tmp,now,".scp")
  MLABFileManager.writeStringToFile(file,script)
  
  winscp = ctx.expandFilename("$(LOCAL)/winscp416.exe")
  
  cmd = "\"" + winscp + "\" /script=\"" + file + "\""
  
  proc = MLAB.newProcess()
  proc.addArgument(cmd)
  proc.setStdOutHandler(ctx,"_procStdOut")
  proc.setStdErrHandler(ctx,"_procStdErr")
  proc.setExitedHandler(ctx,"_procFinished")
  
  global _processes
  _processes[proc] = file
  
  proc.run()
コード例 #16
0
ファイル: WinSCP.py プロジェクト: hjkuijf/communitymodules
def _executeScript(script):
  tmp = MLABFileManager.getTmpDir()
  if not tmp[-1] == "/":
    tmp += "/"
  now = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  
  file = MLABFileManager.getUniqueFilename(tmp,now,".scp")
  MLABFileManager.writeStringToFile(file,script)
  
  winscp = ctx.expandFilename("$(LOCAL)/winscp416.exe")
  
  cmd = "\"" + winscp + "\" /script=\"" + file + "\""
  
  proc = MLAB.newProcess()
  proc.addArgument(cmd)
  proc.setStdOutHandler(ctx,"_procStdOut")
  proc.setStdErrHandler(ctx,"_procStdErr")
  proc.setExitedHandler(ctx,"_procFinished")
  
  global _processes
  _processes[proc] = file
  
  proc.run()
コード例 #17
0
def download(field=None):
  sources = ctx.field("sources").stringValue().split("\n")
  target = ctx.field("target").stringValue()
  
  if not sources or not target:
    return
  
  ctx.field("transferring").value = 1
    
  if not target[-1] == "\\":
     target += "\\"
  target = MLABFileManager.nativePath(target)
     
  for source in sources:
    script  = _getScript()
    script += "get \"" + source + "\" \"" + target + "\"\n"
    script += "close\nexit\n"
    
    _executeScript(script)
コード例 #18
0
ファイル: WinSCP.py プロジェクト: hjkuijf/communitymodules
def download(field=None):
  sources = ctx.field("sources").stringValue().split("\n")
  target = ctx.field("target").stringValue()
  
  if not sources or not target:
    return
  
  ctx.field("transferring").value = 1
    
  if not target[-1] == "\\":
     target += "\\"
  target = MLABFileManager.nativePath(target)
     
  for source in sources:
    script  = _getScript()
    script += "get \"" + source + "\" \"" + target + "\"\n"
    script += "close\nexit\n"
    
    _executeScript(script)
コード例 #19
0
ファイル: WinSCP.py プロジェクト: hjkuijf/communitymodules
def clean(field=None):
  MLABFileManager.recursiveRemoveDir(ctx.field("target").stringValue())
コード例 #20
0
def buildPresentation():

  #set style
  style = ctx.field("style").stringValue()
  
  # check/delete module path
  localPath = ctx.localPath() + "/"
  stylePath = localPath + "Styles/" + style
  contentPath = localPath + "Presentations/" + ctx.field("presentation").stringValue()
  moduleName = ctx.field("module").stringValue()
  modulePath = localPath + "/Generated/" + moduleName
  
  # create directories
  MLABFileManager.mkdir(modulePath)
  MLABFileManager.mkdir(modulePath + "/style")
  MLABFileManager.mkdir(modulePath + "/data")
  MLABFileManager.mkdir(modulePath + "/macros")
  MLABFileManager.mkdir(modulePath + "/scripts")
  
  slashRe = re.compile('(.*?)[\/]{3,}',re.DOTALL)
    
  #parse style.script
  global _styleTags
  _styleTags = {}
  
  if MLABFileManager.exists(stylePath + "/tags"):
    tagRe = re.compile('\[(.*?)\]\s*=\s*(.*)',re.DOTALL)
    content = MLABFileManager.readStringFromFile(stylePath + "/tags")
    matches = slashRe.findall(content)
    for styleTag in matches:
      if styleTag == "": continue
      tagMatches = tagRe.findall(styleTag)      
      _styleTags[tagMatches[0][0]] = tagMatches[0][1]
      
  # generate content: slides
  global _slideBullets
  _slideBullets = {}
  global _slideNames
  _slideNames = []
  global _slideModules
  _slideModules = {}  
  
  slides = ""
  if MLABFileManager.exists(contentPath + "/slides"):
    content = MLABFileManager.readStringFromFile(contentPath + "/slides")
    matches = slashRe.findall(content)
    count = 0
    for slide in matches:
      if slide == "": continue
      result = parseSlide(slide,count+1)
      if not result == "":
        count += 1
        slides += result
    
  # generate content: menu
  menu = ""
  if MLABFileManager.exists(contentPath + "/menu"):
    content = MLABFileManager.readStringFromFile(contentPath + "/menu")
    menuRe = re.compile('(.*?)[\/]+',re.DOTALL)
    matches = menuRe.findall(content)
    for menuItem in matches:
      if menuItem == "": continue
      menu += parseMenuItem(menuItem)
    
  # generate def file
  defFile = "MacroModule " + moduleName + " { externalDefinition = $(LOCAL)/" + moduleName + ".script }" 
  MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".def",defFile)
  
  # copy py file
  MLABFileManager.copy(localPath + "template_py",modulePath + "/" + moduleName + ".py")
  
  # load styles
  styleFile = MLABFileManager.readStringFromFile(stylePath + "/style")
  styleRe = re.compile('DefineStyle\s*(.*?)\s*\{(.*?)[\/]{3,}',re.DOTALL)  
  styles = styleRe.findall(styleFile)
  
  # process slideBullets
  for i in range(len(styles)):
    styleName = styles[i][0].strip()
    styleDef = styles[i][1].strip()    
    for k,v in _slideBullets.iteritems():
      for i in range(len(v)):
        _slideBullets[k][i] = _slideBullets[k][i].replace("style = " + styleName,"style { " + styleDef)
        _slideBullets[k][i] = _slideBullets[k][i].replace("\n"," ")

  sources = ""
  # write slideBullets file
  if len(_slideBullets):
    bulletFile = "_bullets = {\n"
    num = 0
    for k,v in _slideBullets.iteritems():
      if num > 0:
        bulletFile += ","
      bulletFile += "'" + `k` + "':['" + "','".join(v) + "']\n"
      num = num + 1
    bulletFile += "}"
    sources += "source = $(LOCAL)/scripts/bullets.py\n"
    MLABFileManager.writeStringToFile(modulePath + "/scripts/bullets.py",bulletFile)
  
  # process script file -> replace content tags
  scriptFile = MLABFileManager.readStringFromFile(stylePath + "/template")
  scriptFile = scriptFile.replace("template.py",moduleName + ".py")  
  files = MLABFileManager.recursiveContentOfDirectory(contentPath + "/scripts")
  for file in files:
    if not file == "":
      sources += "source = $(LOCAL)/scripts/" + file.strip() + "\n"
      
  # print sources
  if not sources == "":
    scriptFile = scriptFile.replace("Commands {","Commands {\n" + sources)       
  scriptFile = scriptFile.replace("[HEADER]","\"" + ctx.field("header").stringValue() + "\"")
  scriptFile = scriptFile.replace("[FOOTER]","\"" + ctx.field("footer").stringValue() + "\"")
  scriptFile = scriptFile.replace("[MENU]",menu)
  scriptFile = scriptFile.replace("[SLIDES]",slides)
  
  # process script file -> replace style tags
  for i in range(len(styles)):
    styleName = styles[i][0].strip()
    style = styles[i][1].strip()    
    scriptFile = scriptFile.replace("style = " + styleName,"style { " + style)
  
  # write script file  
  MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".script",scriptFile)
  
  # copy style data from stylePath
  styleDataPath = stylePath + "/data/"
  if MLABFileManager.exists(styleDataPath):
    
    files = MLABFileManager.recursiveContentOfDirectory(styleDataPath)
    for file in files:
      if MLABFileManager.isDir(styleDataPath + file):
        MLABFileManager.mkdir(modulePath + "/style/" + file)
      else:
        MLABFileManager.copy(styleDataPath + file,modulePath + "/style/" + file)
  else:
    print(styleDataPath)
    
  # write .mlab file for module
  # write .def and .script files for used modules
  mlabFile = "//MDL v1 utf8\n network {\n watchlist = \"\"\n}\n"
  for k,v in _slideModules.iteritems():
    macro = k.strip()
    mlabFile += "module " + macro + " {\n fields {\n  instanceName = " + macro + "\n }\n internalFields = \"\"\n}\n"
    
    defFile = "MacroModule " + macro + " { externalDefinition = $(LOCAL)/" + macro + ".script }"
    scriptFile = "Interface { Inputs {} Outputs {} Parameters {} } Commands { }"

    MLABFileManager.writeStringToFile(modulePath + "/macros/" + macro + ".def",defFile)
    MLABFileManager.writeStringToFile(modulePath + "/macros/" + macro + ".script",scriptFile)  
    
  mlabFile += "connections = \"\"\n"
  
  MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".mlab",mlabFile)
      
  # copy data, macros, networks, scripts, etc from contentPath
  files = MLABFileManager.recursiveContentOfDirectory(contentPath)
  extRE = re.compile('(\.dcm|\.tiff|\.tif|\.avi)')
  for file in files:
    if file == "slides": continue
    if file == "menu": continue
    if file == "config": continue
    if MLABFileManager.isDir(contentPath + "/" + file):
      if not MLABFileManager.exists(modulePath + "/" + file):
        MLABFileManager.mkdir(modulePath + "/" + file)
    else:
      if not MLABFileManager.exists(modulePath + "/" + file):
        MLABFileManager.copy(contentPath + "/" + file,modulePath + "/" + file)
      else:
        if not len(extRE.findall(file)):
          MLABFileManager.copy(contentPath + "/" + file,modulePath + "/" + file)
コード例 #21
0
def clean(field=None):
  MLABFileManager.recursiveRemoveDir(ctx.field("target").stringValue())
コード例 #22
0
def ShowEatDicomOptions():
  MLAB.runCommandInConsole(MLABFileManager.getExecutable("eatDicom"), ["-help"], "", "", "Dicom Import Options Help", ctx.window());
コード例 #23
0
def ShowEatDicomOptions():
  MLAB.runCommandInConsole(MLABFileManager.getExecutable("eatDicom"), ["-help"], "", "", "Dicom Import Options Help", ctx.window())
コード例 #24
0
def buildPresentation():

    #set style
    style = ctx.field("style").stringValue()

    # check/delete module path
    localPath = ctx.localPath() + "/"
    stylePath = localPath + "Styles/" + style
    contentPath = localPath + "Presentations/" + ctx.field(
        "presentation").stringValue()
    moduleName = ctx.field("module").stringValue()
    modulePath = localPath + "/Generated/" + moduleName

    # create directories
    MLABFileManager.mkdir(modulePath)
    MLABFileManager.mkdir(modulePath + "/style")
    MLABFileManager.mkdir(modulePath + "/data")
    MLABFileManager.mkdir(modulePath + "/macros")
    MLABFileManager.mkdir(modulePath + "/scripts")

    slashRe = re.compile('(.*?)[\/]{3,}', re.DOTALL)

    #parse style.script
    global _styleTags
    _styleTags = {}

    if MLABFileManager.exists(stylePath + "/tags"):
        tagRe = re.compile('\[(.*?)\]\s*=\s*(.*)', re.DOTALL)
        content = MLABFileManager.readStringFromFile(stylePath + "/tags")
        matches = slashRe.findall(content)
        for styleTag in matches:
            if styleTag == "": continue
            tagMatches = tagRe.findall(styleTag)
            _styleTags[tagMatches[0][0]] = tagMatches[0][1]

    # generate content: slides
    global _slideBullets
    _slideBullets = {}
    global _slideNames
    _slideNames = []
    global _slideModules
    _slideModules = {}

    slides = ""
    if MLABFileManager.exists(contentPath + "/slides"):
        content = MLABFileManager.readStringFromFile(contentPath + "/slides")
        matches = slashRe.findall(content)
        count = 0
        for slide in matches:
            if slide == "": continue
            result = parseSlide(slide, count + 1)
            if not result == "":
                count += 1
                slides += result

    # generate content: menu
    menu = ""
    if MLABFileManager.exists(contentPath + "/menu"):
        content = MLABFileManager.readStringFromFile(contentPath + "/menu")
        menuRe = re.compile('(.*?)[\/]+', re.DOTALL)
        matches = menuRe.findall(content)
        for menuItem in matches:
            if menuItem == "": continue
            menu += parseMenuItem(menuItem)

    # generate def file
    defFile = "MacroModule " + moduleName + " { externalDefinition = $(LOCAL)/" + moduleName + ".script }"
    MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".def",
                                      defFile)

    # copy py file
    MLABFileManager.copy(localPath + "template_py",
                         modulePath + "/" + moduleName + ".py")

    # load styles
    styleFile = MLABFileManager.readStringFromFile(stylePath + "/style")
    styleRe = re.compile('DefineStyle\s*(.*?)\s*\{(.*?)[\/]{3,}', re.DOTALL)
    styles = styleRe.findall(styleFile)

    # process slideBullets
    for i in range(len(styles)):
        styleName = styles[i][0].strip()
        styleDef = styles[i][1].strip()
        for k, v in _slideBullets.iteritems():
            for i in range(len(v)):
                _slideBullets[k][i] = _slideBullets[k][i].replace(
                    "style = " + styleName, "style { " + styleDef)
                _slideBullets[k][i] = _slideBullets[k][i].replace("\n", " ")

    sources = ""
    # write slideBullets file
    if len(_slideBullets):
        bulletFile = "_bullets = {\n"
        num = 0
        for k, v in _slideBullets.iteritems():
            if num > 0:
                bulletFile += ","
            bulletFile += "'" + ` k ` + "':['" + "','".join(v) + "']\n"
            num = num + 1
        bulletFile += "}"
        sources += "source = $(LOCAL)/scripts/bullets.py\n"
        MLABFileManager.writeStringToFile(modulePath + "/scripts/bullets.py",
                                          bulletFile)

    # process script file -> replace content tags
    scriptFile = MLABFileManager.readStringFromFile(stylePath + "/template")
    scriptFile = scriptFile.replace("template.py", moduleName + ".py")
    files = MLABFileManager.recursiveContentOfDirectory(contentPath +
                                                        "/scripts")
    for file in files:
        if not file == "":
            sources += "source = $(LOCAL)/scripts/" + file.strip() + "\n"

    # print sources
    if not sources == "":
        scriptFile = scriptFile.replace("Commands {", "Commands {\n" + sources)
    scriptFile = scriptFile.replace(
        "[HEADER]", "\"" + ctx.field("header").stringValue() + "\"")
    scriptFile = scriptFile.replace(
        "[FOOTER]", "\"" + ctx.field("footer").stringValue() + "\"")
    scriptFile = scriptFile.replace("[MENU]", menu)
    scriptFile = scriptFile.replace("[SLIDES]", slides)

    # process script file -> replace style tags
    for i in range(len(styles)):
        styleName = styles[i][0].strip()
        style = styles[i][1].strip()
        scriptFile = scriptFile.replace("style = " + styleName,
                                        "style { " + style)

    # write script file
    MLABFileManager.writeStringToFile(
        modulePath + "/" + moduleName + ".script", scriptFile)

    # copy style data from stylePath
    styleDataPath = stylePath + "/data/"
    if MLABFileManager.exists(styleDataPath):

        files = MLABFileManager.recursiveContentOfDirectory(styleDataPath)
        for file in files:
            if MLABFileManager.isDir(styleDataPath + file):
                MLABFileManager.mkdir(modulePath + "/style/" + file)
            else:
                MLABFileManager.copy(styleDataPath + file,
                                     modulePath + "/style/" + file)
    else:
        print(styleDataPath)

    # write .mlab file for module
    # write .def and .script files for used modules
    mlabFile = "//MDL v1 utf8\n network {\n watchlist = \"\"\n}\n"
    for k, v in _slideModules.iteritems():
        macro = k.strip()
        mlabFile += "module " + macro + " {\n fields {\n  instanceName = " + macro + "\n }\n internalFields = \"\"\n}\n"

        defFile = "MacroModule " + macro + " { externalDefinition = $(LOCAL)/" + macro + ".script }"
        scriptFile = "Interface { Inputs {} Outputs {} Parameters {} } Commands { }"

        MLABFileManager.writeStringToFile(
            modulePath + "/macros/" + macro + ".def", defFile)
        MLABFileManager.writeStringToFile(
            modulePath + "/macros/" + macro + ".script", scriptFile)

    mlabFile += "connections = \"\"\n"

    MLABFileManager.writeStringToFile(modulePath + "/" + moduleName + ".mlab",
                                      mlabFile)

    # copy data, macros, networks, scripts, etc from contentPath
    files = MLABFileManager.recursiveContentOfDirectory(contentPath)
    extRE = re.compile('(\.dcm|\.tiff|\.tif|\.avi)')
    for file in files:
        if file == "slides": continue
        if file == "menu": continue
        if file == "config": continue
        if MLABFileManager.isDir(contentPath + "/" + file):
            if not MLABFileManager.exists(modulePath + "/" + file):
                MLABFileManager.mkdir(modulePath + "/" + file)
        else:
            if not MLABFileManager.exists(modulePath + "/" + file):
                MLABFileManager.copy(contentPath + "/" + file,
                                     modulePath + "/" + file)
            else:
                if not len(extRE.findall(file)):
                    MLABFileManager.copy(contentPath + "/" + file,
                                         modulePath + "/" + file)