adding progress step + bugfix cli
This commit is contained in:
parent
0d67d7bbcb
commit
c367db484c
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
@ -84,21 +84,22 @@ class Cli(AbstractCli):
|
||||||
Sys.g.GUI = thread is not None
|
Sys.g.GUI = thread is not None
|
||||||
|
|
||||||
init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)
|
init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
|
|
@ -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)
|
||||||
|
|
310
kirmah/crypt.py
310
kirmah/crypt.py
|
@ -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,16 +497,16 @@ 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()
|
||||||
if c:
|
if c:
|
||||||
hlst = self.ck.getHashList(label, cpart, False)
|
hlst = self.ck.getHashList(label, cpart, False)
|
||||||
hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[0])
|
hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[0])
|
||||||
size = Sys.getsize(fromPath)
|
size = Sys.getsize(fromPath)
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -608,8 +547,8 @@ class Kirmah:
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
|
|
||||||
@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,12 +576,12 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
# # SPLIT # #
|
# # SPLIT # #
|
||||||
|
|
||||||
@Log()
|
@Log()
|
||||||
def splitFile(self, fromPath, hlst, nproc=1):
|
def splitFile(self, fromPath, hlst, nproc=1):
|
||||||
|
@ -660,10 +599,10 @@ class Kirmah:
|
||||||
@Log()
|
@Log()
|
||||||
def kcfEnc(self, hlst, nproc=1):
|
def kcfEnc(self, hlst, nproc=1):
|
||||||
if not Sys.is_cli_cancel():
|
if not Sys.is_cli_cancel():
|
||||||
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)
|
||||||
|
@ -671,7 +610,7 @@ class Kirmah:
|
||||||
return self.DIR_DEPLOY+hlst['head'][2]+'.kcf'
|
return self.DIR_DEPLOY+hlst['head'][2]+'.kcf'
|
||||||
|
|
||||||
|
|
||||||
@Log()
|
@Log()
|
||||||
def split(self, fromPath, hlst):
|
def split(self, fromPath, hlst):
|
||||||
""""""
|
""""""
|
||||||
if not Sys.is_cli_cancel():
|
if not Sys.is_cli_cancel():
|
||||||
|
@ -697,7 +636,7 @@ class Kirmah:
|
||||||
Sys.cli_emit_progress(perc)
|
Sys.cli_emit_progress(perc)
|
||||||
p += 1
|
p += 1
|
||||||
m.close()
|
m.close()
|
||||||
|
|
||||||
# ensure random order
|
# ensure random order
|
||||||
hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4])
|
hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4])
|
||||||
hlst['head'].append(psize)
|
hlst['head'].append(psize)
|
||||||
|
@ -717,7 +656,7 @@ class Kirmah:
|
||||||
|
|
||||||
|
|
||||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||||
# # MERGE # #
|
# # MERGE # #
|
||||||
|
|
||||||
@Log()
|
@Log()
|
||||||
def mergeFile(self, fromPath, toPath=None, uid=''):
|
def mergeFile(self, fromPath, toPath=None, uid=''):
|
||||||
|
@ -787,10 +726,23 @@ 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)
|
||||||
Sys.ptask('Compressing data')
|
d = Sys.datetime.now()
|
||||||
self.compress_start(fp, tp, compstart)
|
if compstart :
|
||||||
|
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
|
||||||
|
Sys.ptask('Compressing data')
|
||||||
|
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)
|
||||||
Sys.ptask('Compressing data')
|
|
||||||
self.compress_end(fp, toPath, compend)
|
if compend :
|
||||||
|
d = Sys.datetime.now()
|
||||||
|
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
|
||||||
|
Sys.ptask('Compressing data')
|
||||||
|
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)
|
||||||
Sys.ptask('Uncompressing data')
|
if compend :
|
||||||
self.uncompress_end(fp, tp, compend)
|
d = Sys.datetime.now()
|
||||||
|
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
|
||||||
|
Sys.ptask('Uncompressing data')
|
||||||
|
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()
|
||||||
Sys.ptask('Uncompressing data')
|
if emit : Sys.cli_emit_progress(80)
|
||||||
self.uncompress_start(fromPath, toPath, compstart)
|
if compstart :
|
||||||
Sys.wlog(Sys.dprint())
|
if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
|
||||||
|
Sys.ptask('Uncompressing data')
|
||||||
|
self.uncompress_start(fromPath, toPath, compstart, emit=emit)
|
||||||
|
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)
|
||||||
|
|
|
@ -101,27 +101,27 @@ class AppGui(Gui):
|
||||||
self.get('entry1').set_text(mark)
|
self.get('entry1').set_text(mark)
|
||||||
|
|
||||||
Sys.g.UI_AUTO_SCROLL = True
|
Sys.g.UI_AUTO_SCROLL = True
|
||||||
self.textview = self.get('textview1')
|
self.textview = self.get('textview1')
|
||||||
self.textview.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 1.0))
|
self.textview.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 1.0))
|
||||||
self.textview.modify_font(Pango.font_description_from_string ('DejaVu Sans Mono Book 11'))
|
self.textview.modify_font(Pango.font_description_from_string ('DejaVu Sans Mono Book 11'))
|
||||||
self.textbuffer = self.textview.get_buffer()
|
self.textbuffer = self.textview.get_buffer()
|
||||||
self.tags = self.buildTxtTags(self.textbuffer)
|
self.tags = self.buildTxtTags(self.textbuffer)
|
||||||
self.progressbar = self.get('progressbar1')
|
self.progressbar = self.get('progressbar1')
|
||||||
cbt = self.get('comboboxtext1')
|
cbt = self.get('comboboxtext1')
|
||||||
cbt.connect("changed", self.on_compression_changed)
|
cbt.connect("changed", self.on_compression_changed)
|
||||||
tree_iter = cbt.get_model().get_iter_first()
|
tree_iter = cbt.get_model().get_iter_first()
|
||||||
print(cbt.get_model().get_string_from_iter(tree_iter))
|
print(cbt.get_model().get_string_from_iter(tree_iter))
|
||||||
tree_iter = cbt.get_model().get_iter_from_string('3')
|
tree_iter = cbt.get_model().get_iter_from_string('3')
|
||||||
cbt.set_active_iter(tree_iter)
|
cbt.set_active_iter(tree_iter)
|
||||||
cbt = self.get('comboboxtext2')
|
cbt = self.get('comboboxtext2')
|
||||||
cbt.connect("changed", self.on_logging_changed)
|
cbt.connect("changed", self.on_logging_changed)
|
||||||
tree_iter = cbt.get_model().get_iter_first()
|
tree_iter = cbt.get_model().get_iter_first()
|
||||||
tree_iter = cbt.get_model().get_iter_from_string('4')
|
tree_iter = cbt.get_model().get_iter_from_string('4')
|
||||||
cbt.set_active_iter(tree_iter)
|
cbt.set_active_iter(tree_iter)
|
||||||
Sys.clear()
|
Sys.clear()
|
||||||
Sys.dprint('INIT UI')
|
Sys.dprint('INIT UI')
|
||||||
self.start = True
|
self.start = True
|
||||||
self.thkmh = None
|
self.thkmh = None
|
||||||
|
|
||||||
|
|
||||||
@Log(Const.LOG_UI)
|
@Log(Const.LOG_UI)
|
||||||
|
@ -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()
|
||||||
|
@ -388,7 +387,7 @@ class AppGui(Gui):
|
||||||
|
|
||||||
|
|
||||||
@Log(Const.LOG_UI)
|
@Log(Const.LOG_UI)
|
||||||
def halt_thread(self, *args):
|
def halt_thread(self, *args):
|
||||||
Sys.wlog(Sys.dprint())
|
Sys.wlog(Sys.dprint())
|
||||||
Sys.pwarn(('thread interrupt',), False)
|
Sys.pwarn(('thread interrupt',), False)
|
||||||
self.get('button1').set_sensitive(False)
|
self.get('button1').set_sensitive(False)
|
||||||
|
@ -404,11 +403,11 @@ class AppGui(Gui):
|
||||||
try :
|
try :
|
||||||
btn = self.get('button1')
|
btn = self.get('button1')
|
||||||
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:
|
||||||
Sys.pwarn((('on_proceed_end : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), False)
|
Sys.pwarn((('on_proceed_end : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), False)
|
||||||
pass
|
pass
|
||||||
|
|
14
kirmah/ui.py
14
kirmah/ui.py
|
@ -56,7 +56,7 @@ class Gui():
|
||||||
threads_init()
|
threads_init()
|
||||||
self.wname = wname
|
self.wname = wname
|
||||||
self.builder = Builder()
|
self.builder = Builder()
|
||||||
self.builder.add_from_file(conf.PRG_GLADE_PATH)
|
self.builder.add_from_file(conf.PRG_GLADE_PATH)
|
||||||
self.builder.connect_signals(self)
|
self.builder.connect_signals(self)
|
||||||
self.win = self.get(wname)
|
self.win = self.get(wname)
|
||||||
self.win.connect('destroy', self.onDeleteWindow)
|
self.win.connect('destroy', self.onDeleteWindow)
|
||||||
|
@ -222,7 +222,7 @@ class Gui():
|
||||||
self.textbuffer.insert_at_cursor(item[0])
|
self.textbuffer.insert_at_cursor(item[0])
|
||||||
ei = self.textbuffer.get_end_iter()
|
ei = self.textbuffer.get_end_iter()
|
||||||
oi = self.textbuffer.get_iter_at_offset(offs)
|
oi = self.textbuffer.get_iter_at_offset(offs)
|
||||||
tagName = item[1]
|
tagName = item[1]
|
||||||
self.textbuffer.apply_tag(self.tags[tagName], oi, ei)
|
self.textbuffer.apply_tag(self.tags[tagName], oi, ei)
|
||||||
self.textbuffer.insert_at_cursor('\n')
|
self.textbuffer.insert_at_cursor('\n')
|
||||||
self.scroll_end()
|
self.scroll_end()
|
||||||
|
@ -230,11 +230,11 @@ class Gui():
|
||||||
Sys.dprint('STOP')
|
Sys.dprint('STOP')
|
||||||
thread.cancel()
|
thread.cancel()
|
||||||
self.update_progress(progress)
|
self.update_progress(progress)
|
||||||
|
|
||||||
|
|
||||||
@Log(Const.LOG_NEVER)
|
@Log(Const.LOG_NEVER)
|
||||||
def update_progress(self, progress, lvl=50):
|
def update_progress(self, progress, lvl=50):
|
||||||
if progress > 0 :
|
if progress > 0 :
|
||||||
self.progressbar.set_text(str(progress))
|
self.progressbar.set_text(str(progress))
|
||||||
lp = self.progressbar.get_fraction()
|
lp = self.progressbar.get_fraction()
|
||||||
diff = (progress/100.0 - lp)
|
diff = (progress/100.0 - lp)
|
||||||
|
@ -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)
|
||||||
|
@ -355,11 +357,11 @@ class CliThread(Thread, IdleObject):
|
||||||
def stop(self):
|
def stop(self):
|
||||||
""""""
|
""""""
|
||||||
if self.isAlive():
|
if self.isAlive():
|
||||||
self.cancel()
|
self.cancel()
|
||||||
if current_thread() .getName()==self.getName():
|
if current_thread() .getName()==self.getName():
|
||||||
try:
|
try:
|
||||||
self.emit("interrupted")
|
self.emit("interrupted")
|
||||||
Sys.thread_exit()
|
Sys.thread_exit()
|
||||||
except RuntimeError as e :
|
except RuntimeError as e :
|
||||||
print(str(self.getName()) + ' COULD NOT BE TERMINATED')
|
print(str(self.getName()) + ' COULD NOT BE TERMINATED')
|
||||||
raise e
|
raise e
|
||||||
|
|
17
psr/cli.py
17
psr/cli.py
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user