用于简单命令行执行的构建块

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用于简单命令行执行的构建块相关的知识,希望对你有一定的参考价值。

  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, ' '
  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 ' % (scriptPath, scriptOpts)
  88. for opt in opts:
  89. print 'Option missing: %s ' % opt
  90.  
  91.  
  92.  
  93. if __name__ == '__main__':
  94. main()
  95. sys.exit(0)

以上是关于用于简单命令行执行的构建块的主要内容,如果未能解决你的问题,请参考以下文章

用于开源编译/构建的 Apple 命令行工具和 XCode?

命令行执行Ant构建Jmeter,一直报Java(TM) Platform SE binary 已停止工作

命令行执行jenkins,构建job(可传递参数)

XCode:用于 xcode 命令行构建的 Documents and Library 文件夹

sqlite-utils:用于构建SQLite数据库的Python库和命令行工具

maven 命令行指定 localRepository 路径