Advertisement
Guest User

Untitled

a guest
Sep 19th, 2011
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | None | 0 0
  1. import nuke
  2.  
  3. import os
  4.  
  5. import socket
  6.  
  7. import platform
  8. import re
  9.  
  10.  
  11.  
  12. AUCKLAND_SUBNET = "9"
  13.  
  14. WELLINGTON_SUBNET = "4"
  15.  
  16.  
  17.  
  18. def makeWindowsPath(server, share, job, path):
  19.  
  20.     return "//" + server + "/" + share + "/" + job + "/" + path
  21.  
  22.    
  23.  
  24. def makeLinuxPath(server, share, job, path):
  25.  
  26.     return "/" + server + "/" + share + "/"  + job + "/" + path
  27.  
  28.  
  29.  
  30. def pathFixes():
  31.  
  32.     readNodes = []
  33.  
  34.     affectedNodes = []
  35.  
  36.     for n in nuke.allNodes():
  37.  
  38.         if n.Class() == "Read":
  39.  
  40.             readNodes.append(n)
  41.  
  42.             affectedNodes.append(n)
  43.  
  44.         elif n.Class() == "Write":
  45.  
  46.             affectedNodes.append(n)
  47.  
  48.            
  49.  
  50.     if len(affectedNodes) < 1:
  51.  
  52.         return
  53.  
  54.    
  55.  
  56.     # Set server depending on Location by IP
  57.  
  58.     addr = socket.gethostbyname(socket.gethostname())
  59.  
  60.     if addr.split(".")[2] == AUCKLAND_SUBNET:
  61.  
  62.         server = "sam"
  63.  
  64.         altserver = "flash"
  65.  
  66.     else:
  67.  
  68.         server = "flash"
  69.  
  70.         altserver = "sam"
  71.  
  72.    
  73.  
  74.     for node in affectedNodes:
  75.  
  76.  
  77.  
  78.         filename = nuke.filename(node).replace("\\", "/")
  79.  
  80.         filenameSplit = filter(lambda x: x != "", filename.split("/"))
  81.  
  82.  
  83.  
  84.        
  85.  
  86.         share = str.upper(filenameSplit[1])
  87.  
  88.         job = str.upper(filenameSplit[2])
  89.  
  90.         path = "/".join(filenameSplit[3:])
  91.  
  92.  
  93.  
  94.         if platform.system() in ("Windows", "Microsoft"):
  95.  
  96.             pathFunc = makeWindowsPath
  97.  
  98.         elif platform.system() in ("Linux", "Ubuntu"):
  99.  
  100.             pathFunc = makeLinuxPath
  101.  
  102.         else:
  103.  
  104.             node['file'].setValue(filename)
  105.  
  106.             return
  107.  
  108.  
  109.  
  110.         fixedFilename = pathFunc(server, share, job, path)
  111.  
  112.         if node in readNodes:
  113.  
  114.             if not os.path.exists(fixedFilename):
  115.  
  116.                 fixedFilename = pathFunc(altserver, share, job, path)
  117.  
  118.        
  119.  
  120.         node['file'].setValue(fixedFilename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement