import bit import os import shutil import math import time from datetime import datetime def restartI2Service(headendIds): HeadendList = '' for x in headendIds: HeadendList += ('' + x + '') bit.sendCommand('' + HeadendList + 'I2MSG', 1) #print('' + HeadendList + '') def rebootI2(headendIds): HeadendList = '' for x in headendIds: HeadendList += ('' + x + '') commands = [] command = '' + HeadendList + '' commands.append(command) bit.sendCommand(commands, 1) def clearStarBundle(headendIds, btype): HeadendList = '' for x in headendIds: HeadendList += ('' + x + '') commands = [] command = '' + HeadendList + '' commands.append(command) bit.sendCommand(commands, 1) def changePasswords(PasswordFile, headendIds): HeadendList = '' files = [] files.append(PasswordFile) commands = [] numSegs = 1 if headendIds != None: for x in headendIds: HeadendList += ('' + x + '') command = '' + HeadendList + '' commands.append(command) bit.sendFile(files, commands, numSegs, 0) else: command = '' commands.append(command) bit.sendFile(files, commands, numSegs, 0) os.remove(PasswordFile) def sendMaintCommand(File, headendIds): HeadendList = '' files = [] files.append(File) commands = [] numSegs = 1 if headendIds != None: for x in headendIds: HeadendList += ('' + x + '') #command = '' + HeadendList + '' #command = '' + HeadendList + '' #command = '' + HeadendList + '' #command = '' + HeadendList + '' #command = '' + HeadendList + '' #command = '' + HeadendList + '' #command = '' + HeadendList + '' #I2 HD #command = '' + HeadendList + '' commands.append(command) bit.sendFile(files, commands, numSegs, 0) else: #command = '' commands.append(command) bit.sendFile(files, commands, numSegs, 0) os.remove(File) def loadRunPres(headendIds, Flavor, Logo, Duration, Id): HeadendList = '' for x in headendIds: HeadendList += ('' + x + '') if Logo == '': command = ['' + HeadendList + ''] bit.sendCommand(command, 1) else: command = ['' + HeadendList + ''] bit.sendCommand(command, 1) def sendStarBundle(File): size = os.path.getsize(File) if size >= 67550000: CHUNK_SIZE = 67550000 file_number = 1 fPath = os.path.dirname(File) fpToSplit = os.path.splitext(File) splitFn = fpToSplit[0].split('\\') newFn = splitFn[-1] eCount = size / CHUNK_SIZE estCount = math.ceil(eCount) print("File size is greater than 64MB. Will need to split the files for transmission...\n") time.sleep(1) with open(File, "rb") as f: chunk = f.read(CHUNK_SIZE) while chunk: if file_number < 10: fileNum = '0' + str(file_number) else: fileNum = file_number with open(fPath + '\\split\\' + newFn + '_' + str(fileNum), "wb") as chunk_file: chunk_file.write(chunk) print('Successfully split file ' + str(file_number) + ' out of ' + str(estCount) + '\n') file_number += 1 chunk = f.read(CHUNK_SIZE) count = file_number - 1 part = 1 with open('./.temp/msgId.txt', "r") as f: oMsgId = f.read() Id = int(oMsgId) f.close() for x in os.listdir(fPath + '\\split'): path = fPath + '\\split\\' y = path + x if part != count: print(x) bit.sendFile([y],[''], 1, 0) part += 1 time.sleep(30) elif part == count: print(x) bit.sendFile([y],[''], 1, 0) time.sleep(30) bit.sendCommand([''], 0) for f in os.listdir(path): os.remove(os.path.join(path, f)) else: bit.sendFile([File],[''], 1, 0) os.remove(File) def sendUpgrade(File, RelName): size = os.path.getsize(File) if size >= 67550000: CHUNK_SIZE = 67550000 file_number = 1 fPath = os.path.dirname(File) fpToSplit = os.path.splitext(File) splitFn = fpToSplit[0].split('\\') newFn = splitFn[-1] eCount = size / CHUNK_SIZE estCount = math.ceil(eCount) print("File size is greater than 64MB. Will need to split the files for transmission...\n") time.sleep(1) with open(File, "rb") as f: chunk = f.read(CHUNK_SIZE) while chunk: if file_number < 10: fileNum = '0' + str(file_number) else: fileNum = file_number with open(fPath + '\\split\\' + newFn + '_' + str(fileNum), "wb") as chunk_file: chunk_file.write(chunk) print('Successfully split file ' + str(file_number) + ' out of ' + str(estCount) + '\n') file_number += 1 chunk = f.read(CHUNK_SIZE) count = file_number - 1 part = 1 with open('./.temp/msgId.txt', "r") as f: oMsgId = f.read() Id = int(oMsgId) f.close() for x in os.listdir(fPath + '\\split'): path = fPath + '\\split\\' y = path + x if part != count: print(x) bit.sendFile([y],[''], 1, 0) part += 1 time.sleep(10) elif part == count: print(x) bit.sendFile([y],[''], 1, 0) part += 1 time.sleep(15) bit.sendCommand([''], 0) for f in os.listdir(path): os.remove(os.path.join(path, f)) else: bit.sendFile([File],[''], 1, 0) os.remove(File) def makeStarBundle(Directory, Type, flag, Version, date, sendAfter): header = '\n ' + Version + '\n ' + date + '\n ' + Type + '\n \n' with open('./.temp/i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'w') as ma: ma.write(header) ma.close() for (root,dirs,files) in os.walk(Directory, topdown=True): for name in files: rootDir = root[24:] bDest = os.path.join(rootDir,name) fDest = os.path.join(root,name) shutil.copy(fDest, './.temp/i2State\\SD\\ChangesetBundle') for name in files: if flag == 'Domestic_Universe': flag = 'flags="Domestic_Universe"' elif flag == 'Domestic_SD_Universe': flag = 'flags="Domestic_SD_Universe"' else: pass with open('./.temp/i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'a') as mb: mb.write(' \n') mb.close() closer = ' \n' with open('./.temp/i2State\\SD\\ChangesetBundle\\MetaData\\manifest.xml', 'a') as ma: ma.write(closer) ma.close() #restartI2Service(['006833']) #rebootI2(['006833']) #clearStarBundle(['006833'], 'Changeset') #bit.sendCommand([''], 1) #loadRunPres(['038488'], 'domestic/ldlE', '', '72000', 'LDL1') #changePasswords('./.temp/passwords2.gz', ['006833']) #sendMaintCommand('./.temp/maint\\temp\\passwords',['040500']) #sendStarBundle("./.temp/Bundle.zip") #sendUpgrade("./.temp/Upgrades\\wireshark_1.4.6.0.zip", "wireshark_1.4.6.0") #For splitting #sendUpgrade("./.temp/ChangesetHD.zip", "PipelineMaint_6.15.1.5714") #For no split upgrades #bit.sendFile('./.temp/Upgrades\\vizRequiredFilesForI2_1.2.0.0.zip', '040500I2MSG', 0) #For split upgrades #bit.sendFile('./.temp/split\\ChangesetHD_04', 'I2MSG', 0) #Command for split upgrades #commands = [] #command = '' #commands.append(command) #bit.sendCommand(commands, 1, 0) #bit.sendFile(['./.temp/Alert.gz'], [''], 1, 0) ''' bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) bit.sendCommand([''], 0) ''' #bit.sendCommand(['006833'], 1) #bit.sendCommand('./.temp/Upgrades\\split\\PipelineMaint_6.15.1.5714_03', 'I2MSG', 0) #bit.sendCommand([''], 0) #bit.sendCommand([''], 1) #bit.sendCommand([''], 1) #bit.sendCommand([''], 1) #makeStarBundle('./.temp/i2State\\SD\\Changeset\\audio\\domesticSD\\vocalLocal\\Cantore', 'Changeset', 'Domestic_SD_Universe', '63702614401035937', '09/19/2022', 0)