We are trying to pass a file name that contains the “½” character to a program that trims the image, but it keeps failing no matter how we do it … so any suggestions as to what we are doing wrong would be appriciated
we are using deadline 8.0.13.3 and python 2.7.11
(we will be upgrading to 10 soon if that makes any difference)
I wonder if it’s because you’re shelling out with that character and the shell or Windows API doesn’t like it. Doing some Googling, this makes sense: stackoverflow.com/a/9951851/187769
So, instead of using UTF-8, use what the shell is expecting. From that link:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
import subprocess
import time
import urllib
import urllib2
import os
import sys
import json
import locale
from System.IO import *
from Deadline.Scripting import *
def __main__( *args ):
deadlinePlugin = args[0]
job = deadlinePlugin.GetJob()
outputDirectories = job.OutputDirectories
outputFilenames = job.OutputFileNames
jobid = job.JobId
fullfilename = u'{0}\{1}'.format(outputDirectories[0], outputFilenames[0])
time.sleep(3)
exeFile = u'"l:\Clients\#ImageCustomizer\Tools\PNGTrim\PNGtrim.exe" trim=tblr i="{0}"'.format(fullfilename)
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = subprocess.SW_HIDE
jobaction = 'delete'
p = subprocess.Popen(exeFile.encode(locale.getpreferredencoding()), startupinfo=startupinfo)
stdout, stderr = p.communicate()
if os.path.isfile(fullfilename):
statinfo = os.stat(fullfilename)
if statinfo.st_size < 2048:
jobaction = 'fail'
print ("File is too small - less than 2KB")
else:
print ("File does not exist")
jobaction = 'fail'
if jobaction == 'delete':
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request("http://cs02:8082/api/jobs?JobID=" + jobid)
request.add_header('Content-Type', 'application/json')
request.get_method = lambda: 'DELETE'
url = opener.open(request)
else:
opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request("http://cs02:8082/api/jobs", data = json.dumps({'Command': 'fail', 'JobID': jobid}))
request.add_header('Content-Type', 'application/json')
request.get_method = lambda: 'PUT'
url = opener.open(request)
pretty sure we added an extra “u” somwhere … to make it work …
the problem is that I can’t code, and the guy helping me write the script don’t know python, so we are doing a lot of copy n pasting and wishing for the best!