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