diff options
author | Thanasis Antoniou | 2019-07-23 12:30:39 +0300 |
---|---|---|
committer | Thanasis Antoniou | 2019-07-23 12:50:44 +0300 |
commit | 1450a240a00a6a90f9c0f2cb837266a9d61d4281 (patch) | |
tree | ed35fef2a0d2dd3d395a0a58cfcfce2751b39f54 /devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator | |
parent | 5b3a087e978eb785c6c72bae66d43153e3e412c8 (diff) | |
download | scummvm-rg350-1450a240a00a6a90f9c0f2cb837266a9d61d4281.tar.gz scummvm-rg350-1450a240a00a6a90f9c0f2cb837266a9d61d4281.tar.bz2 scummvm-rg350-1450a240a00a6a90f9c0f2cb837266a9d61d4281.zip |
DEVTOOLS: BLADERUNNER: Code quality improvements (Codacy issues)
Diffstat (limited to 'devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator')
6 files changed, 145 insertions, 143 deletions
diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileDecode.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileDecode.py index 15733488bb..febd0c59f0 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileDecode.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileDecode.py @@ -5,23 +5,15 @@ ctypesLibFound = False structLibFound = False try: - import ctypes + import ctypes except ImportError: - print "[Error] ctypes python library is required to be installed!" + print "[Error] ctypes python library is required to be installed!" else: ctypesLibFound = True -try: - import struct -except ImportError: - print "[Error] struct python library is required to be installed!" -else: - structLibFound = True - -if (not ctypesLibFound) \ - or (not structLibFound): +if (not ctypesLibFound): sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n") - sys.exit(1) + sys.exit(1) from struct import * @@ -97,7 +89,7 @@ def aud_decode_ima_chunk(audioBufferIn, index, sample, cs_chunk): index = 0 elif (index > 88): index = 88 - ## output buffer of shorts + ## output buffer of shorts #binDataOut = struct.pack('h'*len(audioBufferOut), *audioBufferOut) #return (binDataOut, index, sample) return (audioBufferOut, index, sample) @@ -126,23 +118,23 @@ def aud_decode_ws_chunk(inputChunkBuffer, cb_s, cb_d): #return binDataOut return outputChunkBuffer -# const xccTHA::byte* s_end = inputChunkBuffer + cb_s; # FIX +# const xccTHA::byte* s_end = inputChunkBuffer + cb_s; # FIX s_end = inpChBuffIter + cb_s - sample = ctypes.c_int(0x80).value #int sample + sample = ctypes.c_int(0x80).value #int sample while (inpChBuffIter < s_end): inpChBuffIter += 1 - count = ctypes.c_char(inputChunkBuffer[inpChBuffIter] & 0x3f).value # char count - switchKey = inputChunkBuffer[inpChBuffIter - 1] >> 6 # inputChunkBuffer[-1] # b[-1] is *(b - 1) + count = ctypes.c_char(inputChunkBuffer[inpChBuffIter] & 0x3f).value # char count + switchKey = inputChunkBuffer[inpChBuffIter - 1] >> 6 # inputChunkBuffer[-1] # b[-1] is *(b - 1) if switchKey == 0: count += 1 - for iter in range (count, 0, -1): + for iter0 in range (count, 0, -1): inpChBuffIter += 1 - code = ctypes.c_int(inputChunkBuffer[inpChBuffIter]).value # int code + code = ctypes.c_int(inputChunkBuffer[inpChBuffIter]).value # int code # assignment in C was right to left so: - # *(outputChunkBuffer++) = sample = clip8(sample + aud_ws_step_table2[code & 3]) + # *(outputChunkBuffer++) = sample = clip8(sample + aud_ws_step_table2[code & 3]) # is: - # *(outputChunkBuffer++) = (sample = clip8(sample + aud_ws_step_table2[code & 3])) + # *(outputChunkBuffer++) = (sample = clip8(sample + aud_ws_step_table2[code & 3])) # which is equivalent to these two commands: # sample = clip8(sample + aud_ws_step_table2[code & 3]) # *(outputChunkBuffer++) = sample @@ -163,7 +155,7 @@ def aud_decode_ws_chunk(inputChunkBuffer, cb_s, cb_d): count += 1 for iter in range (count, 0, -1): inpChBuffIter += 1 - code = inputChunkBuffer[inpChBuffIter] # int code + code = inputChunkBuffer[inpChBuffIter] # int code sample += aud_ws_step_table4[code & 0xf] sample = aud_decode_clip8(sample) outputChunkBuffer.append(ctypes.c_char(sample).value) @@ -181,7 +173,7 @@ def aud_decode_ws_chunk(inputChunkBuffer, cb_s, cb_d): outChBuffIter += 1 else: count += 1 - # memcpy(outputChunkBuffer, inputChunkBuffer, count) # FIX + # memcpy(outputChunkBuffer, inputChunkBuffer, count) # FIX for mcp in range(0, count): outputChunkBuffer.append(ctypes.c_char(inputChunkBuffer[inpChBuffIter + mcp]).value) inpChBuffIter += count @@ -193,7 +185,7 @@ def aud_decode_ws_chunk(inputChunkBuffer, cb_s, cb_d): for mst in range(0, count): outputChunkBuffer.append(ctypes.c_char(sample).value) outChBuffIter += count; - # output buffer of chars + # output buffer of chars #binDataOut = struct.pack('b'*len(outputChunkBuffer), *outputChunkBuffer) #return binDataOut return outputChunkBuffer @@ -201,7 +193,7 @@ def aud_decode_ws_chunk(inputChunkBuffer, cb_s, cb_d): # # # -class audFileDecode: +class audFileDecode(object): m_index = -1 m_sample = -1 m_traceModeEnabled = False @@ -228,7 +220,7 @@ if __name__ == '__main__': decodeInstance = audFileDecode() if decodeInstance.m_traceModeEnabled: print "[Debug] Running %s (%s) as main module" % (MY_MODULE_NAME, MY_MODULE_VERSION) - + else: #debug #print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION) diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileLib.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileLib.py index 60dc3d6ab8..7cb4f455df 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileLib.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/audFileLib.py @@ -9,55 +9,39 @@ ctypesLibFound = False structLibFound = False try: - import os + import os except ImportError: - print "[Error] os python library is required to be installed!" + print "[Error] os python library is required to be installed!" else: osLibFound = True try: import sys except ImportError: - print "[Error] sys python library is required to be installed!" + print "[Error] sys python library is required to be installed!" else: sysLibFound = True try: - import shutil -except ImportError: - print "[Error] Shutil python library is required to be installed!" -else: - shutilLibFound = True - -try: import wave except ImportError: - print "[Error] Wave python library is required to be installed!" + print "[Error] Wave python library is required to be installed!" else: waveLibFound = True try: - import ctypes + import struct except ImportError: - print "[Error] ctypes python library is required to be installed!" -else: - ctypesLibFound = 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 osLibFound) \ or (not sysLibFound) \ - or (not shutilLibFound) \ or (not waveLibFound) \ - or (not ctypesLibFound) \ or (not structLibFound): sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n") - sys.exit(1) + sys.exit(1) from struct import * from audFileDecode import * @@ -70,24 +54,24 @@ aud_chunk_id = 0x0000deaf SIZE_OF_AUD_HEADER_IN_BYTES = 12 SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES = 8 -class AudHeader: - m_samplerate = 0 #// Frequency // int16_t // TODO should be unsigned (?) - m_size_in = 0 #// Size of file (without header) // int32_t // TODO should be unsigned (?) - m_size_out = 0 #// Size of output data // int32_t // TODO should be unsigned (?) - m_flags = 0 #// bit 0=stereo, bit 1=16bit // int8_t - m_compression = 0 #// 1=WW compressed, 99=IMA ADPCM (0x63) // int8_t +class AudHeader(object): + m_samplerate = 0 # Frequency // int16_t // TODO should be unsigned (?) + m_size_in = 0 # Size of file (without header) // int32_t // TODO should be unsigned (?) + m_size_out = 0 # Size of output data // int32_t // TODO should be unsigned (?) + m_flags = 0 # bit 0=stereo, bit 1=16bit // int8_t + m_compression = 0 # 1=WW compressed, 99=IMA ADPCM (0x63) // int8_t m_populated = False def __init__(self): return -#//The rest of the AUD files is divided in chunks. These are usually 512 -#//bytes long, except for the last one. -class AudChunkHeader: - m_ch_size_in = 0 #// Size of compressed data // int16_t // TODO should be unsigned (?) - m_ch_size_out = 0 #// Size of output data // int16_t // TODO should be unsigned (?) - m_ch_id = 0x0000FFFF #// Always 0x0000DEAF // int32_t +# The rest of the AUD files is divided in chunks. +# These are usually 512 bytes long, except for the last one. +class AudChunkHeader(object): + m_ch_size_in = 0 # Size of compressed data // int16_t // TODO should be unsigned (?) + m_ch_size_out = 0 # Size of output data // int16_t // TODO should be unsigned (?) + m_ch_id = 0x0000FFFF # Always 0x0000DEAF // int32_t def __init__(self): return @@ -95,7 +79,7 @@ class AudChunkHeader: # # # -class audFile: +class audFile(object): m_header = AudHeader() m_traceModeEnabled = False m_simpleAudioFileName = 'GENERIC.AUD' @@ -121,6 +105,8 @@ class audFile: cbinaryDataOutLst = [] offsInAudFile = SIZE_OF_AUD_HEADER_IN_BYTES for i in range(0, (len(audBytesBuff) - SIZE_OF_AUD_HEADER_IN_BYTES) / 2): + if (self.m_traceModeEnabled): + print "[Trace] Reading bytes %d, %d" % (2*i, 2*i + 1) tmpTupleL = struct.unpack_from('B', audBytesBuff, offsInAudFile) offsInAudFile += 1 tmpTupleH = struct.unpack_from('B', audBytesBuff, offsInAudFile) @@ -128,7 +114,7 @@ class audFile: cbinaryDataOutLst.append(tmpTupleL[0]) cbinaryDataOutLst.append(tmpTupleH[0]) cvirtualBinaryD = struct.pack('B'*len(cbinaryDataOutLst), *cbinaryDataOutLst) - + if (not cvirtualBinaryD and (len(audBytesBuff) - SIZE_OF_AUD_HEADER_IN_BYTES) > 0): print "[Error] audio file could not be exported properly (0 data read): %s" % (filename) return 1 @@ -163,7 +149,7 @@ class audFile: # header.data_chunk_header.id = wav_data_id; # "data" # header.data_chunk_header.size = cb_sample * cs_remaining; # error = f.write(&header, sizeof(t_wav_header)); -# return error ? error : f.write(d); +# return error ? error : f.write(d); return 0 # TODO fix @@ -192,7 +178,7 @@ class audFile: if self.get_samplerate() < 8000 or self.get_samplerate() > 48000 or self.header().m_size_in > (maxLength - SIZE_OF_AUD_HEADER_IN_BYTES ): print "[Warning] Bad AUD Header info in file %s, size_in: %d, maxLen: %d" % (self.m_simpleAudioFileName, self.header().m_size_in, (maxLength - SIZE_OF_AUD_HEADER_IN_BYTES)) if self.header().m_size_in == 0: - # handle special case where only the header of the AUD file is present and the size_in is 0. + # handle special case where only the header of the AUD file is present and the size_in is 0. # fill the header with "valid" info for an empty wav file self.header().m_size_out = 0 self.header().m_samplerate = 22050 @@ -212,20 +198,22 @@ class audFile: elif self.header().m_compression == 0: # no compression. At least some AUD files in SFX.MIX have this if (self.header().m_flags != 2): return False - self.header().m_populated = True + self.header().m_populated = True return True - + # int AudFile::get_chunk_header(int i, std::fstream& fs, AudFileNS::pos_type startAudFilepos, AudFileNS::pos_type endAudFilepos, AudChunkHeader& outAudChunkHeader) - def get_chunk_header(self, chunkIdx, inAudFileBytesBuffer, inAudFileSize ): + def get_chunk_header(self, chunkIdx, inAudFileBytesBuffer, inAudFileSize): #fs.seekg(int(startAudFilepos) + int(SIZE_OF_AUD_HEADER_IN_BYTES), fs.beg); #AudFileNS::pos_type rAudPos; #rAudPos = fs.tellg(); outAudChunkHeader = AudChunkHeader() rAudPos = SIZE_OF_AUD_HEADER_IN_BYTES + if (self.m_traceModeEnabled): + print "[Trace] Getting chunk header at %d" % (rAudPos) #AudChunkHeader tmpInremediateChunkheader; tmpInremediateChunkheader = AudChunkHeader() - #while (i--) # value of i is decreased after checked by while loop + #while (i--) # value of i is decreased after checked by while loop while(chunkIdx > 0): chunkIdx -= 1 if (rAudPos + SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES > inAudFileSize): @@ -240,9 +228,9 @@ class audFile: tmpAudFileOffset += 2 tmpTuple = struct.unpack_from('I', inAudFileBytesBuffer, tmpAudFileOffset) tmpInremediateChunkheader.m_ch_id = tmpTuple[0] - tmpAudFileOffset += 4 + tmpAudFileOffset += 4 #fs.read((char*)&tmpInremediateChunkheader, SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES); - rAudPos += SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES + tmpInremediateChunkheader.m_ch_size_in + rAudPos += SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES + tmpInremediateChunkheader.m_ch_size_in #fs.seekg(int(rAudPos), fs.beg); if (rAudPos + SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES > inAudFileSize ): @@ -263,12 +251,14 @@ class audFile: return (-1, rAudPos, None) rAudPos += SIZE_OF_AUD_CHUNK_HEADER_IN_BYTES return (0, rAudPos, outAudChunkHeader) # //reinterpret_cast<const AudChunkHeader*>(r); - + # int AudFile::get_chunk_data(int i, std::fstream& fs, int sizeToRead, AudFileNS::byte* byteChunkDataPtr) def get_chunk_data(self, inAudFileBytesBuffer, startOffs, sizeToRead): #fs.read((char*)byteChunkDataPtr, sizeToRead) outChunkDataLst = [] - #print "[Debug] startOffs: %d, sizeToRead: %d" % (startOffs, sizeToRead) + if (self.m_traceModeEnabled): + print "[Trace] Getting chunk data" + print "[Trace] startOffs: %d, sizeToRead: %d" % (startOffs, sizeToRead) for i in range(startOffs, startOffs + sizeToRead): #outChunkDataLst.append(ctypes.c_char(inAudFileBytesBuffer[i]).value) #outChunkDataLst.append(ctypes.c_byte(inAudFileBytesBuffer[i]).value) @@ -289,22 +279,25 @@ class audFile: # Cvirtual_binary d; binaryDataOutLst = [] binaryDataOutBuff = None - cb_audio = self.get_cb_sample() * self.get_c_samples() # int cb_audio - basically this should be the size_out + cb_audio = self.get_cb_sample() * self.get_c_samples() # int cb_audio - basically this should be the size_out if speccompression == 1: # write_start allocates space for virtualBinary # AudFileNS::byte* w = d.write_start(cb_audio); - errGetChunk = 0 # int errGetChunk + errGetChunk = 0 # int errGetChunk #for (int chunk_i = 0; w != d.data_end(); chunk_i++) chunk_i = 0 wIndex = 0 while (wIndex < cb_audio): - #AudChunkHeader out_chunk_header; + #AudChunkHeader out_chunk_header; #out_chunk_header = AudChunkHeader() - (errGetChunk, bufferDataPos, out_chunk_header) = self.get_chunk_header(chunk_i, audBytesBuff, len(audBytesBuff)) + (errGetChunk, bufferDataPos, out_chunk_header) = self.get_chunk_header(chunk_i, audBytesBuff, len(audBytesBuff)) if errGetChunk != 0: -# print "[Warning] Error OR End file case while getting uncompressed chunk header!" + if self.m_traceModeEnabled: + print "[Trace] Error OR End file case while getting uncompressed chunk header!" break - #print "[Debug] Get uncompressed chunk header returned: %d " % (out_chunk_header.m_ch_id) + + if self.m_traceModeEnabled: + print "[Trace] Get uncompressed chunk header returned: %d " % (out_chunk_header.m_ch_id) #Cvirtual_binary out_chunk_data; #AudFileNS::byte* byteChunkDataPtr = out_chunk_data.write_start(out_chunk_header.m_ch_size_in); (errorGCD, byteChunkDataLst) = self.get_chunk_data(audBytesBuff, bufferDataPos, out_chunk_header.m_ch_size_in) @@ -318,60 +311,64 @@ class audFile: decodeInstance = audFileDecode(self.m_traceModeEnabled); #decodeInstance.init(); #AudFileNS::byte* w = d.write_start(cb_audio); - errGetChunk = 0 # int errGetChunk + errGetChunk = 0 # int errGetChunk # for (int chunk_i = 0; w != d.data_end(); chunk_i++) chunk_i = 0 wIndex = 0 while (wIndex < cb_audio): - #print("[Debug] chunkI: %d\t Windex: %d\t cb_audio: %d") % (chunk_i,wIndex,cb_audio) - #AudChunkHeader out_chunk_header; + if self.m_traceModeEnabled: + print("[Trace] chunkI: %d\t Windex: %d\t cb_audio: %d") % (chunk_i,wIndex,cb_audio) + #AudChunkHeader out_chunk_header; #out_chunk_header = AudChunkHeader() #errGetChunk = self.get_chunk_header(chunk_i, fs, startAudFilepos, endAudFilepos, out_chunk_header); (errGetChunk, bufferDataPos, out_chunk_header) = self.get_chunk_header(chunk_i, audBytesBuff, len(audBytesBuff)) if errGetChunk != 0: print "[Warning] Error OR End file case while getting COMPRESSED chunk header!" break - #print "[Debug] Get COMPRESSED chunk header returned:: headerInSize: %d headerOutSize: %d id: %d" % (out_chunk_header.m_ch_size_in, out_chunk_header.m_ch_size_out, out_chunk_header.m_ch_id) + if self.m_traceModeEnabled: + print "[Trace] Get COMPRESSED chunk header returned:: headerInSize: %d headerOutSize: %d id: %d" % (out_chunk_header.m_ch_size_in, out_chunk_header.m_ch_size_out, out_chunk_header.m_ch_id) #Cvirtual_binary out_chunk_data; #AudFileNS::byte* byteChunkDataPtr = out_chunk_data.write_start(out_chunk_header.m_ch_size_in); (errorGCD, byteChunkDataLst) = self.get_chunk_data(audBytesBuff, bufferDataPos, out_chunk_header.m_ch_size_in) # export decoded chunk to w (output) buffer (of SHORTS) at the point where we're currently at (so append there) - #print "[Debug] byteChunkDataLst len: %d, m_ch_size_in was: %d" % (len(byteChunkDataLst), out_chunk_header.m_ch_size_in) + if self.m_traceModeEnabled: + print "[Trace] byteChunkDataLst len: %d, m_ch_size_in was: %d" % (len(byteChunkDataLst), out_chunk_header.m_ch_size_in) decodedAudioChunkAsLst = decodeInstance.decode_chunk(byteChunkDataLst, out_chunk_header.m_ch_size_out / self.get_cb_sample()); binaryDataOutLst.extend(decodedAudioChunkAsLst) wIndex += out_chunk_header.m_ch_size_out - #print("[Debug] New Windex: %d\t cb_audio: %d") % (wIndex,cb_audio) + if self.m_traceModeEnabled: + print("[Trace] New Windex: %d\t cb_audio: %d") % (wIndex,cb_audio) chunk_i += 1 binaryDataOutBuff = struct.pack('h'*len(binaryDataOutLst), *binaryDataOutLst) if self.m_traceModeEnabled: if binaryDataOutBuff is not None: if self.m_traceModeEnabled: - print "[Debug] Decoding Done." + print "[Trace] Decoding Done." else: #if binaryDataOutBuff is None: print "[Error] Decoding yielded errors (data out buffer is null)." return binaryDataOutBuff - + def header(self): return self.m_header - - def get_c_samples(self): + + def get_c_samples(self): return self.m_header.m_size_out / self.get_cb_sample() - + def get_samplerate(self): return self.m_header.m_samplerate; - + # flag bit 0 is stereo(set) mono(clear) - def get_c_channels(self): + def get_c_channels(self): return 2 if (self.m_header.m_flags & 0x01) else 1; - - # flag bit 1 is 16bit(set) 8bit (clear) + + # flag bit 1 is 16bit(set) 8bit (clear) def get_cb_sample(self): return 2 if (self.m_header.m_flags & 0x02) else 1 # # -# +# if __name__ == '__main__': - # main() + # main() errorFound = False # By default assumes a file of name 000000.AUD in same directory # otherwise tries to use the first command line argument as input file @@ -389,7 +386,7 @@ if __name__ == '__main__': else: print "[Error] No valid input file argument was specified and default input file %s is missing." % (inAUDFileName) errorFound = True - + if not errorFound: try: print "[Info] Opening %s" % (inAUDFileName) @@ -398,7 +395,7 @@ if __name__ == '__main__': errorFound = True print "[Error] Unexpected event:", sys.exc_info()[0] raise - if not errorFound: + if not errorFound: allOfAudFileInBuffer = inAUDFile.read() audFileInstance = audFile(True) if audFileInstance.m_traceModeEnabled: @@ -412,4 +409,5 @@ if __name__ == '__main__': else: #debug #print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION) - pass
\ No newline at end of file + pass +
\ No newline at end of file diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/devCommentaryText.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/devCommentaryText.py index 9ec4e10cdf..2bf04f1d3b 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/devCommentaryText.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/devCommentaryText.py @@ -28,7 +28,7 @@ EXTRA_SPEECH_AUDIO_TUPLE_LIST = [ ('67_1080R.AUD', "*Crowd talk*"), ('67_1100R.AUD', "*Crowd talk*"), ('67_1140R.AUD', "*Crowd talk*"), - ('67_1160R.AUD', "*Crowd talk*") + ('67_1160R.AUD', "*Crowd talk*") ] # we use the spoken quote id that triggers the comment as an ID for the DEV commentary quote @@ -40,7 +40,7 @@ DEV_ISEZ_QUOTES_TUPLE_LIST = [ ("IS-23-0130.AUD", "JM: Did it have a huge, ugly piece of chrome on it?"), # Officer Leary ("IS-23-0090.AUD", "JM: This officer has a talent for vivid metaphors."), # Officer Leary ("IS-00-4540.AUD", "DL: What is that supposed to mean? I didn't write this line..."), - ("IS-00-4515.AUD", "MG: Hey, leave that officer alone. Can't you see he's busy?\nJM: (...mmm, donuts...)"), # clicking on Leary after we get his statement + ("IS-00-4515.AUD", "MG: Hey, leave that officer alone. Can't you see he's busy?\nJM: (...mmm, donuts...)"), # clicking on Leary after we get his statement ("IS-23-0060.AUD", "MG: It's all fun and games until someone loses a tiger cub."), # Officer Leary ("IS-00-9991.AUD", "JM: Chrome...is that what that is?"), # pick up chrome ("IS-00-4510.AUD", "JM: It's hard to imagine that thing on either a car or a horse.\nMG: McCoy! What a witty chap...\nJM: He keeps me chuckling non-stop!"), @@ -50,7 +50,7 @@ DEV_ISEZ_QUOTES_TUPLE_LIST = [ # # # -class devCommentaryText: +class devCommentaryText(object): m_traceModeEnabled = True # traceModeEnabled is bool to enable more printed debug messages def __init__(self, traceModeEnabled = True): @@ -58,6 +58,8 @@ class devCommentaryText: return def printTexts(self): + if self.m_traceModeEnabled: + print "[Trace] Printing all dev commentary text" print "\nAUDIO COMMENTARY" print "------------------" for (idTre, textTre) in DEV_AUDIO_COMMENTARY_TUPLE_LIST: @@ -73,16 +75,25 @@ class devCommentaryText: return def getAudioCommentaryTextEntriesList(self): + if self.m_traceModeEnabled: + print "[Trace] getAudioCommentaryTextEntriesList" return DEV_AUDIO_COMMENTARY_TUPLE_LIST def getISEZTextEntriesList(self): + + if self.m_traceModeEnabled: + print "[Trace] getISEZTextEntriesList" return DEV_ISEZ_QUOTES_TUPLE_LIST - + def getExtraSpeechAudioEntriesList(self): + if self.m_traceModeEnabled: + print "[Trace] getExtraSpeechAudioEntriesList" return EXTRA_SPEECH_AUDIO_TUPLE_LIST - +# +# +# if __name__ == '__main__': - # main() + # main() print "[Debug] Running %s as main module" % (my_module_name) traceModeEnabled = False devCommentaryTextInstance = devCommentaryText(traceModeEnabled) diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/pogoTextResource.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/pogoTextResource.py index ca7ca3c0e1..0130cc0d92 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/pogoTextResource.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/pogoTextResource.py @@ -167,10 +167,9 @@ POGO_TEXT_RESOURCE_TUPLE_LIST = [ (157, "Zion National Park"), (158, "We 3 coders give special thanks to:") ] -# -# -# -class pogoTextResource: + + +class pogoTextResource(object): m_traceModeEnabled = True # traceModeEnabled is bool to enable more printed debug messages def __init__(self, traceModeEnabled = True): @@ -178,15 +177,22 @@ class pogoTextResource: return def printPogo(self): + if self.m_traceModeEnabled: + print "[Trace] printing Pogo..." for (idTre, textTre) in POGO_TEXT_RESOURCE_TUPLE_LIST: print "%s\t%s" % (idTre, textTre) return def getPogoEntriesList(self): + if self.m_traceModeEnabled: + print "[Trace] getPogoEntriesList()" return POGO_TEXT_RESOURCE_TUPLE_LIST - + +# +# +# if __name__ == '__main__': - # main() + # main() print "[Debug] Running %s as main module" % (my_module_name) traceModeEnabled = False pogoTRInstance = pogoTextResource(traceModeEnabled) diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/quoteSpreadsheetCreator.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/quoteSpreadsheetCreator.py index 82481433b7..2db0228479 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/quoteSpreadsheetCreator.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/quoteSpreadsheetCreator.py @@ -2,20 +2,22 @@ # -*- coding: UTF-8 -*- sysLibFound = False try: - import sys + import sys except ImportError: print ("[Error] sys python library is required to be installed!") else: sysLibFound = True - -if (not sysLibFound): + +if (not sysLibFound): sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n") - sys.exit(1) + sys.exit(1) -if not (sys.version_info[0] == 2 and sys.version_info[1] == 7): +if not (sys.version_info[0] == 2 and sys.version_info[1] == 7): sys.stdout.write("[Error] Blade Runner Quotes Spreadsheet Creator script requires Python 2.7\n") sys.exit(1) - + import sortBladeRunnerWavs02 + if __name__ == "__main__": - sortBladeRunnerWavs02.main(sys.argv[0:])
\ No newline at end of file + sortBladeRunnerWavs02.main(sys.argv[0:]) +
\ No newline at end of file diff --git a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py index a76673ef0c..b83a34b975 100644 --- a/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py +++ b/devtools/create_bladerunner/subtitles/quotesSpreadsheetCreator/treFileLib.py @@ -7,36 +7,28 @@ shutilLibFound = False structLibFound = False try: - import os + import os except ImportError: - print "[Error] os python library is required to be installed!" + print "[Error] os python library is required to be installed!" else: osLibFound = True try: - import sys + import sys except ImportError: - print "[Error] sys python library is required to be installed!" + print "[Error] sys python library is required to be installed!" else: sysLibFound = True try: - import shutil + import struct except ImportError: - 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 osLibFound) \ or (not sysLibFound) \ - or (not shutilLibFound) \ or (not structLibFound): sys.stdout.write("[Error] Errors were found when trying to import required python libraries\n") sys.exit(1) @@ -47,27 +39,27 @@ MY_MODULE_VERSION = "0.50" MY_MODULE_NAME = "treFileLib" -class TreHeader: +class TreHeader(object): numOfTextResources = -1 def __init__(self): return -class treFile: +class treFile(object): m_header = TreHeader() simpleTextResourceFileName = 'GENERIC.TRE' stringEntriesLst = [] # list of two-value tuples. First value is ID, second value is String content stringOffsets = [] m_traceModeEnabled = False - # traceModeEnabled is bool to enable more printed debug messages + # 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, treFileName): self.simpleTextResourceFileName = treFileName offsInTreFile = 0 @@ -87,7 +79,7 @@ class treFile: tmpTuple = struct.unpack_from('I', treBytesBuff, offsInTreFile) # unsigned integer 4 bytes self.stringEntriesLst.append( (tmpTuple[0], '') ) offsInTreFile += 4 - + # string offsets table (each entry is unsigned integer 4 bytes) for idx in range(0, self.header().numOfTextResources): tmpTuple = struct.unpack_from('I', treBytesBuff, offsInTreFile) # unsigned integer 4 bytes @@ -95,13 +87,13 @@ class treFile: offsInTreFile += 4 # # strings (all entries are null terminated) - # TODO +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + # TODO +++ absStartOfIndexTable = 4 #absStartOfOffsetTable = absStartOfIndexTable + (self.header().numOfTextResources * 4) #absStartOfStringTable = absStartOfOffsetTable + ((self.header().numOfTextResources+1) * 4) - + #print "[Debug] buffer type: " , type(treBytesBuff) # it is str - + for idx in range(0, self.header().numOfTextResources): currOffset = self.stringOffsets[idx] + absStartOfIndexTable # the buffer (treBytesBuff) where we read the TRE file into, is "str" type but contains multiple null terminated strings @@ -122,7 +114,7 @@ class treFile: except: print "[Error] Loading Text Resource %s failed!" % (self.simpleTextResourceFileName) return False - + def header(self): return self.m_header # @@ -147,7 +139,7 @@ if __name__ == '__main__': else: print "[Error] No valid input file argument was specified and default input file %s is missing." % (inTREFileName) errorFound = True - + if not errorFound: try: print "[Info] Opening %s" % (inTREFileName) @@ -169,4 +161,5 @@ if __name__ == '__main__': else: #debug #print "[Debug] Running %s (%s) imported from another module" % (MY_MODULE_NAME, MY_MODULE_VERSION) - pass
\ No newline at end of file + pass +
\ No newline at end of file |