Return to Snippet

Revision: 30628
at August 18, 2010 16:25 by throb


Updated Code
import os, platform, sys, getopt

####################### CONFIG
## Put the path to the nuke exe here
nkExePath = 'Z:/software/Nuke6.1v1_x64/Nuke6.1.exe --nukex'
## Put the path to NUKE_PATH here so nuke can find scripts.
## Set this to '' if you dont have anything for this.
nkPath = 'z:/software/nuke_throb'


def main():

    # Parse command line
    options = 'h'
    longOptions = ['img=',
                   'out=',
                   'script=',
                   'startframe=',
                   'endframe='
                   ]
    opts, pargs = getopt.getopt(sys.argv[1:], options, longOptions)
    

        
    # Extract command line options
    for opt in opts:
        if opt[0] == '--img':
            img = opt[1]
        elif opt[0] == '--out':
            out = opt[1]            
        elif opt[0] == '--script':
            script = opt[1]            
        elif opt[0] == '--startframe':
            startframe = opt[1]
        elif opt[0] == '--endframe':
            endframe = opt[1]

    
    # Check for a command
    missingOpts = []
    try:
        img
    except NameError:
        missingOpts.append('img')
    try:
        out
    except NameError:
        missingOpts.append('out')
    try:
        startframe
    except NameError:
        missingOpts.append('startframe')
    try:
        script
    except NameError:
        missingOpts.append('script')
    try:
        endframe
    except NameError:
        missingOpts.append('endframe')
    
    if len(missingOpts) > 0 :
        usage(missingOpts, longOptions)
        sys.exit(1)

    #job = getJob(img)
    #sequence = getSeq(img)
    #shot = getShot(img)
    
    #os.putenv('JOB',job)
    if nkPath != '':
        os.putenv('NUKE_PATH',nkPath)
    
    if os.path.exists(os.path.dirname(out)) == False:
        os.makedirs(os.path.dirname(out))
    
    cmdLine = '%s -x %s %s %s %d,%d' % (nkExePath, script, img, out, int(startframe), int(endframe))

    os.system(cmdLine)

def usage (opts, allOpts):
    print '=' * 20, 'Usage','=' * 20, '\n'
    scriptOpts = ''
    scriptPath = os.path.basename(sys.argv[0])
    for curOpt in allOpts:
        scriptOpts = '%s --%s [option]' % (scriptOpts, curOpt.replace('=',''))
    print '%s %s\n' % (scriptPath, scriptOpts)
    for opt in opts:
        print 'Option missing: %s\n' % opt
    
    
        
if __name__ == '__main__':
    main()
    sys.exit(0)

Revision: 30627
at August 18, 2010 16:13 by throb


Initial Code
import os, platform, sys, getopt

####################### CONFIG
## Put the path to the nuke exe here
nkExePath = 'Z:/software/Nuke6.1v1_x64/Nuke6.1.exe --nukex'
## Put the path to NUKE_PATH here so nuke can find scripts.
## Set this to '' if you dont have anything for this.
nkPath = 'z:/software/nuke_throb'


def main():

    # Parse command line
    options = 'h'
    longOptions = ['img=',
                   'out=',
                   'script=',
                   'startframe=',
                   'endframe='
                   ]
    opts, pargs = getopt.getopt(sys.argv[1:], options, longOptions)
    

        
    # Extract command line options
    for opt in opts:
        if opt[0] == '--img':
            img = opt[1]
        elif opt[0] == '--out':
            outPath = opt[1]            
        elif opt[0] == '--script':
            script = opt[1]            
        elif opt[0] == '--startframe':
            startframe = opt[1]
        elif opt[0] == '--endframe':
            endframe = opt[1]

    
    # Check for a command
    missingOpts = []
    try:
        img
    except NameError:
        missingOpts.append('img')
    try:
        outPath
    except NameError:
        missingOpts.append('outPath')
    try:
        startframe
    except NameError:
        missingOpts.append('startframe')
    try:
        script
    except NameError:
        missingOpts.append('script')
    try:
        endframe
    except NameError:
        missingOpts.append('endframe')
    
    if len(missingOpts) > 0 :
        usage(missingOpts, longOptions)
        sys.exit(1)

    #job = getJob(img)
    #sequence = getSeq(img)
    #shot = getShot(img)
    
    #os.putenv('JOB',job)
    if nkPath != '':
        os.putenv('NUKE_PATH',nkPath)
    
    if os.path.exists(os.path.dirname(outPath)) == False:
        os.makedirs(os.path.dirname(outPath))
    
    cmdLine = '%s -x %s %s %s %d,%d' % (nkExePath, script, img, outPath, int(startframe), int(endframe))

    os.system(cmdLine)

def usage (opts, allOpts):
    for opt in opts:
        print 'Option missing: %s\n' % opt
    print '=' * 20, 'Usage','=' * 20, '\n'
    scriptOpts = ''
    scriptPath = os.path.basename(sys.argv[0])
    for opt in allOpts:
        scriptOpts = '%s --%s [option]' % (scriptOpts, opt.replace('=',''))
    print '%s %s\n' % (scriptPath, scriptOpts)
    print '\n'
        
if __name__ == '__main__':
    main()
    sys.exit(0)

Initial URL


Initial Description


Initial Title
Building block for simple command line execution

Initial Tags
command, python, line

Initial Language
Python