pep8
This commit is contained in:
40
blendfile.py
40
blendfile.py
@@ -46,6 +46,8 @@ import sys
|
||||
|
||||
log = logging.getLogger("blendfile")
|
||||
FILE_BUFFER_SIZE = 1024 * 1024
|
||||
|
||||
|
||||
######################################################
|
||||
# module global routines
|
||||
######################################################
|
||||
@@ -86,6 +88,7 @@ def openBlendFile(filename, access="rb"):
|
||||
res.originalfilename = filename
|
||||
return res
|
||||
|
||||
|
||||
def closeBlendFile(afile):
|
||||
"""close the blend file
|
||||
writes the blend file to disk if changes has happened"""
|
||||
@@ -104,6 +107,7 @@ def closeBlendFile(afile):
|
||||
|
||||
handle.close()
|
||||
|
||||
|
||||
######################################################
|
||||
# Write a string to the file.
|
||||
######################################################
|
||||
@@ -122,6 +126,7 @@ STRING=[]
|
||||
for i in range(0, 2048):
|
||||
STRING.append(struct.Struct(str(i) + "s"))
|
||||
|
||||
|
||||
def ReadString(handle, length):
|
||||
st = STRING[length]
|
||||
return st.unpack(handle.read(st.size))[0].decode("iso-8859-1")
|
||||
@@ -133,6 +138,7 @@ ZEROTESTER = 0
|
||||
if sys.version_info < (3, 0):
|
||||
ZEROTESTER = "\0"
|
||||
|
||||
|
||||
def ReadString0(data, offset):
|
||||
add = 0
|
||||
|
||||
@@ -153,6 +159,7 @@ def ReadUShort(handle, fileheader):
|
||||
us = USHORT[fileheader.LittleEndiannessIndex]
|
||||
return us.unpack(handle.read(us.size))[0]
|
||||
|
||||
|
||||
######################################################
|
||||
# ReadUInt reads an unsigned integer from a file handle
|
||||
######################################################
|
||||
@@ -161,16 +168,21 @@ def ReadUInt(handle, fileheader):
|
||||
us = UINT[fileheader.LittleEndiannessIndex]
|
||||
return us.unpack(handle.read(us.size))[0]
|
||||
|
||||
|
||||
def ReadInt(handle, fileheader):
|
||||
return struct.unpack(fileheader.StructPre+"i", handle.read(4))[0]
|
||||
|
||||
|
||||
def ReadFloat(handle, fileheader):
|
||||
return struct.unpack(fileheader.StructPre+"f", handle.read(4))[0]
|
||||
|
||||
|
||||
SSHORT = [struct.Struct("<h"), struct.Struct(">h")]
|
||||
def ReadShort(handle, fileheader):
|
||||
us = SSHORT[fileheader.LittleEndiannessIndex]
|
||||
return us.unpack(handle.read(us.size))[0]
|
||||
|
||||
|
||||
ULONG = [struct.Struct("<Q"), struct.Struct(">Q")]
|
||||
def ReadULong(handle, fileheader):
|
||||
us = ULONG[fileheader.LittleEndiannessIndex]
|
||||
@@ -189,6 +201,7 @@ def ReadPointer(handle, header):
|
||||
us = ULONG[header.LittleEndiannessIndex]
|
||||
return us.unpack(handle.read(us.size))[0]
|
||||
|
||||
|
||||
######################################################
|
||||
# Allign alligns the filehandle on 4 bytes
|
||||
######################################################
|
||||
@@ -202,6 +215,7 @@ def Allign(offset):
|
||||
# module classes
|
||||
######################################################
|
||||
|
||||
|
||||
######################################################
|
||||
# BlendFile
|
||||
# - Header (BlendFileHeader)
|
||||
@@ -246,8 +260,8 @@ class BlendFile:
|
||||
def FindBlendFileBlockWithOffset(self, offset):
|
||||
for block in self.Blocks:
|
||||
if block.OldAddress == offset:
|
||||
return block;
|
||||
return None;
|
||||
return block
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
if not self.Modified:
|
||||
@@ -255,6 +269,7 @@ class BlendFile:
|
||||
else:
|
||||
closeBlendFile(self)
|
||||
|
||||
|
||||
######################################################
|
||||
# BlendFileBlock
|
||||
# File=BlendFile
|
||||
@@ -308,6 +323,7 @@ class BlendFileBlock:
|
||||
self.File.Modified = True
|
||||
return dnaStruct.SetField(self.File.Header, self.File.handle, path, value)
|
||||
|
||||
|
||||
######################################################
|
||||
# BlendFileHeader allocates the first 12 bytes of a blend file
|
||||
# it contains information about the hardware architecture
|
||||
@@ -323,6 +339,8 @@ BLOCKHEADERSTRUCT["<8"] = struct.Struct("<4sIQII")
|
||||
BLOCKHEADERSTRUCT[">8"] = struct.Struct(">4sIQII")
|
||||
FILEHEADER = struct.Struct("7s1s1s3s")
|
||||
OLDBLOCK = struct.Struct("4sI")
|
||||
|
||||
|
||||
class BlendFileHeader:
|
||||
def __init__(self, handle):
|
||||
log.debug("reading blend-file-header")
|
||||
@@ -349,6 +367,7 @@ class BlendFileHeader:
|
||||
def CreateBlockHeaderStruct(self):
|
||||
return BLOCKHEADERSTRUCT[self.StructPre+str(self.PointerSize)]
|
||||
|
||||
|
||||
######################################################
|
||||
# DNACatalog is a catalog of all information in the DNA1 file-block
|
||||
#
|
||||
@@ -369,7 +388,7 @@ class DNACatalog:
|
||||
self.Types = []
|
||||
self.Structs = []
|
||||
|
||||
offset = 8;
|
||||
offset = 8
|
||||
numberOfNames = intstruct.unpack_from(data, offset)[0]
|
||||
offset += 4
|
||||
|
||||
@@ -426,6 +445,7 @@ class DNACatalog:
|
||||
fsize = fType[1]*fName.ArraySize
|
||||
structure.Fields.append([fType, fName, fsize])
|
||||
|
||||
|
||||
######################################################
|
||||
# DNAName is a C-type name stored in the DNA
|
||||
# Name=str
|
||||
@@ -440,7 +460,7 @@ class DNAName:
|
||||
self.ArraySize = self.DetermineArraySize()
|
||||
|
||||
def AsReference(self, parent):
|
||||
if parent == None:
|
||||
if parent is None:
|
||||
Result = ""
|
||||
else:
|
||||
Result = parent+"."
|
||||
@@ -449,7 +469,7 @@ class DNAName:
|
||||
return Result
|
||||
|
||||
def DetermineShortName(self):
|
||||
Result = self.Name;
|
||||
Result = self.Name
|
||||
Result = Result.replace("*", "")
|
||||
Result = Result.replace("(", "")
|
||||
Result = Result.replace(")", "")
|
||||
@@ -478,6 +498,7 @@ class DNAName:
|
||||
|
||||
return Result
|
||||
|
||||
|
||||
######################################################
|
||||
# DNAType is a C-type structure stored in the DNA
|
||||
#
|
||||
@@ -495,7 +516,7 @@ class DNAStructure:
|
||||
splitted = path.partition(".")
|
||||
name = splitted[0]
|
||||
rest = splitted[2]
|
||||
offset = 0;
|
||||
offset = 0
|
||||
for field in self.Fields:
|
||||
fname = field[1]
|
||||
if fname.ShortName == name:
|
||||
@@ -525,7 +546,7 @@ class DNAStructure:
|
||||
splitted = path.partition(".")
|
||||
name = splitted[0]
|
||||
rest = splitted[2]
|
||||
offset = 0;
|
||||
offset = 0
|
||||
for field in self.Fields:
|
||||
fname = field[1]
|
||||
if fname.ShortName == name:
|
||||
@@ -542,7 +563,6 @@ class DNAStructure:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
######################################################
|
||||
# DNAField is a coupled DNAType and DNAName
|
||||
# Type=DNAType
|
||||
@@ -560,6 +580,7 @@ class DNAField:
|
||||
else:
|
||||
return self.Type.Size*self.Name.ArraySize
|
||||
|
||||
|
||||
# determine the relative production location of a blender path.basename
|
||||
def blendPath2AbsolutePath(productionFile, blenderPath):
|
||||
productionFileDir = os.path.dirname(productionFile)
|
||||
@@ -568,7 +589,4 @@ def blendPath2AbsolutePath(productionFile, blenderPath):
|
||||
abspath = os.path.join(productionFileDir, relpath)
|
||||
return abspath
|
||||
|
||||
|
||||
return blenderPath
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user