def buildFile(self, fromPath, label="", catg=""): count = self.getCountParts(fromPath) Sys.pwlog([(" Get Hash... ", Const.CLZ_7, True)]) sha256 = hash_sha256_file(fromPath) Sys.pwlog([(" hash : ", Const.CLZ_0), (sha256, Const.CLZ_2, True), (" Build File...", Const.CLZ_0, True)]) kg = KeyGen(128) size = Sys.getsize(fromPath) row = self.idxu.index.get(sha256) if row is None: if label == "": label, ext = Sys.getFileExt(Sys.basename(fromPath)) else: label, ext = Sys.getFileExt(label) if catg == "": catg = self.idxu.index.getAutoCatg(ext) size = Sys.getsize(fromPath) Sys.pwlog( [ (" Splitting ", Const.CLZ_1), (label, Const.CLZ_7), (ext, Const.CLZ_7), (" (", Const.CLZ_0), (Sys.readableBytes(size), Const.CLZ_3), (")", Const.CLZ_0, True), ] ) Sys.cli_emit_progress(0) Sys.sleep(0.2) km = Kirmah(kg.key) km.DIR_OUTBOX = self.outbox # hlst genetate with sha256 hlst = km.ck.getHashList(sha256, int(count), True) usr = self.idxu.conf.get("name", "infos") ownerHash = self.idxu.mb.getHashName(usr) km.split(fromPath, hlst) Sys.pwlog([(" done ", Const.CLZ_2, True)]) row = [kg.key, label, ext, count, catg, hlst, usr, ownerHash, sha256, size] self.backupAddMap(row) else: Sys.pwlog( [ (" File Already exist ! ", Const.CLZ_1, True), (" id : ".rjust(10, " "), Const.CLZ_0), (str(row[ImpraIndex.UID]), Const.CLZ_1, True), (" label : ".rjust(10, " "), Const.CLZ_0), (row[ImpraIndex.LABEL], Const.CLZ_3, True), ] ) row = None return row
def getFile(self, uid): """""" # ~ Sys.pwlog([(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0, True)]) done = False key = self.idxu.index.getById(uid) row = self.idxu.index.get(key) filePath = None try: if row is not None: account = self.idxu.switchFileAccount(row[self.idxu.index.ACCOUNT]) km = Kirmah(row[self.idxu.index.KEY]) hlst = km.ck.getHashList(key, row[self.idxu.index.PARTS], True) ids = self.idxu.ih.searchBySubject(hlst["head"][2], True) Sys.cli_emit_progress(0) Sys.sleep(0.2) Sys.pwlog( [ (" Downloading : ", Const.CLZ_7), (row[self.idxu.index.LABEL] + row[self.idxu.index.EXT], Const.CLZ_2), (" (", Const.CLZ_0), (Sys.readableBytes(row[self.idxu.index.SIZE]), Const.CLZ_3), (")", Const.CLZ_0), (" please wait...", Const.CLZ_7, True), ] ) if len(ids) >= row[self.idxu.index.PARTS]: self.getFileParts(row, ids) Sys.pwlog([(" Merging parts...", Const.CLZ_7, True)]) Sys.cli_emit_progress(0) Sys.sleep(0.2) filePath = km.merge( hlst, self.deploy + row[self.idxu.index.CATG] + Sys.sep + row[self.idxu.index.LABEL], ext=row[self.idxu.index.EXT], uid=row[self.idxu.index.UID], dirs=self.inbox, ) Sys.pwlog( [ (" Deployed as ", Const.CLZ_7), (filePath, Const.CLZ_2), (" (", Const.CLZ_0), (Sys.readableBytes(Sys.getsize(filePath)), Const.CLZ_3), (") ", Const.CLZ_0, True), (" Checking integrity...", Const.CLZ_7, True), ] ) Sys.sleep(0.2) sha256 = hash_sha256_file(filePath) done = sha256 == row[ImpraIndex.HASH] done = True else: print("incomplete") except Exception as e: print(e) Sys.pwlog([(" done" if done else "ko", Const.CLZ_2 if done else Const.CLZ_1, True)]) return done, filePath