aboutsummaryrefslogtreecommitdiff
path: root/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py')
-rw-r--r--devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py52
1 files changed, 32 insertions, 20 deletions
diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py
index 9c5d56b5dc..34435eb0c5 100644
--- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py
+++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py
@@ -9,19 +9,19 @@ structLibFound = False
try:
import shutil
except ImportError:
- print "Error:: Shutil python library is required to be installed!"
+ print "[Error] Shutil python library is required to be installed!"
else:
shutilLibFound = True
try:
import struct
except ImportError:
- print "Error:: struct python library is required to be installed!"
+ print "[Error] struct python library is required to be installed!"
else:
structLibFound = True
if (not shutilLibFound) or (not structLibFound):
- sys.stdout.write("Error:: Errors were found when trying to import required python libraries\n")
+ sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n")
sys.exit(1)
from struct import *
@@ -38,14 +38,21 @@ class TreHeader:
class treFile:
m_header = TreHeader()
+ simpleTextResourceFileName = 'GENERIC.TRE'
stringEntriesLst = [] # list of two-value tuples. First value is ID, second value is String content
stringOffsets = []
- def __init__(self):
+ m_traceModeEnabled = False
+
+ # traceModeEnabled is bool to enable more printed debug messages
+ def __init__(self, traceModeEnabled = True):
del self.stringEntriesLst[:]
del self.stringOffsets[:]
+ self.simpleTextResourceFileName = 'GENERIC.TRE'
+ self.m_traceModeEnabled = traceModeEnabled
return
- def loadTreFile(self, treBytesBuff, maxLength):
+ def loadTreFile(self, treBytesBuff, maxLength, treFileName):
+ self.simpleTextResourceFileName = treFileName
offsInTreFile = 0
#
# parse TRE file fields for header
@@ -57,7 +64,8 @@ class treFile:
#
# string IDs table (each entry is unsigned integer 4 bytes)
#
- print "Info:: Total texts in Text Resource file= %d" % (self.header().numOfTextResources)
+ if self.m_traceModeEnabled:
+ print "[Info] Total texts in Text Resource file: %d" % (self.header().numOfTextResources)
for idx in range(0, self.header().numOfTextResources):
tmpTuple = struct.unpack_from('I', treBytesBuff, offsInTreFile) # unsigned integer 4 bytes
self.stringEntriesLst.append( (tmpTuple[0], '') )
@@ -75,7 +83,7 @@ class treFile:
#absStartOfOffsetTable = absStartOfIndexTable + (self.header().numOfTextResources * 4)
#absStartOfStringTable = absStartOfOffsetTable + ((self.header().numOfTextResources+1) * 4)
- #print "Debug:: buffer type " , type(treBytesBuff) # it is str
+ #print "[Debug] buffer type: " , type(treBytesBuff) # it is str
for idx in range(0, self.header().numOfTextResources):
currOffset = self.stringOffsets[idx] + absStartOfIndexTable
@@ -86,15 +94,15 @@ class treFile:
#
allTextsFound = treBytesBuff[currOffset:].split('\x00')
## check "problematic" character cases:
- #if currOffset == 5982 or currOffset == 6050 or currOffset == 2827 or currOffset == 2880:
- # print "Debug:: Offs= %d\tFound String= %s" % ( currOffset,''.join(allTextsFound[0]) )
- # #print "Debug:: Offs: %d\tFound String= %s" % ( currOffset,''.join(allTextsFound[0]) )
+ if self.m_traceModeEnabled:
+ if currOffset == 5982 or currOffset == 6050 or currOffset == 2827 or currOffset == 2880:
+ print "[Debug] Offs: %d\tFound String: %s" % ( currOffset,''.join(allTextsFound[0]) )
(theId, stringOfIdx) = self.stringEntriesLst[idx]
self.stringEntriesLst[idx] = (theId, ''.join(allTextsFound[0]))
- #print "Debug:: ID= %d\tFound String= %s" % ( theId,''.join(allTextsFound[0]) )
+ #print "[Debug] ID: %d\tFound String: %s" % ( theId,''.join(allTextsFound[0]) )
return True
except:
- print "Error:: Loading Text Resource Failed!"
+ print "[Error] Loading Text Resource %s failed!" % (self.simpleTextResourceFileName)
return False
def header(self):
@@ -104,25 +112,29 @@ class treFile:
#
if __name__ == '__main__':
# main()
- print "Debug:: Running %s as main module" % (my_module_name)
+ print "[Debug] Running %s as main module" % (my_module_name)
# assumes a file of name ACTORS.TRE in same directory
inTREFile = None
+ inTREFileName = 'ACTORS.TRE'
+
errorFound = False
+
try:
- inTREFile = open(os.path.join('.','ACTORS.TRE'), 'rb')
+ print "[Info] Opening %s" % (inTREFileName)
+ inTREFile = open(os.path.join('.',inTREFileName), 'rb')
except:
errorFound = True
- print "Error:: Unexpected event= ", sys.exc_info()[0]
+ print "[Error] Unexpected event: ", sys.exc_info()[0]
raise
if not errorFound:
allOfTreFileInBuffer = inTREFile.read()
- treFileInstance = treFile()
- if (treFileInstance.loadTreFile(allOfTreFileInBuffer, len(allOfTreFileInBuffer))):
- print "Info:: Text Resource file loaded successfully!"
+ treFileInstance = treFile(True)
+ if (treFileInstance.loadTreFile(allOfTreFileInBuffer, len(allOfTreFileInBuffer, inTREFileName))):
+ print "[Info] Text Resource file loaded successfully!"
else:
- print "Error:: Error while loading Text Resource file!"
+ print "[Error] Error while loading Text Resource file!"
inTREFile.close()
else:
#debug
- #print "Debug:: Running %s imported from another module" % (my_module_name)
+ #print "[Debug] Running %s imported from another module" % (my_module_name)
pass \ No newline at end of file