Building block for simple command line execution


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import os, platform, sys, getopt
  2.  
  3. ####################### CONFIG
  4. ## Put the path to the nuke exe here
  5. nkExePath = 'Z:/software/Nuke6.1v1_x64/Nuke6.1.exe --nukex'
  6. ## Put the path to NUKE_PATH here so nuke can find scripts.
  7. ## Set this to '' if you dont have anything for this.
  8. nkPath = 'z:/software/nuke_throb'
  9.  
  10.  
  11. def main():
  12.  
  13. # Parse command line
  14. options = 'h'
  15. longOptions = ['img=',
  16. 'out=',
  17. 'script=',
  18. 'startframe=',
  19. 'endframe='
  20. ]
  21. opts, pargs = getopt.getopt(sys.argv[1:], options, longOptions)
  22.  
  23.  
  24.  
  25. # Extract command line options
  26. for opt in opts:
  27. if opt[0] == '--img':
  28. img = opt[1]
  29. elif opt[0] == '--out':
  30. out = opt[1]
  31. elif opt[0] == '--script':
  32. script = opt[1]
  33. elif opt[0] == '--startframe':
  34. startframe = opt[1]
  35. elif opt[0] == '--endframe':
  36. endframe = opt[1]
  37.  
  38.  
  39. # Check for a command
  40. missingOpts = []
  41. try:
  42. img
  43. except NameError:
  44. missingOpts.append('img')
  45. try:
  46. out
  47. except NameError:
  48. missingOpts.append('out')
  49. try:
  50. startframe
  51. except NameError:
  52. missingOpts.append('startframe')
  53. try:
  54. script
  55. except NameError:
  56. missingOpts.append('script')
  57. try:
  58. endframe
  59. except NameError:
  60. missingOpts.append('endframe')
  61.  
  62. if len(missingOpts) > 0 :
  63. usage(missingOpts, longOptions)
  64. sys.exit(1)
  65.  
  66. #job = getJob(img)
  67. #sequence = getSeq(img)
  68. #shot = getShot(img)
  69.  
  70. #os.putenv('JOB',job)
  71. if nkPath != '':
  72. os.putenv('NUKE_PATH',nkPath)
  73.  
  74. if os.path.exists(os.path.dirname(out)) == False:
  75. os.makedirs(os.path.dirname(out))
  76.  
  77. cmdLine = '%s -x %s %s %s %d,%d' % (nkExePath, script, img, out, int(startframe), int(endframe))
  78.  
  79. os.system(cmdLine)
  80.  
  81. def usage (opts, allOpts):
  82. print '=' * 20, 'Usage','=' * 20, '\n'
  83. scriptOpts = ''
  84. scriptPath = os.path.basename(sys.argv[0])
  85. for curOpt in allOpts:
  86. scriptOpts = '%s --%s [option]' % (scriptOpts, curOpt.replace('=',''))
  87. print '%s %s\n' % (scriptPath, scriptOpts)
  88. for opt in opts:
  89. print 'Option missing: %s\n' % opt
  90.  
  91.  
  92.  
  93. if __name__ == '__main__':
  94. main()
  95. sys.exit(0)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.