adding progress step + bugfix cli

This commit is contained in:
a-Sansara 2013-05-15 20:47:12 +02:00
parent 0d67d7bbcb
commit c367db484c
9 changed files with 212 additions and 185 deletions

View File

@ -36,6 +36,7 @@ def main():
c = 0 c = 0
Cli('.'+Sys.sep) Cli('.'+Sys.sep)
except Exception as e : except Exception as e :
raise e
Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True) Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
c = 1 c = 1
return c return c

View File

@ -36,6 +36,7 @@ def main():
c = 0 c = 0
AppGui() AppGui()
except Exception as e: except Exception as e:
raise e
Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True) Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
c = 1 c = 1
return c return c

View File

@ -46,7 +46,7 @@ class Cli(AbstractCli):
def __init__(self, path, remote=False, rwargs=None, thread=None, loglvl=Const.LOG_DEFAULT): def __init__(self, path, remote=False, rwargs=None, thread=None, loglvl=Const.LOG_DEFAULT):
"""""" """"""
AbstractCli.__init__(self, conf) AbstractCli.__init__(self, conf, self)
Cli.HOME = conf.DEFVAL_USER_PATH Cli.HOME = conf.DEFVAL_USER_PATH
@ -87,18 +87,19 @@ class Cli(AbstractCli):
if not a: if not a:
try : try :
if not o.help : if not o.help or not o.version:
Cli.error_cmd(('no command specified',)) self.parser.error_cmd(('no command specified',), True)
else : else :
Sys.clear() Sys.clear()
Cli.print_help() Cli.print_help()
except : except :
Cli.error_cmd(('no command specified',)) if not o.version :
self.parser.error_cmd(('no command specified',), True)
else :
Cli.print_header()
else: else:
if a[0] == 'help': if a[0] == 'help':
Sys.clear() Sys.clear()
Cli.print_help() Cli.print_help()
@ -111,9 +112,9 @@ class Cli(AbstractCli):
app.onCommandKey() app.onCommandKey()
else : else :
if not len(a)>1 : if not len(a)>1 :
Cli.error_cmd((('an ',('inputFile',Sys.Clz.fgb3),' is required !'),)) self.parser.error_cmd((('an ',('inputFile',Sys.Clz.fgb3),' is required !'),), True)
elif not Io.file_exists(a[1]): elif not Io.file_exists(a[1]):
Cli.error_cmd((('the file ',(a[1], Sys.Clz.fgb3), ' doesn\'t exists !'),)) self.parser.error_cmd((('the file ',(a[1], Sys.Clz.fgb3), ' doesn\'t exists !'),), True)
elif a[0]=='enc' : app.onCommandEnc() elif a[0]=='enc' : app.onCommandEnc()
elif a[0]=='dec' : app.onCommandDec() elif a[0]=='dec' : app.onCommandDec()
@ -125,10 +126,19 @@ class Cli(AbstractCli):
Sys.g.LOG_QUEUE.put(Sys.g.SIGNAL_STOP) Sys.g.LOG_QUEUE.put(Sys.g.SIGNAL_STOP)
else : else :
Cli.error_cmd((('unknow command ',(a[0],Sys.Clz.fgb3)),)) self.parser.error_cmd((('unknow command ',(a[0],Sys.Clz.fgb3)),))
if not o.quiet : Sys.dprint() if not o.quiet : Sys.dprint()
#~
#~ @staticmethod
#~ def error_cmd(data):
#~ """"""
#~ Cli.print_usage('')
#~ Sys.dprint()
#~ Sys.pwarn(data, True)
#~ Cli.exit(1)
@staticmethod @staticmethod
def print_usage(data, withoutHeader=False): def print_usage(data, withoutHeader=False):

View File

@ -288,7 +288,7 @@ class CliApp:
Sys.pwarn((str(e),)) Sys.pwarn((str(e),))
if not Sys.g.QUIET : if not Sys.g.QUIET :
self.onend_cmd('Merging file', self.stime, done, toPath) self.onend_cmd('Kirmah Merge', self.stime, done, toPath)
@Log(Const.LOG_ALL) @Log(Const.LOG_ALL)

View File

@ -363,39 +363,29 @@ class Kirmah:
@Log() @Log()
def compress_start(self, fromPath, toPath, compress=True, lvl=9): def compress_start(self, fromPath, toPath, compress=True, lvl=9, emit=True):
"""""" """"""
d = Sys.datetime.now() if not Sys.is_cli_cancel():
c = not Sys.is_cli_cancel()
if c :
with Io.rfile(fromPath) as fi : with Io.rfile(fromPath) as fi :
with Io.wfile(toPath) as fo : with Io.wfile(toPath) as fo :
data = fi.read() if not compress else Io.gzcompress(fi.read(), lvl) data = fi.read() if not compress else Io.gzcompress(fi.read(), lvl)
fo.write(b2a_base64(data)) fo.write(b2a_base64(data))
Sys.wlog(Sys.dprint())
Sys.pstep('Compression', d, c)
@Log() @Log()
def uncompress_start(self, fromPath, toPath, decompress=True): def uncompress_start(self, fromPath, toPath, decompress=True, emit=True):
"""""" """"""
d = Sys.datetime.now() if not Sys.is_cli_cancel():
c = not Sys.is_cli_cancel()
if c :
with Io.rfile(fromPath) as fi : with Io.rfile(fromPath) as fi :
with Io.wfile(toPath) as fo : with Io.wfile(toPath) as fo :
data = a2b_base64(fi.read()) data = a2b_base64(fi.read())
fo.write(data if not decompress else Io.gzdecompress(data)) fo.write(data if not decompress else Io.gzdecompress(data))
Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, c)
@Log() @Log()
def compress_end(self, fromPath, toPath, compress=True, lvl=9): def compress_end(self, fromPath, toPath, compress=True, lvl=9, emit=True):
"""""" """"""
d = Sys.datetime.now() if not Sys.is_cli_cancel():
c = not Sys.is_cli_cancel()
if c:
with Io.rfile(fromPath) as fi : with Io.rfile(fromPath) as fi :
with Io.wfile(toPath) as fo : with Io.wfile(toPath) as fo :
data = fi.read() data = fi.read()
@ -403,25 +393,19 @@ class Kirmah:
header = self.kh.buildHeader(len(data)) header = self.kh.buildHeader(len(data))
fo.write(header) fo.write(header)
fo.write(data) fo.write(data)
Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, c)
@Log() @Log()
def uncompress_end(self, fromPath, toPath, decompress=True): def uncompress_end(self, fromPath, toPath, decompress=True, emit=True):
"""""" """"""
d = Sys.datetime.now() if not Sys.is_cli_cancel():
c = not Sys.is_cli_cancel()
if c:
with Io.rfile(fromPath) as fi : with Io.rfile(fromPath) as fi :
with Io.wfile(toPath) as fo : with Io.wfile(toPath) as fo :
fi.seek(self.kh.POS_END) fi.seek(self.kh.POS_END)
fo.write(fi.read() if not decompress else Io.gzdecompress(fi.read())) fo.write(fi.read() if not decompress else Io.gzdecompress(fi.read()))
Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, c)
@Log(Const.LOG_ALL) @Log(Const.LOG_ALL)
def encryptStr(self, data): def encryptStr(self, data, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
s, lk, i = [], len(self.key), 0 s, lk, i = [], len(self.key), 0
@ -435,7 +419,7 @@ class Kirmah:
@Log() @Log()
def encryptToFile(self, fromPath, toPath, i=0, event=None): def encryptToFile(self, fromPath, toPath, i=0, event=None, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
with Io.ufile(fromPath) as fi : with Io.ufile(fromPath) as fi :
@ -452,7 +436,7 @@ class Kirmah:
@Log() @Log()
def decryptToFile(self, fromPath, toPath, i=0, event=None): def decryptToFile(self, fromPath, toPath, i=0, event=None, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
with Io.ufile(fromPath) as fi : with Io.ufile(fromPath) as fi :
@ -478,7 +462,7 @@ class Kirmah:
@Log() @Log()
def randomFileContent(self, fromPath, toPath): def randomFileContent(self, fromPath, toPath, emit=True):
"""""" """"""
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
@ -491,57 +475,12 @@ class Kirmah:
for piece, i in Io.read_in_chunks(fi, chsize): for piece, i in Io.read_in_chunks(fi, chsize):
fo.seek(lst[i]*chsize-(rest if lst[i] > lst[size-1] else 0)) fo.seek(lst[i]*chsize-(rest if lst[i] > lst[size-1] else 0))
fo.write(piece[::-1]) fo.write(piece[::-1])
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Random mode', d, c) Sys.pstep('Random mode', d, c)
@Log() @Log()
def mpRandomFileContent(self, fromPath, toPath, nproc): def unRandomFileContent(self, fromPath, toPath, emit=True):
""""""
if not Sys.is_cli_cancel():
Io.copy(fromPath, fromPath+'.ori')
fsize, chsize, size = Kirmah.getSizes(fromPath)
mpchsize = (fsize//nproc)+1
if fsize % mpchsize == 0 : mpchsize -= 1
#~ print('fsize : '+str(fsize))
#~ print('chsize : '+str(chsize))
#~ print('mpchsize : '+str(mpchsize))
hlstPaths = []
with Io.rfile(fromPath) as fi :
s, piece, fo = 0, 0, Io.wfile('proc_0')
hlstPaths.append('proc_0')
for pdata, _ in Io.read_in_chunks(fi, chsize):
s += chsize
if s > mpchsize :
piece += 1
s = 0
try :
fo.close()
except :
pass
fo = Io.wfile('proc_'+str(piece))
hlstPaths.append('proc_'+str(piece))
fo.write(pdata)
self.mpMergeFiles(hlstPaths, fromPath+'.copy', True)
self.randomFileContent(fromPath, toPath)
@Log()
def mpMergeFiles(self,hlstPaths, toPath, noRemove=False):
""""""
d = Sys.datetime.now()
c = not Sys.is_cli_cancel()
if c:
with Io.wfile(toPath) as fo:
for fromPath in hlstPaths :
with Io.rfile(fromPath) as fi :
fo.write(fi.read())
if not noRemove : Sys.removeFile(fromPath)
@Log()
def unRandomFileContent(self, fromPath, toPath):
"""""" """"""
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
@ -558,12 +497,12 @@ class Kirmah:
if i == size-1 and rest > 0 : if i == size-1 and rest > 0 :
piece = piece[:-rest] if lst[i]==0 else piece[rest:] piece = piece[:-rest] if lst[i]==0 else piece[rest:]
fo.write(piece[::-1]) fo.write(piece[::-1])
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Random mode', d, c) Sys.pstep('Random mode - inv', d, c)
@Log() @Log()
def mixdata(self, fromPath, toPath, encryptNoise=False, label='kirmah', cpart=22): def mixdata(self, fromPath, toPath, encryptNoise=False, label='kirmah', cpart=22, emit=True):
"""""" """"""
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
@ -585,7 +524,7 @@ class Kirmah:
fi.seek(psize*row[5]) fi.seek(psize*row[5])
fo.write(bdata[:row[2]] + fi.read(psize) + adata[:row[3]]) fo.write(bdata[:row[2]] + fi.read(psize) + adata[:row[3]])
cp += 1 cp += 1
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Mix mode', d, c) Sys.pstep('Mix mode', d, c)
@ -609,7 +548,7 @@ class Kirmah:
@Log() @Log()
def unmixdata(self, fromPath, toPath, label='kirmah', cpart=22): def unmixdata(self, fromPath, toPath, label='kirmah', cpart=22, emit=True):
"""""" """"""
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
@ -637,8 +576,8 @@ class Kirmah:
fo.write(dp[:rest]) fo.write(dp[:rest])
break break
fo.write(dp) fo.write(dp)
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Mix mode', d, c) Sys.pstep('Mix mode - inv', d, c)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@ -663,7 +602,7 @@ class Kirmah:
d = Sys.datetime.now() d = Sys.datetime.now()
theStr = {'name': hlst['head'][0], 'count': hlst['head'][1] } theStr = {'name': hlst['head'][0], 'count': hlst['head'][1] }
Io.set_data(self.DIR_DEPLOY+hlst['head'][2]+'.tmp', str(theStr)) Io.set_data(self.DIR_DEPLOY+hlst['head'][2]+'.tmp', str(theStr))
self.encrypt(self.DIR_DEPLOY+hlst['head'][2]+'.tmp', self.DIR_DEPLOY+hlst['head'][2]+'.kcf', nproc, KirmahHeader(self.VERSION, Io.bytes(self.mark), KirmahHeader.COMP_NONE, True, True)) self.encrypt(self.DIR_DEPLOY+hlst['head'][2]+'.tmp', self.DIR_DEPLOY+hlst['head'][2]+'.kcf', nproc, KirmahHeader(self.VERSION, Io.bytes(self.mark), KirmahHeader.COMP_NONE, True, True), False)
Sys.removeFile(self.DIR_DEPLOY+hlst['head'][2]+'.tmp') Sys.removeFile(self.DIR_DEPLOY+hlst['head'][2]+'.tmp')
if Sys.g.DEBUG : Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Encrypting Kirmah configuration file', d, True) Sys.pstep('Encrypting Kirmah configuration file', d, True)
@ -790,7 +729,20 @@ class Kirmah:
# # ENCRYPT # # # # ENCRYPT # #
@Log() @Log()
def encrypt_sp_start(self, fromPath, toPath, header=None): def mpMergeFiles(self,hlstPaths, toPath, noRemove=False, emit=True):
""""""
if not Sys.is_cli_cancel():
with Io.wfile(toPath) as fo:
for fromPath in hlstPaths :
with Io.rfile(fromPath) as fi :
fo.write(fi.read())
if not noRemove : Sys.removeFile(fromPath)
#~ if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
#~ Sys.pstep('Encrypt Data (multiprocessing)', d, c)
@Log()
def encrypt_sp_start(self, fromPath, toPath, header=None, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
if header is not None : if header is not None :
@ -803,41 +755,61 @@ class Kirmah:
self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2' self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2'
compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL
fp, tp = fromPath, self.tmpPath1 fp, tp = fromPath, self.tmpPath1
Sys.wlog(Sys.dprint()) if emit : Sys.cli_emit_progress(2)
d = Sys.datetime.now()
if compstart :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Compressing data') Sys.ptask('Compressing data')
self.compress_start(fp, tp, compstart) self.compress_start(fp, tp, compstart, emit=emit)
if compstart :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, True)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
if emit : Sys.cli_emit_progress(5)
return fp, tp, decHeader['rmode'], decHeader['mmode'], compend return fp, tp, decHeader['rmode'], decHeader['mmode'], compend
@Log() @Log()
def encrypt_sp_end(self, fp, tp, toPath, rmode, mmode, compend): def encrypt_sp_end(self, fp, tp, toPath, rmode, mmode, compend, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
if rmode : if rmode :
#~ self.mpRandomFileContent(fp, tp, 4) #~ self.mpRandomFileContent(fp, tp, 4)
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Randomizing data') Sys.ptask('Randomizing data')
self.randomFileContent(fp, tp) self.randomFileContent(fp, tp, emit=emit)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
if emit : Sys.cli_emit_progress(75)
if mmode : if mmode :
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Mixing data') Sys.ptask('Mixing data')
self.mixdata(fp, tp, True) self.mixdata(fp, tp, True, emit=emit)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
Sys.wlog(Sys.dprint()) if emit : Sys.cli_emit_progress(85)
if compend :
d = Sys.datetime.now()
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Compressing data') Sys.ptask('Compressing data')
self.compress_end(fp, toPath, compend) self.compress_end(fp, toPath, compend, emit=emit)
if emit : Sys.cli_emit_progress(95)
if compend :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, True)
# clean tmp files # clean tmp files
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Cleaning') Sys.ptask('Cleaning')
try : try :
Sys.removeFile(self.tmpPath1) Sys.removeFile(self.tmpPath1)
Sys.removeFile(self.tmpPath2) Sys.removeFile(self.tmpPath2)
except: except:
pass pass
if emit : Sys.cli_emit_progress(97)
@Log() @Log()
@ -859,49 +831,53 @@ class Kirmah:
@Log() @Log()
def mproc_encode_part(self, id, event=None): def mproc_encode_part(self, id, event=None, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
mpfile, mpfilenc = self.KMP_FILE+'_'+str(Sys.g.MAIN_PROC)+'_'+str(id), self.KMP_FILE+'enc_'+str(Sys.g.MAIN_PROC)+'_'+str(id) mpfile, mpfilenc = self.KMP_FILE+'_'+str(Sys.g.MAIN_PROC)+'_'+str(id), self.KMP_FILE+'enc_'+str(Sys.g.MAIN_PROC)+'_'+str(id)
self.encryptToFile(mpfile, mpfilenc, self.getSubStartIndice(id), event) self.encryptToFile(mpfile, mpfilenc, self.getSubStartIndice(id), event, emit=emit)
Sys.removeFile(mpfile) Sys.removeFile(mpfile)
@Log() @Log()
def encrypt_mproc(self, fp, tp, nproc=1): def encrypt_mproc(self, fp, tp, nproc=1, emit=True):
"""""" """"""
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Encrypting data') Sys.ptask('Encrypting data')
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
if c: if c:
if nproc == 1 : if nproc == 1 :
self.encryptToFile(fp, tp) self.encryptToFile(fp, tp)
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Encrypt data', d, c)
else : else :
hlstPaths = self.prepare_mproc_encode(fp, nproc) hlstPaths = self.prepare_mproc_encode(fp, nproc)
mg = Manager(self.mproc_encode_part, nproc, None, Sys.g.MPEVENT) mg = Manager(self.mproc_encode_part, nproc, None, Sys.g.MPEVENT)
mg.run() mg.run()
self.mpMergeFiles(hlstPaths, tp) self.mpMergeFiles(hlstPaths, tp, emit=emit)
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Encrypt data', d, c) Sys.pstep('Encrypt data (multiproc)', d, c)
if emit : Sys.cli_emit_progress(70)
@Log() @Log()
def encrypt(self, fromPath, toPath, nproc=1, header=None): def encrypt(self, fromPath, toPath, nproc=1, header=None, emit=True):
"""""" """"""
if emit : Sys.cli_emit_progress(0)
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
fp, tp, rmode, mmode, compend = self.encrypt_sp_start(fromPath, toPath, header) fp, tp, rmode, mmode, compend = self.encrypt_sp_start(fromPath, toPath, header, emit=True)
self.encrypt_mproc(fp, tp, nproc, emit=True)
self.encrypt_mproc(fp, tp, nproc)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
self.encrypt_sp_end(fp, tp, toPath, rmode, mmode, compend, emit=True)
self.encrypt_sp_end(fp, tp, toPath, rmode, mmode, compend) if emit : Sys.cli_emit_progress(100)
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # DECRYPT # # # # DECRYPT # #
@Log() @Log()
def decrypt_sp_start(self, fromPath, toPath): def decrypt_sp_start(self, fromPath, toPath, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
if Sys.getsize(fromPath) > 0 : if Sys.getsize(fromPath) > 0 :
@ -910,67 +886,101 @@ class Kirmah:
fsize = Sys.getsize(fromPath) fsize = Sys.getsize(fromPath)
fsize -= self.kh.POS_END fsize -= self.kh.POS_END
with Io.rfile(fromPath) as f : with Io.rfile(fromPath) as f :
d = Sys.datetime.now()
if emit : Sys.cli_emit_progress(1)
decHeader = self.kh.readHeader(f.read(self.kh.POS_END)) decHeader = self.kh.readHeader(f.read(self.kh.POS_END))
print(decHeader) if emit : Sys.cli_emit_progress(2)
#~ print(decHeader)
if len(decHeader) > 0 : if len(decHeader) > 0 :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
if decHeader['smode'] == self.mark[fsize%len(self.mark)] : if decHeader['smode'] == self.mark[fsize%len(self.mark)] :
Sys.pstep('Reading Header', d, True)
#~ print('ok valid') #~ print('ok valid')
"""""" """"""
else : raise BadKeyException() else :
Sys.pstep('Reading Header', d, False)
raise BadKeyException()
compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL
fp, tp = fromPath, self.tmpPath1 fp, tp = fromPath, self.tmpPath1
Sys.wlog(Sys.dprint()) if emit : Sys.cli_emit_progress(3)
if compend :
d = Sys.datetime.now()
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Uncompressing data') Sys.ptask('Uncompressing data')
self.uncompress_end(fp, tp, compend) self.uncompress_end(fp, tp, compend, emit=emit)
if emit : Sys.cli_emit_progress(10)
if compend :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, True)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
if decHeader['mmode'] : if decHeader['mmode'] :
Sys.wlog(Sys.dprint()) d = Sys.datetime.now()
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Sorting data') Sys.ptask('Sorting data')
self.unmixdata(fp, tp) self.unmixdata(fp, tp, emit=emit)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
if emit : Sys.cli_emit_progress(20)
if decHeader['rmode'] : if decHeader['rmode'] :
Sys.wlog(Sys.dprint()) d = Sys.datetime.now()
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Reordering data') Sys.ptask('Reordering data')
self.unRandomFileContent(fp, tp) self.unRandomFileContent(fp, tp, emit=emit)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1 fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
if emit : Sys.cli_emit_progress(25)
return fp, tp, compstart return fp, tp, compstart
@Log() @Log()
def decrypt_sp_end(self, fromPath, toPath, compstart): def decrypt_sp_end(self, fromPath, toPath, compstart, emit=True):
"""""" """"""
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
Sys.wlog(Sys.dprint()) d = Sys.datetime.now()
if emit : Sys.cli_emit_progress(80)
if compstart :
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Uncompressing data') Sys.ptask('Uncompressing data')
self.uncompress_start(fromPath, toPath, compstart) self.uncompress_start(fromPath, toPath, compstart, emit=emit)
Sys.wlog(Sys.dprint()) if emit : Sys.cli_emit_progress(90)
if compstart:
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Compression mode', d, True)
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Cleaning') Sys.ptask('Cleaning')
if emit : Sys.cli_emit_progress(95)
try : try :
Sys.removeFile(self.tmpPath1) Sys.removeFile(self.tmpPath1)
Sys.removeFile(self.tmpPath2) Sys.removeFile(self.tmpPath2)
except: except:
pass pass
if emit : Sys.cli_emit_progress(97)
@Log() @Log()
def decrypt_mproc(self, fromPath, toPath, nproc=1): def decrypt_mproc(self, fromPath, toPath, nproc=1, emit=True):
"""""" """"""
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.ptask('Decrypting data') Sys.ptask('Decrypting data')
d = Sys.datetime.now() d = Sys.datetime.now()
c = not Sys.is_cli_cancel() c = not Sys.is_cli_cancel()
if c: if c:
if emit : Sys.cli_emit_progress(30)
if nproc == 1 : if nproc == 1 :
self.decryptToFile(fromPath, toPath) self.decryptToFile(fromPath, toPath)
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Decrypt data', d, True)
else : else :
hlstPaths = self.prepare_mproc_decode(fromPath, nproc) hlstPaths = self.prepare_mproc_decode(fromPath, nproc)
mg = Manager(self.mproc_decode_part, nproc, None, Sys.g.MPEVENT) mg = Manager(self.mproc_decode_part, nproc, None, Sys.g.MPEVENT, emit=True)
mg.run() mg.run()
self.mpMergeFiles(hlstPaths, toPath) self.mpMergeFiles(hlstPaths, toPath, emit=emit)
Sys.wlog(Sys.dprint()) if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
Sys.pstep('Decrypt data', d, c) Sys.pstep('Decrypt data (multiproc)', d, True)
@Log() @Log()
@ -995,21 +1005,25 @@ class Kirmah:
@Log() @Log()
def mproc_decode_part(self, id, event=None): def mproc_decode_part(self, id, event=None, emit=True):
"""""" """"""
if emit : Sys.cli_emit_progress(-1)
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
mpfile, mpfiledec = self.KMP_FILE+'_'+str(Sys.g.MAIN_PROC)+'_'+str(id), self.KMP_FILE+'dec_'+str(Sys.g.MAIN_PROC)+'_'+str(id) mpfile, mpfiledec = self.KMP_FILE+'_'+str(Sys.g.MAIN_PROC)+'_'+str(id), self.KMP_FILE+'dec_'+str(Sys.g.MAIN_PROC)+'_'+str(id)
self.decryptToFile(mpfile, mpfiledec, self.getSubStartIndice(id), event) self.decryptToFile(mpfile, mpfiledec, self.getSubStartIndice(id), event, emit=emit)
Sys.removeFile(mpfile) Sys.removeFile(mpfile)
@Log() @Log()
def decrypt(self, fromPath, toPath, nproc=1): def decrypt(self, fromPath, toPath, nproc=1, emit=True):
"""""" """"""
Sys.cli_emit_progress(0)
if not Sys.is_cli_cancel(): if not Sys.is_cli_cancel():
fp, tp, compstart = self.decrypt_sp_start(fromPath, toPath) fp, tp, compstart = self.decrypt_sp_start(fromPath, toPath, emit=emit)
self.decrypt_mproc(fp, tp, nproc) self.decrypt_mproc(fp, tp, nproc, emit=emit)
self.decrypt_sp_end(tp, toPath, compstart) self.decrypt_sp_end(tp, toPath, compstart, emit=emit)
Sys.cli_emit_progress(100)
@Log(Const.LOG_DEBUG) @Log(Const.LOG_DEBUG)

View File

@ -359,7 +359,6 @@ class AppGui(Gui):
def on_proceed(self, btn): def on_proceed(self, btn):
"""""" """"""
if btn.get_label() == conf.GUI_LABEL_OK : if btn.get_label() == conf.GUI_LABEL_OK :
btn = self.get('button1')
btn.set_label(conf.GUI_LABEL_PROCEED) btn.set_label(conf.GUI_LABEL_PROCEED)
self.PROCEED = False self.PROCEED = False
self.pb.hide() self.pb.hide()
@ -367,10 +366,10 @@ class AppGui(Gui):
else : else :
if not self.PROCEED : if not self.PROCEED :
self.list_threads()
self.PROCEED = True self.PROCEED = True
self.STOPPED = False self.STOPPED = False
btn.set_sensitive(False) btn.set_sensitive(False)
self.on_new_file_dest(self.get('filechooserbutton3'))
self.pb = self.get('progressbar1') self.pb = self.get('progressbar1')
self.pb.set_fraction(0) self.pb.set_fraction(0)
self.pb.show() self.pb.show()
@ -406,7 +405,7 @@ class AppGui(Gui):
btn.set_label('Proceed') btn.set_label('Proceed')
btn.set_sensitive(True) btn.set_sensitive(True)
self.PROCEED = False self.PROCEED = False
btn.set_label(conf.GUI_LABEL_OK) if not abort : btn.set_label(conf.GUI_LABEL_OK)
self.get('checkbutton3').hide() self.get('checkbutton3').hide()
except Exception as e: except Exception as e:

View File

@ -243,6 +243,8 @@ class Gui():
if nf < progress/100.0 : if nf < progress/100.0 :
self.progressbar.set_fraction(nf) self.progressbar.set_fraction(nf)
self.progressbar.set_fraction(progress/100.0) self.progressbar.set_fraction(progress/100.0)
else :
self.progressbar.set_fraction(self.progressbar.get_fraction()+0.01)
@Log(Const.LOG_NEVER) @Log(Const.LOG_NEVER)

View File

@ -54,7 +54,7 @@ class TinyParser(OptionParser):
def error(self, errMsg, errData=None): def error(self, errMsg, errData=None):
"""""" """"""
self.print_usage('') self.print_usage('')
AbstractCli.error_cmd((errMsg,)) self.error_cmd((errMsg,))
@ -88,8 +88,9 @@ class AbstractCli():
if not Sys.isUnix : Const.LINE_SEP_CHAR = '-' if not Sys.isUnix : Const.LINE_SEP_CHAR = '-'
AbstractCli.conf = prgconf AbstractCli.conf = prgconf
self.parser = TinyParser() self.parser = TinyParser()
self.parser.print_help = AbstractCli.print_help self.parser.print_help = self.print_help
self.parser.print_usage = AbstractCli.print_usage self.parser.print_usage = self.print_usage
self.parser.error_cmd = self.error_cmd
self.parser.add_option('-v', '--version' , action='store_true', default=False) self.parser.add_option('-v', '--version' , action='store_true', default=False)
self.parser.add_option('-d', '--debug' , action='store_true', default=False) self.parser.add_option('-d', '--debug' , action='store_true', default=False)
@ -99,15 +100,13 @@ class AbstractCli():
self.parser.add_option('--no-color' , action='store_true' , default=False) self.parser.add_option('--no-color' , action='store_true' , default=False)
@staticmethod def error_cmd(self, data, pusage=False):
def error_cmd(data):
"""""" """"""
AbstractCli.print_usage('') if pusage : self.print_usage('')
Sys.dprint() Sys.dprint()
Sys.pwarn(data, True) Sys.pwarn(data, True)
AbstractCli.exit(1) AbstractCli.exit(1)
@staticmethod @staticmethod
def exit(code): def exit(code):
"""""" """"""
@ -197,8 +196,8 @@ class AbstractCli():
Sys.print(' '*50+'description option b' , Sys.CLZ_HELP_ARG_INFO) Sys.print(' '*50+'description option b' , Sys.CLZ_HELP_ARG_INFO)
@staticmethod
def print_usage(data, withoutHeader=False): def print_usage(self, data, withoutHeader=False):
"""""" """"""
if not withoutHeader : AbstractCli.print_header() if not withoutHeader : AbstractCli.print_header()

View File

@ -77,6 +77,7 @@ class Sys:
g.GUI = False g.GUI = False
g.GUI_PRINT_STDOUT = True g.GUI_PRINT_STDOUT = True
g.MPEVENT = Event() g.MPEVENT = Event()
g.LOG_QUEUE = None
@staticmethod @staticmethod