Module commandHandlers
[hide private]
[frames] | no frames]

Source Code for Module commandHandlers

  1  #====================================== 
  2  #  $Revision: #7 $ 
  3  #  $Change: 13873 $ 
  4  #====================================== 
  5   
  6   
  7  import os.path 
  8  import logging 
  9  import platform 
 10  import re 
 11   
 12  import qb.backend.utils as backendUtils 
 13   
 14   
15 -class CommandHandler(object):
16 """ 17 Some applications have different ways to start or be called, depending on either OS or 18 application version; this base class defines the default behavior. 19 20 Classes derived from this class can be used to define these differences on a case-by-case basis 21 at submission time, then the generic L{prepareCmd} method is called to setup the command to run. 22 """
23 - def __init__(self):
24 self.logging = logging.getLogger('%s' % self.__class__.__name__)
25
26 - def prepareCommand(self, job, cmd):
27 ''' 28 This method can be used to apply application version-specific or os-specific modifications 29 to the commandline necessary to run the job 30 31 @param job: the job object that has been passed to the instance in the back-end code 32 @type job: C{qb.Job} 33 34 @param cmd: the cmdline that the job will run 35 @type cmd: C{str} 36 37 @return: the cmd, modified for the appVersion or OS 38 ''' 39 if platform.system() == 'Windows': 40 # subprocess.list2cmdline() behaves differently < 2.7 41 if backendUtils.pyVerAsFloat() < 2.7: 42 cmd = '"%s"' % cmd 43 44 return cmd
45 46
47 -class MayaBatchCommandHandler(CommandHandler):
48 ''' 49 On OS X, source the MayaEnv.sh, otherwise do nothing. 50 '''
51 - def prepareCommand(self, job, cmd):
52 cmd = super(MayaBatchCommandHandler, self).prepareCommand(job, cmd) 53 54 if platform.system() == 'Darwin': 55 if 'appToken' in job['package'] and 'appVersion' in job['package']: 56 appToken = job['package']['appToken'] 57 appVersion = job['package']['appVersion'] 58 59 mayaExe = backendUtils.translateAppPath(appToken, appVersion) 60 mayaExe = mayaExe.replace('"', '') 61 mayaDir = os.path.dirname(mayaExe) 62 63 cmd = '. "%s/MayaENV.sh" && %s' % (mayaDir, cmd) 64 65 return cmd
66 67
68 -class Cinema4DCommandHandler(CommandHandler):
69 ''' 70 On Windows, ensure that the slashes face the right way, and escape any ctrl-characters 71 '''
72 - def prepareCommand(self, job, cmd):
73 cmd = super(Cinema4DCommandHandler, self).prepareCommand(job, cmd) 74 75 if platform.system() == 'Windows': 76 cmd = cmd.replace('/', '\\') 77 cmd = 'start /b /wait "parentconsole" %s' % cmd 78 79 return cmd
80 81
82 -class SketchUpCommandHandler(CommandHandler):
83 ''' 84 On 85 '''
86 - def prepareCommand(self, job, cmd):
87 cmd = super(SketchUpCommandHandler, self).prepareCommand(job, cmd) 88 89 if platform.system() == 'Windows': 90 cmd = cmd.replace('/', '\\') 91 cmd = '%s & echo return_code = %%ERRORLEVEL%%' % cmd 92 93 elif platform.system() == 'Darwin': 94 cmd = re.sub('__SKETCHUP__', 'open --wait-apps --fresh -a %s --args ' % job['package']['appToken'], cmd) 95 96 return cmd
97
98 -def getCommandHandlerClass(appName):
99 ''' 100 Return the base CommandHandler class if there is not a derived one for the application 101 ''' 102 klass = { 103 104 'mayaBatch': MayaBatchCommandHandler, 105 'C4D': Cinema4DCommandHandler, 106 'SketchUp': SketchUpCommandHandler, 107 108 }.get(appName, CommandHandler) 109 110 return klass
111