Example #1
0
def persist_map(map, file):
    """
   Writes the given map of strings-to-values into a file, by converting all of 
   its values into strings.  Any key value pair that contains the ':' 
   character will not be written out.  All other contents that were in the 
   given file will be destroyed.  Returns True on success, False on failure.
   """

    try:
        import log
        with StreamWriter(file, False, Encoding.UTF8) as sw:
            sw.Write(":: This file was generated on "\
               + strftime(r'%Y.%m.%d %X') + "\n\n")
            keys = map.keys()
            keys.sort()
            for key in keys:
                value = sstr(map[key]).strip()
                key = sstr(key).strip()
                if ':' in key or ':' in value:
                    log.debug(
                        "WARNING: can't write map entry containing ':'; ", key,
                        " -> ", value)
                else:
                    sw.Write(key + ' : ' + value + "\n")
        return True
    except:
        log.debug_exc("problem persisting map to file: " + sstr(file))
        return False
Example #2
0
def SaveFile(filename, data):
    store = IsolatedStorageFile.GetUserStoreForApplication()
    isolatedStream = IsolatedStorageFileStream(filename, FileMode.Create,
                                               store)

    writer = StreamWriter(isolatedStream)
    writer.Write(data)

    writer.Close()
    isolatedStream.Close()
Example #3
0
	def __enter__(self):
		self.file = StreamWriter( self.temp )
		while self.filereader.Peek() > -1:
			line = self.filereader.ReadLine()
			if line.startswith(('*', '#', 'META')):
				self.file.WriteLine( line )
		self.file.Close()

		self.uidoc.Application.Application.SharedParametersFilename = self.temp
		self.fileDefinition = self.uidoc.Application.Application.OpenSharedParameterFile()
		self.groupDefinition = self.fileDefinition.Groups.Create('temp_group')

		return self
def execute():
    try:
        table = Document.ActiveDataTableReference

        outputFile = StreamWriter(outputFilePath, "w+")
        outputFile.Write(
            "<html><head><title>Spotfire SDBF Uploader</title></head><body><script>setTimeout(function(){window.location.reload(true);}, 5000);</script><div style='font-size:16px;padding:12px;'>\n"
        )
        outputFile.Write("<p>Export Folder is '" + folder + "'</p>\n")
        outputFile.Close()

        print "start infinite loop"
        while True:
            print "START refreshing all tables"
            for table in Document.Data.Tables:
                print "Processing - " + table.Name + ""
                ps.CurrentProgress.ExecuteSubtask("Processing - " +
                                                  table.Name + "")
                uploadOneFile(table)
                print "Processing - " + table.Name + " - DONE"
                ps.CurrentProgress.CheckCancel()
                print "Processing - " + table.Name + " - DONE CheckCancel"
            print "END refreshing all tables"

            ps.CurrentProgress.CheckCancel()
            print "CheckCancel Done, sleeping 10ms"
            time.sleep(10)
            print "waking up"

    except BaseException as e:  # user canceled
        print "Cancelation, excpetion: " + str(e)
        outputFile = StreamWriter(Document.Properties["outputFilePath"], "a")
        outputFile.Write(str(e) + " - Export Stopped")
        outputFile.Write(str(datetime.datetime.now()) + " - Export Stopped")
        outputFile.Write("</div></body></html>")
        outputFile.Close()
        print "end of exec"
        pass
Example #5
0
def table_text_writer(list_input):

    """Writes table input

    args:

    list_input (list of lists): input to be written

    returns: stream
    """
    from System.IO import  StreamWriter, MemoryStream, SeekOrigin


    list_input = controlled_list(list_input)
    LOGGER.debug(list_input)
    LOGGER.debug('--------')
    header = controlled_list(list_input.pop(0))
    length_of_header = len(header)
    head_line = create_line(header)

    # if only a header line
    if not list_input:
        text = ' ' * (length_of_header)

    else:
        text =''

        LOGGER.debug('Loop')
        for i, text_list in enumerate(list_input):

            text_list = controlled_list(text_list)
            LOGGER.debug(text_list)
            if len(text_list) != length_of_header:

                message = ('Line {} in text: [{}] does not have ' +
                           ' same length as header [{}], will be ' +
                           'skipped').format(i, join_list(text_list),
                                             join_list(header))
                ok_message(message)
            else:

                text += create_line(text_list)

    text = head_line + text
    stream = MemoryStream()
    writer = StreamWriter(stream)
    writer.Write(text)
    writer.Flush()
    stream.Seek(0, SeekOrigin.Begin)
    return stream
def uploadOneFile(dataTable):
    outputFile = StreamWriter(outputFilePath, "a")
    fileName = dataTable.Name
    outputFile.Write("<p>" + str(datetime.datetime.now()) + " - " + fileName +
                     " - start <br/>\n")

    webRequest = HttpWebRequest.Create(rcqBackendURI + fileName)
    response = webRequest.GetResponse()
    streamReader = StreamReader(response.GetResponseStream())
    jsonData = streamReader.ReadToEnd()
    ps.CurrentProgress.CheckCancel()

    outputFile.Write(
        str(datetime.datetime.now()) + " - " + fileName + " " + str(jsonData) +
        "<br/>\n")

    outputFile.Write(
        str(datetime.datetime.now()) + " - " + fileName +
        " - SDBF file re-generated <br/>\n")
    dataTable.Refresh()
    ps.CurrentProgress.CheckCancel()
    outputFile.Write(
        str(datetime.datetime.now()) + " - " + fileName +
        " - Analysis Refreshed <br/>\n")

    try:
        (found,
         item) = lm.TryGetItem(folder + fileName, LibraryItemType.SbdfDataFile,
                               LibraryItemRetrievalOption.IncludeProperties)
        if found:
            table.ExportDataToLibrary(item, fileName)
            outputFile.Write(
                str(datetime.datetime.now()) + " - " + fileName +
                " - exported (ow) <br/>\n")
        else:
            (found2, item2) = lm.TryGetItem(
                folder, LibraryItemType.Folder,
                LibraryItemRetrievalOption.IncludeProperties)
            if found2:
                table.ExportDataToLibrary(item2, fileName)
                outputFile.Write(
                    str(datetime.datetime.now()) + " - " + fileName +
                    " - exported (1st) <br/>\n")
    except Exception as e:
        outputFile.Write(
            str(datetime.datetime.now()) + " - " + "Exception Occured:" +
            str(e) + " <br/>\n")

    outputFile.Write("</p>\n")
    outputFile.Close()
Example #7
0
def persist_string(s, file):
    """
   Writes the given stringsinto a file. All other contents that were in the 
   given file will be destroyed.  Returns True on success, False on failure.
   """

    try:
        import log
        with StreamWriter(file, False, Encoding.UTF8) as sw:
            sw.Write(s)
        return True
    except:
        log.debug_exc("problem persisting string to file: " + sstr(file))
        return False
Example #8
0
 def SaveList(self, exportlist, week, path, price, publisher):
     if path:
         print "Creating file"
         w = StreamWriter(path, False)
         w.WriteLine("Checklist for week of " + week)
         w.WriteLine()
         w.WriteLine()
         for item in exportlist:
             w.Write("[] ")
             if publisher:
                 w.Write(item["Publisher"] + " ")
             w.Write(item["Title"])
             if price:
                 w.Write(" " + item["Price"])
             w.WriteLine()
         w.Close()
         w.Dispose()
Example #9
0
def accepted():
    """
    Executes whenever the accepted signal fires. Writes out the pipeline tools settings based on the version of pipeline tools, then closes.
    """
    global integration_dialog
    global appName
    global extraKVPIndex
    global settingsWriterObj
    global pipelineToolsVersionNumber

    if integration_dialog.IntegrationProcessingRequested():
        # Check if Integration options are valid.
        if not integration_dialog.CheckIntegrationSanity():
            return

        if pipelineToolsVersionNumber == 2:
            # Write to the pipeline tool settings file and get the status message of which tools are currently enabled.
            settingsWriterObj.WritePipelineToolSettings()
            SetPipelineToolStatus()
        else:
            # Determine a unique integration settings filename .
            randomKey = ''.join(
                random.choice(string.digits) for i in range(10))
            integrationSettingsPath = os.path.join(
                ClientUtils.GetDeadlineTempPath(),
                appName + "IntegrationSettings_" + randomKey + ".txt")

            # Write the integration settings file.
            writer = StreamWriter(integrationSettingsPath, False)
            extraKVPIndex = integration_dialog.WriteIntegrationInfo(
                writer, extraKVPIndex)
            writer.Close()

            # Build output for Integrated Submitter.
            ClientUtils.LogText("integrationSettingsPath=%s" %
                                integrationSettingsPath)
            ClientUtils.LogText("extraKVPIndex=%s" % extraKVPIndex)
            ClientUtils.LogText(
                "batchMode=%s" %
                integration_dialog.IntegrationGroupBatchRequested())

    # Make sure all the project management connections are closed properly.
    integration_dialog.CloseProjectManagementConnections()
Example #10
0
 def save(self, filename):
    """ Implements the module-level save() method by writing the 
        debug log information to the given file. """
    
    # protect access to the logLines with a mutex (for multiple threads)
    self._mutex.WaitOne(-1)
    try:
       if self._loglines == None:
          raise Exception("you must install the __Logger before using it")
       loglines_copy = list(self._loglines)
    finally:
       self._mutex.ReleaseMutex()
       
    try:
       writer = StreamWriter(filename, False, UTF8Encoding())
       for line in loglines_copy:
          writer.Write(line)
    finally:
       if writer: writer.Dispose()
Example #11
0
def exportSignalsToFile(dc,	dayToExport, deviceNameToExport, targetFilePath, subroutineName, \
	exportFileSystemSignals = False, exportWifiSignals = False):
	"""
	Exports signal data of activity log to a file.

	Keyword arguments:
	dc -- DataContext that should be used to read activity log (TimeCockpit.Data.DataContext)
	dayToExport -- Day that should be exported (DateTime; time-part has to be 0)
	deviceNameToExport -- Name of the device that should be exported
	targetFilePath -- Full path to the target file (UTF-8, overwrites file if it exists)
	subroutineName -- Name of the generated routine (should be unique for each export)
	exportFileSystemSignals -- Indicates whether file system signals should be exported (bool); default is False
	exportWifiSignals -- Indicates whether WIFI signals should be exported (bool); default is False
	"""
	targetStream = StreamWriter(targetFilePath)
	try:
		exportSignalsToStream(dc, dayToExport, deviceNameToExport, targetStream, subroutineName, \
			exportFileSystemSignals, exportWifiSignals)
	finally:
		targetStream.Close()
def csvToDataSource(csv, columnDataTypes):
    # Create memorystream to read from
    stream = MemoryStream()
    writer = StreamWriter(stream)
    writer.Write(csv)
    writer.Flush()
    stream.Seek(0, SeekOrigin.Begin)

    # Create text file data source
    readerSettings = TextDataReaderSettings()
    readerSettings.Separator = ','
    readerSettings.AddColumnNameRow(0)
    print 'columnDataTypes ', columnDataTypes
    for i, columnDataType in enumerate(columnDataTypes):
        readerSettings.SetDataType(i, columnDataType)

    dataSource = TextFileDataSource(stream, readerSettings)
    dataSource.ReuseSettingsWithoutPrompting = True
    dataSource.IsPromptingAllowed = False
    return dataSource
Example #13
0
    def save_file_dialog(self, sender, event):
        """open a savefiledialog dialog"""

        self.save_file_dialog = SaveFileDialog()
        self.save_file_dialog.InitialDirectory = "%s/winforms" % uiaqa_path
        self.save_file_dialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
        self.save_file_dialog.FilterIndex = 2
        self.save_file_dialog.RestoreDirectory = True
        
        # save the label content to a file.
        try:
            if self.save_file_dialog.ShowDialog() == DialogResult.OK:
                filepath = self.save_file_dialog.FileName
                s_buf = StreamWriter(filepath)
                s_buf.Write(self.label.Text)
                s_buf.Flush()
                s_buf.Close()
                self.label.Text = "The path you selected is: " + filepath + '\n'
        except IOError, event:
            print 'An error occurred:', event
Example #14
0
def SubmitButtonPressed(*args):
    global scriptDialog
    
    # Check if scene file exists.
    sceneFile = scriptDialog.GetValue( "SceneBox" )
    #scriptDialog.ShowMessageBox(sceneFile, "")
    if( not File.Exists( sceneFile ) ):
        scriptDialog.ShowMessageBox( "The sceen {0} does not exist".format(sceneFile), "Error" )
        return
    elif (PathUtils.IsPathLocal(sceneFile)):
        result = scriptDialog.ShowMessageBox( "The scene file {0} is local. Are you sure you want to continue?".format(sceneFile), "Warning", ("Yes","No") )
        if(result=="No"):
            return
    
    # Create job info file.
    jobInfoFilename = Path.Combine( GetDeadlineTempPath(), "pdplayer_job_info.job" )
    #scriptDialog.ShowMessageBox(str(jobInfoFilename), "")
    try:
        writer = StreamWriter( jobInfoFilename, False, Encoding.Unicode ) #<- this is the line messing up
    except Exception, e:
        scriptDialog.ShowMessageBox("error: " + str(e) , "")
Example #15
0
                def onSave():
                    try:
                        fs = None
                        sr = None
                        sw = None

                        try:
                            fs = FileStream(__file__, FileMode.Open,
                                            FileAccess.ReadWrite,
                                            FileShare.Read)
                            encoding = UTF8Encoding(False)
                            sr = StreamReader(fs, encoding, True)
                            lines = Regex.Replace(
                                Regex.Replace(
                                    sr.ReadToEnd(), "username\\s*=\\s*\"\"",
                                    String.Format("username = \"{0}\"",
                                                  username),
                                    RegexOptions.CultureInvariant),
                                "password\\s*=\\s*\"\"",
                                String.Format("password = \"{0}\"", password),
                                RegexOptions.CultureInvariant)
                            fs.SetLength(0)
                            sw = StreamWriter(fs, encoding)
                            sw.Write(lines)

                        finally:
                            if sw is not None:
                                sw.Close()

                            if sr is not None:
                                sr.Close()

                            if fs is not None:
                                fs.Close()

                    except Exception, e:
                        Trace.WriteLine(e.clsException.Message)
                        Trace.WriteLine(e.clsException.StackTrace)
from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Application.Visuals import TablePlot
 
#Temp file for storing the table data
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()

#Export table data to the temp file
writer = StreamWriter(tempFilename)
vTable.As[TablePlot]().ExportText(writer)

print tempFilename
Example #17
0
from System.Web.Script.Serialization import JavaScriptSerializer
from System.Net import WebClient

# Create a web client
client = WebClient()


# Download the results of that URL
results = client.DownloadString("http://localhost:8888/spotfireFramework/assetMarketPlace/customLibs/visTimeline/dxp/eventsGroup.csv")

# print these results
print results


stream = MemoryStream()
writer = StreamWriter(stream)
writer.Write(results)
writer.Flush()
stream.Seek(0, SeekOrigin.Begin)

readerSettings = TextDataReaderSettings()
readerSettings.Separator = ","
readerSettings.AddColumnNameRow(0)
readerSettings.SetDataType(0, DataType.String)
readerSettings.SetDataType(1, DataType.String)
readerSettings.SetDataType(2, DataType.DateTime)
readerSettings.SetDataType(3, DataType.DateTime)
readerSettings.SetDataType(4, DataType.String)
readerSettings.SetDataType(5, DataType.String)
readerSettings.SetDataType(6, DataType.String)
Example #18
0
        print("Parsed file with {} warnings.".format(errorHandler.warnings))

    errorHandler = ErrorHandler()
    tree.Validate(errorHandler)

    if (errorHandler.warnings == 0):
        print("Validated parsed data with no warnings.")
    else:
        print("Validated parsed data with {} warnings.".format(
            errorHandler.warnings))

    input("Press enter to serialise data.")

    tree.elements.Insert(0, comment)
    ms = MemoryStream()
    stream = StreamWriter(ms, UTF8Encoding(True))
    parser.Serialise(tree, stream)
    ms.Position = 0
    sr = StreamReader(ms)
    myStr = sr.ReadToEnd()
    print(myStr)

    # output to the file
    #f = codecs.open("testFileNew.a2l", 'w+', 'utf-8')
    #f.write(myStr)
    #f.close()

    input("Press enter to close...")
else:
    print("Parsing failed!")
    if preset != None:

        # check if preset already exists
        path = Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", preset)
        if not Directory.Exists(path):

            # prompt for target material
            target = BrawlAPI.UserStringInput("Target Material", "")
            if target != None:

                textures = []
                export_animations()

                # edit and include import and delete script to preset folder
                import_script = File.ReadAllText(Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", "Import Preset.txt"))
                import_script = import_script.Replace("preset_name = \"\"", "preset_name = \"" + preset + "\"")

                delete_script = File.ReadAllText(Path.Combine(BrawlAPI.PluginPath, "MKWii Animations", "Remove Preset.txt"))
                delete_script = delete_script.Replace("preset_name = \"\"", "preset_name = \"" + preset + "\"")

                with StreamWriter(Path.Combine(path, "Import " + preset + ".py")) as writer:
                    writer.Write(import_script)

                with StreamWriter(Path.Combine(path, "Remove " + preset + ".py")) as writer:
                    writer.Write(delete_script)

                BrawlAPI.RootNode._mainForm.reloadPluginsToolStripMenuItem_Click(None, None)
        else:

            BrawlAPI.ShowMessage("Preset name already in use", "")
Example #20
0
    def gen_springs(self, solver_data, stream):
        # pylint: disable=too-many-statements
        stream.WriteLine(
            "/com,*********** Elastic Foundation - {0} ***********".format(
                self.load.Properties['id'].Value))
        et_x = solver_data.GetNewElementType()
        et_y = solver_data.GetNewElementType()
        et_z = solver_data.GetNewElementType()

        mesh = self.load.Analysis.MeshData

        # Get Node Ids
        node_ids = []
        for geo_id in self.load.Properties['Geometry'].Value.Ids:
            node_ids += mesh.MeshRegionById(geo_id).NodeIds

        node_ids = list(set(node_ids))

        #Gen Coincident nodes
        cnode_ids = [int(solver_data.GetNewNodeId()) for x in node_ids]
        node_count = len(cnode_ids)

        stream.WriteLine('nblock, 3, , {0}'.format(len(cnode_ids)))
        stream.WriteLine('(1i9,3e25.16e3)')
        factor = self.api.Application.InvokeUIThread(lambda: solver_unit(
            self.api, 1.0, mesh.Unit, 'Length', self.load.Analysis))

        for node_id, cnode_id in zip(node_ids, cnode_ids):
            pos = [
                x * factor
                for x in (mesh.NodeById(node_id).X, mesh.NodeById(node_id).Y,
                          mesh.NodeById(node_id).Z)
            ]
            stream.WriteLine('{0:9d}{1:25.16e}{2:25.16e}{3:25.16e}'.format(
                cnode_id, *pos))
        stream.WriteLine('-1')

        # Check to see if using Name Selection
        if self.load.Properties[
                'Geometry/DefineBy'].Value == 'Named Selection':
            comp_mob_name = self.load.Properties['Geometry'].Value.Name
        else:
            comp_mob_name = 'elasfound_targ_{0}'.format(
                self.load.Properties['id'].Value)
            ansys.createNodeComponent(node_ids,
                                      comp_mob_name,
                                      mesh,
                                      stream,
                                      fromGeoIds=False)

        comp_ref_name = 'elasfound_ref_{0}'.format(
            self.load.Properties['id'].Value)
        ansys.createNodeComponent(cnode_ids,
                                  comp_ref_name,
                                  mesh,
                                  stream,
                                  fromGeoIds=False)

        factor = self.api.Application.InvokeUIThread(lambda: to_solve_unit(
            self.api, 1.0, 'Stiffness', self.load.Analysis))

        stream.WriteLine('ET, {0}, COMBIN14, 0, 1, 0'.format(et_x))
        stream.WriteLine('R, {0},{1:25.16e},{2:25.16e}'.format(
            et_x, self.load.Properties['SpringDef/xStiff'].Value / node_count *
            factor, self.load.Properties['SpringDef/Damping/xDamp'].Value
            if self.load.Properties['SpringDef/Damping/xDamp'].Value else 0.0))
        stream.WriteLine()

        stream.WriteLine('ET, {0}, COMBIN14, 0, 2, 0'.format(et_y))
        stream.WriteLine('R, {0},{1:25.16e},{2:25.16e}'.format(
            et_y, self.load.Properties['SpringDef/yStiff'].Value / node_count *
            factor, self.load.Properties['SpringDef/Damping/yDamp'].Value
            if self.load.Properties['SpringDef/Damping/yDamp'].Value else 0.0))
        stream.WriteLine()

        stream.WriteLine('ET, {0}, COMBIN14, 0, 3, 0'.format(et_z))
        stream.WriteLine('R, {0},{1:25.16e},{2:25.16e}'.format(
            et_z, self.load.Properties['SpringDef/zStiff'].Value / node_count *
            factor, self.load.Properties['SpringDef/Damping/zDamp'].Value
            if self.load.Properties['SpringDef/Damping/zDamp'].Value else 0.0))
        stream.WriteLine()

        stream.WriteLine('CMSEL, S, {0}'.format(comp_mob_name))
        stream.WriteLine('CMSEL, A, {0}'.format(comp_ref_name))
        stream.WriteLine('CSYS, {0}'.format(
            self.api.Application.InvokeUIThread(lambda: self.load.Properties[
                'SpringDef/cs'].Value.CoordinateSystemID)))
        stream.WriteLine('NROTAT, ALL')
        stream.WriteLine('ALLSELL, ALL')
        stream.WriteLine()

        stream.WriteLine('EBLOCK,19,SOLID')
        stream.WriteLine('(19i9)')
        line = '{0:9d}' * 4 + '{1:9d}' * 4 + '{2:9d}{3:9d}{4:9d}{5:9d}{6:9d}'
        for e_num in [et_x, et_y, et_z]:
            for node_id, cnode_id in zip(node_ids, cnode_ids):
                stream.WriteLine(
                    line.format(int(e_num), 0, 2, 0,
                                int(solver_data.GetNewElementId()), cnode_id,
                                node_id))
        stream.WriteLine('-1')
        stream.WriteLine('D, {0}, ALL, 0.0'.format(comp_ref_name))

        self.load.Properties['nodeFile'].Value = comp_ref_name + '.dat'
        node_stream = StreamWriter(self.load.Properties['nodeFile'].Value)
        ansys.createNodeComponent(cnode_ids,
                                  comp_ref_name,
                                  mesh,
                                  node_stream,
                                  fromGeoIds=False)
        node_stream.Close()
path = r"lib/EnyimMemcached/build/CommonProperties.targets"

sr = StreamReader(path)
sb = StringBuilder()

line = sr.ReadLine()
while not line is None:
    
    #I'm sure this could all be done in a couple of lines with a nice multi-line Regex
    #All this does is comment out property groups that attempt to set signing 
    if line.Trim().StartsWith("<PropertyGroup") and line.Contains("PrivateKey"):
        
        sb.AppendFormat("<!--{0}\r\n", line)                 
        while line is not None and line.Trim() != "</PropertyGroup>":
            sb.AppendLine(line)
            line = sr.ReadLine()
        else:
            sb.AppendFormat("{0}-->\r\n", line)            
    else:
        sb.AppendLine(line)
    
    line = sr.ReadLine()
        
content = sb.ToString()
content = content.Replace("<DelaySign>true</DelaySign>", "<DelaySign>false</DelaySign>")
content = content.Replace("<SignAssembly>true</SignAssembly>", "<SignAssembly>false</SignAssembly>")
sr.Dispose()

sw = StreamWriter(path, False)
sw.Write(sb.ToString())
sw.Dispose()
from System.Reflection import Assembly
from System.Text import Encoding
from System import Array, Object, String, Convert, Console
from System.IO import StreamWriter, MemoryStream

encoded_assembly = "ASSEMBLY_BASE64"

assembly = Assembly.Load(Convert.FromBase64String(encoded_assembly))
args = Array[Object]([Array[String](["ARGS"])])

# For some reason if we don't set the console output back to stdout after executing the assembly IronPython throws a fit
orig_out = Console.Out
orig_error = Console.Error

with MemoryStream() as ms:
    with StreamWriter(ms) as sw:
        Console.SetOut(sw)
        Console.SetError(sw)
        assembly.EntryPoint.Invoke(None, args)
        sw.Flush()
        buffer = ms.ToArray()
        print Encoding.UTF8.GetString(buffer, 0, buffer.Length)
        Console.SetOut(orig_out)
        Console.SetError(orig_error)
Example #23
0
def SubmitButtonPressed(*args):
    global scriptDialog
    global jobOptionsDialog
    global submittedFromMonitor
    global imageRender
    global outputFile
    global rndFileName

    warnings = []
    errors = []

    # Check if Mistika VR render files exist.
    sceneFiles = StringUtils.FromSemicolonSeparatedString(
        scriptDialog.GetValue("SceneBox"), False)
    if len(sceneFiles) == 0:
        errors.append("No Mistika VR render file specified.")

    submitScene = scriptDialog.GetValue("SubmitSceneBox")

    # Check if Mistika VR render file exists.
    for sceneFile in sceneFiles:
        if not os.path.isfile(sceneFile):
            errors.append("Mistika VR render file: %s does not exist." %
                          sceneFile)
        elif not submitScene and PathUtils.IsPathLocal(sceneFile):
            warnings.append(
                "The Mistika VR render file: " + sceneFile +
                " is local and is not being submitted with the job, are you sure you want to continue?"
            )

    # Check if a valid frame range has been specified.
    frames = scriptDialog.GetValue("FramesBox")
    if not FrameUtils.FrameRangeValid(frames):
        errors.append("Frame range %s is not valid." % frames)

    if len(errors) > 0:
        scriptDialog.ShowMessageBox(
            "The following errors were encountered:\n\n%s\n\nPlease resolve these issues and submit again.\n"
            % ("\n\n".join(errors)), "Errors")
        return

    if len(warnings) > 0:
        result = scriptDialog.ShowMessageBox(
            "Warnings:\n\n%s\n\nDo you still want to continue?" %
            ("\n\n".join(warnings)), "Warnings", ("Yes", "No"))
        if result == "No":
            return

    jobOptions = jobOptionsDialog.GetJobOptionsValues()

    successes = 0
    failures = 0

    # Submit each Mistika VR render file separately.
    for sceneFile in sceneFiles:
        originalJobName = jobOptions["Name"]
        if len(sceneFiles) > 1:
            newJobName = "%s [%s]" % (originalJobName,
                                      os.path.basename(sceneFile))
            jobOptions["Name"] = newJobName

        # Create job info file.
        jobInfoFilename = os.path.join(ClientUtils.GetDeadlineTempPath(),
                                       "mistikavr_job_info.job")
        writer = StreamWriter(jobInfoFilename, False, Encoding.Unicode)
        writer.WriteLine("Plugin=MistikaVR")

        for option, value in jobOptions.iteritems():
            writer.WriteLine("%s=%s" % (option, value))

        writer.WriteLine("Frames=%s" % frames)
        writer.WriteLine("ChunkSize=%s" %
                         scriptDialog.GetValue("ChunkSizeBox"))

        if not submittedFromMonitor and sceneFile == rndFileName:
            writer.WriteLine("OutputFilename0=%s" %
                             outputFile.replace("%06d", "######"))

        writer.Close()

        if len(sceneFiles) > 1:
            # reset the job name for the next job to be submitted
            jobOptions["Name"] = originalJobName

        # Create plugin info file.
        pluginInfoFilename = os.path.join(ClientUtils.GetDeadlineTempPath(),
                                          "mistikavr_plugin_info.job")
        writer = StreamWriter(pluginInfoFilename, False, Encoding.Unicode)

        if not submitScene:
            writer.WriteLine("SceneFile=%s" % sceneFile)

        writer.WriteLine("ImageRender=%s" % scriptDialog.GetValue("ImageBox"))
        writer.Close()

        # Setup the command line arguments.
        arguments = [jobInfoFilename, pluginInfoFilename]

        if submitScene:
            arguments.append(sceneFile)

        if len(sceneFiles) == 1:
            results = ClientUtils.ExecuteCommandAndGetOutput(arguments)
            scriptDialog.ShowMessageBox(results, "Submission Results")
        else:
            # Now submit the job.
            exitCode = ClientUtils.ExecuteCommand(arguments)
            if exitCode == 0:
                successes = successes + 1
            else:
                failures = failures + 1

    if len(sceneFiles) > 1:
        scriptDialog.ShowMessageBox(
            "Jobs submitted successfully: %d\nJobs not submitted: %d" %
            (successes, failures), "Submission Results")
Example #24
0
    writer.WriteLine( "TaskTimeoutMinutes=%s" % scriptDialog.GetValue( "TaskTimeoutBox" ) )
    writer.WriteLine( "LimitGroups=%s" % scriptDialog.GetValue( "LimitGroupBox" ) )
    writer.WriteLine( "JobDependencies=%s" % scriptDialog.GetValue( "DependencyBox" ) )
    writer.WriteLine( "OnJobComplete=%s" % scriptDialog.GetValue( "OnJobCompleteBox" ) )
    writer.WriteLine( "Frames=0" )
    writer.WriteLine( "ChunkSize=1" )
    
    if( bool(scriptDialog.GetValue( "IsBlacklistBox" )) ):
        writer.WriteLine( "Blacklist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
    else:
        writer.WriteLine( "Whitelist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
    
    if( bool(scriptDialog.GetValue( "SubmitSuspendedBox" )) ):
        writer.WriteLine( "InitialStatus=Suspended" )
    writer.Close()
    
    # Create plugin info file. Empty for now.
    pluginInfoFilename = Path.Combine( GetDeadlineTempPath(), "pdplayer_plugin_info.job" )
    writer = StreamWriter( pluginInfoFilename, False, Encoding.Unicode )
    writer.Close()
    
    # Setup the command line arguments.
    arguments = StringCollection()
    arguments.Add( jobInfoFilename )
    arguments.Add( pluginInfoFilename )
    arguments.Add( sceneFile )
    
    # Now submit the job.
    results = ClientUtils.ExecuteCommandAndGetOutput( arguments )
    scriptDialog.ShowMessageBox( results, "Submission Results" )
Example #25
0
def GetStreamWriter(stream, autoFlush=True):
    writer = StreamWriter(stream)
    writer.AutoFlush = autoFlush
    return writer
def SubmitButtonPressed(*args):
    global scriptDialog
    global integration_dialog

    try:
        submitScene = scriptDialog.GetValue("SubmitSceneBox")

        # Check if Integration options are valid
        if not integration_dialog.CheckIntegrationSanity():
            return

        warnings = []
        errors = []

        # Check if max files exist.
        sceneFiles = StringUtils.FromSemicolonSeparatedString(
            scriptDialog.GetValue("SceneBox"), False)
        if not sceneFiles:
            errors.append("No 3dsmax file specified")

        for sceneFile in sceneFiles:
            if not File.Exists(sceneFile):
                errors.append("3dsmax file %s does not exist" % sceneFile)
                return
            elif not submitScene and PathUtils.IsPathLocal(sceneFile):
                warnings.append(
                    "The scene file " + sceneFile +
                    " is local and is not being submitted with the job, are you sure you want to continue?"
                )

        # Check if path config file exists.
        pathConfigFile = scriptDialog.GetValue("PathConfigBox").strip()
        if pathConfigFile:
            if not File.Exists(pathConfigFile):
                errors.append("Path configuration file %s does not exist" %
                              pathConfigFile)

        # Check if PreLoad script file exists.
        preLoadFile = scriptDialog.GetValue("PreLoadBox").strip()
        if preLoadFile:
            if not File.Exists(preLoadFile):
                errors.append("PreLoad MAXScript file %s does not exist" %
                              preLoadFile)

        # Check if PostLoad script file exists.
        postLoadFile = scriptDialog.GetValue("PostLoadBox").strip()
        if postLoadFile:
            if not File.Exists(postLoadFile):
                errors.append("PostLoad MAXScript file %s does not exist" %
                              postLoadFile)

        # Check if PreFrame script file exists.
        preFrameFile = scriptDialog.GetValue("PreFrameBox").strip()
        if preFrameFile:
            if not File.Exists(preFrameFile):
                errors.append("PreFrame MAXScript file %s does not exist" %
                              preFrameFile)

        # Check if PostFrame script file exists.
        postFrameFile = scriptDialog.GetValue("PostFrameBox").strip()
        if postFrameFile:
            if not File.Exists(postFrameFile):
                errors.append("PostFrame MAXScript file %s does not exist" %
                              postFrameFile)

        # Check if a valid frame range has been specified.
        frames = scriptDialog.GetValue("FramesBox")
        if scriptDialog.GetValue("DBRModeBox") != "Disabled":
            frameArray = FrameUtils.Parse(frames)
            if len(frameArray) != 1:
                errors.append(
                    "Please specify a single frame for distributed rendering in the Frame List."
                )
            elif not FrameUtils.FrameRangeValid(frames):
                errors.append(
                    "Please specify a valid single frame for distributed rendering in the Frame List."
                )

            frames = "0-" + str(scriptDialog.GetValue("DBRServersBox") - 1)
        else:
            if not FrameUtils.FrameRangeValid(frames):
                errors.append("Frame range %s is not valid" % frames)

        # If using 'select GPU device Ids' then check device Id syntax is valid
        if scriptDialog.GetValue(
                "GPUsPerTaskBox") == 0 and scriptDialog.GetValue(
                    "GPUsSelectDevicesBox"):
            regex = re.compile("^(\d{1,2}(,\d{1,2})*)?$")
            validSyntax = regex.match(
                scriptDialog.GetValue("GPUsSelectDevicesBox"))
            if not validSyntax:
                errors.append(
                    "'Select GPU Devices' syntax is invalid!\nTrailing 'commas' if present, should be removed.\nValid Examples: 0 or 2 or 0,1,2 or 0,3,4 etc"
                )

            # Check if concurrent threads > 1
            if scriptDialog.GetValue("ConcurrentTasksBox") > 1:
                errors.append(
                    "If using 'Select GPU Devices', then 'Concurrent Tasks' must be set to 1"
                )

        if errors:
            scriptDialog.ShowMessageBox(
                "The following errors were encountered:\n\n%s\n\nPlease resolve these issues and submit again.\n"
                % ("\n\n".join(errors)), "Errors")
            return

        if warnings:
            result = scriptDialog.ShowMessageBox(
                "Warnings:\n\n%s\n\nDo you still want to continue?" %
                ("\n\n".join(warnings)), "Warnings", ("Yes", "No"))
            if result == "No":
                return

        successes = 0
        failures = 0

        # Submit each scene file separately.
        for sceneFile in sceneFiles:
            jobName = scriptDialog.GetValue("NameBox")
            if len(sceneFiles) > 1:
                jobName = jobName + " [" + Path.GetFileName(sceneFile) + "]"

            # Create job info file.
            jobInfoFilename = Path.Combine(ClientUtils.GetDeadlineTempPath(),
                                           "max_job_info.job")
            writer = StreamWriter(jobInfoFilename, False, Encoding.Unicode)
            writer.WriteLine("Plugin=3dsmax")
            writer.WriteLine("Name=%s" % jobName)
            writer.WriteLine("Comment=%s" %
                             scriptDialog.GetValue("CommentBox"))
            writer.WriteLine("Department=%s" %
                             scriptDialog.GetValue("DepartmentBox"))
            writer.WriteLine("Pool=%s" % scriptDialog.GetValue("PoolBox"))
            writer.WriteLine("SecondaryPool=%s" %
                             scriptDialog.GetValue("SecondaryPoolBox"))
            writer.WriteLine("Group=%s" % scriptDialog.GetValue("GroupBox"))
            writer.WriteLine("Priority=%s" %
                             scriptDialog.GetValue("PriorityBox"))
            writer.WriteLine("TaskTimeoutMinutes=%s" %
                             scriptDialog.GetValue("TaskTimeoutBox"))
            writer.WriteLine("EnableAutoTimeout=%s" %
                             scriptDialog.GetValue("AutoTimeoutBox"))
            writer.WriteLine("ConcurrentTasks=%s" %
                             scriptDialog.GetValue("ConcurrentTasksBox"))
            writer.WriteLine("LimitConcurrentTasksToNumberOfCpus=%s" %
                             scriptDialog.GetValue("LimitConcurrentTasksBox"))

            writer.WriteLine("MachineLimit=%s" %
                             scriptDialog.GetValue("MachineLimitBox"))
            if scriptDialog.GetValue("IsBlacklistBox"):
                writer.WriteLine("Blacklist=%s" %
                                 scriptDialog.GetValue("MachineListBox"))
            else:
                writer.WriteLine("Whitelist=%s" %
                                 scriptDialog.GetValue("MachineListBox"))

            writer.WriteLine("LimitGroups=%s" %
                             scriptDialog.GetValue("LimitGroupBox"))
            writer.WriteLine("JobDependencies=%s" %
                             scriptDialog.GetValue("DependencyBox"))
            writer.WriteLine("OnJobComplete=%s" %
                             scriptDialog.GetValue("OnJobCompleteBox"))

            if scriptDialog.GetValue("SubmitSuspendedBox"):
                writer.WriteLine("InitialStatus=Suspended")

            writer.WriteLine("Frames=%s" % frames)
            if scriptDialog.GetValue("DBRModeBox") == "Disabled":
                writer.WriteLine("ChunkSize=%s" %
                                 scriptDialog.GetValue("ChunkSizeBox"))

            # Integration
            extraKVPIndex = 0
            groupBatch = False

            if integration_dialog.IntegrationProcessingRequested():
                extraKVPIndex = integration_dialog.WriteIntegrationInfo(
                    writer, extraKVPIndex)
                groupBatch = groupBatch or integration_dialog.IntegrationGroupBatchRequested(
                )

            if groupBatch:
                writer.WriteLine("BatchName=%s\n" % jobName)

            writer.Close()

            # Create plugin info file.
            pluginInfoFilename = Path.Combine(
                ClientUtils.GetDeadlineTempPath(), "max_plugin_info.job")
            writer = StreamWriter(pluginInfoFilename, False, Encoding.Unicode)

            writer.WriteLine("Version=%s" %
                             scriptDialog.GetValue("VersionBox"))
            writer.WriteLine("IsMaxDesign=%s" %
                             scriptDialog.GetValue("IsMaxDesignBox"))

            if int(scriptDialog.GetValue("VersionBox")) < 2014:
                writer.WriteLine("MaxVersionToForce=%s" %
                                 scriptDialog.GetValue("BuildBox"))
                writer.WriteLine("MaxVersionToForce0=None")
                writer.WriteLine("MaxVersionToForce1=32bit")
                writer.WriteLine("MaxVersionToForce2=64bit")

            writer.WriteLine("UseSlaveMode=%d" %
                             (not scriptDialog.GetValue("WorkstationModeBox")))
            if scriptDialog.GetValue("WorkstationModeBox"):
                writer.WriteLine("UseSilentMode=%s" %
                                 (scriptDialog.GetValue("SilentModeBox")))
            else:
                writer.WriteLine("UseSilentMode=False")

            writer.WriteLine("ShowFrameBuffer=%s" %
                             scriptDialog.GetValue("ShowVfbBox"))
            writer.WriteLine("RemovePadding=%s" %
                             scriptDialog.GetValue("RemovePaddingBox"))
            writer.WriteLine("RestartRendererMode=%s" %
                             scriptDialog.GetValue("RestartRendererBox"))
            writer.WriteLine(
                "IgnoreMissingExternalFiles=%s" %
                scriptDialog.GetValue("IgnoreMissingExternalFilesBox"))
            writer.WriteLine("IgnoreMissingUVWs=%s" %
                             scriptDialog.GetValue("IgnoreMissingUVWsBox"))
            writer.WriteLine("IgnoreMissingXREFs=%s" %
                             scriptDialog.GetValue("IgnoreMissingXREFsBox"))
            writer.WriteLine("IgnoreMissingDLLs=%s" %
                             scriptDialog.GetValue("IgnoreMissingDLLsBox"))
            writer.WriteLine("LocalRendering=%s" %
                             scriptDialog.GetValue("LocalRenderingBox"))
            writer.WriteLine("DisableMultipass=%s" %
                             scriptDialog.GetValue("DisableMultipassBox"))
            writer.WriteLine("OneCpuPerTask=%s" %
                             scriptDialog.GetValue("OneCpuPerTaskBox"))

            if pathConfigFile:
                writer.WriteLine("PathConfigFile=%s" %
                                 Path.GetFileName(pathConfigFile))
                writer.WriteLine("MergePathConfigFile=%s" %
                                 scriptDialog.GetValue("MergePathConfigBox"))

            if preLoadFile:
                writer.WriteLine("PreLoadScript=%s" %
                                 Path.GetFileName(preLoadFile))

            if postLoadFile:
                writer.WriteLine("PostLoadScript=%s" %
                                 Path.GetFileName(postLoadFile))

            if preFrameFile:
                writer.WriteLine("PreFrameScript=%s" %
                                 Path.GetFileName(preFrameFile))

            if postFrameFile:
                writer.WriteLine("PostFrameScript=%s" %
                                 Path.GetFileName(postFrameFile))

            pluginIniOverride = scriptDialog.GetValue("PluginIniBox").strip()
            if pluginIniOverride:
                writer.WriteLine("OverridePluginIni=%s" % pluginIniOverride)

            writer.WriteLine("GammaCorrection=%s" %
                             scriptDialog.GetValue("GammaCorrectionBox"))
            writer.WriteLine("GammaInput=%s" %
                             scriptDialog.GetValue("GammaInputBox"))
            writer.WriteLine("GammaOutput=%s" %
                             scriptDialog.GetValue("GammaOutputBox"))

            if int(scriptDialog.GetValue("VersionBox")) >= 2013:
                if scriptDialog.GetValue("OverrideLanguageBox"):
                    writer.WriteLine("Language=%s" %
                                     scriptDialog.GetValue("LanguageBox"))
                else:
                    writer.WriteLine("Language=Default")

            camera = scriptDialog.GetValue("CameraBox")
            if camera:
                writer.WriteLine("Camera=%s" % camera)
                writer.WriteLine("Camera0=")
                writer.WriteLine("Camera1=%s" % camera)

            if not submitScene:
                writer.WriteLine("SceneFile=%s" % sceneFile)

            if scriptDialog.GetValue("DBRModeBox") != "Disabled":
                if scriptDialog.GetValue("DBRModeBox") == "VRay DBR":
                    writer.WriteLine("VRayDBRJob=True")
                elif scriptDialog.GetValue(
                        "DBRModeBox") == "Mental Ray Satellite":
                    writer.WriteLine("MentalRayDBRJob=True")
                elif scriptDialog.GetValue("DBRModeBox") == "VRay RT DBR":
                    writer.WriteLine("VRayRtDBRJob=True")
                writer.WriteLine("DBRJobFrame=%s" %
                                 scriptDialog.GetValue("FramesBox"))

            if scriptDialog.GetValue("DBRModeBox") == "Disabled":
                writer.WriteLine("GPUsPerTask=%s" %
                                 scriptDialog.GetValue("GPUsPerTaskBox"))
                writer.WriteLine("GPUsSelectDevices=%s" %
                                 scriptDialog.GetValue("GPUsSelectDevicesBox"))

            writer.Close()

            # Setup the command line arguments.
            arguments = [jobInfoFilename, pluginInfoFilename]
            if scriptDialog.GetValue("SubmitSceneBox"):
                arguments.append(sceneFile)

            if pathConfigFile:
                arguments.append(pathConfigFile)
            if preLoadFile:
                arguments.append(preLoadFile)
            if postLoadFile:
                arguments.append(postLoadFile)
            if preFrameFile:
                arguments.append(preFrameFile)
            if postFrameFile:
                arguments.append(postFrameFile)

            if len(sceneFiles) == 1:
                results = ClientUtils.ExecuteCommandAndGetOutput(arguments)
                scriptDialog.ShowMessageBox(results, "Submission Results")
            else:
                # Now submit the job.
                exitCode = ClientUtils.ExecuteCommand(arguments)
                if exitCode == 0:
                    successes += 1
                else:
                    failures += 1

        if len(sceneFiles) > 1:
            scriptDialog.ShowMessageBox(
                "Jobs submitted successfully: %d\nJobs not submitted: %d" %
                (successes, failures), "Submission Results")
    except:
        scriptDialog.ShowMessageBox(traceback.format_exc(), "")
Example #27
0
    def _submit_button_pressed( self, *args ):
        """
        Callback for the "submit" button. Submits a job to Deadline
        :param args:
        :return:
        """
        warnings = []
        errors = []

        # If using 'select GPU device Ids' then check device Id syntax is valid.
        if self.GetValue( "GPUsPerTaskBox" ) == 0 and self.GetValue( "GPUsSelectDevicesBox" ) != "":
            # regex = re.compile( "^(\d{1,2}(,\d{1,2})*)?$" ) # Multiple gpu check
            regex = re.compile( "^([0-9]|1[0-6])$" ) # Single gpu check (Altus 1.8 currently only supports 1 gpu)

            valid_syntax = regex.match( self.GetValue( "GPUsSelectDevicesBox" ) )
            if not valid_syntax:
                # errors.append( "'Select GPU Devices' syntax is invalid!\nTrailing 'commas' if present, should be removed.\nValid Examples: 0 or 2 or 0,1,2 or 0,3,4 etc" ) # Multiple gpu check
                errors.append( "'Select GPU Device' syntax is invalid!\nSingle GPU ID 0-16 supported only.\nValid Examples: 0 or 1 or 2 etc" ) # Single gpu check (Altus 1.8 currently only supports 1 gpu per thread)

            # Check if concurrent threads > 1.
            if self.GetValue( "ConcurrentTasksBox" ) > 1:
                errors.append( "If using 'Select GPU Devices', then 'Concurrent Tasks' must be set to 1" )

        stereo_enabled = self.GetValue( "StereoBox" )
        version = float( self.GetValue( "VersionBox" ) )
        full_output_path = self.GetValue( "OutputBox" )
        use_config = self.GetValue( "configCheck" )

        # Check if a valid frame range has been specified.
        frames = self.GetValue( "FramesBox" )
        if not FrameUtils.FrameRangeValid( frames ):
            errors.append( "Frame range: %s is not valid" % frames )

        if not full_output_path:
            errors.append( "The output image name is required." )

        self._check_output_destination( errors, warnings )

        if use_config:
            self._check_config_input( errors, warnings )
        else:
            self._check_file_inputs( errors, warnings )

        # Check if Integration options are valid.
        if not self.integration_dialog.CheckIntegrationSanity( full_output_path ):
            return

        if errors:
            self.ShowMessageBox( "The following errors were encountered:\n\n%s\n\nPlease resolve these issues and submit again.\n" % ( "\n".join( errors ) ), "Errors" )
            return

        if warnings:
            result = self.ShowMessageBox( "Warnings:\n\n%s\n\nDo you still want to continue?" % ( "\n".join( warnings ) ), "Warnings", ( "Yes","No" ) )
            if result == "No":
                return

        # Create job info file.
        job_info_file = os.path.join( ClientUtils.GetDeadlineTempPath(), "altus_job_info.job" )
        writer = StreamWriter( job_info_file, False, Encoding.Unicode )
        writer.WriteLine( "Plugin=Altus" )
        writer.WriteLine( "Name=%s" % self.GetValue( "NameBox" ) )
        writer.WriteLine( "Comment=%s" % self.GetValue( "CommentBox" ) )
        writer.WriteLine( "Department=%s" % self.GetValue( "DepartmentBox" ) )
        writer.WriteLine( "Pool=%s" % self.GetValue( "PoolBox" ) )
        writer.WriteLine( "SecondaryPool=%s" % self.GetValue( "SecondaryPoolBox" ) )
        writer.WriteLine( "Group=%s" % self.GetValue( "GroupBox" ) )
        writer.WriteLine( "Priority=%s" % self.GetValue( "PriorityBox" ) )
        writer.WriteLine( "TaskTimeoutMinutes=%s" % self.GetValue( "TaskTimeoutBox" ) )
        writer.WriteLine( "EnableAutoTimeout=%s" % self.GetValue( "AutoTimeoutBox" ) )
        writer.WriteLine( "ConcurrentTasks=%s" % self.GetValue( "ConcurrentTasksBox" ) )
        writer.WriteLine( "LimitConcurrentTasksToNumberOfCpus=%s" % self.GetValue( "LimitConcurrentTasksBox" ) )

        writer.WriteLine( "MachineLimit=%s" % self.GetValue( "MachineLimitBox" ) )
        if self.GetValue( "IsBlacklistBox" ):
            writer.WriteLine( "Blacklist=%s" % self.GetValue( "MachineListBox" ) )
        else:
            writer.WriteLine( "Whitelist=%s" % self.GetValue( "MachineListBox" ) )

        writer.WriteLine( "LimitGroups=%s" % self.GetValue( "LimitGroupBox" ) )
        writer.WriteLine( "JobDependencies=%s" % self.GetValue( "DependencyBox" ) )
        writer.WriteLine( "OnJobComplete=%s" % self.GetValue( "OnJobCompleteBox" ) )

        full_output_path = full_output_path.replace( "\\", "/" )
        writer.WriteLine( "OutputFilename0=%s" % full_output_path )

        if self.GetValue( "SubmitSuspendedBox" ):
            writer.WriteLine( "InitialStatus=Suspended" )

        writer.WriteLine( "Frames=%s" % frames )
        writer.WriteLine( "ChunkSize=%s" % self.GetValue( "ChunkSizeBox" ) )

        extra_kvp_index = 0
        group_batch = False
        if self.integration_dialog.IntegrationProcessingRequested():
            extra_kvp_index = self.integration_dialog.WriteIntegrationInfo( writer, extra_kvp_index )
            group_batch = group_batch or self.integration_dialog.IntegrationGroupBatchRequested()

        if group_batch:
            writer.WriteLine( "BatchName=%s" % ( self.GetValue( "NameBox" ) ) )

        writer.Close()

        # Create plugin info file.
        plugin_info_file = os.path.join( ClientUtils.GetDeadlineTempPath(), "altus_plugin_info.job" )
        writer = StreamWriter( plugin_info_file, False, Encoding.Unicode )

        exe_type = self.GetValue( "ExecutableTypeBox" )
        writer.WriteLine( "ExecutableType=%s" % exe_type )

        writer.WriteLine( "Version=%s" % version )
        writer.WriteLine( "OutputFile=%s" % full_output_path )

        if exe_type in [ "OpenCl", "GPU", "Auto Select" ]:
            writer.WriteLine( "GPUsPerTask=%s" % self.GetValue( "GPUsPerTaskBox" ) )
            writer.WriteLine( "GPUsSelectDevices=%s" % self.GetValue( "GPUsSelectDevicesBox" ) )

        # If config file defined, then skip all other settings.
        if use_config:
            writer.WriteLine( "Config=%s" % self.GetValue( "ConfigBox" ) )
        else:
            for passType in AltusSubmissionDialog.PASS_TYPES:
                if self._pass_enabled( passType ):
                    writer.WriteLine( "%sFiles=%s;" % ( passType, self.GetValue( "%sBox" % passType ) ) )

            writer.WriteLine( "Renderer=%s" % self.GetValue( "RendererBox" ) )
            writer.WriteLine( "PreserveLayers=%s" % self.GetValue( "LayerPreservationBox" ) )
            writer.WriteLine( "OutputQuality=%s" % self.GetValue( "QualityBox" ) )
            writer.WriteLine( "AOVQuality=%s" % self.GetValue( "AOVQualityBox" ) )
            writer.WriteLine( "FrameRadius=%s" % self.GetValue( "FrameRadiusBox" ) )
            writer.WriteLine( "FilterRadius=%s" % self.GetValue( "FilterRadiusBox" ) )
            writer.WriteLine( "Kc_1=%s" % self.GetValue( "Kc1Box" ) )
            writer.WriteLine( "Kc_2=%s" % self.GetValue( "Kc2Box" ) )
            writer.WriteLine( "Kc_4=%s" % self.GetValue( "Kc4Box" ) )
            writer.WriteLine( "Kf=%s" % self.GetValue( "KfBox" ) )
            writer.WriteLine( "Stereo=%s" % stereo_enabled )
            if version == 1.8:
                # 1.8 is either False (Level 0) or True (Level 3)
                writer.WriteLine( "ForceContinue=%s" % bool( self.GetValue( "ForceContinueIntBox" )[ 0 ] ) )
            else:
                writer.WriteLine( "ForceContinueInt=%s" % self.GetValue( "ForceContinueIntBox" )[ 0 ] ) # Just need first character

            # Tile options
            writer.WriteLine( "Tile=%s" % self.GetValue( "TileBox" ) )
            writer.WriteLine( "TileSize=%s" % self.GetValue( "TileSizeBox" ) )

            writer.WriteLine( "FireFly=%s" % self.GetValue( "FireFlyBox" ) )

            if version >= 1.9:
                writer.WriteLine( "SkipFrameRadius=%s" % self.GetValue( "SkipFrameRadiusBox" ) )
                writer.WriteLine( "IgnoreAlpha=%s" % self.GetValue( "IgnoreAlphaBox" ) )

            if version >= 2.1:
                writer.WriteLine( "SinglePass=%s" % self.GetValue( "SinglePassBox" ) )

            if version >= 2.3:
                writer.WriteLine( "Force16bitOutput=%s" % self.GetValue( "Force16bitOutputBox" ) )
                writer.WriteLine( "EXRCompression=%s" % self.GetValue( "EXRCompressionBox" ) )

        writer.Close()

        # Setup the command line arguments.
        arguments = [ job_info_file, plugin_info_file ]

        # Now submit the job.
        results = ClientUtils.ExecuteCommandAndGetOutput( arguments )
        self.ShowMessageBox( results, "Submission Results" )
Example #28
0
#imports
from System.IO import StreamWriter, FileMode
from Spotfire.Dxp.Application.Visuals import CrossTablePlot
from Spotfire.Dxp.Data.Export import DataWriterTypeIdentifiers
import tempfile
import os

#create a temporary

tmp = os.path.join(tempfile.gettempdir(), "forecast_input.csv")
stream = StreamWriter(tmp)

#export the cross table
crossTable.As[CrossTablePlot]().ExportText(stream)
stream.Close()

f = open(tmp, 'r')

csv = ""

month_map = {
    "Jan": "01",
    "Feb": "02",
    "Mar": "03",
    "Apr": "04",
    "May": "05",
    "Jun": "06",
    "Jul": "07",
    "Aug": "08",
    "Sep": "09",
    "Oct": "10",
Example #29
0
def SubmitButtonPressed(*args):
    global scriptDialog
    global integration_dialog
    
    submitScene = bool(scriptDialog.GetValue("SubmitSceneBox"))
    multiMachine = bool(scriptDialog.GetValue("MultiMachineBox"))
    
    # Check if scene file exists
    sceneFile = scriptDialog.GetValue( "SceneBox" )
    if( not File.Exists( sceneFile ) ):
        scriptDialog.ShowMessageBox("Project file %s does not exist." % sceneFile, "Error" )
        return
    elif(not submitScene and PathUtils.IsPathLocal(sceneFile)):
        result = scriptDialog.ShowMessageBox("The project file " + sceneFile + " is local, are you sure you want to continue?","Warning", ("Yes","No") )
        if( result == "No" ):
            return
    
    concurrentTasks = scriptDialog.GetValue( "ConcurrentTasksBox" )
    if concurrentTasks > 1:
        result = scriptDialog.ShowMessageBox("The concurrent tasks is set to a value greater than 1.  This can cause Jobs to hang when rendering, are you sure you want to continue?","Warning", ("Yes","No") )
        if( result == "No" ):
            return
    
    outputFile = ""
    frames = ""
    jobName = scriptDialog.GetValue( "NameBox" )
    
    # Get the comp
    comp = scriptDialog.GetValue("CompBox")
    if comp != "":
        # Check that the output is valid
        outputFile = scriptDialog.GetValue( "OutputBox" ).strip()
        if len(outputFile) > 0:
            if not Directory.Exists( Path.GetDirectoryName(outputFile) ):
                scriptDialog.ShowMessageBox( "The directory of the output file does not exist:\n" + Path.GetDirectoryName(outputFile), "Error" )
                return
            elif(PathUtils.IsPathLocal(outputFile)):
                result = scriptDialog.ShowMessageBox("The output file " + outputFile + " is local, are you sure you want to continue?","Warning", ("Yes","No") )
                if( result == "No" ):
                    return
            
            extension = Path.GetExtension( outputFile )
            if not IsMovieFormat( extension ):
                if outputFile.find( "[#" ) < 0 and outputFile.find( "#]" ) < 0:
                    directory = Path.GetDirectoryName( outputFile )
                    filename = Path.GetFileNameWithoutExtension( outputFile )
                    outputFile = Path.Combine( directory, filename + "[#####]" + extension )
        
        #Since we don't specify ranges for multi-machine rendering, don't check frame range when Multi-Machine Rendering = True
        if not multiMachine:
            # Check if a valid frame range has been specified.
            frames = scriptDialog.GetValue( "FramesBox" )
            if( not FrameUtils.FrameRangeValid( frames ) ):
                scriptDialog.ShowMessageBox( "Frame range %s is not valid" % frames, "Error" )
                return
    else:
        jobName = jobName + " - Entire Render Queue"
    
    if multiMachine:
        jobName = jobName + " (multi-machine rendering)"
    
    # Check if Integration options are valid
    if not integration_dialog.CheckIntegrationSanity( outputFile ):
        return
    
    # Create job info file.
    jobInfoFilename = Path.Combine( ClientUtils.GetDeadlineTempPath(), "ae_job_info.job" )
    writer = StreamWriter( jobInfoFilename, False, Encoding.Unicode )
    writer.WriteLine( "Plugin=AfterEffects" )
    writer.WriteLine( "Name=%s" % jobName )
    writer.WriteLine( "Comment=%s" % scriptDialog.GetValue( "CommentBox" ) )
    writer.WriteLine( "Department=%s" % scriptDialog.GetValue( "DepartmentBox" ) )
    writer.WriteLine( "Pool=%s" % scriptDialog.GetValue( "PoolBox" ) )
    writer.WriteLine( "SecondaryPool=%s" % scriptDialog.GetValue( "SecondaryPoolBox" ) )
    writer.WriteLine( "Group=%s" % scriptDialog.GetValue( "GroupBox" ) )
    writer.WriteLine( "Priority=%s" % scriptDialog.GetValue( "PriorityBox" ) )
    writer.WriteLine( "TaskTimeoutMinutes=%s" % scriptDialog.GetValue( "TaskTimeoutBox" ) )
    writer.WriteLine( "EnableAutoTimeout=%s" % scriptDialog.GetValue( "AutoTimeoutBox" ) )
    writer.WriteLine( "ConcurrentTasks=%s" % concurrentTasks )
    writer.WriteLine( "LimitConcurrentTasksToNumberOfCpus=%s" % scriptDialog.GetValue( "LimitConcurrentTasksBox" ) )
    
    if( bool(scriptDialog.GetValue( "IsBlacklistBox" )) ):
        writer.WriteLine( "Blacklist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
    else:
        writer.WriteLine( "Whitelist=%s" % scriptDialog.GetValue( "MachineListBox" ) )
    
    writer.WriteLine( "LimitGroups=%s" % scriptDialog.GetValue( "LimitGroupBox" ) )
    writer.WriteLine( "JobDependencies=%s" % scriptDialog.GetValue( "DependencyBox" ) )
    writer.WriteLine( "OnJobComplete=%s" % scriptDialog.GetValue( "OnJobCompleteBox" ) )
    
    if( bool(scriptDialog.GetValue( "SubmitSuspendedBox" )) ):
        writer.WriteLine( "InitialStatus=Suspended" )
    
    if multiMachine:
        writer.WriteLine( "MachineLimit=0" )
        writer.WriteLine( "Frames=1-%s" % scriptDialog.GetValue( "MultiMachineTasksBox" ) )
        writer.WriteLine( "ChunkSize=1" )
    else:
        if comp != "":
            writer.WriteLine( "MachineLimit=%s" % scriptDialog.GetValue( "MachineLimitBox" ) )
            writer.WriteLine( "Frames=%s" % frames )
            writer.WriteLine( "ChunkSize=%s" % scriptDialog.GetValue( "ChunkSizeBox" ) )
        else:
            writer.WriteLine( "MachineLimit=1" )
            writer.WriteLine( "Frames=0" )
            writer.WriteLine( "ChunkSize=1" )
    
    if len(outputFile) > 0:
        writer.WriteLine( "OutputFilename0=%s" % outputFile.replace( "[#####]", "#####" ) )
    
    extraKVPIndex = 0
    groupBatch = False
    if integration_dialog.IntegrationProcessingRequested():
        extraKVPIndex = integration_dialog.WriteIntegrationInfo( writer, extraKVPIndex )
        groupBatch = groupBatch or integration_dialog.IntegrationGroupBatchRequested()
        
    if groupBatch:
        writer.WriteLine( "BatchName=%s\n" % ( jobName ) ) 
    writer.Close()
    # Create plugin info file.
    version = GetVersionNumber()
    
    pluginInfoFilename = Path.Combine( ClientUtils.GetDeadlineTempPath(), "ae_plugin_info.job" )
    writer = StreamWriter( pluginInfoFilename, False, Encoding.Unicode )
    
    if(not bool(scriptDialog.GetValue("SubmitSceneBox"))):
        writer.WriteLine("SceneFile=%s" % scriptDialog.GetValue("SceneBox").replace("\\","/").strip())
        
    writer.WriteLine("Comp=%s" % scriptDialog.GetValue("CompBox"))
    writer.WriteLine("Version=%s" % str(version) )
    writer.WriteLine("IgnoreMissingLayerDependenciesErrors=%s" % scriptDialog.GetValue("MissingLayers"))
    writer.WriteLine("IgnoreMissingEffectReferencesErrors=%s" % scriptDialog.GetValue("MissingEffects"))
    writer.WriteLine("FailOnWarnings=%s" % scriptDialog.GetValue("FailOnWarnings"))
    
    if multiMachine:
        writer.WriteLine("MultiMachineMode=True")
    else:
        writer.WriteLine("LocalRendering=%s" % scriptDialog.GetValue("LocalRendering"))
    
    writer.WriteLine("OverrideFailOnExistingAEProcess=%s" % scriptDialog.GetValue("OverrideFailOnExistingAEProcess"))
    writer.WriteLine("FailOnExistingAEProcess=%s" % scriptDialog.GetValue("OverrideFailOnExistingAEProcess"))

    writer.WriteLine("MemoryManagement=%s" % scriptDialog.GetValue("MemoryManagement"))
    writer.WriteLine("ImageCachePercentage=%s" % scriptDialog.GetValue("ImageCachePercentage"))
    writer.WriteLine("MaxMemoryPercentage=%s" % scriptDialog.GetValue("MaxMemoryPercentage"))
    
    writer.WriteLine("MultiProcess=%s" % scriptDialog.GetValue("MultiProcess"))
    if version > 8:
        writer.WriteLine("ContinueOnMissingFootage=%s" % scriptDialog.GetValue("MissingFootage"))
    
    if len(outputFile) > 0:
        writer.WriteLine("Output=%s" % outputFile)
    
    writer.Close()
    
    # Setup the command line arguments.
    arguments = [ jobInfoFilename, pluginInfoFilename ]
    if scriptDialog.GetValue( "SubmitSceneBox" ):
        arguments.append( sceneFile )
    
    # Now submit the job.
    results = ClientUtils.ExecuteCommandAndGetOutput( arguments )
    scriptDialog.ShowMessageBox( results, "Submission Results" )