def loadRequiredPackages(required, loadingProgressBar):
    try:  # protect the required functions in a try statement, we want to load these things and they should be there but we can't force it to exist in older schemas, so this is in a try.
        required = cPickle.loads(required)
        if len(required) > 0:
            if 'CRANrepos' in redREnviron.settings.keys():
                repo = redREnviron.settings['CRANrepos']
            else:
                repo = None
            loadingProgressBar.setLabelText(_('Loading required R Packages. If not found they will be downloaded.\n This may take a while...'))
            RSession.require_librarys(required['R'], repository=repo)
        
        installedPackages = redRPackageManager.getInstalledPackages()
        downloadList = {}
        print type(required['RedR'])
        #print required['RedR']
        
        for name,package in required['RedR'].items():
            #print package
            if (package['Name'] not in installedPackages.keys()) or (float(package['Version']['Number']) > float(installedPackages[package['Name']]['Version']['Number'])):
                print 'my package number %s' % str(float(installedPackages[package['Name']]['Version']['Number'])), 'their package number %s' % str(float(package['Version']['Number']))
                downloadList[package['Name']] = {'Version':unicode(package['Version']['Number']), 'installed':False}

        if len(downloadList.keys()) > 0:
            pm = redRPackageManager.packageManager(canvasDlg)
            pm.show()
            pm.askToInstall(downloadList, _('The following packages need to be installed before the session can be loaded.'))
    except Exception as inst: 
        redRLog.log(redRLog.REDRCORE, redRLog.ERROR, _('redRSaveLoad loadRequiredPackages; error loading package %s') % inst)  
def loadBaseLibs():
    try:
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        RSession.updatePackages(repository = redREnviron.settings['CRANrepos'])
        RSession.install_libraries(['RSvgDevice', 'reshape', 'lattice', 'hexbin', 'ggplot2', 'graph', 'grid', 'limma', 'gregmisc', 'MASS', 'Matrix', 'RSQLite', 'splines'], repository = redREnviron.settings['CRANrepos'])
    finally:
        QApplication.restoreOverrideCursor()
Beispiel #3
0
 def setMirror(self):
     # print 'setMirror'
     item = self.libListBox.currentRow()
     self.settings['CRANrepos'] = unicode(self.libs['URL'][item])
     RSession.Rcommand('local({r <- getOption("repos"); r["CRAN"] <- "' + unicode(self.libs['URL'][item]) + '"; options(repos=r)})')
     #print self.settings['CRANrepos']
     self.libInfo.setText('Repository URL changed to: '+unicode(self.libs['URL'][item]))
Beispiel #4
0
 def loadMirrors(self):
     self.libMessageBox.clear()
     if not redREnviron.checkInternetConnection():
         self.libMessageBox.setText(
             _('No Internet Connection, please try again'))
         return
     self.libs = RSession.Rcommand('getCRANmirrors()')
     self.libListBox.update(self.libs['Name'])
Beispiel #5
0
    def require_librarys(self, librarys, repository=None):
        qApp.setOverrideCursor(Qt.WaitCursor)
        if not repository and 'CRANrepos' in redREnviron.settings.keys():
            repository = redREnviron.settings['CRANrepos']

        #print _('Loading required librarys')
        success = RSession.require_librarys(librarys=librarys,
                                            repository=repository)
        self.requiredRLibraries.extend(librarys)
        qApp.restoreOverrideCursor()
        return success
Beispiel #6
0
def loadRequiredPackages(required, loadingProgressBar):
    try:  # protect the required functions in a try statement, we want to load these things and they should be there but we can't force it to exist in older schemas, so this is in a try.
        required = cPickle.loads(required)
        if len(required) > 0:
            if 'CRANrepos' in redREnviron.settings.keys():
                repo = redREnviron.settings['CRANrepos']
            else:
                repo = None
            loadingProgressBar.setLabelText(
                _('Loading required R Packages. If not found they will be downloaded.\n This may take a while...'
                  ))
            RSession.require_librarys(required['R'], repository=repo)

        installedPackages = redRPackageManager.packageManager.getInstalledPackages(
        )
        downloadList = {}
        print type(required['RedR'])
        #print required['RedR']

        for name, package in required['RedR'].items():
            #print package
            if not (package['Name'] in installedPackages.keys()
                    and package['Version']['Number'] == installedPackages[
                        package['Name']]['Version']['Number']):
                downloadList[package['Name']] = {
                    'Version': unicode(package['Version']['Number']),
                    'installed': False
                }

        if len(downloadList.keys()) > 0:
            pm = redRPackageManager.packageManagerDialog()
            pm.show()
            pm.askToInstall(
                downloadList,
                _('The following packages need to be installed before the session can be loaded.'
                  ))
    except Exception as inst:
        redRLog.log(
            redRLog.REDRCORE, redRLog.ERROR,
            _('redRSaveLoad loadRequiredPackages; error loading package %s') %
            inst)
Beispiel #7
0
    def R(self,
          query,
          callType='getRData',
          processingNotice=False,
          silent=False,
          showException=True,
          wantType='convert',
          listOfLists=True):

        self.setRIndicator(True)
        #try:
        if processingNotice:
            self.status.setStatus(4)

        qApp.setOverrideCursor(Qt.WaitCursor)
        try:
            commandOutput = RSession.Rcommand(query=query,
                                              silent=silent,
                                              wantType=wantType,
                                              listOfLists=listOfLists)
        except RuntimeError as inst:
            #print _('asdfasdfasdf'), inst
            redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                        redRLog.formatException())
            qApp.restoreOverrideCursor()
            self.setRIndicator(False)
            if showException:
                QMessageBox.information(self, _('Red-R Canvas'),
                                        _('R Error: ') + unicode(inst),
                                        QMessageBox.Ok + QMessageBox.Default)

            raise RuntimeError(unicode(inst))
            return None  # now processes can catch potential errors

        #except:
        #    print _('R exception occurred')
        self.processing = False
        if processingNotice:
            self.status.setStatus(5)

            #self.progressBarFinished()
        if not silent:
            OWRpy.globalRHistory.append(query)
            self.widgetRHistory.append(query)

            self.ROutput.setCursorToEnd()
            self.ROutput.append(
                '> ' + query
            )  #Keep track automatically of what R functions were performed.

        qApp.restoreOverrideCursor()
        self.setRIndicator(False)
        return commandOutput
Beispiel #8
0
    def assignR(self, name, object):
        assignOK = RSession.assign(name, object)
        if not assignOK:
            QMessageBox.information(self, _('Red-R Canvas'),_('Object was not assigned correctly in R, please tell package manager.'),  
            QMessageBox.Ok + QMessageBox.Default)
            raise Exception, _('Object was not assigned correctly in R, please tell package manager.')
        else:
            histquery = _('Assign ')+unicode(name)+_(' to ')+unicode(object)
            OWRpy.globalRHistory.append(histquery)
            self.widgetRHistory.append(histquery)

            self.ROutput.setCursorToEnd()
            self.ROutput.append('> '+ histquery)
Beispiel #9
0
 def onTabChange(self,index):
     # print 'onTabChange',index
     # get a data frame (dict) of r libraries
     if self.tabs.tabText(index) != _('R Settings'):
         return
     try:
         if not self.libListBox: return
     except:
         redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
         self.libs = RSession.Rcommand('getCRANmirrors()')
         # place a listBox in the widget and fill it with a list of mirrors
         
         self.libListBox = redRlistBox(self.rlibrariesBox, label = _('Mirrors'), 
         items = self.libs['Name'], callback = self.setMirror)
Beispiel #10
0
 def require_librarys(self, librarys, repository = None, load = True):
     """Load R libraries using the :mod:`RSession` require_librarys function.
     
     Takes a list of strings as R libraries to load.  These should be valid R packages or an error will occur.  repository is an optional argument to specity a custom repository if the library is not in a standard location.
     """
     qApp.setOverrideCursor(Qt.WaitCursor)
     if not repository and 'CRANrepos' in redREnviron.settings.keys():
         repository = redREnviron.settings['CRANrepos']
     
     #print _('Loading required librarys')
     try:
         success = RSession.require_librarys(librarys = librarys, repository = repository, load = load)
         self.requiredRLibraries.extend(librarys)
     finally:
         qApp.restoreOverrideCursor()
         return success
Beispiel #11
0
    def assignR(self, name, object):
        assignOK = RSession.assign(name, object)
        if not assignOK:
            QMessageBox.information(
                self, _('Red-R Canvas'),
                _('Object was not assigned correctly in R, please tell package manager.'
                  ), QMessageBox.Ok + QMessageBox.Default)
            raise Exception, _(
                'Object was not assigned correctly in R, please tell package manager.'
            )
        else:
            histquery = _('Assign ') + unicode(name) + _(' to ') + unicode(
                object)
            OWRpy.globalRHistory.append(histquery)
            self.widgetRHistory.append(histquery)

            self.ROutput.setCursorToEnd()
            self.ROutput.append('> ' + histquery)
Beispiel #12
0
 def R(self, query):
     return RSession.Rcommand(query = query)
Beispiel #13
0
 def require_librarys(self, libraries):
     return RSession.require_librarys(libraries)
Beispiel #14
0
 def require_librarys(self, libraries):
     return RSession.require_librarys(libraries)
Beispiel #15
0
 def resolveRDependencies(self, packageList):
     import RSession
     packageList = [x.strip() for x in packageList]
     RSession.require_librarys(packageList)
Beispiel #16
0
def loadDocument180(filename, caption=None, freeze=0, importing=0):
    global sessionID
    import redREnviron
    if filename.split('.')[-1] in ['rrts']:
        tmp = True
    elif filename.split('.')[-1] in ['rrs']:
        tmp = False
    else:
        QMessageBox.information(
            self, _('Red-R Error'),
            _('Cannot load file with extension %s') %
            unicode(filename.split('.')[-1]),
            QMessageBox.Ok + QMessageBox.Default)
        return

    loadingProgressBar = startProgressBar(
        _('Loading %s') % unicode(os.path.basename(filename)),
        _('Loading ') + unicode(filename), 2)

    ## What is the purpose of this???
    if not os.path.exists(filename):
        if os.path.splitext(filename)[1].lower() != ".tmp":
            QMessageBox.critical(self, _('Red-R Canvas'),
                                 _('Unable to locate file "%s"') % filename,
                                 QMessageBox.Ok)
        return
        loadingProgressBar.hide()
        loadingProgressBar.close()
    ###

    # set cursor
    qApp.setOverrideCursor(Qt.WaitCursor)

    if os.path.splitext(filename)[1].lower() == ".rrs":
        schemaPath, _schemaName = os.path.split(filename)
        canvasDlg.setCaption(caption or _schemaName)
    if importing:  # a normal load of the session
        _schemaName = ""

    loadingProgressBar.setLabelText(_('Loading Schema Data, please wait'))

    ### unzip the file ###

    zfile = zipfile.ZipFile(unicode(filename), "r")
    for name in zfile.namelist():
        file(
            os.path.join(redREnviron.directoryNames['tempDir'],
                         os.path.basename(name)), 'wb'
        ).write(
            zfile.read(name)
        )  ## put the data into the tempdir for this session for each file that was in the temp dir for the last schema when saved.
    doc = parse(
        os.path.join(redREnviron.directoryNames['tempDir'], 'tempSchema.tmp')
    )  # load the doc data for the data in the temp dir.

    ## get info from the schema
    schema = doc.firstChild
    widgets = schema.getElementsByTagName("widgets")[0]
    lines = schema.getElementsByTagName('channels')[0]
    f = open(
        os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'))
    settingsDict = eval(unicode(f.read()))
    f.close()

    #settingsDict = eval(unicode(settings[0].getAttribute("settingsDictionary")))
    loadedSettingsDict = settingsDict

    loadRequiredPackages(settingsDict['_requiredPackages'],
                         loadingProgressBar=loadingProgressBar)

    ## make sure that there are no duplicate widgets.
    if not tmp:
        ## need to load the r session before we can load the widgets because the signals will beed to check the classes on init.
        if not checkWidgetDuplication(widgets=widgets):
            QMessageBox.information(
                self, _('Schema Loading Failed'),
                _('Duplicated widgets were detected between this schema and the active one.  Loading is not possible.'
                  ), QMessageBox.Ok + QMessageBox.Default)

            return
        RSession.Rcommand('load("' +
                          os.path.join(redREnviron.directoryNames['tempDir'],
                                       "tmp.RData").replace('\\', '/') + '")')

    loadingProgressBar.setLabelText(_('Loading Widgets'))
    loadingProgressBar.setMaximum(
        len(widgets.getElementsByTagName("widget")) + 1)
    loadingProgressBar.setValue(0)
    globalData.globalData = cPickle.loads(loadedSettingsDict['_globalData'])
    (loadedOkW,
     tempFailureTextW) = loadWidgets180(widgets=widgets,
                                        loadingProgressBar=loadingProgressBar,
                                        loadedSettingsDict=loadedSettingsDict,
                                        tmp=tmp)

    lineList = lines.getElementsByTagName("channel")
    loadingProgressBar.setLabelText(_('Loading Lines'))
    (loadedOkL,
     tempFailureTextL) = loadLines(lineList,
                                   loadingProgressBar=loadingProgressBar,
                                   freeze=freeze,
                                   tmp=tmp)

    #for widget in redRObjects.instances(): widget.updateTooltip()
    #activeCanvas().update()
    #saveTempDoc()

    if not loadedOkW and loadedOkL:
        failureText = tempFailureTextW + tempFailureTextL
        QMessageBox.information(
            canvasDlg, _('Schema Loading Failed'),
            _('The following errors occured while loading the schema: <br><br>'
              ) + failureText, QMessageBox.Ok + QMessageBox.Default)

    for widget in redRObjects.instances():
        widget.setLoadingSavedSession(False)
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    loadingProgressBar.hide()
    loadingProgressBar.close()
    if tmp:
        sessionID += 1
Beispiel #17
0
def loadDocument(filename, caption=None, freeze=0, importing=0):
    global _schemaName
    global schemaPath
    global globalNotes
    redRLog.log(redRLog.REDRCORE, redRLog.INFO,
                _('Loading Document %s') % filename)
    import redREnviron
    if filename.split('.')[-1] in ['rrts']:
        tmp = True
        pipe = False
    elif filename.split('.')[-1] in ['rrs']:
        tmp = False
        pipe = False
    elif filename.split('.')[-1] in [
            'rrpipe'
    ]:  ## pipeline, no data but everything else there.
        pipe = True
        tmp = False
    else:
        QMessageBox.information(
            None, 'Red-R Error',
            _('Cannot load file with extension %s') %
            unicode(filename.split('.')[-1]),
            QMessageBox.Ok + QMessageBox.Default)
        return

    loadingProgressBar = startProgressBar(
        _('Loading %s') % unicode(os.path.basename(filename)),
        _('Loading %s') % unicode(filename), 2)

    # set cursor
    qApp.setOverrideCursor(Qt.WaitCursor)

    if os.path.splitext(filename)[1].lower() == ".rrs":
        schemaPath, _schemaName = os.path.split(filename)
        canvasDlg.setCaption(caption or _schemaName)
    if importing:  # a normal load of the session
        _schemaName = ""

    loadingProgressBar.setLabelText(_('Loading Schema Data, please wait'))

    ### unzip the file ###

    zfile = zipfile.ZipFile(unicode(filename), "r")
    for name in zfile.namelist():
        file(
            os.path.join(redREnviron.directoryNames['tempDir'],
                         os.path.basename(name)), 'wb'
        ).write(
            zfile.read(name)
        )  ## put the data into the tempdir for this session for each file that was in the temp dir for the last schema when saved.
    doc = parse(
        os.path.join(redREnviron.directoryNames['tempDir'], 'tempSchema.tmp')
    )  # load the doc data for the data in the temp dir.

    ## get info from the schema
    schema = doc.firstChild
    try:

        version = schema.getElementsByTagName("header")[0].getAttribute(
            'version')
        if not version:
            redRLog.log(
                redRLog.REDRCORE, redRLog.WARNING,
                _('Version Tag Missing, using Red-R 1.80 loading specifications'
                  )
            )  ## we should move everything to the earlier versions of orngDoc for loading.
            loadDocument180(filename, caption=None, freeze=0, importing=0)
            loadingProgressBar.hide()
            loadingProgressBar.close()
            return
        else:
            print _('The version is:%s') % version
    except Exception as inst:
        redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException())
        redRLog.log(
            redRLog.REDRCORE, redRLog.WARNING,
            _('Error in loading the schema %s, reverting to load with 1.80 settings'
              ) % inst)
        loadDocument180(filename, caption=None, freeze=0, importing=0)
        loadingProgressBar.hide()
        loadingProgressBar.close()
        return
    widgets = schema.getElementsByTagName("widgets")[0]
    tabs = schema.getElementsByTagName("tabs")[0]
    #settings = schema.getElementsByTagName("settings")
    f = open(
        os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'))
    settingsDict = eval(unicode(f.read()))
    f.close()

    ## load the required packages
    loadRequiredPackages(settingsDict['_requiredPackages'],
                         loadingProgressBar=loadingProgressBar)

    ## make sure that there are no duplicate widgets.
    if not tmp and not pipe:
        ## need to load the r session before we can load the widgets because the signals will beed to check the classes on init.
        if not checkWidgetDuplication(widgets=widgets):
            QMessageBox.information(
                canvasDlg, _('Schema Loading Failed'),
                _('Duplicated widgets were detected between this schema and the active one.  Loading is not possible.'
                  ), QMessageBox.Ok + QMessageBox.Default)

            return
        RSession.Rcommand('load("' +
                          os.path.join(redREnviron.directoryNames['tempDir'],
                                       "tmp.RData").replace('\\', '/') + '")')

    loadingProgressBar.setLabelText(_('Loading Widgets'))
    loadingProgressBar.setMaximum(
        len(widgets.getElementsByTagName("widget")) + 1)
    loadingProgressBar.setValue(0)
    if not tmp:
        globalData.globalData = cPickle.loads(settingsDict['_globalData'])
        if notesTextWidget and ('none' in globalData.globalData.keys()) and (
                'globalNotes' in globalData.globalData['none'].keys()):
            notesTextWidget.setHtml(
                globalData.globalData['none']['globalNotes']['data'])
        (loadedOkW,
         tempFailureTextW) = loadWidgets(widgets=widgets,
                                         loadingProgressBar=loadingProgressBar,
                                         loadedSettingsDict=settingsDict,
                                         tmp=tmp)

    ## LOAD tabs
    #####  move through all of the tabs and load them.
    (loadedOkT,
     tempFailureTextT) = loadTabs(tabs=tabs,
                                  loadingProgressBar=loadingProgressBar,
                                  tmp=tmp,
                                  loadedSettingsDict=settingsDict)
    if not tmp:
        redRLog.log(10, 9, 3, _('Setting Signals'))
        for widget in redRObjects.instances():
            redRLog.log(10, 9, 9, _('Setting Signals for %s') % widget)
            try:
                if widget.widgetID not in settingsDict.keys(): continue
                widget.outputs.setOutputs(
                    cPickle.loads(
                        settingsDict[widget.widgetID]['connections']), tmp)
            except Exception as inst:
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                            redRLog.formatException())
                redRLog.log(
                    1, 9, 1,
                    _('Error setting signals %s, Settings are %s') %
                    (inst, settingsDict[widget.widgetID].keys()))
    else:
        for widget in redRObjects.instances():
            if widget.tempID and widget.tempID in settingsDict.keys():
                widget.outputs.setOutputs(
                    cPickle.loads(settingsDict[widget.tempID]['connections']),
                    tmp)
    if pipe:  ## send none through all of the data.
        for w in redRObjects.instances():
            w.outputs.propogateNone(ask=False)
    for widget in redRObjects.instances():
        widget.tempID = None  ## we set the temp ID to none so that there won't be a conflict with other temp loading.

    ## some saved sessions may have widget instances that are available but that do not match to icons.  This shouldn't happen normally but if it does then we have instances that can persist without us knowing about it.  We clear those here.
    for i in redRObjects.instances():
        try:
            redRObjects.getWidgetByInstance(i)
        except:
            redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                        redRLog.formatException())
            try:
                redRObjects.removeWidgetInstance(i)
            except:
                redRLog.log(redRLog.REDRCORE, redRLog.ERROR,
                            redRLog.formatException())
                pass
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    qApp.restoreOverrideCursor()
    loadingProgressBar.hide()
    loadingProgressBar.close()
    redRObjects.updateLines()
Beispiel #18
0
def save(filename=None, template=False, copy=False, pipe=False):
    global _schemaName
    global schemaPath
    global notesTextWidget
    #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, '%s' % filename)
    if filename == None and not copy:
        filename = os.path.join(schemaPath, _schemaName)
    elif copy:
        filename = os.path.join(redREnviron.directoryNames['tempDir'],
                                'copy.rrts')
    #redRLog.log(redRLog.REDRCORE, redRLog.ERROR, 'Saveing file as name %s' % filename)
    progressBar = startProgressBar(
        _('Saving ') + unicode(os.path.basename(filename)),
        _('Saving ') + unicode(os.path.basename(filename)),
        len(redRObjects.instances()) + len(redRObjects.lines()) + 3)
    progress = 0

    # create xml document
    (doc, schema, header, widgets, lines, settings, required, tabs,
     saveTagsList, saveDescription) = makeXMLDoc()
    requiredRLibraries = {}

    #save widgets
    tempWidgets = redRObjects.instances(
        wantType='dict'
    )  ## all of the widget instances, these are not the widget icons
    (widgets, settingsDict,
     requireRedRLibraries) = saveInstances(tempWidgets, widgets, doc,
                                           progressBar)

    # save tabs and the icons and the channels
    if not copy or template:
        #tabs.setAttribute('tabNames', unicode(self.canvasTabs.keys()))
        for t in redRObjects.tabNames():
            temp = doc.createElement('tab')
            temp.setAttribute('name', t)
            ## set all of the widget icons on the tab
            widgetIcons = doc.createElement('widgetIcons')
            for wi in redRObjects.getIconsByTab(
                    t
            )[t]:  ## extract only the list for this tab thus the [t] syntax
                saveIcon(widgetIcons, wi, doc)
            # tabLines = doc.createElement('tabLines')
            # for line in self.widgetLines(t)[t]:
            # saveLine(tabLines, line)

            temp.appendChild(
                widgetIcons)  ## append the widgetIcons XML to the global XML
            #temp.appendChild(tabLines)          ## append the tabLines XML to the global XML
            tabs.appendChild(temp)

    ## save the global settings ##
    if notesTextWidget:
        globalData.setGlobalData('Notes', 'globalNotes',
                                 unicode(notesTextWidget.toHtml()))

    settingsDict['_globalData'] = cPickle.dumps(globalData.globalData, 2)
    settingsDict['_requiredPackages'] = cPickle.dumps(
        {
            'R': requiredRLibraries.keys(),
            'RedR': requireRedRLibraries
        }, 2)

    #print requireRedRLibraries
    file = open(
        os.path.join(redREnviron.directoryNames['tempDir'], 'settings.pickle'),
        "wt")
    file.write(unicode(settingsDict))
    file.close()
    if template:
        taglist = unicode(tempDialog.tagsList.text())
        tempDescription = unicode(tempDialog.descriptionEdit.toPlainText())
        saveTagsList.setAttribute("tagsList", taglist)
        saveDescription.setAttribute("tempDescription", tempDescription)

    xmlText = doc.toprettyxml()
    progress += 1
    progressBar.setValue(progress)

    if not template and not copy and not pipe:
        tempschema = os.path.join(redREnviron.directoryNames['tempDir'],
                                  "tempSchema.tmp")
        tempR = os.path.join(redREnviron.directoryNames['tempDir'],
                             "tmp.RData").replace('\\', '/')
        file = open(tempschema, "wt")
        file.write(xmlText)
        file.close()
        doc.unlink()

        progressBar.setLabelText('Saving Data...')
        progress += 1
        progressBar.setValue(progress)

        RSession.Rcommand('save.image("' + tempR + '")')  # save the R data

        createZipFile(
            filename, [], [redREnviron.directoryNames['tempDir']]
        )  # collect the files that are in the tempDir and save them into the zip file.
    elif template:
        tempschema = os.path.join(redREnviron.directoryNames['tempDir'],
                                  "tempSchema.tmp")
        file = open(tempschema, "wt")
        file.write(xmlText)
        file.close()
        zout = zipfile.ZipFile(filename, "w")
        zout.write(tempschema, "tempSchema.tmp")
        zout.write(
            os.path.join(redREnviron.directoryNames['tempDir'],
                         'settings.pickle'), 'settings.pickle')
        zout.close()
        doc.unlink()
    elif copy:
        tempschema = os.path.join(redREnviron.directoryNames['tempDir'],
                                  "tempSchema.tmp")
        file = open(tempschema, "wt")
        file.write(xmlText)
        file.close()
        zout = zipfile.ZipFile(filename, "w")
        zout.write(tempschema, "tempSchema.tmp")
        zout.write(
            os.path.join(redREnviron.directoryNames['tempDir'],
                         'settings.pickle'), 'settings.pickle')
        zout.close()
        doc.unlink()
        loadTemplate(filename)

    progress += 1
    progressBar.setValue(progress)
    progressBar.close()
    if os.path.splitext(filename)[1].lower() == ".rrs":
        (schemaPath, schemaName) = os.path.split(filename)
        redREnviron.settings["saveSchemaDir"] = schemaPath
        canvasDlg.toolbarFunctions.addToRecentMenu(filename)
        canvasDlg.setCaption(schemaName)
    redRLog.log(redRLog.REDRCORE, redRLog.INFO,
                'Document Saved Successfully to %s' % filename)
    return True