def onCommandSplit(self): """""" done = True Sys.cli_emit_progress(1) if not self.o.parts is None and not(int(self.o.parts)>=12 and int(self.o.parts) <=62) : self.parser.error_cmd((('invalid option ',('-p, --parts', Sys.Clz.fgb3), ' value (', ('12',Sys.Clz.fgb3),' to ', ('62',Sys.Clz.fgb3),')'),)) else : self.o.parts = int(self.o.parts) if not Sys.g.QUIET : self.parser.print_header() if self.o.outputfile is not None : if self.o.outputfile[-5:]!='.tark' : self.o.outputfile += '.tark' if Io.file_exists(self.o.outputfile) and not self.o.force: Sys.pwarn((('the file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),)) done = Sys.pask('Are you sure to rewrite this file') self.stime = Sys.datetime.now() if done : try : Sys.ptask() Sys.cli_emit_progress(2) key = Io.get_data(self.o.keyfile) km = Kirmah(key) hlst = km.ck.getHashList(Sys.basename(self.a[1]), self.o.parts, True) Sys.cli_emit_progress(3) kcf = km.splitFile(self.a[1], hlst) t = int(Sys.time()) times = (t,t) p = 85 Sys.cli_emit_progress(p) Io.touch(kcf, times) frav = 0.24 for row in hlst['data']: p += frav Io.touch(row[1]+km.EXT,times) Sys.cli_emit_progress(p) if self.o.outputfile is not None : d = Sys.datetime.now() if Sys.g.DEBUG : Sys.wlog(Sys.dprint()) Sys.ptask('Preparing tark file') hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4]) with tarfile.open(self.o.outputfile, mode='w') as tar: tar.add(kcf, arcname=Sys.basename(kcf)) p = 90 for row in hlst['data']: tar.add(row[1]+km.EXT, arcname=Sys.basename(row[1]+km.EXT)) p += frav Sys.cli_emit_progress(p) Sys.pstep('Packing destination file', d, True) d = Sys.datetime.now() Sys.ptask('Finalize') for row in hlst['data']: Io.removeFile(row[1]+km.EXT) p += frav Sys.cli_emit_progress(p) Io.removeFile(kcf) Sys.pstep('Cleaning', d, True) except Exception as e : done = False if Sys.g.DEBUG : print('split exception') print(e) #~ raise e elif not Sys.g.QUIET : Sys.pwarn((str(e),)) if not Sys.g.QUIET: Sys.cli_emit_progress(100) self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)
def onCommandSplit(self): """""" done = True Sys.cli_emit_progress(1) if not self.o.parts is None and not (int(self.o.parts) >= 12 and int(self.o.parts) <= 62): self.parser.error_cmd( (('invalid option ', ('-p, --parts', Sys.Clz.fgb3), ' value (', ('12', Sys.Clz.fgb3), ' to ', ('62', Sys.Clz.fgb3), ')'), )) else: self.o.parts = int(self.o.parts) if not Sys.g.QUIET: self.parser.print_header() if self.o.outputfile is not None: if self.o.outputfile[-5:] != '.tark': self.o.outputfile += '.tark' if Io.file_exists(self.o.outputfile) and not self.o.force: Sys.pwarn((('the file ', (self.o.outputfile, Sys.Clz.fgb3), ' already exists !'), )) done = Sys.pask('Are you sure to rewrite this file') self.stime = Sys.datetime.now() if done: try: Sys.ptask() Sys.cli_emit_progress(2) key = Io.get_data(self.o.keyfile) km = Kirmah(key) hlst = km.ck.getHashList(Sys.basename(self.a[1]), self.o.parts, True) Sys.cli_emit_progress(3) kcf = km.splitFile(self.a[1], hlst) t = int(Sys.time()) times = (t, t) p = 85 Sys.cli_emit_progress(p) Io.touch(kcf, times) frav = 0.24 for row in hlst['data']: p += frav Io.touch(row[1] + km.EXT, times) Sys.cli_emit_progress(p) if self.o.outputfile is not None: d = Sys.datetime.now() if Sys.g.DEBUG: Sys.wlog(Sys.dprint()) Sys.ptask('Preparing tark file') hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4]) with tarfile.open(self.o.outputfile, mode='w') as tar: tar.add(kcf, arcname=Sys.basename(kcf)) p = 90 for row in hlst['data']: tar.add(row[1] + km.EXT, arcname=Sys.basename(row[1] + km.EXT)) p += frav Sys.cli_emit_progress(p) Sys.pstep('Packing destination file', d, True) d = Sys.datetime.now() Sys.ptask('Finalize') for row in hlst['data']: Io.removeFile(row[1] + km.EXT) p += frav Sys.cli_emit_progress(p) Io.removeFile(kcf) Sys.pstep('Cleaning', d, True) except Exception as e: done = False if Sys.g.DEBUG: print('split exception') print(e) #~ raise e elif not Sys.g.QUIET: Sys.pwarn((str(e), )) if not Sys.g.QUIET: Sys.cli_emit_progress(100) self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)