Personal Project: Renderfarm Folder Creator
For my personal project, I wanted to use the skills I've gained to create a utility for a task done all the time in Montgomery Hall. When sending a project to the renderfarm, it is most efficient to create a new folder that contains only the files needed for that render, excluding past scene saves and extraneous files. The script I have created reads a Maya ASCII file, and gathers all the external files referenced by that scene. It then copies the .ma and all of it's needed files to a new, leaner folder that can be sent to the renderfarm. I received additional help on this project from Will Cavanagh, who created the UI elements.
When the script is launched, the user is prompted with this UI window(created by Will). The user may then input the path to the Maya ASCII file and the prefix of their new folder name, which are the two main arguments to my script.
When the script is executed from the UI, it runs through the .ma line by line, looking for file paths. Based on these file paths, the folder structure of the Maya project is reconstructed, and filled with the files being accessed in the .ma.
The UI elements are not included here, but this is my script that searches the file, and creates the new directory.
import os import re import shutil import linecache import sys argparsePath = "/usr/local/python-2.7/lib/python2.7/" if not argparsePath in sys.path: sys.path.append(argparsePath) import argparse def farmFolder(name, date, scene = None, prefix = None, args = None): if(args): scene = args.f prefix = args.p scenecall = args.f prefixcall = args.p elif not(scene and prefix): raise ValueError("Must provide scene and prefix") sceneFolder = os.path.dirname(scene) projectFolder = os.path.dirname(sceneFolder) ###Create list of all subdirectories in the project folder### subDirs =  for n in os.walk(projectFolder): subDirs.append(n) ###Make all directory paths relative### relSubDirs =  for n in subDirs: n = os.path.relpath(n, projectFolder) relSubDirs.append(n) del relSubDirs ###Search .ma for file names### refFiles =  searchfile = open(scene, "r") count = 0 for line in searchfile: if re.search('^\s*[\d]', line) != None: continue for d in relSubDirs: if d + "/" in line: refFiles.append(line) ###Strip file names of quotes and semicolons### stripFiles =  for n in refFiles: n = n.strip() stripFiles.append(n) onlyFiles =  for n in stripFiles: for d in relSubDirs: if "/" + d + "/" in n: var = n.find(d) n = n[var:] n = n[:-2] onlyFiles.append(n) ###Make all path names absolute### absLineVar =  for n in onlyFiles: n = projectFolder + "/" + n absLineVar.append(n) ###Check for .vrimg calls, as these are not individually referenced, and need to be treated differently.### vrCheck = 0 vrLoc =  vrFiles =  for f in absLineVar: if f.endswith (".vrmap"): vrCheck = 1 vrLoc = f vrFolder = os.path.dirname(vrLoc) for files in os.listdir(vrFolder): vrFiles.append(files) vrTrueFiles =  for f in vrFiles: if f.endswith(".vrmap"): vrTrueFiles.append(f) for m in vrTrueFiles: absLineVar.append(m) makeFolder(scene, projectFolder, prefix, absLineVar, onlyFiles, relSubDirs) def makeFolder(scene, projectFolder, farmName, absLineVar, onlyFiles, relSubDirs): projDir = os.path.dirname(projectFolder) newDir = projDir + "/" + farmName + "Farm" ###Make new project directory### if os.path.exists(newDir): print "Directory already exists! Don't delete valuable files." else: os.makedirs(newDir) ###Copy workspace.mel### workspace = projectFolder + "/workspace.mel" newWorkspace = newDir + "/workspace.mel" shutil.copyfile(workspace, newWorkspace) ###Make the relative directories absolute, now pointing to our new farm folder. Then make those directories.### newDirs =  for n in relSubDirs: n = newDir + "/" + n newDirs.append(n) del newDirs for n in newDirs: os.makedirs(n) ###Make new file path strings for every file extracted from the MA### newLineName =  for n in onlyFiles: n = newDir + "/" + n n = n.strip() newLineName.append(n) fileCounter = 0 for n in newLineName: try: shutil.copyfile(absLineVar[fileCounter], n) except: pass fileCounter += 1 print "done!" if __name__ == "__main__": parser = argparse.ArgumentParser(description='Based on a Maya ASCII file, make a folder with all files needed for the renderfarm.') parser.add_argument('-f', '-path', type=str, help="absolute path to the Maya ASCII file in quotations") parser.add_argument('-p', '-prefix', type=str, help="prefix that will be added to the newly generated folder") args = parser.parse_args() farmFolder(args=args)