maya.py :  » Game-2D-3D » CGKit » cgkit-2.0.0alpha9 » cgkit » jobqueue » defaultprocs » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Game 2D 3D » CGKit 
CGKit » cgkit 2.0.0alpha9 » cgkit » jobqueue » defaultprocs » maya.py
# Render using Maya

import os, os.path, subprocess, sys, traceback
import cgkit.jobqueue

class maya(cgkit.jobqueue.JobProc):
    """Render a Maya file.
    """
    
    def __init__(self, sceneFile=None, project=None,
                 startFrame=None, endFrame=None,
                 renderCmd = "Render",
                 label=None):
        """Constructor.
        
        label: The GUI label string
        """
        # Check the parameter types...
        if not isinstance(sceneFile, basestring):
            raise TypeError("sceneFile argument must be a string, got a %s instead"%getattr(type(sceneFile), "__name__", "?"))
        if not (project is None or isinstance(project, basestring)):
            raise TypeError("project argument must be a string or None, got a %s instead"%getattr(type(project), "__name__", "?"))
        if not (startFrame is None or type(startFrame) in [int, float]):
            raise TypeError("startFrame must be a number type or None, got a %s instead"%getattr(type(startFrame), "__name__", "?"))
        if not (endFrame is None or type(endFrame) in [int, float]):
            raise TypeError("endFrame must be a number type or None, got a %s instead"%getattr(type(endFrame), "__name__", "?"))
        if not isinstance(renderCmd, basestring):
            raise TypeError("renderCmd argument must be a string, got a %s instead"%getattr(type(renderCmd), "__name__", "?"))

        # Set the default label if no label was given
        if label is None:
            label = 'Maya "%s"'%os.path.basename(sceneFile)
            
        cgkit.jobqueue.JobProc.__init__(self, label=label)
        
        # Store the parameters
        toks = [renderCmd] 
        if startFrame is not None:
            toks.append("-s %s"%startFrame)
        if endFrame is not None:
            toks.append("-e %s"%endFrame)
        if project is not None and project!="":
            toks.append('-proj "%s"'%project)
        toks.append('"%s"'%sceneFile)
    
        self._cmdLine = " ".join(toks)
        
    def run(self):
        """Run the Render tool.
        """
        print >>self.stdout, self._cmdLine
        ret = self.execCmd(self._cmdLine)
        if ret!=0:
            print >>self.stderr, "\nReturn code:",ret
            self.setError()
        else:
            self.setStatusLine("Done")

    def stdoutCallback(self, lineNr, line):
        """Scan stdout for status/errors.
        """
        pass

    def stderrCallback(self, lineNr, line):
        """Scan stderr for status/errors.
        """
        # Does a frame begin?
        if line.startswith("Starting Rendering"):
            # Get the image path (remove the prefix and the trailing dot)
            fileName = os.path.normpath(line.strip()[19:-1])
            p,n = os.path.split(fileName)
            self.setStatusLine("Rendering %s (%s)"%(n,p))
        # Is there an error line?
        elif line.startswith("Error:"):
            self.setStatusLine(line.strip())
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.