throb

VFX Job/Folder Structure Creator

Jun 25th, 2016
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.92 KB | None | 0 0
  1. #### Job Structure Creator
  2. #### (c) Robert Nederhorst
  3.  
  4. ###################################################################
  5. ##
  6. ##  Creates a job structure on disk
  7. ##  
  8. ###################################################################
  9.  
  10. import sys, os, getopt, platform, logging
  11.  
  12. ###################################################################
  13. ###     VARIABLES
  14. jobpath = 'z:/job'
  15. imgpath = 'z:/job'
  16. ###################################################################
  17.  
  18. # create logger
  19. logger = logging.getLogger("executeScript")
  20. logger.setLevel(logging.DEBUG)
  21.  
  22. # create console handler and set level to debug
  23. ch = logging.StreamHandler()
  24. ch.setLevel(logging.INFO)
  25.  
  26. # create formatter
  27. #formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
  28. formatter = logging.Formatter('%(levelname)s : %(message)s')
  29.  
  30. # add formatter to ch
  31. ch.setFormatter(formatter)
  32.  
  33. # add ch to logger
  34. logger.addHandler(ch)
  35.  
  36. def main():
  37.     options = 'h'
  38.     longOptions = [
  39.         'job=',
  40.         'seq=',
  41.         'shot=',
  42.         'shotend=',
  43.         'shotincr=',
  44.         'shotgun',
  45.         'asset=',
  46.         'type=',
  47.         'debug',
  48.         'help'
  49.     ]
  50.     opts, pargs = getopt.getopt(sys.argv[1:], options, longOptions)
  51.    
  52.    
  53.     shotEnd = -1
  54.     shotIncr = 10    
  55.     useShotgun = False
  56.     assetName = None
  57.     assetType = None
  58.     shot = None
  59.     seq = None
  60.     # Extract command line options
  61.     for opt in opts:
  62.         if opt[0] == '--job':
  63.             job = opt[1]
  64.         elif opt[0] == '--seq':
  65.             seq = opt[1]            
  66.         elif opt[0] == '--shot':
  67.             shot = opt[1]
  68.         elif opt[0] == '--shotend':
  69.             shotEnd = opt[1]
  70.         elif opt[0] == '--shotincr':
  71.             shotIncr = opt[1]    
  72.         elif opt[0] == '--debug':
  73.             ch.setLevel(logging.DEBUG)
  74.         elif opt[0] == '--shotgun':
  75.             useShotgun = True
  76.         elif opt[0] == '--asset':
  77.             assetName = opt[1]
  78.         elif opt[0] == '--type':
  79.             assetType = opt[1]
  80.         elif opt[0] == '--help':
  81.             usage()
  82.     # Check for a command
  83.     missingOpts = []
  84.     try:
  85.         job
  86.     except NameError:
  87.         missingOpts.append('job')
  88.     try:
  89.         seq
  90.     except NameError:
  91.         missingOpts.append('seq')
  92.     try:
  93.         shot
  94.     except NameError:
  95.         missingOpts.append('shot')
  96.  
  97.     if len(missingOpts) > 0 :
  98.         usage(missingOpts)
  99.         sys.exit(1)
  100.    
  101.     if job != None:
  102.         jobname = job.lower()
  103.     if seq != None:
  104.         sequence = seq.lower()
  105.    
  106.    
  107.     assetPath = '%s/%s/assets' % (jobpath, jobname)
  108.  
  109.  
  110.     shotPaths = []
  111.     allShots = []
  112.     if shot != None and seq != None:
  113.         if len(shot.split(',')) > 1 :
  114.             for curShot in shot.split(','):
  115.                 paddedshot = '%04d' % (int(curShot))
  116.                 allShots.append (paddedshot)
  117.                 shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))    
  118.         elif shotEnd != -1:
  119.             for curShotNum in range (int(shot), int(shotEnd)+1, int(shotIncr)):
  120.                 paddedshot = '%04d' % (int(curShotNum))
  121.                 allShots.append(paddedshot)
  122.                 shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))
  123.         else:
  124.             paddedshot = '%04d' % (int(shot))
  125.             allShots.append(paddedshot)
  126.             shotPaths.append ('%s/%s/shots/%s/%s' % (jobpath, jobname, sequence, paddedshot))
  127.  
  128.     commonPath = '%s/%s/common' % (jobpath, jobname)
  129.     prodPath = '%s/%s/prod' % (jobpath, jobname)
  130.    
  131.     assetTypes = ['env','char','prop','vehicle','fx']
  132.     assetItems = ['master','images','work']
  133.     shotAssets = ['anim','cache','comp','fx','light','mpaint','paint','plates','roto','tracking','lut','model']
  134.     assetData = ['images','work']
  135.     frameAssets = ['comp','fx','light','precomp','plates','matchmove','matte']
  136.     commonAssets = ['nuke','max','maya','scripts','specs']
  137.     prod = ['io','cam_data','demo','edit','lineups','reference','reviews','shotgun']
  138.     io = ['client','internal','archive']
  139.    
  140.     dirsToMake = []
  141.     if len(shotPaths) > 0 :
  142.         for shotPath in shotPaths:
  143.             for asset in shotAssets:
  144.                 for data in assetData:
  145.                     dirsToMake.append('%s/%s/%s' % (shotPath,asset,data))
  146.  
  147.     if assetName != None and assetType in assetTypes:
  148.         for item in assetItems:
  149.             dirsToMake.append('%s/%s/%s/%s' % (assetPath,assetType,assetName,item))
  150.         for asset in assetTypes:
  151.             dirsToMake.append('%s/%s' % (assetPath,asset))
  152.  
  153.         for asset in commonAssets:
  154.             if asset == 'nuke':
  155.                 dirsToMake.append('%s/%s/gizmos' % (commonPath,asset))
  156.                 dirsToMake.append('%s/%s/python' % (commonPath,asset))
  157.                 dirsToMake.append('%s/%s/menu' % (commonPath,asset))
  158.                 dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
  159.             dirsToMake.append('%s/%s/luts' % (commonPath,asset))
  160.             if asset == 'max':
  161.                 dirsToMake.append('%s/%s/scripts' % (commonPath,asset))
  162.                 dirsToMake.append('%s/%s/scriptsource' % (commonPath,asset))
  163.                 dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
  164.             if asset == 'maya' :
  165.                 dirsToMake.append('%s/%s/scripts/python' % (commonPath,asset))
  166.                 dirsToMake.append('%s/%s/scripts/mel' % (commonPath,asset))
  167.                 dirsToMake.append('%s/%s/plugins' % (commonPath,asset))
  168.             if asset == 'scripts' :
  169.                 dirsToMake.append('%s/%s/python' % (commonPath,asset))
  170.                
  171.         for asset in prod:
  172.             dirsToMake.append ('%s/%s' % (prodPath, asset))
  173.         if asset == 'io':
  174.             for ioData in io:
  175.                 dirsToMake.append ('%s/%s/%s/%s_in' % (prodPath,asset, ioData, ioData))
  176.                 dirsToMake.append ('%s/%s/%s/%s_out' % (prodPath,asset, ioData, ioData))
  177.    
  178.     dirsToMake.sort()
  179.  
  180.     # Go through and make all the dirs if it's not debugging
  181.     for current in dirsToMake:    
  182.         if ch.level == 10:
  183.             logger.debug(current)
  184.         else:
  185.             if os.path.exists(current) != True:
  186.                 os.makedirs(current)
  187.  
  188.     # Time for Shotgun!
  189.     if useShotgun == True and ch.level != 10:
  190.     # Try to load ol Shotgun
  191.         try:
  192.             import shotgunUtils
  193.         except:
  194.             logger.info("No Shotgun module installed.  Skipping Shotgun.")
  195.  
  196.         sg = shotgunUtils.shotgunConnect()
  197.  
  198.         sgProj = shotgunUtils.sgProject(sg, jobname)
  199.         if sgProj == '':
  200.             sgProj = sg.create('Project',{'name':jobname})
  201.  
  202.         sgSeq = shotgunUtils.sgSequence(sg, sgProj, sequence)
  203.         if sgSeq == '' or sgSeq == None:
  204.             sgSeq = shotgunUtils.createSequence(sg, sgProj, sequence)
  205.            
  206.         for curShot in allShots:
  207.             sgShot = shotgunUtils.sgShot(sg, '%s%s' % (sequence, curShot), sgProj)
  208.             if sgShot == '' or sgShot == None:
  209.                 sgShot = shotgunUtils.createShot(sg, sgProj, '%s%s' % (sequence, curShot), sgSeq)
  210.  
  211.    
  212.            
  213.  
  214. def usage (opts=''):
  215.     if opts != '':
  216.         for opt in opts:
  217.             print 'Option missing: %s\n' % opt
  218.     print '=' * 20, 'Usage','=' * 20, '\n'
  219.     print '''
  220.     --job [jobname] **REQUIRED\n
  221.     --seq [sequence name] **REQUIRED\n
  222.     --shot [number (no characters)] (You can use multiples like 1000,1020,1045) **REQUIRED\n
  223.     --shotend [last shot # to make]\n
  224.     --shotincr [increment the shot # by this]\n
  225.     --asset [create an asset name]\n
  226.     --type [pick the asset type "env","char","prop","vehicle","fx"]\n
  227.     --shotgun (Add shots in Shotgun)\n
  228.     --debug (Print out stuff only.  This will do NO work.)\n
  229.     --help (This message)\n\n
  230.     Example:\n
  231.     job_make.py --job starwars --seq luke --shot 10
  232.     job_make.py --job starwars --asset speederbike --type vehicle
  233.     '''
  234.     print '\n'
  235.     sys.exit(1)                    
  236.                        
  237. if __name__ == '__main__':
  238.     main()
Advertisement
Add Comment
Please, Sign In to add comment