HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

Movie-making script

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
scriptmakingmovie

Problem

The purpose of making this code is to copy/paste and run it (and it should run). I'm open to all feedback.

```
#!/usr/bin/python
# -- coding: utf-8 --
#
# Author: Nishith
# Version: 1.0
#
# Description:
# A quicktime (part 2 ) generator from ready image sequence. User is
# prompted to this path. "First_part_of_image_sequence".mov is created
# in same folder
#
# switch: 1 if works, 0 if does not work
# variable names selected randomly
# This script is as loosely coupled as possible. There can be more scope
# of it being as would be seen as design pattern

import maya.cmds as cmds
import maya.OpenMaya as OpenMaya
import os,subprocess, re
import random
import tempfile
from types import *
import shutil
import unicodedata
import time
import ctypes

class makeQuicktime(object):

def __init__(self):

self.fileExtension = ""
self.backgroundImage = ""
self.thumbnailImage = ""
self.firstImage = ""
self.tempFolder = ""
self.symlinkFolder = ""
self.oneImage = ""
self.myTemp = ""

self.elementName = ""
self.qeName = ""
self.date = ""
self.imageSequence = ""
self.lens = ""
self.frameRange = ""
self.notes = ""
self.qnotes = ""
self.currentFrame = ""
self.imageregex = ""

self.exepath = "D:/mayaslate/"
self.ffmpeg = "ffmpeg.exe"
self.composite = "composite.exe"
self.dll = "vcomp100.dll"
self.kerneldll = "kernel32.dll"

def thirdpartyapp(self):
"""
D:/mayaslate/ has 3 executables. if any is missing admin will put it
"""
if not os.path.isfile(os.path.join (self.exepath ,self.ffmpeg)):
OpenMaya.MGlobal.displayError("% app not present") % self.ffmpeg
if not os.path.isfile(os.path.join (self.exepath ,self.composite)):
OpenMaya.MGlobal.displayError("% app not present") % self.composite
if not

Solution

Disclaimer: I haven't actually got to trying to run your code yet, this was all done by inspection. However, I think there's enough here to be getting on with...

Style

Style is important; it makes your code easier to read and understand. Python has a style guide, and (unless you're following a different one*) you should follow it, for example:

  • your imports aren't laid out correctly (and you use a wildcard import from types, which isn't recommended, particularly as you only need NoneType);



  • line lengths are well over 80 characters (particularly a problem when trying to read it here!);



  • your function/method/variable names aren't lowercase_with_underscores; and



  • your class names aren't UppercaseWords.



There is also a guide to docstrings (great to see some documentation, by the way!); single line docstrings should be on one line. There are more prescriptive styles, especially if you're using some kind of autodocumentation system (I like the Google style), but that sets out a good minimum.

At the very least, I would expect to tee the same style throughout, and the class and method docs to be inside the classes and methods, in terms of both position (just after class/def line) and indentation (same level as first line inside definition).

* If you are following a different style guide, please mention which (and provide a link, if available).

Substance

Generally, you seem to have a lot of long, deeply-nested classes and methods. Try to refactor to keep each method short, shallow and single-purpose (see the Zen of Python; import this). Not everything has to be in a class, either...

I've put a few more specific issues below.
makeQuicktime

This class seems to do a lot of things that aren't strictly related to its name. Consider moving all the folder-y stuff out into a separate class (or standalone functions).
firstImageCount

This seems to be one of several methods in your code that predominantly exists to deal with zero-padded numbers, and they all take different approaches. Write one, then call it from the others! You should get to grips with str.format and the other str methods, which will make this kind of padding much easier (and, I think, is clearer and less error-prone than % formatting).

See also makeQuicktime.setImageRegex, symlinkHouseKeep.givenos.
makeTempFolder

You defined self.exepath = "D:/mayaslate/" in __init__, then assign sysTemp = "D:/mayaslate" here. If you change the folder location, that's now two places you have to go looking for it (or, more likely, one place you'll find it and one place you'll forget it, causing bugs).

Rather than returning 0 or 1 use Python's booleans True and False.
selectFolder

This method is extremely long, and does things that aren't selecting a folder. This should be split out into a few separate methods with descriptive names.

This line:

if not isinstance(oldid,NoneType):


would normally be written:

if oldid is not None:


None is a singleton, it's appropriate to test by identity.
symlinkHouseKeep

This is a much better example in terms of length and focus, aspire to this with your other class! The attribute and parameter names are a bit cryptic, though, particularly as the docstrings have disappeared.
Running the script

The lines at the end of the script (a = makeQuicktime() onwards) would usually be guarded by:

if __name__ == '__main__':


to prevent them from running when you aren't running the script directly (e.g. when you import it).

Code Snippets

if not isinstance(oldid,NoneType):
if oldid is not None:
if __name__ == '__main__':

Context

StackExchange Code Review Q#59563, answer score: 6

Revisions (0)

No revisions yet.