AWS Thinkbox Discussion Forums

Web Service - Plain/Raw Html Text in browser

hi,

i am on deadline 10.2.0.10 and when executing this script i get plain html-text in the browser (the generated html is interpreted as plain text)…any hints?

script:

from System import String
from System import DateTime
from System.IO import *
from System.Security import *
from System.Text import *

from Deadline.Scripting import *

import traceback

########################################################################
## Main Function Called By Deadline
########################################################################
def __main__( dlArgs, qsArgs ):
    returnVal = ""
    
    sb = StringBuilder()
    
    # Get the args
    egosort = qsArgs["ego"] if "ego" in qsArgs else None
    primarysort = qsArgs["psort"] if "psort" in qsArgs else None
    primarysortorder = qsArgs["psord"] if "psord" in qsArgs else None
    secondarysort = qsArgs["ssort"] if "ssort" in qsArgs else None
    secondarysortorder = qsArgs["ssord"] if "ssord" in qsArgs else None
    pulseaddress = qsArgs["pulse"] if "pulse" in qsArgs else None
    lastupdate = qsArgs["update"] if "update" in qsArgs else None
    nonplist = qsArgs["plist"] if "plist" in qsArgs else None

    # parse the last update
    if ( lastupdate != None ):
        lastupdate = fromPlatformIndDateTime( lastupdate )#BUG possibility when starting the app for the first time - unable to reproduce
    
    # check if plist is wanted or not

        
    plugins = {}
    users = {}
    statuses = {}
    groups = {}
    pools = {}
    
    thisAddress = ClientUtils.GetMacAddress()
    jobs = WebServiceUtils.GetJobs()
    
    # do the sorts
    if ( secondarysort != None ):
        jobs = SortDictArrayByKey( jobs, secondarysort, secondarysortorder )
    if ( primarysort != None ):
        jobs = SortDictArrayByKey( jobs, primarysort, primarysortorder )
    if ( egosort != None ):
        jobs = EgoSortDictArray( jobs, egosort )

    sb.AppendLine( "<HTML>" )
    sb.AppendLine( "<TABLE>" )
	
    # add each job
    for job in jobs:
        if ( job != None and job["Status"] != "Deleted"):
            try:
                lastJobUpdate = DateTime.Parse( job["LastWriteTime"] )
            except:
                lastJobUpdate = None
			
			# if there was no update time given, or the update time is before this jobs last update

            sb.AppendLine( "\t<TR>" )
            sb.AppendLine( "\t\t<TD>Name: " + SecurityElement.Escape( job["Name"] ) + "</TD>" )
            sb.AppendLine( "\t\t<TD>Comment: " + SecurityElement.Escape( job["Comment"] ) + "</TD>" )
            sb.AppendLine( "\t\t<TD>PluginName: " + job["PluginName"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>UserName: " + job["UserName"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>Status: " + job["Status"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>JobId: " + job["JobId"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>TaskCount: " + job["TaskCount"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>CompletedChunks: " + job["CompletedChunks"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>ErrorReports: " + job["ErrorReports"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>Group: " + job["Group"] + "</TD>" )
            sb.AppendLine( "\t\t<TD>Pool: " + job["Pool"] + "</TD>" )
            sb.AppendLine( "\t</TR>" )
            # if the job is up to date, just print it's id to retrieve its data
	
	
	# add the new update time
    sb.AppendLine( "\t\t<update>" + toPlatformIndDateTime( DateTime.Now ) + "</update>" )

    sb.AppendLine( "</TABLE>" )
	
    returnVal = sb.ToString()
    
    return returnVal

def toPlatformIndDateTime( dt ):
    day = dt.Day
    month = dt.Month
    year = dt.Year
    
    second = dt.Second
    minute = dt.Minute
    hour = dt.Hour
    
    return str(day) + "/" + str(month) + "/" + str(year) + "_" + str(hour) + ":" + str(minute) + ":" + str(second)

# accepts "day/month/year hour:min:sec"
def fromPlatformIndDateTime( dt ):
    dt = str(dt)
    
    (date, time) = dt.split( "_" )
    (day, month, year) = date.split( "/" )
    (hour, minute, second) = time.split( ":" )
    
    return DateTime( int(year), int(month), int(day), int(hour), int(minute), int(second) )

def listKeys( title, dict, sb, useplist ):
    if ( useplist == False ):
        # print the dict
        sb.AppendLine( "\t\t<m" + title + "s>" )
        
        # print the values
        for key in dict:
            sb.AppendLine( "\t\t\t<m" + title + ">" + key + "</m" + title  + ">" )
        
        # close the dict
        sb.AppendLine( "\t\t</m" + title + "s>" )
    else:
        # print the dict
        sb.AppendLine( "\t\t<key>" + title + "</key>" )
        sb.AppendLine( "\t\t<dict>" )
        
        # print the values
        for key in dict:
            sb.AppendLine( "\t\t\t<key>" + key + "</key><true />" )
        
        # close the dict
        sb.AppendLine( "\t\t</dict>" )
        
def EgoSortDictArray( array, user ):
    userArray = []
    otherArray = []
    
    for i in range( 0, len(array) ):
        if ( String.Compare( array[i]["UserName"], user, True ) == 0 ):
            userArray.append( array[i] )
        else:
            otherArray.append( array[i] )
    
    for i in range( 0, len(otherArray) ):
        userArray.append( otherArray[i] )
    
    return userArray

def SortDictArrayByKey( array, key, order ):
    arrayList = []
    for item in array:
        arrayList.append(item)
    
    return mergesort( arrayList, key, order )
    
def mergesort( list, key, order ):
    # base case
    if ( len( list ) <= 1 ):
        return list
    
    # get left and right list
    left = list[:len(list)/2]
    right = list[len(list)/2:len(list)]
    
    # recursively sort the list
    left = mergesort( left, key, order )
    right = mergesort( right, key, order )
    
    # merge the lists into ret
    return merge( left, right, key, order )

def merge( left, right, key, order ):
    # init return list
    ret = []
    
    # init position in left and right lists
    leftPos = 0
    rightPos = 0
    
    # get the length of the two lists
    lenLeft = len( left )
    lenRight = len( right )
    
    # merge the lists
    if ( order == None or order == "0" ):
        while ( leftPos < lenLeft and rightPos < lenRight ):
            if ( String.Compare( key, "SubmitDateTime", True ) != 0 ):
                # Normal String Compare
                if ( left[leftPos] == None ):
                    leftPos += 1
                elif ( right[rightPos] == None ):
                    rightPos += 1
                elif ( String.Compare( left[leftPos][key], right[rightPos][key], True ) <= 0 ):
                    ret.append( left[leftPos] )
                    leftPos += 1
                else:
                    ret.append( right[rightPos] )
                    rightPos += 1
            else:
                # Compare Dates
                if ( left[leftPos] == None ):
                    leftPos += 1
                elif ( right[rightPos] == None ):
                    rightPos += 1
                else:
                    try:
                        if ( DateTime.Compare( DateTime.Parse( left[leftPos][key] ), DateTime.Parse( right[rightPos][key] ) ) >= 0 ):
                            ret.append( left[leftPos] )
                            leftPos += 1
                        else:
                            ret.append( right[rightPos] )
                            rightPos += 1
                    except:
                        leftPos += 1
    else:
        while ( leftPos < lenLeft and rightPos < lenRight ):
            if ( String.Compare( key, "SubmitDateTime", True ) != 0 ):
                # Normal String Compare
                if ( left[leftPos] == None ):
                    leftPos += 1
                elif ( right[rightPos] == None ):
                    rightPos += 1
                elif ( String.Compare( left[leftPos][key], right[rightPos][key], True ) >= 0 ):
                    ret.append( left[leftPos] )
                    leftPos += 1
                else:
                    ret.append( right[rightPos] )
                    rightPos += 1
            else:
                # Compare Dates
                if ( left[leftPos] == None ):
                    leftPos += 1
                elif ( right[rightPos] == None ):
                    rightPos += 1
                else:
                    try:
                        if ( DateTime.Compare( DateTime.Parse( left[leftPos][key] ), DateTime.Parse( right[rightPos][key] ) ) <= 0 ):
                            ret.append( left[leftPos] )
                            leftPos += 1
                        else:
                            ret.append( right[rightPos] )
                            rightPos += 1
                    except:
                        leftPos += 1
    
    # extend ret with the remaining list
    if ( leftPos < lenLeft ):
        while ( leftPos < lenLeft ):
            if ( left[leftPos] == None ):
                leftPos += 1
            else:
                ret.append( left[leftPos] )
                leftPos += 1
    else:
        while ( rightPos < lenRight ):
            if ( right[rightPos] == None ):
                rightPos += 1
            else:
                ret.append( right[rightPos] )
                rightPos += 1
    
    return ret

how it looks in browser:

<HTML>
<TABLE>
	<TR>
		<TD>Name: OpenCue_003 - layer1 - CAM</TD>
		<TD>Comment: </TD>
		<TD>PluginName: MayaBatch</TD>
		<TD>UserName: willi</TD>
		<TD>Status: Completed</TD>
		<TD>JobId: 63c7cea27643c50c7e0674da</TD>
		<TD>TaskCount: 17</TD>
		<TD>CompletedChunks: 17</TD>
		<TD>ErrorReports: 0</TD>
		<TD>Group: none</TD>
		<TD>Pool: none</TD>
	</TR>
	<TR>
		<TD>Name: OpenCue_003 - layer1 - CAM</TD>
		<TD>Comment: </TD>
		<TD>PluginName: MayaBatch</TD>
		<TD>UserName: willi</TD>
		<TD>Status: Completed</TD>
		<TD>JobId: 63c7d7d5020cc1e38b4bb225</TD>
		<TD>TaskCount: 17</TD>
		<TD>CompletedChunks: 17</TD>
		<TD>ErrorReports: 0</TD>
		<TD>Group: none</TD>
		<TD>Pool: none</TD>
	</TR>
	<TR>
		<TD>Name: OpenCue_003 - layer1 - CAM</TD>
		<TD>Comment: </TD>
		<TD>PluginName: MayaBatch</TD>
		<TD>UserName: willi</TD>
		<TD>Status: Completed</TD>
		<TD>JobId: 63c7fb872939215a78e4b5c1</TD>
		<TD>TaskCount: 17</TD>
		<TD>CompletedChunks: 17</TD>
		<TD>ErrorReports: 0</TD>
		<TD>Group: none</TD>
		<TD>Pool: none</TD>
	</TR>
		<update>18/1/2023_16:11:41</update>
</TABLE>

Hello @soulcage

Webservice is outputting it as plain text is not supported as HTML format in Deadline. You will need to find a way to convert the output from webservice in Html format. Like Nginx.

I was going to link the forums post: Simple Web Interface for Deadline but seems like you beat me there.

ahhh. thx for the hint…

i want to try building a web-interface like backburner web.

is the python-api a good way to go or should it be better using directly the mongoDB and php?

btw…
i found out now how to use the deadline standalone python-API in conjunction with xampp and spit out html from python code…

(its a bit hard because there is no real sample code on how to retrieve all the parameters from jobs…)

Privacy | Site terms | Cookie preferences