Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### Job Structure Creator
- #### (c) Robert Nederhorst
- ###################################################################
- ##
- ## Creates a job structure on disk
- ##
- ###################################################################
- import sys, os, getopt, platform, logging
- ###################################################################
- ### VARIABLES
- jobpath = 'z:/job'
- imgpath = 'z:/job'
- ###################################################################
- # create logger
- logger = logging.getLogger("executeScript")
- logger.setLevel(logging.DEBUG)
- # create console handler and set level to debug
- ch = logging.StreamHandler()
- ch.setLevel(logging.INFO)
- # create formatter
- #formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
- formatter = logging.Formatter('%(levelname)s : %(message)s')
- # add formatter to ch
- ch.setFormatter(formatter)
- # add ch to logger
- logger.addHandler(ch)
- def main():
- options = 'h'
- longOptions = [
- 'job=',
- 'seq=',
- 'shot=',
- 'shotend=',
- 'shotincr=',
- 'shotgun',
- 'asset=',
- 'type=',
- 'debug',
- 'help'
- ]
- opts, pargs = getopt.getopt(sys.argv[1:], options, longOptions)
- shotEnd = -1
- shotIncr = 10
- useShotgun = False
- assetName = None
- assetType = None
- shot = None
- seq = None
- # Extract command line options
- for opt in opts:
- if opt[0] == '--job':
- job = opt[1]
- elif opt[0] == '--seq':
- seq = opt[1]
- elif opt[0] == '--shot':
- shot = opt[1]
- elif opt[0] == '--shotend':
- shotEnd = opt[1]
- elif opt[0] == '--shotincr':
- shotIncr = opt[1]
- elif opt[0] == '--debug':
- ch.setLevel(logging.DEBUG)
- elif opt[0] == '--shotgun':
- useShotgun = True
- elif opt[0] == '--asset':
- assetName = opt[1]
- elif opt[0] == '--type':
- assetType = opt[1]
- elif opt[0] == '--help':
- usage()
- # Check for a command
- missingOpts = []
- try:
- job
- except NameError:
- missingOpts.append('job')
- try:
- seq
- except NameError:
- missingOpts.append('seq')
- try:
- shot
- except NameError:
- missingOpts.append('shot')
- if len(missingOpts) > 0 :
- usage(missingOpts)
- sys.exit(1)
- if job != None:
- jobname = job.lower()
- if seq != None:
- sequence = seq.lower()
- assetPath = '%s/%s/assets' % (jobpath, jobname)
- shotPaths = []
- allShots = []
- if shot != None and seq != None:
- if len(shot.split(',')) > 1 :
- for curShot in shot.split(','):
- paddedshot = '%04d' % (int(curShot))
- allShots.append (paddedshot)
- shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))
- elif shotEnd != -1:
- for curShotNum in range (int(shot), int(shotEnd)+1, int(shotIncr)):
- paddedshot = '%04d' % (int(curShotNum))
- allShots.append(paddedshot)
- shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))
- else:
- paddedshot = '%04d' % (int(shot))
- allShots.append(paddedshot)
- shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))
- commonPath = '%s/%s/common' % (jobpath, jobname)
- prodPath = '%s/%s/prod' % (jobpath, jobname)
- assetTypes = ['env','char','prop','vehicle','fx']
- assetItems = ['master','images','work']
- shotAssets = ['anim','cache','comp','fx','light','mpaint','paint','plates','roto','tracking','lut','model']
- assetData = ['images','work']
- frameAssets = ['comp','fx','light','precomp','plates','matchmove','matte']
- commonAssets = ['nuke','max','maya','scripts','specs']
- prod = ['io','cam_data','demo','edit','lineups','reference','reviews','shotgun']
- io = ['client','internal','archive']
- dirsToMake = []
- if len(shotPaths) > 0 :
- for shotPath in shotPaths:
- for asset in shotAssets:
- for data in assetData:
- dirsToMake.append('%s/%s/%s' % (shotPath,asset,data))
- if assetName != None and assetType in assetTypes:
- for item in assetItems:
- dirsToMake.append('%s/%s/%s/%s' % (assetPath,assetType,assetName,item))
- for asset in assetTypes:
- dirsToMake.append('%s/%s' % (assetPath,asset))
- for asset in commonAssets:
- if asset == 'nuke':
- dirsToMake.append('%s/%s/gizmos' % (commonPath,asset))
- dirsToMake.append('%s/%s/python' % (commonPath,asset))
- dirsToMake.append('%s/%s/menu' % (commonPath,asset))
- dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
- dirsToMake.append('%s/%s/luts' % (commonPath,asset))
- if asset == 'max':
- dirsToMake.append('%s/%s/scripts' % (commonPath,asset))
- dirsToMake.append('%s/%s/scriptsource' % (commonPath,asset))
- dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
- if asset == 'maya' :
- dirsToMake.append('%s/%s/scripts/python' % (commonPath,asset))
- dirsToMake.append('%s/%s/scripts/mel' % (commonPath,asset))
- dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
- if asset == 'scripts' :
- dirsToMake.append('%s/%s/python' % (commonPath,asset))
- for asset in prod:
- dirsToMake.append ('%s/%s' % (prodPath, asset))
- if asset == 'io':
- for ioData in io:
- dirsToMake.append ('%s/%s/%s/%s_in' % (prodPath,asset, ioData, ioData))
- dirsToMake.append ('%s/%s/%s/%s_out' % (prodPath,asset, ioData, ioData))
- dirsToMake.sort()
- # Go through and make all the dirs if it's not debugging
- for current in dirsToMake:
- if ch.level == 10:
- logger.debug(current)
- else:
- if os.path.exists(current) != True:
- os.makedirs(current)
- # Time for Shotgun!
- if useShotgun == True and ch.level != 10:
- # Try to load ol Shotgun
- try:
- import shotgunUtils
- except:
- logger.info("No Shotgun module installed. Skipping Shotgun.")
- sg = shotgunUtils.shotgunConnect()
- sgProj = shotgunUtils.sgProject(sg, jobname)
- if sgProj == '':
- sgProj = sg.create('Project',{'name':jobname})
- sgSeq = shotgunUtils.sgSequence(sg, sgProj, sequence)
- if sgSeq == '' or sgSeq == None:
- sgSeq = shotgunUtils.createSequence(sg, sgProj, sequence)
- for curShot in allShots:
- sgShot = shotgunUtils.sgShot(sg, '%s%s' % (sequence, curShot), sgProj)
- if sgShot == '' or sgShot == None:
- sgShot = shotgunUtils.createShot(sg, sgProj, '%s%s' % (sequence, curShot), sgSeq)
- def usage (opts=''):
- if opts != '':
- for opt in opts:
- print 'Option missing: %s\n' % opt
- print '=' * 20, 'Usage','=' * 20, '\n'
- print '''
- --job [jobname] **REQUIRED\n
- --seq [sequence name] **REQUIRED\n
- --shot [number (no characters)] (You can use multiples like 1000,1020,1045) **REQUIRED\n
- --shotend [last shot # to make]\n
- --shotincr [increment the shot # by this]\n
- --asset [create an asset name]\n
- --type [pick the asset type "env","char","prop","vehicle","fx"]\n
- --shotgun (Add shots in Shotgun)\n
- --debug (Print out stuff only. This will do NO work.)\n
- --help (This message)\n\n
- Example:\n
- job_make.py --job starwars --seq luke --shot 10
- job_make.py --job starwars --asset speederbike --type vehicle
- '''
- print '\n'
- sys.exit(1)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment