diff --git a/CHANGELOG b/CHANGELOG
new file mode 100644
index 0000000..f1ad00a
--- /dev/null
+++ b/CHANGELOG
@@ -0,0 +1,12 @@
+Kirmah 2.17 (2013-05-06)
+=========================
+
+New General Features
+-------------------------
+
+ *
+
+Bugfixes
+-------------------------
+
+ * [#] --
diff --git a/README b/README
new file mode 100644
index 0000000..05436c3
--- /dev/null
+++ b/README
@@ -0,0 +1,27 @@
+Kirmah 2.17 (2013-05-06)
+=========================
+
+Install on Archlinux
+-------------------------
+sudo pacman -U http://sourceforge.net/projects/kirmah/files/packages/archlinux/kirmah-2.17-1-any.pkg.tar.xz/download
+
+
+(re)build instruction
+-------------------------
+mkdir /tmp/kirmah; cd /tmp/kirmah;
+wget http://sourceforge.net/projects/kirmah/files/packages/archlinux/PKGBUILD/download
+mv download PKGBUILD
+wget http://sourceforge.net/projects/kirmah/files/packages/archlinux/kirmah.install/download
+mv download kirmah.install
+makepkg -s;
+
+
+Install on other distrib
+-------------------------
+install pkg depends (look at archlinux PKGBUILD file wich provide usefull informations)
+
+simply untar archive, then launch :
+$ python ./kirmah/kirmah.py
+$ python ./kirmah/kirmah-cli.py
+
+you can also use python2 disutils and setup.py
diff --git a/kirmah-cli.py b/kirmah-cli.py
index df78211..905da4c 100644
--- a/kirmah-cli.py
+++ b/kirmah-cli.py
@@ -1,34 +1,44 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah-cli.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-from psr.sys import init, Sys
-from kirmah.cli import Cli
-from kirmah import conf
+from psr.sys import Sys, Const
+from kirmah.cli import Cli
-init(conf.PRG_NAME, False)
-Cli('.'+Sys.sep)
+def main():
+ try:
+ c = 0
+ Cli('.'+Sys.sep)
+ except Exception as e :
+ Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
+ c = 1
+ return c
+
+if __name__ == '__main__':
+ Sys.exit(main())
diff --git a/kirmah.py b/kirmah.py
new file mode 100644
index 0000000..5265d1b
--- /dev/null
+++ b/kirmah.py
@@ -0,0 +1,44 @@
+# !/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# kirmah.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+from psr.sys import Sys, Const
+from kirmah.gui import AppGui
+
+def main():
+ try:
+ c = 0
+ AppGui()
+ except Exception as e:
+ Sys.pwarn((('main : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
+ c = 1
+ return c
+
+if __name__ == '__main__':
+ Sys.exit(main())
diff --git a/kirmah/app.py b/kirmah/app.py
new file mode 100644
index 0000000..83fa253
--- /dev/null
+++ b/kirmah/app.py
@@ -0,0 +1,203 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah.app.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module app ~~
+
+from os.path import splitext
+from threading import Thread, Timer, Event, get_ident, enumerate as thread_enum, current_thread
+from kirmah import conf
+from kirmah.crypt import KeyGen, Kirmah, KirmahHeader
+from psr.sys import Sys, Io, Const, init
+from psr.log import Log
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class KirmahApp ~~
+
+class KirmahApp:
+
+ @Log(Const.LOG_BUILD)
+ def __init__(self, debug=True, color=True, loglvl=Const.LOG_DEFAULT):
+ """"""
+ self.encmode = conf.DEFVAL_ENCMODE
+ self.splitmode = False
+ self.compression = conf.DEFVAL_COMP
+ self.mix = conf.DEFVAL_MIXMODE
+ self.random = conf.DEFVAL_RANDOMMODE
+ self.nproc = conf.DEFVAL_NPROC
+ self.src = None
+ self.dst = None
+ self.kpath = None
+ Sys.g.GUI = True
+ init(conf.PRG_NAME, debug, Sys.getpid(), color, loglvl)
+
+
+ @Log(Const.LOG_DEBUG)
+ def getDefaultKeyPath(self):
+ """"""
+ return conf.DEFVAL_UKEY_PATH+conf.DEFVAL_UKEY_NAME
+
+
+ @Log(Const.LOG_DEBUG)
+ def createDefaultKeyIfNone(self):
+ """"""
+ kpath = self.getDefaultKeyPath()
+ if not Io.file_exists(kpath):
+ if Sys.isUnix() :
+ if not Sys.isdir(conf.DEFVAL_UKEY_PATH) :
+ Sys.mkdir_p(conf.DEFVAL_UKEY_PATH)
+ Io.set_data(kpath, KeyGen(conf.DEFVAL_UKEY_LENGHT).key)
+ self.selectKey(kpath)
+
+
+ @Log(Const.LOG_DEBUG)
+ def createNewKey(self, filename, size):
+ """"""
+ if not Sys.isdir(Sys.dirname(filename)):
+ Sys.mkdir_p(Sys.dirname(filename))
+ Io.set_data(filename,KeyGen(size).key[:size])
+
+
+ @Log(Const.LOG_DEBUG)
+ def getKeyInfos(self, filename=None):
+ """"""
+ if filename is None : filename = self.getDefaultKeyPath()
+ if not Io.file_exists(filename):
+ raise FileNotFoundException(filename)
+ k = Io.get_data(filename)
+ s = len(k)
+ m = KeyGen(s).getMark(k)
+ return k, s, m
+
+
+ @Log(Const.LOG_DEBUG)
+ def selectKey(self, filename):
+ """"""
+ if not Io.file_exists(filename):
+ raise FileNotFoundException(filename)
+ self.kpath = filename
+
+
+ @Log(Const.LOG_DEBUG)
+ def setCompression(self, value=1):
+ """"""
+ self.compression = value
+
+
+ @Log(Const.LOG_DEBUG)
+ def setMixMode(self, enable=True):
+ """"""
+ self.mix = enable
+
+
+ @Log(Const.LOG_DEBUG)
+ def setRandomMode(self, enable=True):
+ """"""
+ self.random = enable
+
+
+ @Log(Const.LOG_DEBUG)
+ def setMultiprocessing(self, nproc):
+ """"""
+ # disable
+ if nproc is None or nproc is False or nproc < conf.DEFVAL_NPROC_MIN :
+ self.nproc = 0
+ # enable
+ else :
+ self.nproc = nproc if nproc <= conf.DEFVAL_NPROC_MAX else conf.DEFVAL_NPROC_MAX
+
+
+ @Log(Const.LOG_DEBUG)
+ def switchEncMode(self, isEnc=True):
+ """"""
+ self.encmode = isEnc
+
+
+ @Log(Const.LOG_DEBUG)
+ def switchFormatMode(self, isTxt=True):
+ self.splitmode = not isTxt
+
+
+ @Log(Const.LOG_DEBUG)
+ def setSourceFile(self, filename):
+ """"""
+ if not Io.file_exists(filename) :
+ raise FileNotFoundException()
+ else :
+ self.src = filename
+
+
+ @Log(Const.LOG_DEBUG)
+ def hasSrcFile(self):
+ """"""
+ return Io.file_exists(self.src)
+
+
+ @Log(Const.LOG_DEBUG)
+ def setDestFile(self, path):
+ """"""
+ if path is not None :
+ self.dst = ''.join([path, Sys.sep, '' if self.src is None else Sys.basename(self.src)])
+ if self.encmode:
+ self.dst = ''.join([self.dst, conf.DEFVAL_CRYPT_EXT])
+ else :
+ self.dst, ext = Sys.getFileExt(self.dst)
+ if Io.file_exists(self.dst):
+ raise FileNeedOverwriteException(self.dst)
+ else : self.dst = None
+
+
+ @Log(Const.LOG_DEFAULT)
+ def getCall(self):
+ action = ('enc' if self.encmode else 'dec') if not self.splitmode else ('split' if self.encmode else 'merge')
+ comp = '-a' if self.compression==1 else ('-z' if self.compression==2 else '-Z')
+ mproc = '' if self.nproc==0 or self.splitmode else '-j'+str(self.nproc)
+ rmode = '-r' if self.random else '-R '
+ mmode = '-m' if self.mix else '-M'
+ debug = '-fd' if Sys.g.DEBUG else '-f'
+ #~ q = '"'
+ q = ''
+ call = ['kirmah-cli.py',debug, action,q+self.src+q,comp,mproc,rmode,mmode,'-o',q+self.dst+q]
+ print('python '+(' '.join(call)))
+ return call
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class FileNotFoundException ~~
+
+class FileNotFoundException(BaseException):
+ """"""
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class FileNeedOverwriteException ~~
+
+class FileNeedOverwriteException(BaseException):
+ """"""
diff --git a/kirmah/cli.py b/kirmah/cli.py
index 0b9f6ba..96fa2a3 100755
--- a/kirmah/cli.py
+++ b/kirmah/cli.py
@@ -1,111 +1,121 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah.cli.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# ~~ package cli ~~
-
+# ~~ module cli ~~
+
from optparse import OptionParser, OptionGroup
import kirmah.conf as conf
from kirmah.cliapp import CliApp
-from psr.sys import Sys
-from psr.io import Io
+from psr.sys import Sys, Io, Const, init
+from psr.log import Log
-
-LINE_SEP_LEN = 120
-LINE_SEP_CHAR = '―'
-if not Sys.isUnix : LINE_SEP_CHAR = '-'
+if not Sys.isUnix : Const.LINE_SEP_CHAR = '-'
def printLineSep(sep,lenSep):
""""""
- Sys.print(sep*lenSep, Sys.Clz.fgN0)
+ s = sep*lenSep
+ Sys.print(s, Sys.CLZ_HEAD_LINE)
+ return [(s, Const.CLZ_HEAD_SEP)]
+
+
def printHeaderTitle(title):
""""""
- Sys.print(' == '+title+' == ', Sys.Clz.BG4+Sys.Clz.fgB7, False, True)
+ s = ' == '+title+' == '
+ Sys.print(s, Sys.CLZ_HEAD_APP, False, True)
+ return [(s, Const.CLZ_HEAD_APP)]
+
def printHeaderPart(label,value):
""""""
- Sys.print(' [' , Sys.Clz.fgB0, False)
- Sys.print(label, Sys.Clz.fgB3, False)
- Sys.print(':' , Sys.Clz.fgB0, False)
- Sys.print(value, Sys.Clz.fgB4, False)
- Sys.print('] ' , Sys.Clz.fgB0, False)
-
+ a, b, c = ' [',':' ,'] '
+ Sys.print(a , Sys.CLZ_HEAD_SEP, False)
+ Sys.print(label, Sys.CLZ_HEAD_KEY, False)
+ Sys.print(b , Sys.CLZ_HEAD_SEP, False)
+ Sys.print(value, Sys.CLZ_HEAD_VAL, False)
+ Sys.print(c , Sys.CLZ_HEAD_SEP, False)
+ return [(a,Const.CLZ_HEAD_SEP),(label,Const.CLZ_HEAD_KEY),(b,Const.CLZ_HEAD_SEP),(value,Const.CLZ_HEAD_VAL),(c,Const.CLZ_HEAD_SEP)]
class _OptionParser(OptionParser):
"""A simplified OptionParser"""
-
+
def format_description(self, formatter):
return self.description
+
def format_epilog(self, formatter):
return self.epilog
-
+
+
def error(self, errMsg, errData=None):
-
self.print_usage('')
Cli.error_cmd(self, (errMsg,))
- #~ Sys.exit(1)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Cli ~~
class Cli:
-
- def __init__(self,path):
+
+ def __init__(self, path, remote=False, rwargs=None, thread=None, loglvl=Const.LOG_DEFAULT):
""""""
-
- self.HOME = Sys.sep+'home'+Sys.sep+Sys.getUserLogin()+Sys.sep
+ if thread is not None :
+ Sys.g.THREAD_CLI = thread
+ Sys.g.GUI = True
+ else :
+ Sys.g.GUI = False
+
+
+ self.HOME = conf.DEFVAL_USER_PATH
self.DIRKEY = self.HOME+'.'+conf.PRG_NAME.lower()+Sys.sep
if not Sys.isUnix() :
CHQ = '"'
self.HOME = 'C:'+Sys.sep+conf.PRG_NAME.lower()+Sys.sep
self.DIRKEY = self.HOME+'keys'+Sys.sep
- Sys.mkdir_p(self.DIRKEY)
-
- #~ self.ini = util.IniFile(path+'impra.ini')
+ Sys.mkdir_p(self.DIRKEY)
+
parser = _OptionParser()
parser.print_help = self.print_help
parser.print_usage = self.print_usage
gpData = OptionGroup(parser, '')
- # metavar=' ', nargs=2
parser.add_option('-v', '--version' , action='store_true', default=False)
parser.add_option('-d', '--debug' , action='store_true', default=False)
parser.add_option('-f', '--force' , action='store_true', default=False)
parser.add_option('-q', '--quiet' , action='store_true', default=False)
-
+
parser.add_option('--no-color' , action='store_true' , default=False)
-
+
gpData.add_option('-a', '--fullcompress' , action='store_true' )
gpData.add_option('-z', '--compress' , action='store_true' )
gpData.add_option('-Z', '--nocompress' , action='store_true' )
@@ -120,10 +130,16 @@ class Cli:
gpData.add_option('-o', '--outputfile' , action='store')
parser.add_option_group(gpData)
+ # rewrite argv sended by remote
+ if rwargs is not None :
+ import sys
+ sys.argv = rwargs
+
(o, a) = parser.parse_args()
-
- Sys.g.COLOR_MODE = not o.no_color
- Sys.g.DEBUG = o.debug and not o.quiet
+
+ Sys.g.QUIET = o.quiet
+
+ init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)
if not a:
@@ -136,34 +152,44 @@ class Cli:
except :
self.error_cmd(('no command specified',))
- else:
-
+ else:
+
if a[0] == 'help':
Sys.clear()
parser.print_help()
elif a[0] in ['key','enc','dec','split','merge'] :
- app = CliApp(self.HOME, path, self, a, o)
+ app = CliApp(self.HOME, path, self, a, o)
- if a[0]=='key' :
+ if a[0]=='key' :
app.onCommandKey()
else :
- if not len(a)>1 :
- self.error_cmd((('an ',('inputFile',Sys.Clz.fgb3),' is required !'),))
- elif not Io.file_exists(a[1]):
- self.error_cmd((('the file ',(a[1], Sys.Clz.fgb3), ' doesn\'t exists !'),))
+ if not len(a)>1 :
+ self.error_cmd((('an ',('inputFile',Sys.Clz.fgb3),' is required !'),))
+ elif not Io.file_exists(a[1]):
+ self.error_cmd((('the file ',(a[1], Sys.Clz.fgb3), ' doesn\'t exists !'),))
elif a[0]=='enc' : app.onCommandEnc()
elif a[0]=='dec' : app.onCommandDec()
elif a[0]=='split': app.onCommandSplit()
elif a[0]=='merge': app.onCommandMerge()
+
+ Sys.dprint('PUT END SIGNAL')
+ if Sys.g.LOG_QUEUE is not None :
+ Sys.g.LOG_QUEUE.put(Sys.g.SIGNAL_STOP)
+
else :
self.error_cmd((('unknow command ',(a[0],Sys.Clz.fgb3)),))
if not o.quiet : Sys.dprint()
+ def clean(self):
+ """"""
+ print('cleaning')
+
+
def error_cmd(self, data):
""""""
self.print_usage('')
@@ -178,16 +204,19 @@ class Cli:
def print_header(self):
- """"""
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- printHeaderTitle(conf.PRG_CLI_NAME)
- printHeaderPart('version' ,conf.PRG_VERS)
- printHeaderPart('author' ,conf.PRG_AUTHOR)
- printHeaderPart('license' ,conf.PRG_LICENSE)
- printHeaderPart('copyright',conf.PRG_COPY)
+ """"""
+ a = printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ b = printHeaderTitle(conf.PRG_CLI_NAME)
+ c = printHeaderPart('version' ,conf.PRG_VERS)
+ d = printHeaderPart('author' ,conf.PRG_AUTHOR)
+ e = printHeaderPart('license' ,conf.PRG_LICENSE)
+ f = printHeaderPart('copyright',conf.PRG_COPY)
Sys.print(' ', Sys.Clz.OFF)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- Sys.dprint()
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ Sys.wlog(a)
+ Sys.wlog(b + c + d + e + f )
+ Sys.wlog(a)
+ Sys.wlog(Sys.dprint())
def print_version(self, data):
@@ -198,326 +227,325 @@ class Cli:
def print_usage(self, data, withoutHeader=False):
""""""
if not withoutHeader : self.print_header()
-
- Sys.print(' USAGE :\n' , Sys.Clz.fgB3)
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('help ' , Sys.Clz.fgB3)
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('key ' , Sys.Clz.fgB3, False)
- Sys.print('[ -l ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('length' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('outputFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(']' , Sys.Clz.fgB3)
+ Sys.print(' USAGE :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('help ' , Sys.CLZ_HELP_CMD)
+
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('key ' , Sys.CLZ_HELP_CMD, False)
+ Sys.print('[ -l ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('length' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('outputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(']' , Sys.CLZ_HELP_ARG)
+
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('enc ' , Sys.CLZ_HELP_CMD, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('inputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('} ' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('[' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(' -z|Z|a -r|R -m|M -j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('numProcess' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('keyFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('outputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(']' , Sys.CLZ_HELP_ARG)
+
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('dec ' , Sys.CLZ_HELP_CMD, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('inputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('} ' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('[' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(' -j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('numProcess' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('keyFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('outputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(']' , Sys.CLZ_HELP_ARG)
+
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('split ' , Sys.CLZ_HELP_CMD, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('inputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('} ' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('[' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(' -p ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('numParts' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('keyFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('tarOutputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(']' , Sys.CLZ_HELP_ARG)
+
+ Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.CLZ_HELP_PRG, False)
+ Sys.print('merge ' , Sys.CLZ_HELP_CMD, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('inputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('} ' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('[' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('keyFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('{' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('outputFile' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print('}' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(']' , Sys.CLZ_HELP_ARG)
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('enc ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('inputFile' , Sys.Clz.fgB1, False)
- Sys.print('} ' , Sys.Clz.fgB1, False)
- Sys.print('[' , Sys.Clz.fgB3, False)
- Sys.print(' -z|Z|a -r|R -m|M -j ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('numProcess' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('keyFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('outputFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(']' , Sys.Clz.fgB3)
-
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('dec ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('inputFile' , Sys.Clz.fgB1, False)
- Sys.print('} ' , Sys.Clz.fgB1, False)
- Sys.print('[' , Sys.Clz.fgB3, False)
- Sys.print(' -j ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('numProcess' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('keyFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('outputFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(']' , Sys.Clz.fgB3)
-
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('split ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('inputFile' , Sys.Clz.fgB1, False)
- Sys.print('} ' , Sys.Clz.fgB1, False)
- Sys.print('[' , Sys.Clz.fgB3, False)
- Sys.print(' -p ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('numParts' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('keyFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('tarOutputFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(']' , Sys.Clz.fgB3)
-
- Sys.print(' '+conf.PRG_CLI_NAME+' ' , Sys.Clz.fgb7, False)
- Sys.print('merge ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('inputFile' , Sys.Clz.fgB1, False)
- Sys.print('} ' , Sys.Clz.fgB1, False)
- Sys.print('[' , Sys.Clz.fgB3, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('keyFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('{' , Sys.Clz.fgB1, False)
- Sys.print('outputFile' , Sys.Clz.fgB1, False)
- Sys.print('}' , Sys.Clz.fgB1, False)
- Sys.print(']' , Sys.Clz.fgB3)
-
def print_options(self):
""""""
Sys.dprint('\n')
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+
+ Sys.print(' MAIN OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-v'.ljust(13,' ')+', --version' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'display programm version' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-d'.ljust(13,' ')+', --debug' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'enable debug mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-f'.ljust(13,' ')+', --force' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'force rewriting existing files without alert' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-q'.ljust(13,' ')+', --quiet' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'don\'t print status messages to stdout' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-h'.ljust(13,' ')+', --help' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'display help' , Sys.CLZ_HELP_ARG_INFO)
- Sys.print(' MAIN OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-v'.ljust(13,' ')+', --version' , Sys.Clz.fgB3)
- Sys.print(' '*50+'display programm version' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-d'.ljust(13,' ')+', --debug' , Sys.Clz.fgB3)
- Sys.print(' '*50+'enable debug mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-f'.ljust(13,' ')+', --force' , Sys.Clz.fgB3)
- Sys.print(' '*50+'force rewriting existing files without alert' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-q'.ljust(13,' ')+', --quiet' , Sys.Clz.fgB3)
- Sys.print(' '*50+'don\'t print status messages to stdout' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-h'.ljust(13,' ')+', --help' , Sys.Clz.fgB3)
- Sys.print(' '*50+'display help' , Sys.Clz.fgB7)
-
Sys.dprint('\n')
- Sys.print(' KEY OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-l ' , Sys.Clz.fgB3, False)
- Sys.print('LENGTH'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --length'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('LENGTH'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified key length (128 to 4096 - default:1024)' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-o ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --outputfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified key output filename' , Sys.Clz.fgB7)
-
- Sys.dprint('\n')
- Sys.print(' ENCRYPT OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-a'.ljust(13,' ')+', --fullcompress' , Sys.Clz.fgB3)
- Sys.print(' '*50+'enable full compression mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-z'.ljust(13,' ')+', --compress' , Sys.Clz.fgB3)
- Sys.print(' '*50+'enable compression mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-Z'.ljust(13,' ')+', --nocompress' , Sys.Clz.fgB3)
- Sys.print(' '*50+'disable compression mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-r'.ljust(13,' ')+', --random' , Sys.Clz.fgB3)
- Sys.print(' '*50+'enable random mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-R'.ljust(13,' ')+', --norandom' , Sys.Clz.fgB3)
- Sys.print(' '*50+'disable random mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-m'.ljust(13,' ')+', --mix' , Sys.Clz.fgB3)
- Sys.print(' '*50+'enable mix mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-M'.ljust(13,' ')+', --nomix' , Sys.Clz.fgB3)
- Sys.print(' '*50+'disable mix mode' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-j ' , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --multiprocess'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'number of process for encryption (2 to 8)' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-k ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --keyfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'key filename used to encrypt' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-o ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --outputfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified encrypted output filename' , Sys.Clz.fgB7)
-
- Sys.dprint('\n')
- Sys.print(' DECRYPT OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-j ' , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --multiprocess'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'number of process for decryption (2 to 8)' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-k ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --keyfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'key filename used to decrypt' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-o ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --outputfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified decrypted output filename' , Sys.Clz.fgB7)
+ Sys.print(' KEY OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-l ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('LENGTH'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --length'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('LENGTH'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified key length (128 to 4096 - default:1024)' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --outputfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified key output filename' , Sys.CLZ_HELP_ARG_INFO)
- Sys.dprint('\n')
- Sys.print(' SPLIT OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-p ' , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --part'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('COUNT'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'count part to split' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-k ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --keyfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'key filename used to split' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-o ' , Sys.Clz.fgB3, False)
- Sys.print('TARFILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --outputfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('TARFILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified tar output filename' , Sys.Clz.fgB7)
+ Sys.dprint('\n')
+ Sys.print(' ENCRYPT OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-a'.ljust(13,' ')+', --fullcompress' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'enable full compression mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-z'.ljust(13,' ')+', --compress' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'enable compression mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-Z'.ljust(13,' ')+', --nocompress' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'disable compression mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-r'.ljust(13,' ')+', --random' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'enable random mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-R'.ljust(13,' ')+', --norandom' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'disable random mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-m'.ljust(13,' ')+', --mix' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'enable mix mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-M'.ljust(13,' ')+', --nomix' , Sys.CLZ_HELP_ARG)
+ Sys.print(' '*50+'disable mix mode' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --multiprocess'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'number of process for encryption (2 to 8)' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --keyfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'key filename used to encrypt' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --outputfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified encrypted output filename' , Sys.CLZ_HELP_ARG_INFO)
- Sys.dprint('\n')
- Sys.print(' MERGE OPTIONS :\n' , Sys.Clz.fgB3)
- Sys.print(' '*4+'-k ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --keyfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'key filename used to merge' , Sys.Clz.fgB7)
- Sys.print(' '*4+'-o ' , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1, False)
- Sys.print(', --outputfile'.ljust(18,' ') , Sys.Clz.fgB3, False)
- Sys.print('FILE'.ljust(10,' ') , Sys.Clz.fgB1)
- Sys.print(' '*50+'specified decrypted output filename' , Sys.Clz.fgB7)
-
- Sys.dprint('\n')
+ Sys.dprint('\n')
+ Sys.print(' DECRYPT OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --multiprocess'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'number of process for decryption (2 to 8)' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --keyfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'key filename used to decrypt' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --outputfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified decrypted output filename' , Sys.CLZ_HELP_ARG_INFO)
+
+ Sys.dprint('\n')
+ Sys.print(' SPLIT OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-p ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --part'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('COUNT'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'count part to split' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --keyfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'key filename used to split' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('TARFILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --outputfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('TARFILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified tar output filename' , Sys.CLZ_HELP_ARG_INFO)
+
+ Sys.dprint('\n')
+ Sys.print(' MERGE OPTIONS :\n' , Sys.CLZ_HELP_CMD)
+ Sys.print(' '*4+'-k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --keyfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'key filename used to merge' , Sys.CLZ_HELP_ARG_INFO)
+ Sys.print(' '*4+'-o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(', --outputfile'.ljust(18,' ') , Sys.CLZ_HELP_ARG, False)
+ Sys.print('FILE'.ljust(10,' ') , Sys.CLZ_HELP_PARAM)
+ Sys.print(' '*50+'specified decrypted output filename' , Sys.CLZ_HELP_ARG_INFO)
+
+ Sys.dprint('\n')
def print_help(self):
""""""
-
self.print_header()
- Sys.print(conf.PRG_DESC, Sys.Clz.fgN1)
+ Sys.print(conf.PRG_DESC, Sys.CLZ_HELP_DESC)
self.print_usage('',True)
self.print_options()
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
Sys.dprint()
- Sys.print(' EXEMPLES :\n', Sys.Clz.fgB3)
+ Sys.print(' EXEMPLES :\n', Sys.CLZ_HELP_CMD)
CHQ = "'"
-
- Sys.print(' '*4+'command key :', Sys.Clz.fgB3)
-
- Sys.print(' '*8+'# generate a new crypted key of 2048 length', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('key -l ', Sys.Clz.fgB3, False)
- Sys.print('2048 ', Sys.Clz.fgB1)
- Sys.print(' '*8+'# generate a new crypted key (default length is 1024) in a specified location', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('key -o ', Sys.Clz.fgB3, False)
- Sys.print(self.DIRKEY+'.myNewKey', Sys.Clz.fgB1)
+ Sys.print(' '*4+'command key :', Sys.CLZ_HELP_CMD)
+
+ Sys.print(' '*8+'# generate a new crypted key of 2048 length', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('key -l ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('2048 ', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# generate a new crypted key (default length is 1024) in a specified location', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('key -o ', Sys.CLZ_HELP_CMD, False)
+ Sys.print(self.DIRKEY+'.myNewKey', Sys.CLZ_HELP_PARAM)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- Sys.print('\n'+' '*4+'command encrypt :', Sys.Clz.fgB3)
-
- Sys.print(' '*8+'# encrypt specified file with default crypted key and default options', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('enc ', Sys.Clz.fgB3, False)
- Sys.print(self.HOME+'mySecretTextFile.txt', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# encrypt specified file with specified crypted key (full compression, no random but mix mode)', Sys.Clz.fgn7)
- Sys.print(' '*8+'# on specified output location', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('enc ', Sys.Clz.fgB3, False)
- Sys.print('mySecretTextFile.txt', Sys.Clz.fgB1, False)
- Sys.print(' -aRm -k ' , Sys.Clz.fgB3, False)
- Sys.print(self.DIRKEY+'.myNewKey', Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('test.kmh', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# encrypt specified file with default crypted key (no compression but random & mix mode and multiprocessing)', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('enc ', Sys.Clz.fgB3, False)
- Sys.print('myBigTextFile.txt', Sys.Clz.fgB1, False)
- Sys.print(' -Zrm -j ' , Sys.Clz.fgB3, False)
- Sys.print('4', Sys.Clz.fgB1)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ Sys.print('\n'+' '*4+'command encrypt :', Sys.CLZ_HELP_CMD)
+
+ Sys.print(' '*8+'# encrypt specified file with default crypted key and default options', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('enc ', Sys.CLZ_HELP_CMD, False)
+ Sys.print(self.HOME+'mySecretTextFile.txt', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# encrypt specified file with specified crypted key (full compression, no random but mix mode)', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+'# on specified output location', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('enc ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('mySecretTextFile.txt', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -aRm -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(self.DIRKEY+'.myNewKey', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('test.kmh', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# encrypt specified file with default crypted key (no compression but random & mix mode and multiprocessing)', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('enc ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('myBigTextFile.txt', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -Zrm -j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('4', Sys.CLZ_HELP_PARAM)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- Sys.print('\n'+' '*4+'command decrypt :', Sys.Clz.fgB3)
-
- Sys.print(' '*8+'# decrypt specified file with default crypted key', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('dec ', Sys.Clz.fgB3, False)
- Sys.print(self.HOME+'mySecretFile.kmh', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# decrypt specified file with specified crypted key on specified output location', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('dec ', Sys.Clz.fgB3, False)
- Sys.print('myEncryptedSecretFile.kmh', Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print(self.HOME+'.kirmah'+Sys.sep+'.myNewKey', Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('myDecryptedSecretFile.txt', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# decrypt specified file with default crypted key and multiprocessing', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('dec ', Sys.Clz.fgB3, False)
- Sys.print('myEncryptedSecretFile.kmh', Sys.Clz.fgB1, False)
- Sys.print(' -j ' , Sys.Clz.fgB3, False)
- Sys.print('4' , Sys.Clz.fgB1)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ Sys.print('\n'+' '*4+'command decrypt :', Sys.CLZ_HELP_CMD)
+
+ Sys.print(' '*8+'# decrypt specified file with default crypted key', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('dec ', Sys.CLZ_HELP_CMD, False)
+ Sys.print(self.HOME+'mySecretFile.kmh', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# decrypt specified file with specified crypted key on specified output location', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('dec ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('myEncryptedSecretFile.kmh', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(self.HOME+'.kirmah'+Sys.sep+'.myNewKey', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('myDecryptedSecretFile.txt', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# decrypt specified file with default crypted key and multiprocessing', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('dec ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('myEncryptedSecretFile.kmh', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -j ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('4' , Sys.CLZ_HELP_PARAM)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- Sys.print('\n'+' '*4+'command split :', Sys.Clz.fgB3)
-
- Sys.print(' '*8+'# split specified file with default crypted key', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('split ', Sys.Clz.fgB3, False)
- Sys.print(self.HOME+'myBigBinaryFile.avi', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# split specified file on 55 parts with specified crypted key on specified output location', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('split ', Sys.Clz.fgB3, False)
- Sys.print('myBigBinaryFile.avi', Sys.Clz.fgB1, False)
- Sys.print(' -p ' , Sys.Clz.fgB3, False)
- Sys.print('55' , Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print(self.DIRKEY+'.myNewKey', Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('myBigBinaryFile.encrypted', Sys.Clz.fgB1)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ Sys.print('\n'+' '*4+'command split :', Sys.CLZ_HELP_CMD)
+
+ Sys.print(' '*8+'# split specified file with default crypted key', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('split ', Sys.CLZ_HELP_CMD, False)
+ Sys.print(self.HOME+'myBigBinaryFile.avi', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# split specified file on 55 parts with specified crypted key on specified output location', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('split ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('myBigBinaryFile.avi', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -p ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('55' , Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(self.DIRKEY+'.myNewKey', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('myBigBinaryFile.encrypted', Sys.CLZ_HELP_PARAM)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
- Sys.print('\n'+' '*4+'command merge :', Sys.Clz.fgB3)
-
- Sys.print(' '*8+'# merge specified splitted file with default crypted key', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('merge ', Sys.Clz.fgB3, False)
- Sys.print(self.HOME+'6136bd1b53d84ecbad5380594eea7256176c19e0266c723ea2e982f8ca49922b.kcf', Sys.Clz.fgB1)
-
- Sys.print(' '*8+'# merge specified tark splitted file with specified crypted key on specified output location', Sys.Clz.fgn7)
- Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.Clz.fgB7, False)
- Sys.print('merge ', Sys.Clz.fgB3, False)
- Sys.print('myBigBinaryFile.encrypted.tark', Sys.Clz.fgB1, False)
- Sys.print(' -k ' , Sys.Clz.fgB3, False)
- Sys.print(self.DIRKEY+'.myNewKey', Sys.Clz.fgB1, False)
- Sys.print(' -o ' , Sys.Clz.fgB3, False)
- Sys.print('myBigBinaryFile.decrypted.avi', Sys.Clz.fgB1)
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
+ Sys.print('\n'+' '*4+'command merge :', Sys.CLZ_HELP_CMD)
- printLineSep(LINE_SEP_CHAR,LINE_SEP_LEN)
+ Sys.print(' '*8+'# merge specified splitted file with default crypted key', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('merge ', Sys.CLZ_HELP_CMD, False)
+ Sys.print(self.HOME+'6136bd1b53d84ecbad5380594eea7256176c19e0266c723ea2e982f8ca49922b.kcf', Sys.CLZ_HELP_PARAM)
+
+ Sys.print(' '*8+'# merge specified tark splitted file with specified crypted key on specified output location', Sys.CLZ_HELP_COMMENT)
+ Sys.print(' '*8+conf.PRG_CLI_NAME+' ', Sys.CLZ_HELP_PRG, False)
+ Sys.print('merge ', Sys.CLZ_HELP_CMD, False)
+ Sys.print('myBigBinaryFile.encrypted.tark', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -k ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print(self.DIRKEY+'.myNewKey', Sys.CLZ_HELP_PARAM, False)
+ Sys.print(' -o ' , Sys.CLZ_HELP_ARG, False)
+ Sys.print('myBigBinaryFile.decrypted.avi', Sys.CLZ_HELP_PARAM)
+
+ printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
Sys.dprint()
diff --git a/kirmah/cliapp.py b/kirmah/cliapp.py
index 9a6f01d..5875882 100755
--- a/kirmah/cliapp.py
+++ b/kirmah/cliapp.py
@@ -1,297 +1,318 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah/cliapp.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# ~~ package cliapp ~~
+# ~~ module cliapp ~~
import kirmah.conf as conf
from kirmah.crypt import KirmahHeader, Kirmah, BadKeyException, represents_int, KeyGen
-from kirmah.kctrl import KCtrl
-from psr.sys import Sys
-from psr.io import Io
+from psr.sys import Sys, Const, Io
+from psr.log import Log
+import tarfile
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class CliApp ~~
class CliApp:
-
+
+ @Log(Const.LOG_BUILD)
def __init__(self, home, path, parser, a, o):
""""""
self.parser = parser
self.a = a
self.o = o
self.home = home
- self.stime = Sys.datetime.now()
- if not self.o.keyfile :
+ self.stime = Sys.datetime.now()
+ if not self.o.keyfile :
self.o.keyfile = self.home+'.kirmah'+Sys.sep+'.default.key'
+ @Log(Const.LOG_DEBUG)
def onCommandKey(self):
""""""
if int(self.o.length) >= 128 and int(self.o.length) <= 4096 :
- self.parser.print_header()
+ self.parser.print_header()
if not self.o.outputfile : self.o.outputfile = self.home+'.kirmah'+Sys.sep+'.default.key'
kg = KeyGen(int(self.o.length))
done = True
if Io.file_exists(self.o.outputfile) and not self.o.force :
-
+
Sys.pwarn((('the key file ',(self.o.outputfile, Sys.Clz.fgb3), ' already exists !'),
- 'if you rewrite this file, all previous files encrypted with the corresponding key will be unrecoverable !'))
-
+ 'if you rewrite this file, all previous files encrypted with the corresponding key will be unrecoverable !'))
+
done = Sys.pask('Are you sure to rewrite this file')
- self.stime = Sys.datetime.now()
+ self.stime = Sys.datetime.now()
if done :
Io.set_data(self.o.outputfile, kg.key)
Sys.pstep('Generate key file', self.stime, done)
- if done :
+ if done :
Sys.print(' '*5+Sys.realpath(self.o.outputfile), Sys.Clz.fgB1, True)
-
+
else :
self.parser.error_cmd((('invalid option ',('-l, --length', Sys.Clz.fgb3), ' value (', ('128',Sys.Clz.fgb3),' to ', ('4096',Sys.Clz.fgb3),')'),))
-
+
+ @Log(Const.LOG_DEBUG)
def onCommandEnc(self):
""""""
done = True
- if self.o.outputfile is None :
- self.o.outputfile = Sys.basename(self.a[1])+Kirmah.EXT
+ if self.o.outputfile is None :
+ self.o.outputfile = Sys.basename(self.a[1])
+ if self.o.outputfile[-len(Kirmah.EXT):] != Kirmah.EXT :
+ print(self.o.outputfile[-len(Kirmah.EXT):])
+ self.o.outputfile += Kirmah.EXT
+ print(self.o.outputfile)
- d = self.getDefaultOption((self.o.compress,self.o.fullcompress,self.o.nocompress))
- compress = (KirmahHeader.COMP_END if d == 0 or (d is None and Io.is_binary(self.a[1])) else (KirmahHeader.COMP_ALL if d==1 or d is None else KirmahHeader.COMP_NONE))
- random = True if (self.o.random is None and self.o.norandom is None) or self.o.random else False
+ d = self.getDefaultOption((self.o.compress,self.o.fullcompress,self.o.nocompress))
+ compress = (KirmahHeader.COMP_END if d == 0 or (d is None and Io.is_binary(self.a[1])) else (KirmahHeader.COMP_ALL if d==1 or d is None else KirmahHeader.COMP_NONE))
+ random = True if (self.o.random is None and self.o.norandom is None) or self.o.random else False
mix = True if (self.o.mix is None and self.o.nomix is None) or self.o.mix else False
if (self.o.multiprocess is not None and not represents_int(self.o.multiprocess)) or (not self.o.multiprocess is None and not(int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8)) :
self.parser.error_cmd((('invalid option ',('-j, --multiprocess', Sys.Clz.fgb3), ' value (', ('2',Sys.Clz.fgb3),' to ', ('8',Sys.Clz.fgb3),')'),))
- nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1
+ nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1
+
+ if not Sys.g.QUIET : self.parser.print_header()
- if not self.o.quiet : self.parser.print_header()
-
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()
-
+ self.stime = Sys.datetime.now()
+
if done :
-
+
try :
- if not self.o.quiet and not Sys.g.DEBUG : Sys.print(' Processing, please wait...\n', Sys.Clz.fgB2)
-
+ Sys.ptask()
+
key = Io.get_data(self.o.keyfile)
km = Kirmah(key, None, compress, random, mix)
-
- if nproc > 1 :
- from gi.repository.Gdk import threads_enter, threads_leave
- from gi.repository.GLib import threads_init
- from gi.repository.Gtk import main as gtk_main, main_quit as gtk_quit
-
- threads_init()
- threads_enter()
- kctrl = KCtrl(nproc, None)
- kctrl.encrypt(self.a[1], self.o.outputfile, km, None, self.onend_mproc)
- gtk_main()
- threads_leave()
- else :
- km.encrypt(self.a[1],self.o.outputfile)
+ km.encrypt(self.a[1], self.o.outputfile, nproc)
except Exception as e :
done = False
print(e)
pass
- if not self.o.quiet :
+ if not Sys.g.QUIET :
self.onend_cmd('Encrypting file', self.stime, done, self.o.outputfile)
+ @Log(Const.LOG_DEBUG)
def onCommandDec(self):
""""""
done = True
- if self.o.outputfile is None :
+ if self.o.outputfile is None :
self.o.outputfile = self.a[1][:-4] if self.a[1][-4:] == Kirmah.EXT else self.a[1]
-
- if not self.o.quiet : self.parser.print_header()
-
+
+ if not Sys.g.QUIET : self.parser.print_header()
+
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()
-
+ self.stime = Sys.datetime.now()
+
if done :
-
+
try :
-
+
if (self.o.multiprocess is not None and not represents_int(self.o.multiprocess)) or (not self.o.multiprocess is None and not(int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8)) :
self.parser.error_cmd((('invalid option ',('-j, --multiprocess', Sys.Clz.fgb3), ' value (', ('2',Sys.Clz.fgb3),' to ', ('8',Sys.Clz.fgb3),')'),))
nproc = int(self.o.multiprocess) if not self.o.multiprocess is None and int(self.o.multiprocess)>=2 and int(self.o.multiprocess) <=8 else 1
-
- if not self.o.quiet and not Sys.g.DEBUG : Sys.print(' Processing, please wait...\n', Sys.Clz.fgB2)
-
+
+ Sys.ptask()
+
key = Io.get_data(self.o.keyfile)
km = Kirmah(key)
-
- if nproc > 1 :
- from gi.repository.Gdk import threads_enter, threads_leave
- from gi.repository.GLib import threads_init
- from gi.repository.Gtk import main as gtk_main, main_quit as gtk_quit
-
- threads_init()
- threads_enter()
- kctrl = KCtrl(nproc, None)
- kctrl.decrypt(self.a[1], self.o.outputfile, km, self.onend_mproc)
- gtk_main()
- threads_leave()
- else :
- km.decrypt(self.a[1],self.o.outputfile)
-
+ km.decrypt(self.a[1], self.o.outputfile, nproc)
+
except BadKeyException as e :
done = False
Sys.pwarn(('BadKeyException',))
- if Sys.g.DEBUG :
+ if Sys.g.DEBUG :
raise e
-
- if not self.o.quiet :
+
+ if not Sys.g.QUIET :
self.onend_cmd('Decrypting file', self.stime, done, self.o.outputfile)
-
+ @Log(Const.LOG_DEBUG)
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.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 self.o.quiet : self.parser.print_header()
+
+ 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 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 :
-
+
+ if done :
+
try :
- if not self.o.quiet and not Sys.g.DEBUG : Sys.print(' Processing, please wait...\n', Sys.Clz.fgB2)
-
+ 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']:
- Io.touch(row[1]+km.EXT,times)
-
+ p += frav
+ Io.touch(row[1]+km.EXT,times)
+ Sys.cli_emit_progress(p)
if self.o.outputfile is not None :
- import tarfile
+ 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)
- Io.removeFile(kcf)
- for row in hlst['data']:
- tar.add(row[1]+km.EXT)
- Io.removeFile(row[1]+km.EXT)
+ 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 :
- raise e
- elif not self.o.quiet :
- Sys.pwarn((str(e),))
+ if Sys.g.DEBUG :
+ print('split exception')
+ print(e)
+
+ #~ raise e
+ elif not Sys.g.QUIET :
+ Sys.pwarn((str(e),))
- if not self.o.quiet :
- self.onend_cmd('Splitting file', self.stime, done, self.o.outputfile)
+ if not Sys.g.QUIET:
+ Sys.cli_emit_progress(100)
+ self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)
+
+ @Log(Const.LOG_DEBUG)
def onCommandMerge(self):
""""""
done = True
- if not self.o.quiet : self.parser.print_header()
+ if not Sys.g.QUIET : self.parser.print_header()
if done :
+ toPath = None
try :
- if not self.o.quiet and not Sys.g.DEBUG : Sys.print(' Processing, please wait...\n', Sys.Clz.fgB2)
+ Sys.ptask()
+
key = Io.get_data(self.o.keyfile)
km = Kirmah(key)
-
+
try:
import tarfile
with tarfile.open(self.a[1], mode='r') as tar:
- path = Sys.dirname(self.o.outputfile) if self.o.outputfile is not None else '.'
- tar.extractall(path=path)
+ dpath = Sys.dirname(Sys.realpath(self.o.outputfile))+Sys.sep if self.o.outputfile is not None else '.'+Sys.sep
+ print(dpath)
+ tar.extractall(path=dpath)
+ kcf = None
for tarinfo in tar:
+ print(tarinfo.name)
if tarinfo.isreg() and tarinfo.name[-4:]=='.kcf':
- toPath = km.mergeFile(path+Sys.sep+tarinfo.name)
- except :
- pass
+ kcf = dpath+tarinfo.name
+ if kcf is not None :
+ toPath = km.mergeFile(kcf)
+ except Exception as e:
+ Sys.pwarn((('onCommandMerge : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), False)
+ raise e
toPath = km.mergeFile(self.a[1])
+ if self.o.outputfile is not None :
+ Io.rename(toPath, self.o.outputfile)
+ toPath = self.o.outputfile
except Exception as e :
done = False
- if Sys.g.DEBUG :
+ if Sys.g.DEBUG :
+ print(e)
raise e
- elif not self.o.quiet :
- Sys.pwarn((str(e),))
+ elif not Sys.g.QUIET :
+ Sys.pwarn((str(e),))
- if not self.o.quiet :
+ if not Sys.g.QUIET :
self.onend_cmd('Merging file', self.stime, done, toPath)
- def onend_mproc(self, tstart, done):
- """"""
- from gi.repository.Gtk import main_quit as gtk_quit
- gtk_quit()
-
-
- def getDefaultOption(self, args):
+ @Log(Const.LOG_ALL)
+ def getDefaultOption(self, args):
""""""
c = None
for i, a in enumerate(args) :
- if a :
- c = i
+ if a :
+ c = i
break
- return c
+ return c
-
+
+ @Log(Const.LOG_DEBUG)
def onend_cmd(self, title, stime, done, outputfile):
- """"""
- if Sys.g.DEBUG : Sys.dprint()
- Sys.pstep(title, stime, done)
- if done :
+ """"""
+ s = Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN
+ Sys.print(s, Sys.CLZ_HEAD_LINE)
+ Sys.wlog([(s, Const.CLZ_HEAD_SEP)])
+ Sys.pstep(title, stime, done, True)
+ Sys.print(s, Sys.CLZ_HEAD_LINE)
+ Sys.wlog([(s, Const.CLZ_HEAD_SEP)])
+ if done and outputfile is not None:
Sys.print(' '*5+Sys.realpath(outputfile), Sys.Clz.fgB1, False)
- Sys.print(' ('+Sys.getFileSize(outputfile)+')', Sys.Clz.fgB3)
+ Sys.print(' ('+Sys.getFileSize(outputfile)+')', Sys.Clz.fgB3)
+ bdata = [(' '*5+Sys.realpath(outputfile), 'io'),(' ('+Sys.getFileSize(outputfile)+')','func')]
+ Sys.wlog(bdata)
+ Sys.wlog(Sys.dprint())
diff --git a/kirmah/conf.py b/kirmah/conf.py
index 27d8118..8d086e9 100755
--- a/kirmah/conf.py
+++ b/kirmah/conf.py
@@ -1,70 +1,85 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah/conf.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ module conf ~~
-from getpass import getuser as getUserLogin
+from getpass import getuser as getUserLogin
+from os import sep
+from os.path import dirname, realpath
PRG_NAME = 'Kirmah'
-PRG_CLI_NAME = 'kirmah-cli'
+PRG_PACKAGE = PRG_NAME.lower()
+PRG_SCRIPT = PRG_NAME.lower()
+PRG_CLI_NAME = PRG_SCRIPT+'-cli'
PRG_VERS = '2.1'
PRG_AUTHOR = 'a-Sansara'
-PRG_COPY = 'pluie.org 2013'
+PRG_COPY = 'pluie.org'
+PRG_YEAR = '2013'
PRG_WEBSITE = 'http://kirmah.sourceforge.net'
PRG_LICENSE = 'GNU GPL v3'
-PRG_LICENSE_PATH = 'gpl.txt'
-PRG_LOGO_PATH = 'kirmah.png'
-PRG_LOGO_ICON_PATH = 'kirmah_ico.png'
+PRG_RESOURCES_PATH = '/usr/share/pixmaps/'+PRG_PACKAGE+'/'
+try:
+ with open(PRG_RESOURCES_PATH) as f:
+ pass
+except IOError as e:
+ PRG_RESOURCES_PATH = dirname(dirname(realpath(__file__)))+sep+'resources'+sep
+ pass
+print(PRG_RESOURCES_PATH)
+PRG_GLADE_PATH = PRG_RESOURCES_PATH+PRG_PACKAGE+sep+'glade'+sep+PRG_PACKAGE+'.glade'
+PRG_LICENSE_PATH = PRG_RESOURCES_PATH+PRG_PACKAGE+'/LICENSE'
+PRG_LOGO_PATH = PRG_RESOURCES_PATH+'pixmaps'+sep+PRG_PACKAGE+sep+PRG_PACKAGE+'.png'
+PRG_LOGO_ICON_PATH = PRG_RESOURCES_PATH+'pixmaps'+sep+PRG_PACKAGE+sep+PRG_PACKAGE+'_ico.png'
PRG_ABOUT_LOGO_SIZE = 160
-PRG_ABOUT_COPYRIGHT = '(c) '+PRG_AUTHOR+' - '+PRG_COPY+' 2013'
+PRG_ABOUT_COPYRIGHT = '(c) '+PRG_AUTHOR+' - '+PRG_COPY+' '+PRG_YEAR
PRG_ABOUT_COMMENTS = ''.join(['Kirmah simply encrypt/decrypt files','\n', 'license ',PRG_LICENSE])
PRG_DESC = """
Encryption with symmetric-key algorithm Kirmah.
-
+
three modes are available to encrypt :
-
+
- compression (full / disabled or only final step)
- random (simulate a random order - based on crypted key - to randomize data)
- mix (mix data according to a generated map - based on crypted key - with addition of noise)
-
-
+
+
Process is as follow :
-
+
for encryption :
- file > [ compression > ] encryption > [randomiz data > mix data > compression > ] file.kmh
-
+ file > [ compression > ] encryption > [randomiz data > mix data > compression > ] file.kmh
+
default options depends on file type (binary or text).
- binary files are compressed only at the end of process
- text files have a full compression mode
- random and mix modes are enabled on all files
-
+
for decryption :
file.kmh > [ uncompression > unmix data > unrandomiz data] > decryption > [uncompression > ] file
@@ -81,7 +96,6 @@ PRG_DESC = """
the merge command is the opposite process.
"""
-PRG_GLADE_PATH = 'kirmah.glade'
DEFVAL_NPROC = 2
@@ -89,9 +103,10 @@ DEFVAL_NPROC_MAX = 8
DEFVAL_NPROC_MIN = 2
DEFVAL_COMP = False
DEFVAL_ENCMODE = True
-DEFVAL_MIXDATA = False
-DEFVAL_USER_PATH = ''.join(['/home/', getUserLogin(), '/'])
-DEFVAL_UKEY_PATH = ''.join([DEFVAL_USER_PATH, '.', PRG_NAME.lower(), '/'])
+DEFVAL_MIXMODE = True
+DEFVAL_RANDOMMODE = True
+DEFVAL_USER_PATH = ''.join([sep,'home',sep,getUserLogin(),sep])
+DEFVAL_UKEY_PATH = ''.join([DEFVAL_USER_PATH, '.', PRG_PACKAGE,sep])
DEFVAL_UKEY_NAME = '.default.key'
DEFVAL_UKEY_LENGHT = 1024
DEFVAL_CRYPT_EXT = '.kmh'
@@ -99,3 +114,14 @@ DEFVAL_CRYPT_EXT = '.kmh'
DEBUG = True
UI_TRACE = True
PCOLOR = True
+
+GUI_LABEL_PROCEED = 'Proceed'
+GUI_LABEL_OK = 'OK'
+GUI_LABEL_CANCEL = 'Cancel'
+
+def redefinePaths(path):
+
+ PRG_GLADE_PATH = path+PRG_PACKAGE+sep+'glade'+sep+PRG_PACKAGE+'.glade'
+ PRG_LICENSE_PATH = path+PRG_PACKAGE+sep+'LICENSE'
+ PRG_LOGO_PATH = path+'pixmaps'+sep+PRG_PACKAGE+sep+PRG_PACKAGE+'.png'
+ PRG_LOGO_ICON_PATH = path+'pixmaps'+sep+PRG_PACKAGE+sep+PRG_PACKAGE+'_ico.png'
diff --git a/kirmah/crypt.py b/kirmah/crypt.py
index 3d3866b..9ff31f3 100755
--- a/kirmah/crypt.py
+++ b/kirmah/crypt.py
@@ -1,31 +1,32 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah/crypt.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ module crypt ~~
@@ -39,31 +40,38 @@ from os import urandom
from re import sub
from mmap import mmap
from ast import literal_eval
-from psr.sys import Sys
-from psr.io import Io
-from psr.decorate import log
+from psr.sys import Sys, Io, Const
+from psr.log import Log
+from psr.mproc import Manager
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ methods ~~
+@Log(Const.LOG_ALL)
def hash_sha256(data):
"""Get a sha256 hash of str `data`
:Returns: `str`
"""
return str(sha256(bytes(data,'utf-8')).hexdigest())
+
+@Log(Const.LOG_ALL)
def hash_sha256_file(path):
"""Get a sha256 hash of str `data`
:Returns: `str`
"""
return sha256(open(path, mode='rb').read()).hexdigest()
-@log
+
+
+@Log()
def hash_md5_file(path):
"""Get a md5 hash of file from path
:Returns: `str`
"""
return md5(open(path, mode='rb').read()).hexdigest()
+
+@Log(Const.LOG_ALL)
def randomFrom(val, sval=0):
"""Get a random number from range `sval=0` to `val`
:Returns: `int`
@@ -71,16 +79,19 @@ def randomFrom(val, sval=0):
lst = list(range(sval,val))
return choice(lst)
+
+@Log(Const.LOG_NEVER)
def represents_int(s):
""""""
- try:
+ try:
if s is None : return False
int(s)
return True
except ValueError:
return False
-@log
+
+@Log(Const.LOG_DEBUG)
def getRandomListFromKey(key, size):
""""""
j, ok, lk, r, ho, hr, lv, hv, rev = 0, False, len(key), None, [], [], 0, size-1, False
@@ -102,12 +113,16 @@ def getRandomListFromKey(key, size):
rev = not rev
return getSimulRandomList(ho, getSimulNumber(key, size//5 if not size//5==0 else size*2, size//10 if not size//10 ==0 else size))
+
+@Log(Const.LOG_ALL)
def getSimulRandomList(lst, chsize):
""""""
return _getSimulRandomList(list(reversed(_getSimulRandomList(_getSimulRandomList(lst, chsize), 4))),4)
+
+@Log(Const.LOG_PRIVATE)
def _getSimulRandomList(lst, chsize):
- """"""
+ """"""
size, rlst, pos = len(lst), [], 0
if chsize > 0 :
for i in range(chsize+1):
@@ -116,8 +131,10 @@ def _getSimulRandomList(lst, chsize):
if pos in lst and not lst[pos] in rlst:
rlst.append(lst[pos])
else : rlst = lst
- return rlst
+ return rlst
+
+@Log(Const.LOG_DEBUG)
def getSimulNumber(key, lim, delta=12):
""""""
s = 0
@@ -132,18 +149,21 @@ def getSimulNumber(key, lim, delta=12):
# ~~ class KeyGen ~~
class KeyGen :
- """"""
+
CHSET = [33, 35, 36, 37, 38, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 880, 881, 882, 883, 884, 885, 886, 887, 891, 892, 893, 894, 901, 902, 903, 904, 905, 906, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 3871, 3872, 3873, 3874, 3875, 3876, 3877, 3878, 3879, 3880, 3881, 3882, 3883, 3884, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3894, 3895, 2349, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361, 2362, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, 2377, 2378, 2379, 2380, 2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, 2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, 2422, 2423, 4305, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 4348, 4352, 4353, 4354, 4355, 4356, 4357, 4358, 4359, 4360, 4361, 4362, 4363, 4364, 4365, 4366, 4367, 4368, 4369, 4370, 4371, 4372, 4373, 4374, 4375, 4376, 4377, 4378, 4379, 4380, 4381, 4382, 4383, 4384, 4385, 4386, 4387, 4388, 4389, 4390, 4391, 4392, 4393, 4394, 4395, 4396, 4397, 4398, 4399, 4400, 4401, 4402, 4403, 4404, 4405, 4406, 4407, 4408, 4409, 4410, 4411, 4412, 4413, 4414, 4415, 4416, 4417, 4418, 4419, 4420, 4421, 4422, 4423, 4424, 4425, 4426, 4427, 4428, 4429, 4430, 4431, 4432, 4433, 4434, 4435, 4436, 4437, 4438, 4439, 4440, 4441, 4640, 4641, 4642, 4643, 4644, 4645, 4646, 4647, 4648, 4649, 4650, 4651, 4652, 4653, 4654, 4655, 4656, 4657, 4658, 4659, 4660, 4661, 4662, 4663, 4664, 4665, 4666, 4667, 4668, 4669, 4670, 4671, 4672, 4673, 4674, 4675, 4676, 4677, 4678, 4705, 4706, 4707, 4708, 4709, 4710, 4711, 4712, 4713, 4714, 4715, 4716, 4717, 4718, 4719, 4720, 4721, 4722, 4723, 4724, 4725, 4726, 4727, 4728, 4729, 4730, 4731, 4732, 4733, 4734, 4735, 4736, 4737, 4738, 4739, 4740, 4741, 4742, 4753, 4754, 4755, 4756, 4757, 4758, 4759, 4760, 4761, 4762, 4763, 4764, 4765, 4766, 4767, 4768, 4769, 4770, 4771, 4772, 4773, 4774, 4775, 4776, 4777, 4778, 4779, 4780, 4781, 4782, 4825, 4826, 4827, 4828, 4829, 4830, 4831, 4832, 4833, 4834, 4835, 4836, 4837, 4838, 4839, 4840, 4841, 4842, 4843, 4844, 4845, 4846, 4847, 4848, 4849, 4850, 4851, 4852, 4853, 4854, 4855, 4856, 4857, 4858, 4859, 4860, 4861, 4862, 4863, 4864, 4865, 4866, 4867, 4868] #, 4869, 4870, 4871, 4872, 4873, 4874, 4875, 4876, 4877, 4878, 5025, 5026, 5027, 5028, 5029, 5030, 5031, 5032, 5033, 5034, 5035, 5036, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051, 5052, 5053, 5054, 5055, 5056, 5057, 5058, 5059, 5060, 5061, 5062, 5063, 5064, 5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5075, 5076, 5077, 5078, 5079, 5080, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5099, 5100, 5101, 5102, 5103, 5104, 5105, 5106, 5107, 5196, 5197, 5198, 5199, 5200, 5201, 5202, 5203, 5204, 5205, 5206, 5207, 5208, 5209, 5210, 5211, 5212, 5213, 5214, 5215, 5216, 5217, 5218, 5219, 5220, 5221, 5222, 5223, 5224, 5225, 5226, 5227, 5228, 5229, 5230, 5231, 5232, 5233, 5234, 5235, 5236, 5237, 5238, 5239, 5240, 5241, 5242, 5243, 5244, 5245, 5246, 5247, 5248, 5249, 5250, 5251, 5252, 5253, 5254, 5255, 5256, 5257, 5258, 5259, 5260, 5261, 5262, 5263, 5264, 5265, 5266, 5267, 5268, 5269, 5270, 5271, 5272, 5273, 5274, 5275, 5276, 5277, 5278, 5279, 5280, 5281, 5282, 5283, 5284, 5285, 5286, 5287, 5288, 5289, 5290, 5291, 5292, 5293, 5294, 5295, 5296, 5297, 5298, 5299, 5300, 5301, 5302, 5303, 5304, 5305, 5306, 5307, 5308, 5309, 5310, 5311, 5312, 5313, 5314, 5315, 5316, 5317, 5318, 5319, 5320, 5321, 5322, 5323, 5324, 5325, 5326, 5327, 5328, 5329, 5330, 5331, 5332, 5333, 5334, 5335, 5336, 5337, 5338, 5339, 5340, 5341, 5342, 5343, 5344, 5345, 5346, 5347, 5348, 5349, 5350, 5351, 5352, 5353, 5354, 5355, 5356, 5357, 5358, 5359, 5360, 5361, 5362, 5363, 5364, 5365, 5366, 5367, 5368, 5369, 5370, 5371, 5372, 5373, 5374, 5375, 5376, 5377, 5378, 5379, 5380, 5381, 5382, 5383, 5384, 5385, 5386, 5387, 5388, 5389, 5390, 5391, 5392, 5393, 5394, 5395, 5396, 5397, 5398, 5399, 5400, 5401, 5402, 5403, 5404, 5405, 5406, 5407, 5408, 5409, 5410, 5411, 5412, 5413, 5414, 5415, 5416, 5417, 5418, 5419, 5420, 5421, 5422, 5423, 5424, 5425, 5426, 5427, 5428, 5429, 5430, 5431, 5432, 5433, 5434, 5435, 5436, 5437, 5438, 5439, 5440, 5441, 5442, 5443, 5444, 5445, 5446, 5447, 5448, 5449, 5450, 5451, 5452, 5453, 5454, 5455, 5456, 5457, 5458, 5459, 5460, 5461, 5462, 5463, 5464, 5465, 5466, 5467, 5468, 5469, 5470, 5471, 5472, 5473, 5474, 5475, 5476, 5477, 5478, 5479, 5480, 5481, 5482, 5483, 5484, 5485, 5486, 5487, 5488, 5489, 5490, 5491, 5492, 5493, 5494, 5495, 5496, 5497, 5498, 5499, 5500, 5501, 5502, 5503, 5504, 5505, 5506, 5507, 5508, 5509, 5510, 5511, 5512, 5513, 5514, 5515, 5516, 5517, 5518, 5519, 5520, 5521, 5522, 5523, 5524, 5525, 5526, 5527, 5528, 5529, 5530, 5531, 5532, 5533, 5534, 5535, 5536, 5537, 5538, 5539, 5540, 5541, 5542, 5543, 5544, 5545, 5546, 5547, 5548, 5549, 5550, 5551, 5556, 5557, 5558, 5559, 5560, 5561, 5562, 5563, 5564, 5565, 5566, 5567, 5568, 5569, 5570, 5571, 5572, 5573, 5574, 5575, 5576, 5577, 5578, 5579, 5580, 5581, 5582, 5583, 5584, 5585, 5586, 5587, 5588, 5589, 5590, 5591, 5592, 5593, 5594, 5595, 5596, 5597, 5598, 5599, 5600, 5601, 5602, 5603, 5604, 5605, 5606, 5607, 5608, 5609, 5610, 5611, 5612, 5613, 5614, 5615, 5616, 5617, 5618, 5619, 5620, 5621, 5622, 5623, 5624, 5625, 5626, 5627, 5628, 5629, 5630, 5631, 5632, 5633, 5634, 5635, 5636, 5637, 5638, 5639, 5640, 5641, 5642, 5643, 5644, 5645, 5646, 5647, 5648, 5649, 5650, 5651, 5652, 5653, 5654, 5655, 5656, 5657, 5658, 5659, 5660, 5661, 5662, 5663, 5664, 5665, 5666, 5667, 5668, 5669, 5670, 5671, 5672, 5673, 5674, 5675, 5676, 5677, 5678, 5679, 5680, 5681, 5682, 5683, 5684, 5685, 5686, 5687, 5688, 5689, 5690, 5691, 5692, 5693, 5694, 5695, 5696, 5697, 5698, 5699, 5700, 5701, 5702, 5703, 5704, 5705, 5706, 5707, 5708, 5709, 5710, 5711, 5712, 5713, 5714, 5715, 5716, 5717, 5718, 5719, 5720, 5721, 5722, 5723, 5724, 5725, 5726, 5727, 5728, 5729, 5730, 5731, 5732, 5733, 5734, 5735, 5736, 5737, 5738, 5739, 5740, 5741, 5742, 5743, 5744, 5745, 5746, 5747, 5748, 5749, 5750, 5751, 5752, 5753, 5754, 5755, 5756, 5757, 5758, 5759, 5793, 5794, 5795, 5796, 5797, 5798, 5799, 5800, 5801, 5802, 5803, 5804, 5805, 5806, 5807, 5808, 5809, 5810, 5811, 5812, 5813, 5814, 5815, 5816, 5817, 5818, 5819, 5820, 5821, 5822, 5823, 5824, 5825, 5826, 5827, 5828, 5829, 5830, 5831, 5832, 5833, 5834, 5835, 5836, 5837, 5838, 5839, 5840, 5841, 5842, 5843, 5844, 5845, 5846, 5847, 5848, 5849, 5850, 5851, 5852, 5853, 5854, 5855, 5856, 5857, 5858, 5859, 5860, 5861, 5862, 5863, 5864, 5865, 5866, 5867, 5868, 5869, 5870, 5871, 5872, 7425, 7426, 7427, 7428, 7429, 7430, 7431, 7432, 7433, 7434, 7435, 7436, 7437, 7438, 7439, 7440, 7441, 7442, 7443, 7444, 7445, 7446, 7447, 7448, 7449, 7450, 7451, 7452, 7453, 7454, 7455, 7456, 7457, 7458, 7459, 7460, 7461, 7462, 7463, 7464, 7465, 7466, 7467, 7468, 7469, 7470, 7471, 7472, 7473, 7474, 7475, 7476, 7477, 7478, 7479, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7487, 7488, 7489, 7490, 7491, 7492, 7493, 7494, 7495, 7496, 7497, 7498, 7499, 7500, 7501, 7502, 7503, 7504, 7505, 7506, 7507, 7508, 7509, 7510, 7511, 7512, 7513, 7514, 7515, 7516, 7517, 7518, 7519, 7520, 7521, 7522, 7523, 7524, 7525, 7526, 7527, 7528, 7529, 7530, 7531, 7532, 7533, 7534, 7535, 7536, 7537, 7538, 7539, 7540, 7541, 7542, 7543, 7544, 7545, 7546, 7547, 7548, 7549, 7550, 7551, 7552, 7553, 7554, 7555, 7556, 7557, 7558, 7559, 7560, 7561, 7562, 7563, 7564, 7565, 7566, 7567, 7568, 7569, 7570, 7571, 7572, 7573, 7574, 7575, 7576, 7577, 7578, 7579, 7580, 7581, 7582, 7583, 7584, 7585, 7586, 7587, 7588, 7589, 7590, 7591, 7592, 7593, 7594, 7595, 7596, 7597, 7598, 7599, 7600, 7601, 7602, 7603, 7604, 7605, 7606, 7607, 7608, 7609, 7610, 7611, 7612, 7613, 7614, 7681, 7682, 7683, 7684, 7685, 7686, 7687, 7688, 7689, 7690, 7691, 7692, 7693, 7694, 7695, 7696, 7697, 7698, 7699, 7700, 7701, 7702, 7703, 7704, 7705, 7706, 7707, 7708, 7709, 7710, 7711, 7712, 7713, 7714, 7715, 7716, 7717, 7718, 7719, 7720, 7721, 7722, 7723, 7724, 7725, 7726, 7727, 7728, 7729, 7730, 7731, 7732, 7733, 7734, 7735, 7736, 7737, 7738, 7739, 7740, 7741, 7742, 7743, 7744, 7745, 7746, 7747, 7748, 7749, 7750, 7751, 7752, 7753, 7754, 7755, 7756, 7757, 7758, 7759, 7760, 7761, 7762, 7763, 7764, 7765, 7766, 7767, 7768, 7769, 7770, 7771, 7772, 7773, 7774, 7775, 7776, 7777, 7778, 7779, 7780, 7781, 7782, 7783, 7784, 7785, 7786, 7787, 7788, 7789, 7790, 7791, 7792, 7793, 7794, 7795, 7796, 7797, 7798, 7799, 7800, 7801, 7802, 7803, 7804, 7805, 7806, 7807, 7808, 7809, 7810, 7811, 7812, 7813, 7814, 7815, 7816, 7817, 7818, 7819, 7820, 7821, 7822, 7823, 7824, 7825, 7826, 7827, 7828, 7829, 7830, 7831, 7832, 7833, 7834, 7835, 7836, 7837, 7838, 7839, 7840, 7841, 7842, 7843, 7844, 7845, 7846, 7847, 7848, 7849, 7850, 7851, 7852, 7853, 7854, 7855, 7856, 7857, 7858, 7859, 7860, 7861, 7862, 7863, 7864, 7865, 7866, 7867, 7868, 7869, 7870, 7871, 7872, 7873, 7874, 7875, 7876, 7877, 7878, 7879, 7880, 7881, 7882, 7883, 7884, 7885, 7886, 7887, 7888, 7889, 7890, 7891, 7892, 7893, 7894, 7895, 7896, 7897, 7898, 7899, 7900, 7901, 7902, 7903, 7904, 7905, 7906, 7907, 7908, 7909, 7910, 7911, 7912, 7913, 7914, 7915, 7916, 7917, 7918, 7919, 7920, 7921, 7922, 7923, 7924, 7925, 7926, 7927, 7928, 7929, 7930, 7931, 7932, 7933, 7934, 7935, 7936, 7937, 7938, 7939, 7940, 7941, 7942, 7943, 7944, 7945, 7946, 7947, 7948, 7949, 7950, 7951, 7952, 7953, 7954, 7955, 7956, 7957, 8032, 8033, 8034, 8035, 8036, 8037, 8038, 8039, 8040, 8041, 8042, 8043, 8044, 8045, 8046, 8047, 8048, 8049, 8050, 8051, 8052, 8053, 8054, 8055, 8056, 8057, 8058, 8059, 8060, 8061, 4305, 8065, 8066, 8067, 8068, 8069, 8070, 8071, 8072, 8073, 8074, 8075, 8076, 8077, 8078, 8079, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099, 8100, 8101, 8102, 8103, 8104, 8105, 8106, 8107, 8108, 8109, 8110, 8111, 8112, 8113, 8114, 8115, 8116, 8449, 8450, 8451, 8452, 8453, 8454, 8455, 8456, 8457, 8458, 8459, 8460, 8461, 8462, 8463, 8464, 8465, 8466, 8467, 8468, 8469, 8470, 8471, 8472, 8473, 8474, 8475, 8476, 8477, 8478, 8479, 8480, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488, 8489, 8490, 8491, 8751, 8752, 8753, 8754, 8755, 8756, 8757, 8758, 8759, 8760, 8761, 8762, 8763, 8764, 8765, 8766, 8767, 8768, 8769, 8770, 8771, 8772, 8773, 8774, 8775, 8776, 8777, 8778, 8779, 8780, 8781, 8782, 8783, 8784, 8785, 8786, 8787, 8788, 8789, 8790, 8791, 8792, 8793, 8794, 8795, 8796, 8797, 8798, 8799, 8800, 8801, 8802, 8803, 8804, 8805, 8806, 8807, 8808, 4306, 4307, 4308, 4309, 4310, 4311, 4312, 4313, 4314, 4315, 4316, 4317, 4318, 4319, 4320, 4321, 4322, 4323, 4324, 4325, 4326, 4327, 4328, 4329, 4330, 4331, 4332, 4333, 4334, 4335, 4336, 4337, 4338, 4339, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 1310, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, 1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1370, 1371, 1372, 1373, 1374, 1375, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, 1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1505, 1506, 1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 1521, 1522, 1523, 1524, 1567, 1568, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, 1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 1595, 1596, 1597, 1598, 1599, 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1654, 1655, 1656, 1657, 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, 1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800, 1801, 1802, 1803, 1804, 1805, 1810, 1811, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, 1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, 1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956]
""""""
LEN_FOOTPRINT = 24
""""""
SALT = '-¤-Kirmah-¤-'
""""""
-
- def __init__(self, length, salt=None):
+
+ @Log(Const.LOG_BUILD)
+ def __init__(self, length, salt=None):
""""""
self.new(length, salt)
+
+ @Log(Const.LOG_PRIVATE)
def _build(self,l):
""""""
r = Randomiz(len(self.CHSET),self.CHSET)
@@ -158,6 +178,8 @@ class KeyGen :
kfoo += c
self.mark = hash_sha256(self.salt+kfoo)
+
+ @Log(Const.LOG_DEBUG)
def getMark(self, key=None):
""""""
dic = {}
@@ -172,6 +194,8 @@ class KeyGen :
kfoo += c
return hash_sha256(self.salt+kfoo)
+
+ @Log(Const.LOG_DEBUG)
def new(self, length, salt=None):
""""""
if salt == None : self.salt = self.SALT
@@ -179,62 +203,68 @@ class KeyGen :
self._build(length)
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class ConfigKey ~~
class ConfigKey:
- """"""
- @log
+
+ @Log(Const.LOG_BUILD)
def __init__(self, key=None, salt=None, psize=19710000):
""""""
- self.key = bytes(key,'utf-8') if key is not None else self._build()
+ self.key = bytes(key,'utf-8') if key is not None else self._build()
self.salt = str(self.key[::-10]) if salt is None else salt
self.psize = psize
self.noiser = Noiser(self.key)
self.rdmz = Randomiz(1)
+
@staticmethod
+ @Log(Const.LOG_ALL)
def sumNumber(s,count):
""""""
return sum([ int(c) for j,c in enumerate(s) if represents_int(c)][0:count])
-
- #~ @log
+
+
+ @Log(Const.LOG_DEBUG)
def getHashList(self,name,count,noSorted=False):
""""""
self.rdmz.new(count)
dic, lst, hroot = {}, [], hash_sha256(self.salt+name)
-
- srdl = getRandomListFromKey(self.key, count)
- for i in range(count) :
+
+ #~ srdl = Kirmah.getRandomListFromKey(self.key, count)
+ srdl = getRandomListFromKey(self.key, count)
+ for i in range(count) :
self.noiser.build(i,ConfigKey.sumNumber(hash_sha256(str(i)+self.salt+name),1 if i%2 else 2))
d = str(i).rjust(2,'0')
# part n°, hash, lns, lne, pos
hpart = hash_sha256(self.salt+name+'.part'+d)[:-3]+str(ord(hroot[i])).rjust(3,'0')
lst.append((i, hpart, self.noiser.lns, self.noiser.lne, self.rdmz.get(), srdl[i]))
dic['head'] = [name,count,hroot,self.getKey()]
- if not noSorted :
+ if not noSorted :
lst = sorted(lst, key=lambda lst: lst[4])
dic['data'] = lst
return dic
+
+ @Log(Const.LOG_PRIVATE)
def _build(self,l=48):
""""""
kg = KeyGen(l)
k = urlsafe_b64encode(bytes(kg.key,'utf-8'))
return k
-
+
+
+ @Log(Const.LOG_DEBUG)
def getKey(self):
""""""
return str(self.key,'utf-8')
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Kirmah ~~
class KirmahHeader:
-
+
COMP_NONE = 0
COMP_ALL = 1
COMP_END = 2
@@ -245,13 +275,13 @@ class KirmahHeader:
POS_MIX = 15
POS_SEC = 18
POS_END = 22
-
+
ID = b'\x05\xd9\x83MH'
MODE_COMP = b'Z'
MODE_RAND = b'R'
MODE_MIX = b'M'
MODE_SEC = b'S'
-
+
"""
ex : كMH02Z2499R42M26S0055
@@ -274,7 +304,7 @@ class KirmahHeader:
'?' ord(chr mark pos)%2==0
? random ON
: randon OFF
-
+
3o : M? - Mix Mode
'?' ord(chr mark pos)%2==0
? mix ON
@@ -283,9 +313,9 @@ class KirmahHeader:
3o : S??? - Secure Mode
'?' mark[dlen%len(mark)].rjust(3,'0')
- """
+ """
- @log
+ @Log(Const.LOG_BUILD)
def __init__(self, version, mark, cmode=1, rmode=True, mmode=True):
""""""
self.version = bytes(str(int(float(version))).rjust(2,'0'),'utf-8')
@@ -294,21 +324,26 @@ class KirmahHeader:
self.rmode = rmode
self.mmode = mmode
+
+ @Log(Const.LOG_DEBUG)
def getPositionnalChar(self, sindex, test=True):
""""""
pc = None
for i, c in enumerate(self.mark[sindex:]) :
- if c % 2 == 0 and test or not test and c % 2 != 0 :
+ if c % 2 == 0 and test or not test and c % 2 != 0 :
pc = i+sindex
break
return pc
+
+ @Log(Const.LOG_DEBUG)
def checkPositionnalChar(self, pc):
""""""
- return ord(self.mark[pc:pc+1])%2==0
-
- @log
- def buildHeader(self, dlen, cmode=None, rmode=None, mmode=None):
+ return ord(self.mark[pc:pc+1])%2==0
+
+
+ @Log()
+ def buildHeader(self, dlen, cmode=None, rmode=None, mmode=None):
""""""
if cmode is None : cmode = self.cmode
if rmode is None : rmode = self.rmode
@@ -322,10 +357,11 @@ class KirmahHeader:
head = [self.ID, self.version, self.MODE_COMP, Io.bytes(str(cmpc1).rjust(2,'0')), Io.bytes(str(cmpc2).rjust(2,'0')), self.MODE_RAND, Io.bytes(str(rmpc).rjust(2,'0')), self.MODE_MIX, Io.bytes(str(mmpc).rjust(2,'0')), self.MODE_SEC, Io.bytes(str(smpc).rjust(3,'0'))]
return b''.join(head)
- @log
+
+ @Log()
def readHeader(self, header):
""""""
-
+
isKmh, vers, cmode, rmode, mmode, smode, pc1, badKmh = header[:self.POS_VERS] == self.ID, None, None , None, None, None, None, False
if isKmh :
vers = int(header[self.POS_VERS:self.POS_VERS+2])
@@ -334,23 +370,23 @@ class KirmahHeader:
cmode = self.COMP_ALL if self.checkPositionnalChar(int(header[self.POS_COMP+3:self.POS_COMP+5])) else self.COMP_END
else :
cmode = self.COMP_NONE
- else :
+ else :
badKmh = True
-
+
if header[self.POS_RAND:self.POS_RAND+1] == self.MODE_RAND :
- rmode = self.checkPositionnalChar(int(header[self.POS_RAND+1:self.POS_RAND+3]))
- else :
- badKmh = True
-
- if header[self.POS_MIX:self.POS_MIX+1] == self.MODE_MIX :
- mmode = self.checkPositionnalChar(int(header[self.POS_MIX+1:self.POS_MIX+3]))
- else :
+ rmode = self.checkPositionnalChar(int(header[self.POS_RAND+1:self.POS_RAND+3]))
+ else :
badKmh = True
-
+
+ if header[self.POS_MIX:self.POS_MIX+1] == self.MODE_MIX :
+ mmode = self.checkPositionnalChar(int(header[self.POS_MIX+1:self.POS_MIX+3]))
+ else :
+ badKmh = True
+
if header[self.POS_SEC:self.POS_SEC+1] == self.MODE_SEC :
smode = chr(int(header[self.POS_SEC+1:self.POS_SEC+4]))
else : badKmh = True
-
+
return { 'version':vers, 'cmode':cmode, 'rmode':rmode, 'mmode':mmode,'smode':smode} if isKmh and not badKmh else {}
@@ -362,12 +398,15 @@ class Kirmah:
VERSION = '2.1'
EXT = '.kmh'
+ EXT_TARK = '.tark'
DIR_OUTBOX = ''
DIR_INBOX = ''
DIR_DEPLOY = ''
DIR_TEMP = ''
+ KMP_FILE = '.kmp'
- @log
+
+ @Log(Const.LOG_BUILD)
def __init__(self, key, mark=None, headcompress=2, headrandom=True, headmix=True):
""""""
self.key = Io.bytes(key)
@@ -376,505 +415,621 @@ class Kirmah:
self.ck = ConfigKey(self.mark2)
self.kh = KirmahHeader(Kirmah.VERSION, Io.bytes(self.mark), headcompress, headrandom, headmix)
- @log
+
+ @Log()
def compress_start(self, fromPath, toPath, compress=True, lvl=9):
""""""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- data = fi.read() if not compress else Io.gzcompress(fi.read(), lvl)
- fo.write(b2a_base64(data))
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ data = fi.read() if not compress else Io.gzcompress(fi.read(), lvl)
+ fo.write(b2a_base64(data))
- @log
+
+ @Log()
def uncompress_start(self, fromPath, toPath, decompress=True):
""""""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- data = a2b_base64(fi.read())
- fo.write(data if not decompress else Io.gzdecompress(data))
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ data = a2b_base64(fi.read())
+ fo.write(data if not decompress else Io.gzdecompress(data))
- @log
+
+ @Log()
def compress_end(self, fromPath, toPath, compress=True, lvl=9):
""""""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- data = fi.read()
- if compress : data = Io.gzcompress(data, lvl)
- header = self.kh.buildHeader(len(data))
- fo.write(header)
- fo.write(data)
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ data = fi.read()
+ if compress : data = Io.gzcompress(data, lvl)
+ header = self.kh.buildHeader(len(data))
+ fo.write(header)
+ fo.write(data)
- @log
+
+ @Log()
def uncompress_end(self, fromPath, toPath, decompress=True):
""""""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- fi.seek(self.kh.POS_END)
- fo.write(fi.read() if not decompress else Io.gzdecompress(fi.read()))
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ fi.seek(self.kh.POS_END)
+ fo.write(fi.read() if not decompress else Io.gzdecompress(fi.read()))
- #~ @log
+
+ @Log(Const.LOG_ALL)
def encryptStr(self, data):
""""""
- s, lk, i = [], len(self.key), 0
- for c in data:
- if lk-i <= 0: i = 0
- s.append(chr(c + i//4 + (self.key[i] if c + self.key[i] + i//4 < 11000 else -self.key[i])))
- i += 1
- return Io.bytes(''.join(s))
+ if not Sys.is_cli_cancel():
+ s, lk, i = [], len(self.key), 0
+ for c in data:
+ if lk-i <= 0:
+ i = 0
+ if Sys.is_cli_cancel(): break
+ s.append(chr(c + i//4 + (self.key[i] if c + self.key[i] + i//4 < 11000 else -self.key[i])))
+ i += 1
+ return Io.bytes(''.join(s))
- @log
- def encryptToFile(self, fromPath, toPath, i=0):
+
+ @Log()
+ def encryptToFile(self, fromPath, toPath, i=0, lock=None):
""""""
- with Io.ufile(fromPath) as fi :
- with Io.wfile(toPath, False) as fo :
- s, lk = [], len(self.key)
- for c in Io.read_utf8_chr(fi):
- if i >= lk: i = 0
- fo.write(chr(ord(c) + i//4 + (self.key[i] if ord(c) + self.key[i] + i//4 < 11000 else -self.key[i])))
- i += 1
+ if not Sys.is_cli_cancel():
+ with Io.ufile(fromPath) as fi :
+ with Io.wfile(toPath, False) as fo :
+ s, lk = [], len(self.key)
+ for c in Io.read_utf8_chr(fi):
+ if i >= lk:
+ i = 0
+ if Sys.is_cli_cancel(lock):
+ break
+ fo.write(chr(ord(c) + i//4 + (self.key[i] if ord(c) + self.key[i] + i//4 < 11000 else -self.key[i])))
+ i += 1
- @log
+
+ @Log()
def decryptToFile(self, fromPath, toPath, i=0):
""""""
- with Io.ufile(fromPath) as fi :
- with Io.rfile(fromPath) as fi2 :
- s = fi2.read()
- with Io.wfile(toPath, False) as fo :
- s, lk = [], len(self.key)
+ if not Sys.is_cli_cancel():
+ with Io.ufile(fromPath) as fi :
+ with Io.rfile(fromPath) as fi2 :
+ s = fi2.read()
+ with Io.wfile(toPath, False) as fo :
+ s, lk = [], len(self.key)
- for c in Io.read_utf8_chr(fi):
- if i >= lk: i = 0
- try :
- fo.write(chr(ord(c)- i//4 + (-self.key[i] if ord(c) + self.key[i] +i//4 < 110000 else self.key[i])))
- except Exception as e :
- print('ord c : '+str(ord(c))+' - self.key['+str(i)+'] : '+str(self.key[i]))
- raise e
- i += 1
+ for c in Io.read_utf8_chr(fi):
+ if i >= lk:
+ i = 0
+ if Sys.is_cli_cancel(): break
+ try :
+ fo.write(chr(ord(c)- i//4 + (-self.key[i] if ord(c) + self.key[i] +i//4 < 110000 else self.key[i])))
+ except Exception as e :
+ Sys.pwarn((('decryptToFile : ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),
+ ('ord c : ',(str(ord(c)),Sys.CLZ_ERROR_PARAM), ' - self.key[',(str(i),Sys.CLZ_ERROR_PARAM), '] : ',(str(self.key[i]),Sys.CLZ_ERROR_PARAM)),
+ ), True)
+ raise e
+ i += 1
- @log
+
+ @Log()
def randomFileContent(self, fromPath, toPath):
- """"""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- fsize, chsize, size = Kirmah.getSizes(fromPath)
- lst, rest, data = Kirmah.getRandomListFromKey(self.ck.key, size), chsize - fsize%chsize, ['b']*size
- if rest == chsize : rest = 0
- for piece, i in Io.read_in_chunks(fi, chsize):
- fo.seek(lst[i]*chsize-(rest if lst[i] > lst[size-1] else 0))
- #~ print(piece[::-1])
- fo.write(piece[::-1])
+ """"""
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ fsize, chsize, size = Kirmah.getSizes(fromPath)
+ lst, rest, data = Kirmah.getRandomListFromKey(self.ck.key, size), chsize - fsize%chsize, ['b']*size
+ if rest == chsize : rest = 0
+ 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.write(piece[::-1])
- @log
+
+ @Log()
def mpRandomFileContent(self, fromPath, toPath, nproc):
""""""
- #~ self.randomFileContent(fromPath, toPath+'.monoproc')
- #~ self.randomFileContent(fromPath, toPath+'.monoproc')
+ 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)
-
- 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)
- self.mpMergeFiles(hlstPaths, fromPath+'.copy', True)
-
- self.randomFileContent(fromPath, toPath)
-
- #~ with Io.wfile(toPath) as fo :
- #~ lst, rest, data = Kirmah.getRandomListFromKey(self.ck.key, size), chsize - fsize%chsize, ['b']*size
- #~ if rest == chsize : rest = 0
- #~ for part, fp in enumerate(hlstPaths) :
- #~ with Io.rfile(fp) as fi :
- #~ for piece, i in Io.read_in_chunks(fi, chsize):
- #~ fo.seek(lst[i]*chsize-(rest if lst[i] > lst[size-1] else 0))
- #~ print(piece[::-1])
- #~ fo.write(piece[::-1])
- @log
+ @Log()
def mpMergeFiles(self,hlstPaths, toPath, noRemove=False):
""""""
- 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
+ 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)
+
+
+ @Log()
def unRandomFileContent(self, fromPath, toPath):
""""""
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- fsize, chsize, size = Kirmah.getSizes(fromPath)
- lst, rest, piece, data = Kirmah.getRandomListFromKey(self.ck.key, size), chsize - fsize%chsize, b'', []
- if rest == chsize : rest = 0
- for i, pos in enumerate(lst):
- d = pos*chsize-(rest if pos >= lst[size-1] and pos!=0 else 0)
- if d >= 0 : fi.seek(d)
- piece = fi.read(chsize)
- if i == size-1 and rest > 0 :
- piece = piece[:-rest] if lst[i]==0 else piece[rest:]
- fo.write(piece[::-1])
-
- @log
+ if not Sys.is_cli_cancel():
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ fsize, chsize, size = Kirmah.getSizes(fromPath)
+ lst, rest, piece, data = Kirmah.getRandomListFromKey(self.ck.key, size), chsize - fsize%chsize, b'', []
+ if rest == chsize : rest = 0
+ for i, pos in enumerate(lst):
+ d = pos*chsize-(rest if pos >= lst[size-1] and pos!=0 else 0)
+ if d >= 0 : fi.seek(d)
+ piece = fi.read(chsize)
+ if i == size-1 and rest > 0 :
+ piece = piece[:-rest] if lst[i]==0 else piece[rest:]
+ fo.write(piece[::-1])
+
+
+ @Log()
def mixdata(self, fromPath, toPath, encryptNoise=False, label='kirmah', cpart=22):
""""""
- hlst = self.ck.getHashList(label, cpart, False)
- hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[0])
- size = Sys.getsize(fromPath)
- psize = ceil(size/cpart)
- cp = 0
- rsz = 0
- for row in hlst['data']: rsz += row[2]+row[3]
- with Io.rfile(fromPath) as fi:
- with Io.wfile(toPath) as fo :
- bdata, adata = '', ''
- for row in hlst['data']:
- bdata, adata = self.ck.noiser.getNoise(row[2]), self.ck.noiser.getNoise(row[3])
- if encryptNoise :
- bdata, adata = self.encryptStr(bdata)[:row[2]], self.encryptStr(adata)[:row[3]]
- fi.seek(psize*row[5])
- d = fi.read(psize)
- fo.write(bdata[:row[2]] + d + adata[:row[3]])
- cp += 1
-
+ if not Sys.is_cli_cancel():
+ hlst = self.ck.getHashList(label, cpart, False)
+ hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[0])
+ size = Sys.getsize(fromPath)
+ psize = ceil(size/cpart)
+ cp = 0
+ rsz = 0
+ for row in hlst['data']: rsz += row[2]+row[3]
+ with Io.rfile(fromPath) as fi:
+ with Io.wfile(toPath) as fo :
+ bdata, adata = '', ''
+ for row in hlst['data']:
+ bdata, adata = self.ck.noiser.getNoise(row[2]), self.ck.noiser.getNoise(row[3])
+ if encryptNoise :
+ bdata, adata = self.encryptStr(bdata)[:row[2]], self.encryptStr(adata)[:row[3]]
+ fi.seek(psize*row[5])
+ d = fi.read(psize)
+ fo.write(bdata[:row[2]] + d + adata[:row[3]])
+ cp += 1
+
+
+ @Log(Const.LOG_DEBUG)
def getNoiseLenBeforeIndex(self, hlst, psize, rest, size):
""""""
- lst, l, df, sou, f = [], 0, psize, False, 0
- lst.append(l)
- mxp = size // psize
- if size % psize == 0 : mxp -= 1
- for row in hlst:
- if row[5] == mxp :
- df = rest
- elif row[5] > mxp :
- df = 0
- else : df = psize
- l += row[2]+ row[3] + df
- lst.append(l)
- return lst
-
- @log
+ if not Sys.is_cli_cancel():
+ lst, l, df, sou, f = [], 0, psize, False, 0
+ lst.append(l)
+ mxp = size // psize
+ if size % psize == 0 : mxp -= 1
+ for row in hlst:
+ if row[5] == mxp :
+ df = rest
+ elif row[5] > mxp :
+ df = 0
+ else : df = psize
+ l += row[2]+ row[3] + df
+ lst.append(l)
+ return lst
+
+
+ @Log()
def unmixdata(self, fromPath, toPath, label='kirmah', cpart=22):
""""""
- rsz, cp, hlst = 0, 0, self.ck.getHashList(label, cpart, True)
- for row in hlst['data']:
- rsz += row[2]+row[3]
- size = Sys.getsize(fromPath)-rsz
- psize = ceil(size/cpart)
- rest = size % psize
- if rest == 0 : rest = psize
- lbi = self.getNoiseLenBeforeIndex(hlst['data'],psize,rest, size)
- hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[5])
- mxp = size // psize
- if size % psize == 0 : mxp -= 1
- with Io.rfile(fromPath) as fi :
- with Io.wfile(toPath) as fo :
- header = fi.read(self.kh.POS_END)
- fi.seek(0,Io.SEEK_CUR)
- for row in hlst['data']:
- fi.seek(lbi[row[0]]+row[2])
- d = fi.read(psize if row[5] <= mxp else (rest if rest!=psize or (psize*cpart==size) else 0))
- cp += 1
- if fo.tell() + len(d) > size :
- fo.write(d[:rest])
- break
- fo.write(d)
+ if not Sys.is_cli_cancel():
+ rsz, cp, hlst = 0, 0, self.ck.getHashList(label, cpart, True)
+ for row in hlst['data']:
+ rsz += row[2]+row[3]
+ size = Sys.getsize(fromPath)-rsz
+ psize = ceil(size/cpart)
+ rest = size % psize
+ if rest == 0 : rest = psize
+ lbi = self.getNoiseLenBeforeIndex(hlst['data'],psize,rest, size)
+ hlst['data'] = sorted(hlst['data'], key=lambda hlst: hlst[5])
+ mxp = size // psize
+ if size % psize == 0 : mxp -= 1
+ with Io.rfile(fromPath) as fi :
+ with Io.wfile(toPath) as fo :
+ header = fi.read(self.kh.POS_END)
+ fi.seek(0,Io.SEEK_CUR)
+ for row in hlst['data']:
+ fi.seek(lbi[row[0]]+row[2])
+ d = fi.read(psize if row[5] <= mxp else (rest if rest!=psize or (psize*cpart==size) else 0))
+ cp += 1
+ if fo.tell() + len(d) > size :
+ fo.write(d[:rest])
+ break
+ fo.write(d)
- @log
- def splitFile(self, fromPath, hlst):
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ # # SPLIT # #
+
+ @Log()
+ def splitFile(self, fromPath, hlst, nproc=1):
""""""
- self.split(fromPath, hlst)
- theStr = {'name': hlst['head'][0], 'count': hlst['head'][1] }
- 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', KirmahHeader(self.VERSION, Io.bytes(self.mark), KirmahHeader.COMP_NONE, True, True))
- Sys.removeFile(self.DIR_DEPLOY+hlst['head'][2]+'.tmp')
- return self.DIR_DEPLOY+hlst['head'][2]+'.kcf'
+ if not Sys.is_cli_cancel():
+ d = Sys.datetime.now()
+ Sys.cli_emit_progress(2)
+ self.split(fromPath, hlst)
+ Sys.cli_emit_progress(70)
+ if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
+ Sys.pstep('Splitting file', d, True)
+ return self.kcfEnc(hlst)
- @log
+
+ @Log()
+ def kcfEnc(self, hlst, nproc=1):
+ if not Sys.is_cli_cancel():
+ d = Sys.datetime.now()
+ theStr = {'name': hlst['head'][0], 'count': hlst['head'][1] }
+ 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))
+ Sys.removeFile(self.DIR_DEPLOY+hlst['head'][2]+'.tmp')
+ if Sys.g.DEBUG : Sys.wlog(Sys.dprint())
+ Sys.pstep('Encrypting Kirmah configuration file', d, True)
+ Sys.cli_emit_progress(75)
+ return self.DIR_DEPLOY+hlst['head'][2]+'.kcf'
+
+
+ @Log()
def split(self, fromPath, hlst):
""""""
- self.DIR_OUTBOX = ''
- f = open(fromPath, 'rb+')
- m, p, rsz = mmap(f.fileno(), 0), 0, 0
- fsize = Sys.getsize(fromPath)
-
- for row in hlst['data']: rsz += row[2]+row[3]
- # ensure correct order
- hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[0])
-
- self.splheader = self.kh.buildHeader(fsize)
- psize = ceil(fsize/hlst['head'][1])
+ if not Sys.is_cli_cancel():
+ self.DIR_OUTBOX = ''
+ f = open(fromPath, 'rb+')
+ m, p, rsz = mmap(f.fileno(), 0), 0, 0
+ fsize = Sys.getsize(fromPath)
+ Sys.cli_emit_progress(3)
+ for row in hlst['data']: rsz += row[2]+row[3]
+ # ensure correct order
+ hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[0])
- while m.tell() < m.size():
- self._splitPart(m, psize, hlst['data'][p])
- p += 1
- m.close()
-
- # ensure random order
- hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4])
- hlst['head'].append(psize)
- return hlst
-
- @log
- def _splitPart(self, mmap, size, phlst):
- """"""
- with Io.wfile(self.DIR_OUTBOX+phlst[1]+self.EXT) as fo :
- bdata, adata, part = self.ck.noiser.getNoise(phlst[2], False)[len(self.splheader):], self.ck.noiser.getNoise(phlst[3], False), int(phlst[0])
- zd = Io.gzcompress(bdata+mmap.read(size)+adata)
- hz = Io.bytes(self.offuscate(zd[:self.kh.POS_END], part))
- lhz = Io.bytes(str(part + len(hz)).rjust(3,'0'))
- fo.write(self.splheader+lhz+hz+zd[self.kh.POS_END:])
-
- @log
- def mergeFile(self, fromPath):
- self.decrypt(fromPath, '.cfg')
- data = Io.get_data('.cfg')
- clist = literal_eval(data)
- Sys.removeFile('.cfg')
- theList = self.ck.getHashList(clist['name'], clist['count'], True)
- toPath = self.merge(theList, clist['name'])
- Sys.removeFile(fromPath)
- return toPath
-
- @log
- def merge(self, hlst, fileName, ext='', uid='', dirs=None, fake=False):
- """"""
- p = 0
- # ensure correct order
- hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[0])
-
- if dirs is not None and dirs!='none' :
- dirPath = join(self.DIR_DEPLOY,dirs)+Sys.sep
- Sys.mkdir_p(dirPath)
- else: dirPath = self.DIR_DEPLOY
-
- filePath = dirPath+fileName
- if Io.file_exists(filePath+ext):
- filePath += '-'+str(uid)
- filePath = Sys.abspath(filePath+ext)
- depDir = self.DIR_INBOX if not fake else self.DIR_OUTBOX
- with Io.wfile(filePath) as fo :
- while p < hlst['head'][1] :
- self._mergePart(fo, hlst['data'][p], depDir)
+ self.splheader = self.kh.buildHeader(fsize)
+ psize = ceil(fsize/hlst['head'][1])
+ Sys.cli_emit_progress(4)
+ perc = 5
+ frav = 1.40
+ while m.tell() < m.size():
+ perc += frav
+ Sys.cli_emit_progress(perc)
+ self.splitPart(m, psize, hlst['data'][p])
+ perc += frav
+ Sys.cli_emit_progress(perc)
p += 1
- return filePath
+ m.close()
+
+ # ensure random order
+ hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[4])
+ hlst['head'].append(psize)
+ return hlst
- @log
- def _mergePart(self, fo, phlst, depDir):
- """"""
- with Io.rfile(depDir+phlst[1]+self.EXT) as fi:
- part, head = int(phlst[0]), fi.read(self.kh.POS_END)
- fo.write(Io.gzdecompress(self.deoffuscate(Io.str(fi.read(int(fi.read(3))-part)), part) + fi.read())[phlst[2]-self.kh.POS_END:-phlst[3]])
- Sys.removeFile(depDir+phlst[1]+self.EXT)
-
- @log
+
+ @Log()
+ def splitPart(self, mmap, size, phlst):
+ """"""
+ if not Sys.is_cli_cancel():
+ with Io.wfile(self.DIR_OUTBOX+phlst[1]+self.EXT) as fo :
+ bdata, adata, part = self.ck.noiser.getNoise(phlst[2], False)[len(self.splheader):], self.ck.noiser.getNoise(phlst[3], False), int(phlst[0])
+ zd = Io.gzcompress(bdata+mmap.read(size)+adata)
+ hz = Io.bytes(self.offuscate(zd[:self.kh.POS_END], part))
+ lhz = Io.bytes(str(part + len(hz)).rjust(3,'0'))
+ fo.write(self.splheader+lhz+hz+zd[self.kh.POS_END:])
+
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ # # MERGE # #
+
+ @Log()
+ def mergeFile(self, fromPath, toPath=None, uid=''):
+ """"""
+ if not Sys.is_cli_cancel():
+ Sys.cli_emit_progress(2)
+ self.decrypt(fromPath, '.cfg')
+ Sys.cli_emit_progress(5)
+ data = Io.get_data('.cfg')
+ clist = literal_eval(data)
+ Sys.removeFile('.cfg')
+ theList = self.ck.getHashList(clist['name'], clist['count'], True)
+ dirs = Sys.dirname(Sys.realpath(toPath)) if toPath is not None else None
+ ext = ''
+ if toPath is None :
+ toPath = clist['name']
+ toPath, ext = Sys.getFileExt(toPath)
+ Sys.cli_emit_progress(10)
+ toPath = self.merge(theList, toPath, ext, uid, dirs)
+ Sys.removeFile(fromPath)
+ Sys.cli_emit_progress(90)
+ return toPath
+
+
+ @Log()
+ def merge(self, hlst, fileName, ext='', uid='', dirs=None, fake=False):
+ """"""
+ if not Sys.is_cli_cancel():
+ p = 0
+ # ensure correct order
+ hlst['data'] = sorted(hlst['data'], key=lambda lst: lst[0])
+
+ if dirs is not None and dirs!='none' :
+ dirPath = Sys.join(self.DIR_DEPLOY,dirs)+Sys.sep
+ Sys.mkdir_p(dirPath)
+ else: dirPath = self.DIR_DEPLOY
+ filePath = dirPath+fileName
+ if Io.file_exists(filePath+ext):
+ filePath += '-'+str(uid)
+ filePath = Sys.abspath(filePath+ext)
+ depDir = self.DIR_INBOX if not fake else self.DIR_OUTBOX
+ perc = 10
+ frav = 2.7
+ with Io.wfile(filePath) as fo :
+ while p < hlst['head'][1] :
+ perc += 0.5
+ Sys.cli_emit_progress(perc)
+ try:
+ self.mergePart(fo, hlst['data'][p], depDir)
+ except Exception as e:
+ Sys.pwarn((('merge : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), True)
+ raise e
+ perc += frav
+ Sys.cli_emit_progress(perc)
+ p += 1
+ return filePath
+
+
+ @Log()
+ def mergePart(self, fo, phlst, depDir):
+ """"""
+ if not Sys.is_cli_cancel():
+ with Io.rfile(depDir+phlst[1]+self.EXT) as fi:
+ part, head = int(phlst[0]), fi.read(self.kh.POS_END)
+ fo.write(Io.gzdecompress(self.deoffuscate(Io.str(fi.read(int(fi.read(3))-part)), part) + fi.read())[phlst[2]-self.kh.POS_END:-phlst[3]])
+ Sys.removeFile(depDir+phlst[1]+self.EXT)
+
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ # # ENCRYPT # #
+
+ @Log()
def encrypt_sp_start(self, fromPath, toPath, header=None):
""""""
- if header is not None :
- self.kh = header
- fsize = Sys.getsize(fromPath)
- if fsize > 0 :
- strh = self.kh.buildHeader(fsize)
- decHeader = self.kh.readHeader(strh)
- self.tmpPath1 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp'
- self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2'
- compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL
- fp, tp = fromPath, self.tmpPath1
-
- self.compress_start(fp, tp, compstart)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
- return fp, tp, decHeader['rmode'], decHeader['mmode'], compend
-
- @log
- def encrypt_sp_end(self, fp, tp, toPath, rmode, mmode, compend):
- """"""
- if rmode :
- #~ self.mpRandomFileContent(fp, tp, 4)
- self.randomFileContent(fp, tp)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
-
- if mmode :
- self.mixdata(fp, tp, True)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
-
- self.compress_end(fp, toPath, compend)
-
- # clean tmp files
- try :
- Sys.removeFile(self.tmpPath1)
- Sys.removeFile(self.tmpPath2)
- except:
- pass
-
- @log
- def prepare_mproc_encode(self, fp, nproc):
- """"""
- self.mproc_fsize = []
- fsize = Sys.getsize(fp)
- chsize = (fsize//nproc)+1
- if fsize % chsize == 0 : chsize -= 1
-
- hsltPaths = []
- with Io.rfile(fp) as fi :
- for pdata, part in Io.read_in_chunks(fi, chsize):
- self.mproc_fsize.append(len(pdata))
- Io.set_data('kmp_'+str(Sys.getpid())+'_'+str(part), pdata, True)
- hsltPaths.append('kmpenc_'+str(Sys.getpid())+'_'+str(part))
- return hsltPaths
-
- @log
- def mproc_encode_part(self, part, ppid):
- mpfile, mpfilenc = 'kmp_'+str(ppid)+'_'+str(part), 'kmpenc_'+str(ppid)+'_'+str(part)
- self.encryptToFile(mpfile, mpfilenc, self.getSubStartIndice(part))
- Sys.removeFile(mpfile)
-
- @log
- def encrypt_mproc(self, fp, tp, nproc=1):
- """"""
- if nproc == 1 :
- self.encryptToFile(fp, tp)
- else :
- hsltPaths = self.prepare_mproc_encode(fp, nproc)
- for part in range(nproc):
- self.mproc_encode_part(part)
- self.mpMergeFiles(hsltPaths, tp)
-
- @log
- def encrypt(self, fromPath, toPath, header=None):
- """"""
- fp, tp, rmode, mmode, compend = self.encrypt_sp_start(fromPath, toPath, header)
-
- self.encrypt_mproc(fp, tp)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
-
- self.encrypt_sp_end(fp, tp, toPath, rmode, mmode, compend)
-
- @log
- def decrypt_sp_start(self, fromPath, toPath):
- """"""
- if Sys.getsize(fromPath) > 0 :
- self.tmpPath1 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp'
- self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2'
+ if not Sys.is_cli_cancel():
+ if header is not None :
+ self.kh = header
fsize = Sys.getsize(fromPath)
- fsize -= self.kh.POS_END
- with Io.rfile(fromPath) as f :
- decHeader = self.kh.readHeader(f.read(self.kh.POS_END))
- #~ print(decHeader)
- if len(decHeader) > 0 :
- if decHeader['smode'] == self.mark[fsize%len(self.mark)] :
- #~ print('ok valid')
- """"""
- else : raise BadKeyException()
+ if fsize > 0 :
+ strh = self.kh.buildHeader(fsize)
+ decHeader = self.kh.readHeader(strh)
+ self.tmpPath1 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp'
+ self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2'
compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL
fp, tp = fromPath, self.tmpPath1
- self.uncompress_end(fp, tp, compend)
+ self.compress_start(fp, tp, compstart)
fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
-
- if decHeader['mmode'] :
- self.unmixdata(fp, tp)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
- if decHeader['rmode'] :
- self.unRandomFileContent(fp, tp)
- fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
- return fp, tp, compstart
+ return fp, tp, decHeader['rmode'], decHeader['mmode'], compend
- @log
+
+ @Log()
+ def encrypt_sp_end(self, fp, tp, toPath, rmode, mmode, compend):
+ """"""
+ if not Sys.is_cli_cancel():
+ if rmode :
+ #~ self.mpRandomFileContent(fp, tp, 4)
+ self.randomFileContent(fp, tp)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+
+ if mmode :
+ self.mixdata(fp, tp, True)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+
+ self.compress_end(fp, toPath, compend)
+
+ # clean tmp files
+ try :
+ Sys.removeFile(self.tmpPath1)
+ Sys.removeFile(self.tmpPath2)
+ except:
+ pass
+
+
+ @Log()
+ def prepare_mproc_encode(self, fp, nproc):
+ """"""
+ if not Sys.is_cli_cancel():
+ self.mproc_fsize = []
+ fsize = Sys.getsize(fp)
+ chsize = (fsize//nproc)+1
+ if fsize % chsize == 0 : chsize -= 1
+
+ hlstPaths = []
+ with Io.rfile(fp) as fi :
+ for pdata, part in Io.read_in_chunks(fi, chsize):
+ self.mproc_fsize.append(len(pdata))
+ Io.set_data(self.KMP_FILE+'_'+str(Sys.getpid())+'_'+str(part), pdata, True)
+ hlstPaths.append(self.KMP_FILE+'enc_'+str(Sys.getpid())+'_'+str(part))
+ return hlstPaths
+
+
+ @Log()
+ def mproc_encode_part(self, id, lock=None):
+ """"""
+ 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)
+ self.encryptToFile(mpfile, mpfilenc, self.getSubStartIndice(id), lock)
+ Sys.removeFile(mpfile)
+
+
+ @Log()
+ def encrypt_mproc(self, fp, tp, nproc=1):
+ """"""
+ if not Sys.is_cli_cancel():
+ if nproc == 1 :
+ self.encryptToFile(fp, tp)
+ else :
+ hlstPaths = self.prepare_mproc_encode(fp, nproc)
+ mg = Manager(self.mproc_encode_part, nproc, None, Sys.g.MPRLOCK)
+ mg.run()
+ self.mpMergeFiles(hlstPaths, tp)
+
+
+ @Log()
+ def encrypt(self, fromPath, toPath, nproc=1, header=None):
+ """"""
+ if not Sys.is_cli_cancel():
+ fp, tp, rmode, mmode, compend = self.encrypt_sp_start(fromPath, toPath, header)
+
+ self.encrypt_mproc(fp, tp, nproc)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+
+ self.encrypt_sp_end(fp, tp, toPath, rmode, mmode, compend)
+
+
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+ # # DECRYPT # #
+
+ @Log()
+ def decrypt_sp_start(self, fromPath, toPath):
+ """"""
+ if not Sys.is_cli_cancel():
+ if Sys.getsize(fromPath) > 0 :
+ self.tmpPath1 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp'
+ self.tmpPath2 = self.DIR_TEMP + Sys.basename(fromPath) + '.tmp2'
+ fsize = Sys.getsize(fromPath)
+ fsize -= self.kh.POS_END
+ with Io.rfile(fromPath) as f :
+ decHeader = self.kh.readHeader(f.read(self.kh.POS_END))
+ print(decHeader)
+ if len(decHeader) > 0 :
+ if decHeader['smode'] == self.mark[fsize%len(self.mark)] :
+ #~ print('ok valid')
+ """"""
+ else : raise BadKeyException()
+ compend, compstart = not decHeader['cmode']== KirmahHeader.COMP_NONE, decHeader['cmode']== KirmahHeader.COMP_ALL
+ fp, tp = fromPath, self.tmpPath1
+
+ self.uncompress_end(fp, tp, compend)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+
+ if decHeader['mmode'] :
+ self.unmixdata(fp, tp)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+ if decHeader['rmode'] :
+ self.unRandomFileContent(fp, tp)
+ fp, tp = tp, self.tmpPath2 if tp == self.tmpPath1 else self.tmpPath1
+ return fp, tp, compstart
+
+
+ @Log()
def decrypt_sp_end(self, fromPath, toPath, compstart):
""""""
- self.uncompress_start(fromPath, toPath, compstart)
- try :
- Sys.removeFile(self.tmpPath1)
- Sys.removeFile(self.tmpPath2)
- except:
- pass
+ if not Sys.is_cli_cancel():
+ self.uncompress_start(fromPath, toPath, compstart)
+ try :
+ Sys.removeFile(self.tmpPath1)
+ Sys.removeFile(self.tmpPath2)
+ except:
+ pass
- @log
+
+ @Log()
def decrypt_mproc(self, fromPath, toPath, nproc=1):
""""""
- if nproc == 1 :
- self.decryptToFile(fromPath, toPath)
- else :
- hsltPaths = self.prepare_mproc_decode(fromPath, nproc)
- for part in range(nproc):
- self.mproc_decode_part(part, Sys.getpid())
- self.mpMergeFiles(hsltPaths, toPath)
+ if not Sys.is_cli_cancel():
+ if nproc == 1 :
+ self.decryptToFile(fromPath, toPath)
+ else :
+ hlstPaths = self.prepare_mproc_decode(fromPath, nproc)
+ mg = Manager(self.mproc_decode_part, nproc, None, Sys.g.MPRLOCK)
+ mg.run()
+ self.mpMergeFiles(hlstPaths, toPath)
- @log
+
+ @Log()
def prepare_mproc_decode(self, fp, nproc):
""""""
- self.mproc_fsize = []
- fsize = Sys.getsize(fp)
- chsize = (fsize//nproc)+1
- if fsize % chsize == 0 : chsize -= 1
+ if not Sys.is_cli_cancel():
+ self.mproc_fsize = []
+ fsize = Sys.getsize(fp)
+ chsize = (fsize//nproc)+1
+ if fsize % chsize == 0 : chsize -= 1
- hsltPaths = []
- with Io.rfile(fp) as fi :
- content = ''
- for pdata, part in Io.read_in_chunks(fi, chsize, True):
- content = Io.str(pdata)
- self.mproc_fsize.append(len(content))
- Io.set_data('kmp_'+str(Sys.getpid())+'_'+str(part), content)
- hsltPaths.append('kmpdec_'+str(Sys.getpid())+'_'+str(part))
+ hlstPaths = []
+ with Io.rfile(fp) as fi :
+ content = ''
+ for pdata, part in Io.read_in_chunks(fi, chsize, True):
+ content = Io.str(pdata)
+ self.mproc_fsize.append(len(content))
+ Io.set_data(self.KMP_FILE+'_'+str(Sys.getpid())+'_'+str(part), content)
+ hlstPaths.append(self.KMP_FILE+'dec_'+str(Sys.getpid())+'_'+str(part))
- return hsltPaths
-
- @log
- def mproc_decode_part(self, part, ppid):
- mpfile, mpfiledec = 'kmp_'+str(ppid)+'_'+str(part), 'kmpdec_'+str(ppid)+'_'+str(part)
- self.decryptToFile(mpfile, mpfiledec, self.getSubStartIndice(part))
- Sys.removeFile(mpfile)
+ return hlstPaths
- @log
- def decrypt(self, fromPath, toPath):
+ @Log()
+ def mproc_decode_part(self, id):
""""""
- fp, tp, compstart = self.decrypt_sp_start(fromPath, toPath)
- self.decrypt_mproc(fp, tp)
- self.decrypt_sp_end(tp, toPath, compstart)
+ 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)
+ self.decryptToFile(mpfile, mpfiledec, self.getSubStartIndice(id))
+ Sys.removeFile(mpfile)
+ @Log()
+ def decrypt(self, fromPath, toPath, nproc=1):
+ """"""
+ if not Sys.is_cli_cancel():
+ fp, tp, compstart = self.decrypt_sp_start(fromPath, toPath)
+ self.decrypt_mproc(fp, tp, nproc)
+ self.decrypt_sp_end(tp, toPath, compstart)
+
+
+ @Log(Const.LOG_DEBUG)
def offuscate(self, data, index):
""""""
- adata, lim = [], len(data)
- for i, c in enumerate((self.mark2)[index:]) :
- if i >= lim : break
- d = ord(c) + data[i]
- adata.append(chr(d))
- return ''.join(adata)
+ if not Sys.is_cli_cancel():
+ adata, lim = [], len(data)
+ for i, c in enumerate((self.mark2)[index:]) :
+ if i >= lim : break
+ d = ord(c) + data[i]
+ adata.append(chr(d))
+ return ''.join(adata)
+
+ @Log(Const.LOG_DEBUG)
def deoffuscate(self, adata, index):
""""""
- data, lim = [], len(adata)
- for i, c in enumerate((self.mark2)[index:]) :
- if i >= lim : break
- d = ord(adata[i]) - ord(c)
- data.append(d)
- return bytes(bytearray(data))
+ if not Sys.is_cli_cancel():
+ data, lim = [], len(adata)
+ for i, c in enumerate((self.mark2)[index:]) :
+ if i >= lim : break
+ d = ord(adata[i]) - ord(c)
+ data.append(d)
+ return bytes(bytearray(data))
+
@staticmethod
- @log
+ @Log(Const.LOG_DEBUG)
def getSizes(fromPath):
+ #~ if not Sys.is_cli_cancel():
fsize = Sys.getsize(fromPath)
s = (22,44,122,444,1222,14444,52222,244444,522222,1444444)
a = (2,3,7,9,21,33,87,151,427)
@@ -894,10 +1049,12 @@ class Kirmah:
chsize *= 3
return fsize, chsize, ceil(fsize/chsize)
+
@staticmethod
- @log
+ @Log()
def getRandomListFromKey(key, size):
""""""
+ #~ if not Sys.is_cli_cancel():
j, ok, lk, r, ho, hr, lv, hv, rev = 0, False, len(key), None, [], [], 0, size-1, False
for i in range(size) :
if j >= lk : j = 0
@@ -917,14 +1074,20 @@ class Kirmah:
rev = not rev
return Kirmah.getSimulRandomList(ho, Kirmah.getSimulNumber(key, size//5 if not size//5==0 else size*2, size//10 if not size//10 ==0 else size))
- @staticmethod
- def getSimulRandomList(lst, chsize):
- """"""
- return Kirmah._getSimulRandomList(list(reversed(Kirmah._getSimulRandomList(Kirmah._getSimulRandomList(lst, chsize), 4))),4)
@staticmethod
+ @Log(Const.LOG_DEBUG)
+ def getSimulRandomList(lst, chsize):
+ """"""
+ #~ if not Sys.is_cli_cancel():
+ return Kirmah._getSimulRandomList(list(reversed(Kirmah._getSimulRandomList(Kirmah._getSimulRandomList(lst, chsize), 4))),4)
+
+
+ @staticmethod
+ @Log(Const.LOG_PRIVATE)
def _getSimulRandomList(lst, chsize):
- """"""
+ """"""
+ #~ if not Sys.is_cli_cancel():
size, rlst, pos = len(lst), [], 0
if chsize > 0 :
for i in range(chsize+1):
@@ -933,11 +1096,14 @@ class Kirmah:
if pos in lst and not lst[pos] in rlst:
rlst.append(lst[pos])
else : rlst = lst
- return rlst
-
+ return rlst
+
+
@staticmethod
+ @Log(Const.LOG_DEBUG)
def getSimulNumber(key, lim, delta=12):
""""""
+ #~ if not Sys.is_cli_cancel():
s = 0
for c in key[::-1] :
if represents_int(chr(c)): c = int(chr(c))
@@ -945,6 +1111,8 @@ class Kirmah:
s += c
return s
+
+ @Log(Const.LOG_DEBUG)
def getSubStartIndice(self, idx):
""""""
return sum([ s for j, s in enumerate(self.mproc_fsize) if j < idx ])%len(self.key)
@@ -956,18 +1124,23 @@ class Kirmah:
class Randomiz:
""""""
-
+
+ @Log(Const.LOG_BUILD)
def __init__(self,count,chl=None):
""""""
if chl ==None : self.lst = list(range(0,count))
else: self.lst = chl
self.count = len(self.lst)
-
+
+
+ @Log(Const.LOG_DEBUG)
def new(self,count=None, chl=None):
""""""
if count : self.count = count
self.__init__(self.count,chl)
-
+
+
+ @Log(Const.LOG_NEVER)
def get(self,single=True):
""""""
pos = choice(self.lst)
@@ -980,13 +1153,14 @@ class Randomiz:
# ~~ class Noiser ~~
class Noiser:
- """"""
+ @Log(Const.LOG_BUILD)
def __init__(self, key, part=0):
""""""
self.key = key
self.build(part)
+ @Log(Const.LOG_DEBUG)
def build(self, part, vord=22):
""""""
if not part < len(self.key)-1 : raise Exception('part exceed limit')
@@ -998,6 +1172,7 @@ class Noiser:
if self.lns < 24 : self.lns += 24
if self.lne < 10 : self.lne += 10
+ @Log(Const.LOG_DEBUG)
def getNoise(self, l, b64encode=True, noBytes=False):
""""""
n = urandom(l)
diff --git a/kirmah/gui.py b/kirmah/gui.py
new file mode 100644
index 0000000..726c961
--- /dev/null
+++ b/kirmah/gui.py
@@ -0,0 +1,415 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah.gui.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module gui ~~
+
+from gi.repository import Gtk, GObject, GLib, Gdk, Pango
+from os import sep, remove
+from os.path import abspath, dirname, join, realpath, basename, getsize, isdir, splitext
+from base64 import b64decode, b64encode
+from time import time, sleep
+from getpass import getuser as getUserLogin
+from mmap import mmap
+from math import ceil
+from threading import Thread, Event, Timer, Condition, RLock, current_thread, get_ident, enumerate as thread_enum
+
+from kirmah.crypt import KeyGen, Kirmah, KirmahHeader, ConfigKey, BadKeyException, b2a_base64, a2b_base64, hash_sha256_file
+from kirmah.app import KirmahApp, FileNotFoundException, FileNeedOverwriteException
+from kirmah.ui import Gui, CliThread
+from kirmah import conf
+from psr.sys import Sys, Io, Const
+from psr.log import Log
+from psr.mproc import Manager, Lock
+import pdb
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class AppGui ~~
+
+class AppGui(Gui):
+
+ DEFAULT_KEY = 0
+ EXISTING_KEY = 1
+ NEW_KEY = 2
+
+ IS_SOURCE_DEF = False
+ IS_DEST_DEF = True
+
+ MODE_CRYPT = True
+ COMPRESSION = True
+ NPROC = 2
+ PROCEED = False
+
+ curKey = 0
+ start = False
+ poslog = 0
+
+
+ @Log(Const.LOG_BUILD)
+ def __init__(self, wname='window1'):
+ """"""
+ self.app = KirmahApp(conf.DEBUG, conf.PCOLOR)
+ super().__init__(wname)
+
+
+ @Log(Const.LOG_UI)
+ def on_start(self):
+ """"""
+ self.app.createDefaultKeyIfNone()
+ key, size, mark = self.app.getKeyInfos()
+
+ self.curKey = self.DEFAULT_KEY
+ self.get('filechooserbutton1').set_filename(self.app.getDefaultKeyPath())
+ self.get('filechooserbutton3').set_current_folder(conf.DEFVAL_USER_PATH)
+ devPath = '/home/dev/git_repos/kirmah2.15/'
+ #~ self.get('filechooserbutton3').set_current_folder(devPath)
+ self.get('checkbutton1').set_active(conf.DEFVAL_NPROC>=2)
+ self.get('checkbutton3').set_active(True)
+ self.get('checkbutton4').set_active(True)
+ self.get('spinbutton2').set_value(conf.DEFVAL_NPROC)
+ if conf.DEFVAL_NPROC >= 2:
+ self.disable('spinbutton2', False)
+ self.get('checkbutton2').set_active(conf.DEFVAL_MIXMODE)
+ self.get('checkbutton4').set_active(conf.DEFVAL_RANDOMMODE)
+ self.get('entry1').set_text(mark)
+
+ Sys.g.UI_AUTO_SCROLL = True
+ self.textview = self.get('textview1')
+ 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.textbuffer = self.textview.get_buffer()
+ self.tags = self.buildTxtTags(self.textbuffer)
+ self.progressbar = self.get('progressbar1')
+ cbt = self.get('comboboxtext1')
+ cbt.connect("changed", self.on_compression_changed)
+ tree_iter = cbt.get_model().get_iter_first()
+ print(cbt.get_model().get_string_from_iter(tree_iter))
+ tree_iter = cbt.get_model().get_iter_from_string('3')
+ cbt.set_active_iter(tree_iter)
+ cbt = self.get('comboboxtext2')
+ cbt.connect("changed", self.on_logging_changed)
+ tree_iter = cbt.get_model().get_iter_first()
+ cbt.set_active_iter(tree_iter)
+ Sys.clear()
+ Sys.dprint('INIT UI')
+ self.start = True
+ self.thkmh = None
+
+
+ @Log(Const.LOG_UI)
+ def launch_thread(self, *args):
+ self.progressbar.show()
+ def getKmhThread(on_completed, on_interrupted, on_progress, userData, *args):
+ thread = CliThread(*args)
+ thread.connect("completed" , on_completed , userData)
+ thread.connect("interrupted", on_interrupted , userData)
+ thread.connect("progress" , on_progress , userData)
+ return thread
+ cliargs = ['kirmah-cli.py', 'split', '-df', '/media/Hermes/webbakup/The Raven.avi', '-z', '-r', '-m', '-o', '/home/dev/git_repos/kirmah2.15/The Raven.avi.kmh']
+ cliargs = self.app.getCall()
+ self.thkmh = getKmhThread(self.thread_finished, self.thread_interrupted, self.thread_progress, None, cliargs)
+ self.thkmh.start()
+
+
+ @Log(Const.LOG_UI)
+ def on_mixdata_changed(self, checkbox):
+ """"""
+ self.app.setMixMode(not checkbox.get_active())
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_randomdata_changed(self, checkbox):
+ """"""
+ self.app.setRandomMode(not checkbox.get_active())
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_multiproc_changed(self, checkbox, data = None):
+ """"""
+ disabled = checkbox.get_active()
+ self.disable('spinbutton2',disabled)
+ self.app.setMultiprocessing(int(self.get('spinbutton2').get_value()) if not disabled else 0)
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_logging_changed(self, combo):
+ """"""
+ tree_iter = combo.get_active_iter()
+ if tree_iter != None:
+ v = combo.get_model()[tree_iter][:2][0]
+ if v =='DISABLED' :
+ Sys.g.DEBUG = False
+ elif hasattr(Const, v):
+ Sys.g.DEBUG = True
+ exec('Sys.g.LOG_LEVEL = Const.'+v)
+ else :
+ Sys.g.LOG_LEVEL = Const.LOG_DEFAULT
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_DEFAULT)
+ def on_compression_changed(self, combo):
+ tree_iter = combo.get_active_iter()
+ if tree_iter != None:
+ model = combo.get_model()
+ comp = KirmahHeader.COMP_END if model[tree_iter][:2][0]=='yes' else (KirmahHeader.COMP_NONE if model[tree_iter][:2][0]=='no' else KirmahHeader.COMP_ALL)
+ print(comp)
+ self.app.setCompression(comp)
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_nproc_changed(self, spin):
+ """"""
+ self.app.setMultiprocessing(int(spin.get_value()))
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_keylen_changed(self, spin):
+ """"""
+ filename = self.get('filechooserbutton1').get_filename()
+ if Io.file_exists(filename):
+ self.app.createNewKey(filename, int(self.get('spinbutton1').get_value()))
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_new_file_key(self, fc):
+ """"""
+ filename = fc.get_filename()
+ if self.curKey == self.NEW_KEY:
+ self.app.createNewKey(filename, int(self.get('spinbutton1').get_value()))
+ self.app.selectKey(filename)
+ k, s, m = self.app.getKeyInfos(filename)
+ self.get('spinbutton1').set_value(s)
+ self.get('entry1').set_text(m)
+ self.get('filechooserbutton1').set_filename(filename)
+ if self.curKey == self.NEW_KEY:
+ self.get('radiobutton2').set_active(True)
+ self.disable('spinbutton1', True)
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_switch_mode(self, s, data):
+ """"""
+ self.app.switchEncMode(not s.get_active())
+ if not self.app.splitmode :
+ for n in ['checkbutton2','checkbutton4','comboboxtext1','label12']:
+ self.disable(n, not self.app.encmode)
+ self.on_new_file_dest(self.get('filechooserbutton3'))
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_switch_format(self, s, data):
+ """"""
+ self.app.switchFormatMode(not s.get_active())
+ if self.app.encmode :
+ for n in ['checkbutton1', 'spinbutton2', 'checkbutton2','checkbutton4','comboboxtext1','label12']:
+ self.disable(n, self.app.splitmode)
+ if not s.get_active() :
+ self.get('label8').set_text('encrypt')
+ self.get('label9').set_text('decrypt')
+ self.get('checkbutton1').set_sensitive(True)
+ self.get('spinbutton2').set_sensitive(True)
+ else :
+ self.get('label8').set_text('split')
+ self.get('label9').set_text('merge')
+ self.get('checkbutton1').set_sensitive(False)
+ self.get('spinbutton2').set_sensitive(False)
+ if self.start: self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_new_file_source(self, fc, data=None):
+ """"""
+ try:
+ self.app.setSourceFile(fc.get_filename())
+ self.IS_SOURCE_DEF = True
+ self.on_new_file_dest(self.get('filechooserbutton3'))
+ except FileNotFoundException as e:
+ Sys.eprint('FileNotFoundException :' + str(fc.get_filename()), Const.ERROR)
+ self.IS_SOURCE_DEF = False
+
+
+ @Log(Const.LOG_UI)
+ def on_dest_changed(self, fc, data=None):
+ """"""
+ self.on_new_file_dest(fc, data)
+
+
+ @Log(Const.LOG_UI)
+ def on_new_file_dest(self, fc, data=None):
+ """"""
+ if self.start:
+ try :
+ self.app.setDestFile(fc.get_filename())
+ except :
+ pass
+ self.IS_DEST_DEF = True
+ self.refreshProceed()
+
+
+ @Log(Const.LOG_UI)
+ def on_existing_key(self, button):
+ """"""
+ self.curKey = self.EXISTING_KEY
+ self.disable('spinbutton1',True)
+ self.disable('filechooserbutton1',False)
+ self.get('filechooserbutton1').set_filename(self.app.kpath)
+ fc = self.get('filechooserbutton1')
+ self.on_new_file_key(fc)
+
+
+ @Log(Const.LOG_UI)
+ def on_new_key(self, button):
+ """"""
+ self.curKey = self.NEW_KEY
+ self.disable('spinbutton1',False)
+ self.disable('filechooserbutton1',False)
+ self.get('filechooserbutton1').set_current_folder(conf.DEFVAL_UKEY_PATH)
+
+
+ @Log(Const.LOG_UI)
+ def on_default_key(self, button):
+ """"""
+ self.curKey = self.DEFAULT_KEY
+ self.disable('spinbutton1',True)
+ self.disable('filechooserbutton1',True)
+ fc = self.get('filechooserbutton1')
+ fc.set_filename(self.app.getDefaultKeyPath())
+ self.on_new_file_key(fc)
+
+
+ @Log(Const.LOG_UI)
+ def on_autoscroll_changed(self, btn):
+ """"""
+ Sys.g.UI_AUTO_SCROLL = not btn.get_active()
+
+
+ @Log(Const.LOG_NEVER)
+ def clear_log(self, btn):
+ """"""
+ self.textbuffer.set_text('')
+
+
+ @Log(Const.LOG_UI)
+ def show_log(self):
+ """"""
+ btn = self.get('button1')
+ if not self.PROCEED :
+ self.get('frame3').hide()
+ self.get('frame1').show()
+ self.get('frame2').show()
+ self.get('checkbutton3').hide()
+ self.repack('frame4', True)
+ btn.set_sensitive(self.IS_DEST_DEF and self.IS_SOURCE_DEF)
+
+ else :
+ self.repack('frame4', False)
+ self.get('frame1').hide()
+ self.get('frame2').hide()
+ self.get('frame3').show()
+ self.get('checkbutton3').show()
+ if btn.get_label() == conf.GUI_LABEL_PROCEED :
+ btn.set_sensitive(False)
+
+
+ @Log(Const.LOG_UI)
+ def refreshProceed(self):
+ """"""
+ if self.start :
+ self.get('button1').set_sensitive(self.IS_DEST_DEF and self.IS_SOURCE_DEF)
+
+
+ @Log(Const.LOG_UI)
+ def on_proceed(self, btn):
+ """"""
+ if btn.get_label() == conf.GUI_LABEL_OK :
+ btn = self.get('button1')
+ btn.set_label(conf.GUI_LABEL_PROCEED)
+ self.PROCEED = False
+ self.pb.hide()
+ self.show_log()
+
+ else :
+ if not self.PROCEED :
+ self.list_threads()
+ self.PROCEED = True
+ self.STOPPED = False
+ btn.set_sensitive(False)
+ self.pb = self.get('progressbar1')
+ self.pb.set_fraction(0)
+ self.pb.show()
+ self.pb.pulse()
+ if not Io.file_exists(self.app.dst) or self.warnDialog('file '+self.app.dst+' already exists', 'Overwrite file ?'):
+ btn.set_sensitive(True)
+ btn.set_label(conf.GUI_LABEL_CANCEL)
+ self.clear_log(self.get('checkbutton3'))
+ self.show_log()
+ self.launch_thread()
+ else :
+ self.on_proceed_end(True)
+ else :
+ self.halt_thread()
+
+
+ @Log(Const.LOG_UI)
+ def halt_thread(self, *args):
+ Sys.wlog(Sys.dprint())
+ Sys.pwarn(('thread interrupt',), False)
+ self.get('button1').set_sensitive(False)
+ if self.thkmh is not None and self.thkmh.isAlive():
+ self.thkmh.cancel()
+ else :
+ self.textbuffer.insert_at_cursor('Kmh Thread is not Alive\n')
+
+
+ @Log(Const.LOG_UI)
+ def on_proceed_end(self, abort=False):
+ """"""
+ try :
+ btn = self.get('button1')
+ btn.set_label('Proceed')
+ btn.set_sensitive(True)
+ self.PROCEED = False
+ btn.set_label(conf.GUI_LABEL_OK)
+ self.get('checkbutton3').hide()
+
+ except Exception as e:
+ Sys.pwarn((('on_proceed_end : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),), False)
+ pass
+ return False
diff --git a/kirmah/ui.py b/kirmah/ui.py
new file mode 100644
index 0000000..a357752
--- /dev/null
+++ b/kirmah/ui.py
@@ -0,0 +1,362 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# kirmah/ui.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module ui ~~
+
+from gi.repository import Pango
+from gi.repository.Gdk import threads_enter, threads_leave
+from gi.repository.Gtk import AboutDialog, Builder, main as main_enter, main_quit, MessageDialog, MessageType, ButtonsType, ResponseType, PackType
+from gi.repository.GdkPixbuf import Pixbuf
+from gi.repository.GObject import threads_init, GObject, idle_add, SIGNAL_RUN_LAST, TYPE_NONE, TYPE_STRING, TYPE_FLOAT, TYPE_BOOLEAN
+from threading import Thread, current_thread, enumerate as thread_enum
+from psr.sys import Sys, Io, Const
+from psr.log import Log
+from kirmah import conf
+from kirmah.cli import Cli
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class Gui ~~
+
+class Gui():
+
+
+ @Log(Const.LOG_BUILD)
+ def __init__(self, wname):
+ """"""
+ threads_init()
+ self.wname = wname
+ self.builder = Builder()
+ self.builder.add_from_file(conf.PRG_GLADE_PATH)
+ self.builder.connect_signals(self)
+ self.win = self.get(wname)
+ self.win.connect('destroy', self.onDeleteWindow)
+ self.win.connect('delete-event', self.onDeleteWindow)
+ self.win.set_title(conf.PRG_NAME+' v'+conf.PRG_VERS)
+ self.win.show_all()
+ self.on_start()
+ main_enter()
+
+
+ @Log(Const.LOG_DEBUG)
+ def buildTxtTags(self, textbuffer):
+ tags = {}
+ tags[Const.CLZ_TIME] = textbuffer.create_tag(Const.CLZ_TIME , foreground="#208420", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_SEC] = textbuffer.create_tag(Const.CLZ_SEC , foreground="#61B661", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_DEFAULT] = textbuffer.create_tag(Const.CLZ_DEFAULT , foreground="#FFEDD0")
+ tags[Const.CLZ_IO] = textbuffer.create_tag(Const.CLZ_IO , foreground="#EB3A3A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_FUNC] = textbuffer.create_tag(Const.CLZ_FUNC , foreground="#EBEB3A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_CFUNC] = textbuffer.create_tag(Const.CLZ_CFUNC , foreground="#EBB33A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_DELTA] = textbuffer.create_tag(Const.CLZ_DELTA , foreground="#397BE8", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_ARGS] = textbuffer.create_tag(Const.CLZ_ARGS , foreground="#A1A1A1")
+ tags[Const.CLZ_ERROR] = textbuffer.create_tag(Const.CLZ_ERROR , background="#830005", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_ERROR_PARAM] = textbuffer.create_tag(Const.CLZ_ERROR_PARAM , background="#830005", foreground="#EBEB3A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_WARN] = textbuffer.create_tag(Const.CLZ_WARN , background="#A81459", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_WARN_PARAM] = textbuffer.create_tag(Const.CLZ_WARN_PARAM , background="#A81459", foreground="#EBEB3A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_PID] = textbuffer.create_tag(Const.CLZ_PID , background="#5B0997", foreground="#E4C0FF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_CPID] = textbuffer.create_tag(Const.CLZ_CPID , background="#770997", foreground="#F4CDFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_SYMBOL] = textbuffer.create_tag(Const.CLZ_SYMBOL , background="#61B661", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_OK] = textbuffer.create_tag(Const.CLZ_OK , background="#167B3B", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_KO] = textbuffer.create_tag(Const.CLZ_KO , background="#7B1716", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_TITLE] = textbuffer.create_tag(Const.CLZ_TITLE , foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_TASK] = textbuffer.create_tag(Const.CLZ_TASK , foreground="#61B661", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_HEAD_APP] = textbuffer.create_tag(Const.CLZ_HEAD_APP , background="#2B5BAB", foreground="#FFFFFF", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_HEAD_SEP] = textbuffer.create_tag(Const.CLZ_HEAD_SEP , foreground="#A1A1A1")
+ tags[Const.CLZ_HEAD_KEY] = textbuffer.create_tag(Const.CLZ_HEAD_KEY , foreground="#EBEB3A", weight=Pango.Weight.BOLD)
+ tags[Const.CLZ_HEAD_VAL] = textbuffer.create_tag(Const.CLZ_HEAD_VAL , foreground="#397BE8", weight=Pango.Weight.BOLD)
+ return tags
+
+
+ @Log(Const.LOG_UI)
+ def onDeleteWindow(self, *args):
+ """"""
+ mthread = current_thread()
+ try:
+ self.join_threads(True)
+ self.cleanResources()
+
+ except Exception as e:
+ pass
+
+ finally:
+ main_quit(*args)
+
+
+ @Log(Const.LOG_UI)
+ def list_threads(self):
+ """"""
+ print('thread list : ')
+ for th in thread_enum():
+ print(th)
+
+
+ @Log(Const.LOG_UI)
+ def join_threads(self, join_main=False):
+ """"""
+ mthread = current_thread()
+ try:
+ for th in thread_enum():
+ if th is not mthread :
+ th.join()
+ if join_main: mthread.join()
+
+ except Exception as e:
+ pass
+
+
+ @Log(Const.LOG_UI)
+ def on_about(self, btn):
+ """"""
+ about = AboutDialog()
+ about.set_program_name(conf.PRG_NAME)
+ about.set_version('v '+conf.PRG_VERS)
+ about.set_copyright(conf.PRG_ABOUT_COPYRIGHT)
+ about.set_comments(conf.PRG_ABOUT_COMMENTS)
+ about.set_website(conf.PRG_WEBSITE)
+ about.set_website_label(conf.PRG_WEBSITE)
+ about.set_license(Io.get_data(conf.PRG_LICENSE_PATH))
+ pixbuf = Pixbuf.new_from_file_at_size(conf.PRG_LOGO_PATH, conf.PRG_ABOUT_LOGO_SIZE, conf.PRG_ABOUT_LOGO_SIZE)
+ about.set_logo(pixbuf)
+ pixbuf = Pixbuf.new_from_file_at_size(conf.PRG_LOGO_PATH, conf.PRG_ABOUT_LOGO_SIZE, conf.PRG_ABOUT_LOGO_SIZE)
+ about.set_icon(pixbuf)
+ about.run()
+ about.destroy()
+
+
+ @Log(Const.LOG_DEBUG)
+ def get(self, name):
+ """"""
+ return self.builder.get_object(name)
+
+
+ @Log(Const.LOG_DEBUG)
+ def disable(self, name, disabled):
+ """"""
+ self.get(name).set_sensitive(not disabled)
+
+
+ @Log(Const.LOG_DEBUG)
+ def repack(self, name, expandfill=False, packStart=True):
+ w = self.get(name)
+ w.get_parent().set_child_packing(w, expandfill, expandfill, 0, PackType.START if packStart else PackType.END )
+ return w
+
+
+ @Log(Const.LOG_DEBUG)
+ def detachWidget(self, name, hideParent=True):
+ w = self.get(name)
+ wp = w.get_parent()
+ if wp is not None :
+ wp.remove(w)
+ w.unparent()
+ if hideParent : wp.hide()
+
+
+ @Log(Const.LOG_DEBUG)
+ def attachWidget(self, widget, parentName, expandfill=None, showParent=True):
+ if widget is not None :
+ wp = self.get(parentName)
+ if wp is not None :
+ if expandfill is None : wp.add(widget)
+ else :
+ wp.pack_start(widget,expandfill,expandfill,0)
+ if showParent : wp.show()
+
+
+ @Log(Const.LOG_UI)
+ def thread_finished(self, thread, ref):
+ thread = None
+ self.on_proceed_end(False)
+
+
+ @Log(Const.LOG_UI)
+ def on_proceed_end(self, abort=False):
+ """"""
+
+
+ @Log(Const.LOG_UI)
+ def thread_interrupted(self, thread, ref):
+ thread = None
+ self.end_progress()
+ self.on_proceed_end(False)
+
+
+ @Log(Const.LOG_NEVER)
+ def thread_progress(self, thread, progress, ref):
+ while not Sys.g.LOG_QUEUE.empty():
+ data = Sys.g.LOG_QUEUE.get()
+ if data is not None :
+ if data is not Sys.g.SIGNAL_STOP :
+ for item in data :
+ ei = self.textbuffer.get_end_iter()
+ offs = ei.get_offset()
+ self.textbuffer.insert_at_cursor(item[0])
+ ei = self.textbuffer.get_end_iter()
+ oi = self.textbuffer.get_iter_at_offset(offs)
+ tagName = item[1]
+ self.textbuffer.apply_tag(self.tags[tagName], oi, ei)
+ self.textbuffer.insert_at_cursor('\n')
+ self.scroll_end()
+ else :
+ Sys.dprint('STOP')
+ thread.cancel()
+ self.update_progress(progress)
+
+
+ @Log(Const.LOG_NEVER)
+ def update_progress(self, progress, lvl=50):
+ if progress > 0 :
+ self.progressbar.set_text(str(progress))
+ lp = self.progressbar.get_fraction()
+ diff = (progress/100.0 - lp)
+ for i in range(lvl):
+ nf = lp+(i*diff/lvl)
+ if nf < progress/100.0 :
+ self.progressbar.set_fraction(nf)
+ self.progressbar.set_fraction(progress/100.0)
+
+
+ @Log(Const.LOG_NEVER)
+ def end_progress(self):
+ self.update_progress(100, 10)
+
+
+ @Log(Const.LOG_NEVER)
+ def scroll_end(self):
+ if Sys.g.UI_AUTO_SCROLL :
+ if self.textbuffer is not None :
+ insert_mark = self.textbuffer.get_insert()
+ ei = self.textbuffer.get_end_iter()
+ if ei is not None and insert_mark is not None:
+ self.textbuffer.place_cursor(ei)
+ self.textview.scroll_to_mark(insert_mark , 0.0, True, 0.0, 1.0)
+
+
+ @Log(Const.LOG_UI)
+ def cleanResources(self):
+ """"""
+
+
+ @Log(Const.LOG_UI)
+ def on_start(self):
+ """"""
+
+
+ @Log(Const.LOG_UI)
+ def warnDialog(self, intro, ask):
+ """"""
+ dialog = MessageDialog(self.get(self.wname), 0, MessageType.WARNING, ButtonsType.OK_CANCEL, intro)
+ dialog.format_secondary_text(ask)
+ response = dialog.run()
+ dialog.destroy()
+ return response == ResponseType.OK;
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class IdleObject ~~
+
+class IdleObject(GObject):
+ """
+ Override gi.repository.GObject to always emit signals in the main thread
+ by emmitting on an idle handler
+ """
+
+ @Log(Const.LOG_UI)
+ def __init__(self):
+ """"""
+ GObject.__init__(self)
+
+
+ @Log(Const.LOG_NEVER)
+ def emit(self, *args):
+ """"""
+ idle_add(GObject.emit, self, *args)
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class CliThread ~~
+
+class CliThread(Thread, IdleObject):
+ """
+ Cancellable thread which uses gobject signals to return information
+ to the GUI.
+ """
+ __gsignals__ = { # signal type signal return signal args
+ "completed" : ( SIGNAL_RUN_LAST, TYPE_NONE, ()),
+ "interrupted" : ( SIGNAL_RUN_LAST, TYPE_NONE, ()),
+ "progress" : ( SIGNAL_RUN_LAST, TYPE_NONE, (TYPE_FLOAT,))
+ }
+
+
+ @Log(Const.LOG_DEBUG)
+ def __init__(self, rwargs):
+ Thread.__init__(self)
+ IdleObject.__init__(self)
+ self.setName('CliThread')
+ self.cliargs = rwargs
+
+
+ @Log(Const.LOG_DEBUG)
+ def run(self):
+ """"""
+ self.cancelled = False
+ print(Sys.g.LOG_LEVEL)
+ Cli('./', Sys.getpid(), self.cliargs, self, Sys.g.LOG_LEVEL)
+ self.emit("completed")
+
+
+ @Log(Const.LOG_NEVER)
+ def progress(self, value):
+ """"""
+ self.emit("progress", value)
+
+
+ @Log(Const.LOG_NEVER)
+ def cancel(self):
+ """
+ Threads in python are not cancellable, so we implement our own
+ cancellation logic
+ """
+ self.cancelled = True
+
+
+ @Log(Const.LOG_NEVER)
+ def stop(self):
+ """"""
+ if self.isAlive():
+ self.cancel()
+ if current_thread() .getName()==self.getName():
+ try:
+ self.emit("interrupted")
+ Sys.thread_exit()
+ except RuntimeError as e :
+ print(str(self.getName()) + ' COULD NOT BE TERMINATED')
+ raise e
diff --git a/psr/__init__.py b/psr/__init__.py
index 8b13789..b28b04f 100755
--- a/psr/__init__.py
+++ b/psr/__init__.py
@@ -1 +1,3 @@
+
+
diff --git a/psr/const.py b/psr/const.py
new file mode 100644
index 0000000..1630e92
--- /dev/null
+++ b/psr/const.py
@@ -0,0 +1,94 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/const.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module const ~~
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class Const ~~
+
+class Const:
+
+ LOG_NEVER = -1
+ LOG_ALL = 0
+ LOG_BUILD = 1
+ LOG_PRIVATE = 2
+ LOG_DEBUG = 3
+ LOG_WARN = 4
+ LOG_UI = 5
+ LOG_DEFAULT = 6
+ LOG_APP = 7
+
+ CLZ_TIME = 'time'
+ CLZ_SEC = 'sec'
+ CLZ_CPID = 'cpid'
+ CLZ_PID = 'pid'
+ CLZ_IO = 'io'
+ CLZ_FUNC = 'func'
+ CLZ_CFUNC = 'cfunc'
+ CLZ_ARGS = 'args'
+ CLZ_DELTA = 'delta'
+ CLZ_ERROR = 'error'
+ CLZ_ERROR_PARAM = 'errorp'
+ CLZ_WARN = 'warn'
+ CLZ_WARN_PARAM = 'warnp'
+ CLZ_DEFAULT = 'default'
+ CLZ_TITLE = 'title'
+ CLZ_OK = 'ok'
+ CLZ_KO = 'ko'
+ CLZ_TASK = 'task'
+ CLZ_SYMBOL = 'symbol'
+
+ CLZ_HEAD_APP = 'headapp'
+ CLZ_HEAD_SEP = 'headsep'
+ CLZ_HEAD_KEY = 'headkey'
+ CLZ_HEAD_VAL = 'headval'
+
+ ERROR = 'ERROR'
+ WARN = 'WARNING'
+ OK = 'OK'
+ KO = 'KO'
+
+ LOG_LIM_ARG_LENGTH = 20
+
+ LF = """
+"""
+ LF_STR = '\n'
+
+ UNIT_SHORT_B = 'B'
+ UNIT_SHORT_KIB = 'KiB'
+ UNIT_SHORT_MIB = 'MiB'
+ UNIT_SHORT_GIB = 'GiB'
+ UNIT_SHORT_TIB = 'TiB'
+
+ LINE_SEP_LEN = 100
+ LINE_SEP_CHAR = '―'
+
+const = Const()
diff --git a/psr/io.py b/psr/io.py
index 8219e3c..79c127c 100644
--- a/psr/io.py
+++ b/psr/io.py
@@ -1,31 +1,35 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/io.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module io ~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Io ~~
@@ -36,7 +40,7 @@ class Io:
from gzip import compress as gzcompress, decompress as gzdecompress
from bz2 import compress as bzcompress, decompress as bzdecompress
from errno import EEXIST
- from os import remove as removeFile, utime
+ from os import remove as removeFile, utime, rename
from mmap import mmap, PROT_READ
def __init__(self):
@@ -44,7 +48,8 @@ class Io:
@staticmethod
def read_in_chunks(f, chsize=1024, utf8=False):
- """Lazy function (generator) to read a file piece by piece.
+ """Lazy function (generator) to read a file piece by piece in
+ Utf-8 bytes
Default chunk size: 1k."""
c = 0
while True:
@@ -60,36 +65,40 @@ class Io:
if Io.is_utf8_start_sequence(ord(t)) :
delta += i
break
- f.seek(p)
+ f.seek(p)
data += f.read(delta)
- if not data : break
+ if not data : break
yield data, c
c += 1
-
+
+
@staticmethod
def read_utf8_chr(f, chsize=0, p=0):
""""""
- with Io.mmap(f.fileno(), chsize*p) as mmp:
+ with Io.mmap(f.fileno(), chsize*p) as mmp:
s, b, c = mmp.size(), b'', 0
while mmp.tell() < s :
b = mmp.read(1)
c = Io.count_utf8_continuation_bytes(b)
- if c > 0 : b += mmp.read(c)
+ if c > 0 : b += mmp.read(c)
yield str(b,'utf-8')
-
+
+
@staticmethod
def is_utf8_continuation_byte(b):
""""""
return b >= 0x80 and b <= 0xbf
+
@staticmethod
def is_utf8_start_sequence(b):
""""""
return (b >= 0x00 and b <= 0x7f) or (b>= 0xc2 and b <= 0xf4)
+
@staticmethod
def count_utf8_continuation_bytes(b):
- """"""
+ """"""
c = 0
try : d = ord(b)
except : d = int(b)
@@ -99,6 +108,7 @@ class Io:
else : c = 3
return c
+
@staticmethod
def get_data(path, binary=False, remove=False):
"""Get file content from `path`
@@ -111,13 +121,19 @@ class Io:
Io.removeFile(path)
return d
+
@staticmethod
def get_file_obj(path, binary=False, writing=False, update=False, truncate=False):
""""""
- if not writing :
+ if not writing :
f = open(path, mode='rt' if not binary else 'rb')
else :
- #~ if not Io.file_exists(path): Io.set_data(path, '#')
+ if update and not Io.file_exists(path):
+ if binary :
+ f = open(path, mode='wb')
+ else :
+ f = open(path, mode='wt', encoding='utf-8')
+ return f
m = ('w' if truncate else 'r')+('+' if update else '')+('b' if binary else 't')
if not binary :
f = open(path, mode=m, encoding='utf-8')
@@ -125,37 +141,43 @@ class Io:
f = open(path, mode=m)
return f
+
@staticmethod
def wfile(path, binary=True):
""""""
return Io.get_file_obj(path, binary, True, True, True)
+
@staticmethod
def ufile(path, binary=True):
""""""
return Io.get_file_obj(path, binary, True, True, False)
-
+
+
@staticmethod
def rfile(path, binary=True):
""""""
return Io.get_file_obj(path, binary)
+
@staticmethod
def set_data(path, content, binary=False):
""""""
with Io.wfile(path, binary) as f:
f.write(content)
+
@staticmethod
def readmmline(f, pos=0):
""""""
f.flush()
- with Io.mmap(f.fileno(), 0, prot=Io.PROT_READ) as mmp:
+ with Io.mmap(f.fileno(), 0, prot=Io.PROT_READ) as mmp:
mmp.seek(pos)
for line in iter(mmp.readline, b''):
pos = mmp.tell()
yield pos, Io.str(line[:-1])
+
@staticmethod
def copy(fromPath, toPath):
""""""
@@ -164,17 +186,20 @@ class Io:
with Io.wfile(toPath) as fo :
fo.write(fi.read())
else : raise Exception('can\t copy to myself')
-
+
+
@staticmethod
def bytes(sdata, encoding='utf-8'):
""""""
return bytes(sdata,encoding)
-
+
+
@staticmethod
def str(bdata, encoding='utf-8'):
""""""
return str(bdata,encoding) if isinstance(bdata, bytes) else str(bdata)
-
+
+
@staticmethod
def printableBytes(bdata):
""""""
@@ -182,17 +207,17 @@ class Io:
if isinstance(bdata,bytes) :
try:
data = Io.str(bdata)
- except Exception as e:
+ except Exception as e:
hexv = []
for i in bdata[1:] :
hexv.append(hex(i)[2:].rjust(2,'0'))
- #~ self.app.g.UI_TXTBUF.insert_at_cursor('\n')
data = ' '.join(hexv)
pass
else :
data = bdata
return bdata
-
+
+
@staticmethod
def is_binary(filename):
"""Check if given filename is binary."""
@@ -208,6 +233,7 @@ class Io:
f.close()
return done
+
@staticmethod
def file_exists(path):
""""""
@@ -218,9 +244,9 @@ class Io:
except IOError as e: pass
return exist
-
+
@staticmethod
def touch(fname, times=None):
- """"""
+ """ only existing files """
if Io.file_exists(fname):
Io.utime(fname, times)
diff --git a/psr/log.py b/psr/log.py
new file mode 100644
index 0000000..89d9731
--- /dev/null
+++ b/psr/log.py
@@ -0,0 +1,123 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/log.py
+# # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module log ~~
+
+try :
+ from inspect import signature
+except :
+ # < python 3.3
+ signature = None
+ pass
+
+from psr.sys import Sys, Const
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ Class Log ~~
+
+class Log:
+
+ def __init__(self, level=Const.LOG_DEFAULT, debug=True, wtime=True):
+ self.debug = debug
+ self.level = level
+ self.wtime = wtime
+
+ def __call__(self, func, *args):
+ def wrapped_func(*args, **kwargs):
+ debug, wtime = self.debug and Sys.g.DEBUG and self.level >= Sys.g.LOG_LEVEL, self.wtime and Sys.g.LOG_TIME
+ self.debug_start_time = None if not wtime else Sys.datetime.now()
+ if debug :
+ # >= python 3.3
+ if signature is not None :
+ l = [p.name for p in signature(func).parameters.values()]
+ # < python 3.3
+ # !! BAD FIX !!
+ else :
+ l = ['self' if args[0].__class__ is not None else '']
+
+ n = args+tuple(kwargs.items())
+ if len(n)>0 and l[0] == 'self':
+ n = n[1:]
+ s = args[0].__class__.__name__ +'.'+func.__name__
+ else:
+ s = func.__name__
+ Log._write(s, self.debug_start_time, True, n)
+ f = func(*args, **kwargs)
+ if debug :
+ Log._write(s, self.debug_start_time, False)
+ return f
+ return wrapped_func
+
+
+ @staticmethod
+ def _formatArgs(args):
+ """"""
+ args = list(args)
+ for i,a in enumerate(args) :
+ if not (isinstance(a, str) or isinstance(a, bytes)):
+ a = str(a)
+ if len(a) > Sys.g.LOG_LIM_ARG_LENGTH :
+ args[i] = a[:Sys.g.LOG_LIM_ARG_LENGTH]+'...' if isinstance(a, str) else b'...'
+ args = str(args)[1:-1]
+ if args[-1:] == ',' : args = args[:-1]
+ return args
+
+
+ @staticmethod
+ def _write(sign, t=None, enter=True, args=''):
+ """"""
+ if Sys.g.DEBUG :
+ #~ DONT USE Sys.g.RLOCK
+ isChildProc = not Sys.g_is_main_proc()
+ bind_data = []
+ if t is not None :
+ bind_data += Sys.pdate(t.timetuple() if enter else Sys.datetime.now().timetuple(), isChildProc)
+
+ a, b, c, d, e = ('=> ' if enter else '<= '), '['+str(Sys.getpid())+']', ' '+sign+'(', Log._formatArgs(args), ') '
+ if not isChildProc :
+ Sys.print(a , Sys.CLZ_IO , False)
+ Sys.print(b , Sys.CLZ_PID if not isChildProc else Sys.CLZ_CPID, False)
+ Sys.print(c , Sys.CLZ_FUNC, False)
+ Sys.print(d , Sys.CLZ_ARGS, False)
+ Sys.print(e , Sys.CLZ_FUNC, False)
+
+ bind_data += [(a, Const.CLZ_IO),(b, Const.CLZ_CPID if isChildProc else Const.CLZ_PID),(c , Const.CLZ_CFUNC if isChildProc else Const.CLZ_FUNC),(d , Const.CLZ_ARGS),(e , Const.CLZ_CFUNC if isChildProc else Const.CLZ_FUNC)]
+
+ if not enter and t is not None :
+ bind_data += Sys.pdelta(t, '', isChildProc)
+ else :
+ bind_data += Sys.dprint(dbcall=isChildProc)
+
+ if isChildProc :
+ Sys.sendMainProcMsg(1, bind_data)
+ else :
+ Sys.wlog(bind_data)
diff --git a/psr/mproc.py b/psr/mproc.py
index 48c30e1..1a954e6 100644
--- a/psr/mproc.py
+++ b/psr/mproc.py
@@ -1,153 +1,155 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/mproc.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ module mproc ~~
-from gi.repository.GObject import timeout_add
-from multiprocessing import Process, Lock, Queue
-
-from psr.decorate import log
-from psr.sys import Sys
+from multiprocessing import Process, current_process, Pipe, Lock
+from multiprocessing.connection import wait
+from threading import current_thread
+from psr.sys import Sys, Const, init
+from psr.log import Log
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# ~~ class Ctrl ~~
+# ~~ class Worker ~~
-class Ctrl:
- """"""
- @log
- def __init__(self, nproc, npqueue_bind=None, task=None, *args, **kwargs ):
+class Worker:
+
+ @Log(Const.LOG_BUILD)
+ def __init__(self, appname, debug, gui, color, loglvl, ppid, lock, id, wp, delay, task, *args, **kwargs):
+
+ def mptask(id, *args, **kwargs):
+ Sys.sendMainProcMsg(Manager.MSG_INIT, None)
+ otask = task(id=id, lock=lock, *args, **kwargs)
+ Sys.sendMainProcMsg(Manager.MSG_END, None)
+ return otask
+
+ init(appname, debug, ppid, color, loglvl)
+ Sys.g.WPIPE = wp
+ Sys.g.CPID = id
+ Sys.g.GUI = gui
+ Sys.g.RLOCK = lock
+ if delay : Sys.sleep(delay)
+ mptask(id, *args, **kwargs)
+ # don't directly close pipe 'cause of eventual loging
+ # pipe will auto close on terminating child process
+
+
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ class Manager ~~
+
+class Manager:
+
+ MSG_INIT = 0
+ MSG_PRINT = 1
+ MSG_DATA = 2
+ MSG_END = 3
+ TYPE_MSG = list(range(4))
+ K_ID = 0
+ K_TYPE = 1
+ K_DATA = 2
+ K_PROC = 0
+ K_PIPE = 1
+
+ checktime = None
+
+ @Log(Const.LOG_UI)
+ def __init__(self, task, nproc=2, delay=None, lock=None, *args, **kwargs):
""""""
- self.plist = []
- self.queue = Queue()
- self.npqueue = Queue()
- self.nproc = nproc
- self.done = False
- self.npq_bind = npqueue_bind
- if task is not None :
- self.bind_task(task, *args, **kwargs)
+ self.readers = []
+ self.plist = []
+ self.onstart_bind = None
+ self.onrun_bind = None
+ self.onend_bind = None
+ for id in range(nproc):
+ r, w = Pipe(duplex=False)
+ self.readers.append(r)
+ # (process, wpipe)
+ p = Process(target=Worker, args=tuple([Sys.g.PRJ_NAME, Sys.g.DEBUG, Sys.g.GUI, Sys.g.COLOR_MODE, Sys.g.LOG_LEVEL, Sys.getpid(), lock, id, w, delay, task])+tuple(args), kwargs=kwargs)
+ self.plist.append((p, w))
- def bind_task(self, task, *args, **kwargs):
+ @Log(Const.LOG_APP)
+ def run(self, checktime=None, onstart_bind=None, onrun_bind=None, onend_bind=None):
+ self.checktime = checktime
+ self.onstart_bind = onstart_bind
+ self.onrun_bind = onrun_bind
+ self.onend_bind = onend_bind
+ for p, w in self.plist:
+ p.start()
+ w.close()
+ self.wait()
+
+
+ @Log(Const.LOG_DEBUG)
+ def wait(self):
""""""
- if len(self.plist) > 0 :
- del self.plist
- self.plist = []
- del self.queue
- self.queue = Queue()
- del self.npqueue
- self.npqueue = Queue()
- def mptask(npqueue, mproc_pid, mproc_queue, *args, **kwargs):
- def wrapped(*args, **kwargs):
- """Only queue need result"""
- def orgtask(*args, **kwargs):
- Sys.g.MAIN_PROC = None
- Sys.g.NPQUEUE = npqueue
- return task(*args, **kwargs)
- mproc_queue.put_nowait([mproc_pid, orgtask(*args, **kwargs)])
- return wrapped(*args, **kwargs)
+ while self.readers:
+ self.wait_childs()
+ if self.checktime is not None : Sys.sleep(self.checktime)
- for i in range(self.nproc):
- self.plist.append(Process(target=mptask, args=tuple([self.npqueue,i,self.queue,i])+tuple(args), kwargs=kwargs))
-
- @log
- def start(self, timeout=100, delay=None, maincb=None, childcb=None):
+
+ def getcpid(self, id):
""""""
- if childcb is not None : self.on_child_end = childcb
- if maincb is not None : self.on_end = maincb
- if delay is None :
- self.launch(timeout)
- else :
- timeout_add(delay, self.launch, timeout)
+ return self.plist[id][self.K_PROC].pid
- #~ @log
- def launch(self, timeout):
+
+ @Log(Const.LOG_ALL)
+ def wait_childs(self):
""""""
- for p in self.plist:p.start()
- self.list_process()
- self.tid = timeout_add(timeout, self.check)
- return False
-
- #~ @log
- def list_process(self):
- """"""
- if Sys.g.DEBUG :
- Sys.pcontent('current pid :'+str(Sys.getpid()))
- Sys.pcontent('childs pid :')
- for p in self.plist:
- Sys.pcontent(str(p.pid))
-
- #~ @log
- def end_process(self):
- """"""
- if not self.queue.empty():
- d = self.queue.get_nowait()
- if d is not None :
- self.on_child_end(d[0], d[1])
- p = self.plist[d[0]]
- if p.is_alive(): p.join()
+ for r in wait(self.readers):
+ try:
+ msg = r.recv()
+ except EOFError:
+ self.readers.remove(r)
+ else:
+ if len(msg)==3 and msg[self.K_TYPE] in self.TYPE_MSG :
- #~ @log
- def on_child_end(self, pid, data):
- """"""
+ cpid = self.getcpid(msg[self.K_ID])
- #~ @log
- def end_task(self):
- """"""
- self.queue.close()
- self.queue.join_thread()
- self.done = True
- self.on_end()
+ if msg[self.K_TYPE] == self.MSG_INIT :
+ if hasattr(self.onstart_bind, '__call__'):
+ self.onstart_bind(msg[self.K_ID], cpid, msg[self.K_DATA])
- #~ @log
- def on_end(self):
- """"""
- print(self)
- print('all child process terminated')
-
- #~ @log
- def check(self):
- """"""
- leave = True
- # child process log queue
- if self.npq_bind is not None :
- while not self.npqueue.empty():
- d = self.npqueue.get_nowait()
- if d is not None: self.npq_bind(d)
- # ctrl queue
- if not self.queue.empty():
- self.end_process()
- for p in self.plist: leave = leave and not p.is_alive()
- if leave :
- while not self.queue.empty():
- self.end_process()
- self.end_task()
- else : leave = False
- return not leave
+ elif msg[self.K_TYPE] == self.MSG_PRINT :
+ if Sys.g.DEBUG :
+ if not Sys.g.GUI :
+ for item in msg[self.K_DATA] :
+ Sys.print(item[0], Sys.clzdic[item[1]], False, True)
+ Sys.dprint('')
+ #~ else :
+ Sys.wlog(msg[self.K_DATA])
+ elif msg[self.K_TYPE] == self.MSG_DATA :
+ if hasattr(self.onrun_bind, '__call__'):
+ self.onrun_bind(msg[self.K_ID], cpid, msg[self.K_DATA])
+ elif msg[self.K_TYPE] == self.MSG_END :
+ if hasattr(self.onend_bind, '__call__'):
+ self.onend_bind(msg[self.K_ID], cpid, msg[self.K_DATA])
diff --git a/psr/sys.py b/psr/sys.py
index 47320d7..94f4711 100644
--- a/psr/sys.py
+++ b/psr/sys.py
@@ -1,36 +1,45 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
-# #
-# software : Kirmah #
-# version : 2.1 #
-# date : 2013 #
-# licence : GPLv3.0 #
-# author : a-Sansara #
-# copyright : pluie.org #
-# #
-# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/sys.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# This file is part of Kirmah.
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
#
-# Kirmah is free software (free as in speech) : you can redistribute it
-# and/or modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation, either version 3 of the License,
-# or (at your option) any later version.
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
-# Kirmah is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
#
-# You should have received a copy of the GNU General Public License
-# along with Kirmah. If not, see .
-from psr.io import Io
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~ module sys ~~
-def init(name, debug):
- Sys.g_init(name, debug)
- Sys.g_set_main_proc()
+from psr.io import Io
+from psr.const import Const
+from threading import RLock
+from multiprocessing import RLock as MPRLock
+from queue import Queue
+
+def init(name, debug, remote=False, color=True, loglvl=Const.LOG_DEFAULT):
+ Sys.g_init(name, debug, remote, color, loglvl)
+ Sys.g_set_main_proc(remote)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Sys ~~
@@ -38,101 +47,153 @@ def init(name, debug):
class Sys:
""""""
- from platform import system as getSysName
- from os import system as sysCall, remove as removeFile, makedirs, sep, getpid
- from getpass import getuser as getUserLogin
- from time import strftime, mktime, time, localtime, sleep
- from datetime import datetime
- from sys import exit
- from os.path import abspath, dirname, join, realpath, basename, getsize, isdir
- from math import log, floor, ceil
- from ast import literal_eval
-
+ from platform import system as getSysName
+ from os import system as sysCall, remove as removeFile, makedirs, sep, getpid
+ from getpass import getuser as getUserLogin
+ from time import strftime, mktime, time, localtime, sleep
+ from datetime import datetime
+ from sys import exit
+ from os.path import abspath, dirname, join, realpath, basename, getsize, isdir, splitext
+ from math import log, floor, ceil
+ from _thread import exit as thread_exit
+
import builtins as g
-
- ERROR = 'error'
- WARN = 'warn'
- NOTICE = 'notice'
-
- g.DEBUG = False
-
- def __init__(self):
- """"""
+
+ g.DEBUG = False
+ g.LOG_LEVEL = Const.LOG_DEFAULT
+ g.LOG_TIME = False
+ g.LOG_LIM_ARG_LENGTH = Const.LOG_LIM_ARG_LENGTH
+ g.QUIET = False
+ g.RLOCK = None
+ g.MPRLOCK = None
+ g.WPIPE = None
+ g.THREAD_CLI = None
+ g.UI_AUTO_SCROLL = True
+ g.CPID = None
+ g.SIGNAL_STOP = 0
+ g.SIGNAL_START = 1
+ g.SIGNAL_RUN = 2
+ g.GUI = False
+ g.GUI_PRINT_STDOUT = True
+ g.MPRLOCK = MPRLock()
+
@staticmethod
- def g_init(prjName, debug=False, ui_trace=None, bind=None, color=True):
- Sys.g.PRJ_NAME = prjName
- Sys.g.DEBUG = debug
- Sys.g.LOG_FILE = '.'+prjName+'.log'
- Sys.g.LOG_FO = Io.wfile(Sys.g.LOG_FILE, False) if bind is not None else None
- #~ Sys.g.LOG_FO.write('# log '+prjName+'\n')
- Sys.g.UI_TRACE = ui_trace
- Sys.g.UI_BIND = bind
- Sys.g.COLOR_MODE = color
- #~ Sys.DEBUG = Debug(True,Debug.NOTICE)
- from queue import Queue
- Sys.g.QUEUE = Queue(0)
- Sys.g.NPQUEUE = Queue(0)
- Sys.g.MAIN_PROC = None
-
+ def g_init(prjName, debug=True, remote=False, color=True, loglvl=Const.LOG_DEFAULT):
+ """"""
+ Sys.g.PRJ_NAME = prjName
+ Sys.g.DEBUG = debug
+ Sys.g.COLOR_MODE = color
+ Sys.g.LOG_LEVEL = loglvl
+ Sys.g.LOG_TIME = True
+ Sys.g.MAIN_PROC = None
+ Sys.g.RLOCK = RLock()
+ Sys.g.LOG_QUEUE = Queue() if Sys.g.GUI else None
+
+
@staticmethod
- def g_set_main_proc():
- Sys.g.MAIN_PROC = Sys.getpid()
-
+ def sendMainProcMsg(type, data):
+ """"""
+ if not Sys.g_is_main_proc() and Sys.g.WPIPE is not None and Sys.g.CPID is not None and type in range(4) :
+ Sys.g.WPIPE.send((Sys.g.CPID, type, data))
+
+
+ @staticmethod
+ def g_set_main_proc(ppid=None):
+ """"""
+ Sys.g.MAIN_PROC = Sys.getpid() if ppid is None or ppid is False else ppid
+
+
@staticmethod
def g_is_main_proc():
+ """"""
try :
- return Sys.g.MAIN_PROC is None
+ return Sys.g.MAIN_PROC == Sys.getpid()
except :
- return False
+ return False
+
@staticmethod
- def g_has_ui_bind():
+ def g_has_ui_trace():
+ """"""
try:
- return Sys.g.UI_BIND is not None and Sys.g.DEBUG
+ return Sys.g.GUI and Sys.g.DEBUG
except Exception as e:
return False
+
+ @staticmethod
+ def cli_emit_progress(value=0):
+ """"""
+ if Sys.g.THREAD_CLI is not None : Sys.g.THREAD_CLI.progress(value)
+
+
+ @staticmethod
+ def is_cli_cancel(mprlock=None):
+ """"""
+ if mprlock is None :
+ return Sys.g.THREAD_CLI is not None and Sys.g.THREAD_CLI.cancelled
+ else :
+ with mprlock :
+ try:
+ print(Sys.g.THREAD_CLI)
+ print(Sys.g.THREAD_CLI.cancelled)
+ except:
+ pass
+ return Sys.g.THREAD_CLI is not None and Sys.g.THREAD_CLI.cancelled
+
+
@staticmethod
def isUnix():
""""""
return not Sys.getSysName() == 'Windows'
+
@staticmethod
def clear():
return Sys.sysCall('cls' if not Sys.isUnix() else 'clear')
+
@staticmethod
def mkdir_p(path):
""""""
try:
Sys.makedirs(path)
- except OSError as e: # Python >2.5
+ except OSError as e:
if e.errno == Io.EEXIST:
pass
else: raise
+
@staticmethod
def readableBytes(b, p=2):
"""Give a human representation of bytes size `b`
:Returns: `str`
"""
- units = ['B', 'KiB', 'MiB', 'GiB', 'TiB'];
+ units = [Const.UNIT_SHORT_B, Const.UNIT_SHORT_KIB, Const.UNIT_SHORT_MIB, Const.UNIT_SHORT_GIB, Const.UNIT_SHORT_TIB];
b = max(b,0);
if b == 0 : lb= 0
- else : lb = Sys.log(b)
+ else : lb = Sys.log(b)
p = Sys.floor(lb/Sys.log(1024))
- p = min(p, len(units)- 1)
+ p = min(p, len(units)- 1)
#Uncomment one of the following alternatives
b /= pow(1024,p)
- #b /= (1 << (10 * p))
- return str(round(b, 1))+' '+units[p]
-
+ #b /= (1 << (10 * p))
+ return str(round(b, 1))+' '+units[p]
+
+
+ @staticmethod
+ def getFileExt(fromPath):
+ """"""
+ return Sys.splitext(fromPath)
+
+
@staticmethod
def getFileSize(path):
""""""
return Sys.readableBytes(Sys.getsize(path))
+
@staticmethod
def getPrintableBytes(bdata):
""""""
@@ -150,6 +211,7 @@ class Sys:
data = bdata
return data
+
@staticmethod
def getHexaBytes(bdata):
""""""
@@ -163,16 +225,28 @@ class Sys:
data = bdata
return data
+
@staticmethod
+ # never log this func -> maximum recursion
def wlog(data):
""""""
- Sys.g.LOG_FO.write(str(data)+'\n')
-
+ if not Sys.is_cli_cancel():
+ if Sys.g.LOG_QUEUE is not None :
+ try :
+ Sys.g.LOG_QUEUE.put(data)
+ Sys.cli_emit_progress()
+ except Exception as e:
+ Sys.pwarn((('wlog exception ',(str(e),Sys.CLZ_ERROR_PARAM), ' !'),), True)
+
+ else :
+ Sys.g.THREAD_CLI.stop()
+
+
@staticmethod
def print(data, colors, endLF=True, endClz=True):
""""""
if isinstance(data,bytes) :
- data = Sys.getPrintableBytes(data)
+ data = Sys.getPrintableBytes(data)
ev = '' if not endLF else Sys.Clz._LF
tokens = [c.lstrip(Sys.Clz._MARKER[0]).rstrip(Sys.Clz._SEP) for c in colors.split(Sys.Clz._MARKER) if c is not '']
@@ -180,135 +254,154 @@ class Sys:
if data is None: data = ''
if endClz : data += Sys.Clz._uOFF
if Sys.g.COLOR_MODE :
- Sys.dprint(eval('Sys.Clz._u'+'+Sys.Clz._u'.join(tokens))+data,end=ev, dbcall=True)
+ Sys.dprint(eval('Sys.Clz._u'+'+Sys.Clz._u'.join(tokens))+data,end=ev, dbcall=False)
else :
- Sys.dprint(data,end=ev, dbcall=True)
+ Sys.dprint(data,end=ev, dbcall=False)
else :
if Sys.g.COLOR_MODE : Sys.Clz.setColor(eval('Sys.Clz._w'+'|Sys.Clz._w'.join(tokens)))
- Sys.dprint(data,end=ev, dbcall=True)
+ Sys.dprint(data,end=ev, dbcall=False)
stdout.flush()
if endClz and Sys.g.COLOR_MODE : Sys.Clz.setColor(Sys.Clz._wOFF)
- #~ else:
- #~ self.dprint(data,end=ev)
+
@staticmethod
- def dprint(d='',end='\n', dbcall=False):
+ def dprint(d='',end=Const.LF, dbcall=False):
""""""
- print(d,end=end)
- if Sys.g_has_ui_bind():
- bdata = [(d,'default')]
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+ if not dbcall :
+ if not Sys.g.GUI or Sys.g.GUI_PRINT_STDOUT :
+ with Sys.g.RLOCK :
+ if not Sys.g.QUIET : print(d,end=end)
+
+ bdata = [(d,Const.CLZ_DEFAULT)]
+ return bdata
+
@staticmethod
- def eprint(d='', label='warn', dbcall=False):
+ def eprint(d='', label=Const.WARN, dbcall=False):
""""""
- c = Sys.CLZ_ERROR if label is Sys.ERROR else Sys.CLZ_WARN
+ c = Sys.CLZ_ERROR if label is Const.ERROR else Sys.CLZ_WARN
Sys.print(' '+label+' : ', c, False, False)
Sys.print(str(d)+' ', c, True, True)
- if Sys.g_has_ui_bind():
- bdata = [(label+' : ' , label),(str(d)+' ', label)]
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+
+ bdata = [(label+' : ' , label),(str(d)+' ', label)]
+ return bdata
+
@staticmethod
def pdate(t, dbcall = False):
""""""
t, s = Sys.strftime('%H:%M',t), Sys.strftime(':%S ',t)
- Sys.print(t , Sys.CLZ_TIME, False)
- Sys.print(s , Sys.CLZ_SEC , False)
- if Sys.g_has_ui_bind():
- bdata = [(t , 'time'),(s , 'sec')]
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+ if not dbcall :
+ Sys.print(t , Sys.CLZ_TIME, False)
+ Sys.print(s , Sys.CLZ_SEC , False)
+
+ bdata = [(t , Const.CLZ_TIME),(s , Const.CLZ_SEC)]
+ return bdata
+
@staticmethod
def pkval(label, value, pad=40, dbcall= False):
""""""
- l, v = label.rjust(pad,' '), ' '+str(value)
- Sys.print(l, Sys.CLZ_SEC , False)
- Sys.print(v, Sys.CLZ_TIME , True)
- if Sys.g_has_ui_bind():
- bdata = [(l, 'sec'),(v, 'time')]
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+ l, v = label.rjust(pad,' '), ' '+str(value)
+ if not dbcall :
+ Sys.print(l, Sys.CLZ_SEC , False)
+ Sys.print(v, Sys.CLZ_TIME , True)
+
+ bdata = [(l, Const.CLZ_SEC),(v, Const.CLZ_TIME)]
+ return bdata
+
@staticmethod
def pdelta(t, label='', dbcall= False):
""""""
- if len(label)>0 : Sys.print(label+' ', Sys.CLZ_IO, False)
- v = ''.join(["{:.5f}".format(Sys.time()-(Sys.mktime(t.timetuple())+1e-6*t.microsecond)),' s'])
- Sys.print(v, Sys.CLZ_DELTA)
- if Sys.g_has_ui_bind():
- bdata = []
- if len(label)>0 :
- bdata.append((label+' ', 'io'))
- bdata.append((v, 'delta'))
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+ if len(label)>0 and not dbcall : Sys.print(label+' ', Sys.CLZ_IO, False)
+ v = ''.join(['{:.5f}'.format(Sys.time()-(Sys.mktime(t.timetuple())+1e-6*t.microsecond)),' s'])
+ if not dbcall :
+ Sys.print(v, Sys.CLZ_DELTA)
+
+ bdata = []
+ if len(label)>0 :
+ bdata.append((label+' ', Const.CLZ_IO))
+ bdata.append((v, Const.CLZ_DELTA))
+ return bdata
+
@staticmethod
- def pcontent(content, color=None, bcolor='default', dbcall= False):
+ def pcontent(content, color=None, bcolor=Const.CLZ_DEFAULT, dbcall= False):
""""""
- Sys.print(content, Sys.CLZ_SEC if color is None else color)
- if Sys.g_has_ui_bind():
- bdata = [(content, bcolor)]
- if not dbcall :
- Sys.wlog(bdata)
- else :
- return bdata
+ if not dbcall : Sys.print(content, Sys.CLZ_SEC if color is None else color)
+
+ bdata = [(content, bcolor)]
+ return bdata
+
@staticmethod
- def pwarn(data, isError=False, length=120):
- """ data struct :
- ( # line0
+ def pwarn(data, isError=False, length=Const.LINE_SEP_LEN, dbcall=False):
+ """ data struct :
+ ( # line0
'simple line', # LF
# line1
# p0 p1 p2
- ('complex line with ',('paramValue',fgcolor), ' suit complex line'), # LF
+ ('complex line with ',('paramValue',fgcolor), ' suit complex line'), # LF
# line2
'other simple line '
)
"""
- w = ' WARNING : ' if not isError else ' ERROR : '
- bg = Sys.Clz.bg5 if not isError else Sys.Clz.bg1
-
- Sys.print(w, bg+Sys.Clz.fgb3, False, False)
+ w = ' '+(Const.WARN if not isError else Const.ERROR)+' : '
+ clz = Sys.CLZ_WARN if not isError else Sys.CLZ_ERROR
+ clzp = Sys.CLZ_WARN_PARAM if not isError else Sys.CLZ_ERROR_PARAM
+ uiclz = Const.CLZ_WARN if not isError else Const.CLZ_ERROR
+ uiclzp = Const.CLZ_WARN_PARAM if not isError else Const.CLZ_ERROR_PARAM
+
+ if not dbcall : Sys.print(w, clzp, False, False)
+ bdata = []
+ if Sys.g.DEBUG :
+ bdata.append((w, uiclzp))
for i, line in enumerate(data) :
- if i > 0 :
- Sys.print(' '*len(w), bg+Sys.Clz.fgb7, False, False)
+ if i > 0 :
+ if not dbcall : Sys.print(' '*len(w), clz, False, False)
+ if Sys.g.DEBUG :
+ bdata.append((' '*len(w), uiclz))
if isinstance(line,str) :
- Sys.print(line.ljust(length-len(w),' '), bg+Sys.Clz.fgb7, True, True)
+ s = line.ljust(length-len(w),' ')
+ if not dbcall : Sys.print(s, clz, True, True)
+
+ if Sys.g.DEBUG :
+ bdata.append((s, uiclz))
+ Sys.wlog(bdata)
+ bdata = []
else :
sl = 0
- for p in line :
+ for p in line :
if isinstance(p,str) :
- Sys.print(p, bg+Sys.Clz.fgb7, False, False)
+ Sys.print(p, clz, False, False)
+ bdata.append((p, uiclz))
sl += len(p)
else :
- Sys.print(p[0], bg+p[1], False, False)
+ Sys.print(p[0], clzp+p[1], False, False)
+ bdata.append((p[0], uiclzp))
sl += len(p[0])
- Sys.print(' '.ljust(length-sl-len(w),' '), bg+Sys.Clz.fgb7, True, True)
-
- Sys.dprint()
-
+ s = ' '.ljust(length-sl-len(w),' ')
+ if not dbcall : Sys.print(s, clz, True, True)
+ if Sys.g.DEBUG :
+ bdata.append((s, uiclz))
+ Sys.wlog(bdata)
+ bdata = []
+
+ if not dbcall : Sys.dprint()
+ if Sys.g.DEBUG : Sys.wlog([('',Const.CLZ_DEFAULT)])
+
+
@staticmethod
- def _psymbol(ch):
+ def _psymbol(ch, done=True):
""""""
- Sys.print(' ', Sys.Clz.fgb7, False, False)
- Sys.print(' '+ch+' ', Sys.Clz.BG4+Sys.Clz.fgb7, False, True)
- Sys.print(' ', Sys.Clz.fgb7, False, True)
-
+ Sys.print(' ', Sys.CLZ_DEFAULT, False, False)
+ Sys.print(' '+ch+' ', Sys.CLZ_HEAD_APP if done else Sys.CLZ_SYMBOL, False, True)
+ Sys.print(' ', Sys.CLZ_DEFAULT, False, True)
+ bdata = [(' ', Const.CLZ_DEFAULT),(' '+ch+' ', Const.CLZ_HEAD_APP if done else Sys.CLZ_SYMBOL),(' ', Const.CLZ_DEFAULT)]
+ return bdata
+
+
@staticmethod
def pask(ask, yesValue='yes', noValue='no'):
""""""
@@ -321,26 +414,40 @@ class Sys:
answer = input(' '.ljust(5,' ')+s.ljust(len(ask),' '))
Sys.dprint()
return answer.lower()==yesValue.lower()
-
+
+
@staticmethod
- def pstep(title, stime, done, exitOnFailed=True, length=120):
+ def pstep(title, stime, done, noelf=False, exitOnFailed=True, length=100):
""""""
if stime is not None :
- v = ' ('+''.join(["{:.5f}".format(Sys.time()-(Sys.mktime(stime.timetuple())+1e-6*stime.microsecond)),' s'])+')'
+ v = ' ('+''.join(['{:.5f}'.format(Sys.time()-(Sys.mktime(stime.timetuple())+1e-6*stime.microsecond)),' s'])+')'
else : v = ''
- Sys._psymbol('¤')
- Sys.print(title, Sys.Clz.fgB7, False, False)
+ bdata = Sys._psymbol('¤')
+ Sys.print(title, Sys.CLZ_TITLE, False, False)
Sys.print(v+' '.ljust(length-len(title)-20-len(v), ' '),Sys.CLZ_DELTA, False, True)
- if done :
- Sys.print(' == OK == ', Sys.Clz.bg2+Sys.Clz.fgb7)
+ if done :
+ Sys.print(' == '+Const.OK+' == ', Sys.CLZ_OK)
else :
- Sys.print(' == KO == ', Sys.Clz.bg1+Sys.Clz.fgb7)
- Sys.dprint()
+ Sys.print(' == '+Const.KO+' == ', Sys.CLZ_KO)
+
+ bdata = bdata + [(title, Const.CLZ_TITLE),(v+' '.ljust(length-len(title)-20-len(v)), Const.CLZ_DELTA),(' == '+(Const.OK if done else Const.KO)+' == ', (Const.CLZ_OK if done else Const.CLZ_KO))]
+
+ Sys.wlog(bdata)
+ if not noelf :
+ Sys.wlog(Sys.dprint())
+
if exitOnFailed and not done:
- #~ Sys.dprint(' '.ljust(length-14, ' '),end='')
- #~ Sys.print(' == EXIT == ', Sys.Clz.bg1+Sys.Clz.fgb7)
- #~ Sys.dprint()
- Sys.exit(1)
+ Sys.exit(1)
+
+
+ @staticmethod
+ def ptask(title='Processing, please wait'):
+ if not Sys.g.QUIET :
+ s = ' '+title+'...'
+ Sys.print(s, Sys.CLZ_TASK )
+ Sys.wlog([(s, Const.CLZ_TASK)])
+ Sys.wlog(Sys.dprint())
+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~ class Coloriz ~~
@@ -361,14 +468,14 @@ class Coloriz:
""""""
_wOFF = None
""""""
- _LF = '\n'
+ _LF = Const.LF
""""""
OFF = _MARKER+_MARKER[0]+'OFF'+_SEP+_MARKER
- """"""
+ """"""
def __init__(self):
- """Colors for both plateform are : 0: black - 1: red - 2:green - 3: yellow - 4: blue - 5: purple - 6: cyan - 7: white
+ """Colors for both plateform are : 0: black - 1: red - 2:green - 3: yellow - 4: blue - 5: purple - 6: cyan - 7: white
available class members :
- foreground normal (same as bold for w32):
+ foreground normal (same as bold for w32):
self.fgn0 -> self.fgn7
foreground bold :
self.fgb0 -> self.fgb7
@@ -382,29 +489,23 @@ class Coloriz:
self.BG0 -> self.BG7
default colors :
self.OFF
-
- usage :
- pc = PColor()
- pc.print('%smon label%s:%sma value%s' % (pc.BG4+pc.fgN7, pc.OFF+pc.fgn1, pc.fgb4, pc.OFF))
"""
- global Sys
-
if not Sys.isUnix():
j = 0
for i in (0,4,2,6,1,5,3,7):
- exec('self._wf%i = 0x000%i' % (i,j) + '\nself._wb%i = 0x00%i0' % (i,j) + '\nself._wF%i = 0x000%i | self._wFH' % (i,j) + '\nself._wB%i = 0x00%i0 | self._wBH' % (i,j))
+ exec('self._wf%i = 0x000%i' % (i,j) + Const.LF+'self._wb%i = 0x00%i0' % (i,j) + Const.LF+'self._wF%i = 0x000%i | self._wFH' % (i,j) + Const.LF+'self._wB%i = 0x00%i0 | self._wBH' % (i,j))
# normal eq bold
exec('self._wn%i = self._wf%i' % (i,i))
# normal high intensity eq bold high intensity
exec('self._wN%i = self._wF%i' % (i,i))
j += 1
- import impra.w32color as w32cons
+ import psr.w32color as w32cons
self._wOFF = w32cons.get_text_attr()
self._wOFFbg = self._wOFF & 0x0070
self._wOFFfg = self._wOFF & 0x0007
self.setColor = w32cons.set_text_attr
- for i in range(0,8):
+ for i in range(0,8):
# foreground normal
exec('self.fgn%i = self._MARKER + self._MARKER[0] + "n%i" + self._SEP + self._MARKER' % (i,i))
if True or Sys.isUnix() : exec('self._un%i = "\\033[0;3%im"' % (i,i))
@@ -417,20 +518,45 @@ class Coloriz:
# foreground bold high intensity
exec('self.fgB%i = self._MARKER + self._MARKER[0] + "F%i" + self._SEP + self._MARKER' % (i,i))
if True or Sys.isUnix() : exec('self._uF%i = "\\033[1;9%im"' % (i,i))
- # background
+ # background
exec('self.bg%i = self._MARKER + self._MARKER[0] + "b%i" + self._SEP + self._MARKER' % (i,i))
if True or Sys.isUnix() : exec('self._ub%i = "\\033[4%im"' % (i,i))
# background high intensity
exec('self.BG%i = self._MARKER + self._MARKER[0] + "B%i" + self._SEP + self._MARKER' % (i,i))
if True or Sys.isUnix() : exec('self._uB%i = "\\033[0;10%im"' % (i,i))
-Sys.Clz = Coloriz()
-Sys.CLZ_TIME = Sys.Clz.fgN2+Sys.Clz.bg0
-Sys.CLZ_SEC = Sys.Clz.fgb7+Sys.Clz.bg0
-Sys.CLZ_IO = Sys.Clz.fgB1+Sys.Clz.bg0
-Sys.CLZ_FUNC = Sys.Clz.fgb3+Sys.Clz.bg0
-Sys.CLZ_ARGS = Sys.Clz.fgn7+Sys.Clz.bg0
-Sys.CLZ_DELTA = Sys.Clz.fgN4+Sys.Clz.bg0
-Sys.CLZ_ERROR = Sys.Clz.fgb7+Sys.Clz.bg1
-Sys.CLZ_WARN = Sys.Clz.fgb7+Sys.Clz.bg5
-Sys.CLZ_DEFAULT = Sys.Clz.fgb7+Sys.Clz.bg0
+Sys.Clz = Coloriz()
+Sys.CLZ_TIME = Sys.Clz.fgN2+Sys.Clz.bg0
+Sys.CLZ_SEC = Sys.Clz.fgb7+Sys.Clz.bg0
+Sys.CLZ_PID = Sys.Clz.fgb1+Sys.Clz.bg0
+Sys.CLZ_PPID = Sys.Clz.fgb1+Sys.Clz.bg0
+Sys.CLZ_CPID = Sys.Clz.fgb7+Sys.Clz.bg0
+Sys.CLZ_IO = Sys.Clz.fgB1+Sys.Clz.bg0
+Sys.CLZ_FUNC = Sys.Clz.fgb3+Sys.Clz.bg0
+Sys.CLZ_CFUNC = Sys.Clz.fgb3+Sys.Clz.bg0
+Sys.CLZ_ARGS = Sys.Clz.fgn7+Sys.Clz.bg0
+Sys.CLZ_DELTA = Sys.Clz.fgN4+Sys.Clz.bg0
+Sys.CLZ_TASK = Sys.Clz.fgB2+Sys.Clz.bg0
+Sys.CLZ_ERROR = Sys.Clz.fgb7+Sys.Clz.bg1
+Sys.CLZ_ERROR_PARAM = Sys.Clz.fgb3+Sys.Clz.bg1
+Sys.CLZ_WARN = Sys.Clz.fgb7+Sys.Clz.bg5
+Sys.CLZ_WARN_PARAM = Sys.Clz.fgb3+Sys.Clz.bg5
+Sys.CLZ_DEFAULT = Sys.Clz.fgb7+Sys.Clz.bg0
+Sys.CLZ_TITLE = Sys.Clz.fgB7+Sys.Clz.bg0
+Sys.CLZ_SYMBOL = Sys.Clz.BG4+Sys.Clz.fgB7
+Sys.CLZ_OK = Sys.Clz.bg2+Sys.Clz.fgb7
+Sys.CLZ_KO = Sys.Clz.bg1+Sys.Clz.fgb7
+Sys.CLZ_HELP_PRG = Sys.Clz.fgb7
+Sys.CLZ_HELP_CMD = Sys.Clz.fgB3
+Sys.CLZ_HELP_PARAM = Sys.Clz.fgB1
+Sys.CLZ_HELP_ARG = Sys.Clz.fgB3
+Sys.CLZ_HELP_COMMENT = Sys.Clz.fgn7
+Sys.CLZ_HELP_ARG_INFO = Sys.Clz.fgb7
+Sys.CLZ_HELP_DESC = Sys.Clz.fgN1
+Sys.CLZ_HEAD_APP = Sys.Clz.BG4+Sys.Clz.fgB7
+Sys.CLZ_HEAD_KEY = Sys.Clz.fgB3
+Sys.CLZ_HEAD_VAL = Sys.Clz.fgB4
+Sys.CLZ_HEAD_SEP = Sys.Clz.fgB0
+Sys.CLZ_HEAD_LINE = Sys.Clz.fgN0
+
+Sys.clzdic = { Const.CLZ_TASK : Sys.CLZ_TASK, Const.CLZ_SYMBOL: Sys.CLZ_SYMBOL, Const.CLZ_TIME : Sys.CLZ_TIME, Const.CLZ_SEC : Sys.CLZ_SEC, Const.CLZ_IO : Sys.CLZ_IO, Const.CLZ_CPID : Sys.CLZ_CPID, Const.CLZ_PID : Sys.CLZ_PID, Const.CLZ_CFUNC : Sys.CLZ_CFUNC, Const.CLZ_FUNC : Sys.CLZ_FUNC, Const.CLZ_ARGS : Sys.CLZ_ARGS, Const.CLZ_DELTA : Sys.CLZ_DELTA, Const.CLZ_ERROR : Sys.CLZ_ERROR, Const.CLZ_WARN : Sys.CLZ_WARN, Const.CLZ_ERROR_PARAM : Sys.CLZ_ERROR_PARAM, Const.CLZ_WARN_PARAM : Sys.CLZ_WARN_PARAM, Const.CLZ_DEFAULT : Sys.CLZ_DEFAULT }
diff --git a/psr/w32color.py b/psr/w32color.py
new file mode 100644
index 0000000..b8eb59c
--- /dev/null
+++ b/psr/w32color.py
@@ -0,0 +1,71 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# psr/w32color.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+"""
+Colors text in console mode application (win32).
+Uses ctypes and Win32 methods SetConsoleTextAttribute and
+GetConsoleScreenBufferInfo.
+"""
+
+from ctypes import windll, Structure as Struct, c_short as SHORT, c_ushort as WORD, byref
+
+class Coord(Struct):
+ """struct in wincon.h."""
+ _fields_ = [("X", SHORT),("Y", SHORT)]
+
+class SmallRect(Struct):
+ """struct in wincon.h."""
+ _fields_ = [("Left", SHORT),("Top", SHORT),("Right", SHORT),("Bottom", SHORT)]
+
+class ConsoleScreenBufferInfo(Struct):
+ """struct in wincon.h."""
+ _fields_ = [("dwSize", Coord),("dwCursorPosition", Coord),("wAttributes", WORD),("srWindow", SmallRect),("dwMaximumWindowSize", Coord)]
+
+# winbase.h
+STD_INPUT_HANDLE = -10
+STD_OUTPUT_HANDLE = -11
+STD_ERROR_HANDLE = -12
+
+stdout_handle = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE)
+SetConsoleTextAttribute = windll.kernel32.SetConsoleTextAttribute
+GetConsoleScreenBufferInfo = windll.kernel32.GetConsoleScreenBufferInfo
+
+def get_text_attr():
+ """Returns the character attributes (colors) of the console screen
+ buffer."""
+ csbi = ConsoleScreenBufferInfo()
+ GetConsoleScreenBufferInfo(stdout_handle, byref(csbi))
+ return csbi.wAttributes
+
+def set_text_attr(color):
+ """Sets the character attributes (colors) of the console screen
+ buffer. Color is a combination of foreground and background color,
+ foreground and background intensity."""
+ SetConsoleTextAttribute(stdout_handle, color)
diff --git a/resources/kirmah.desktop b/resources/kirmah.desktop
new file mode 100644
index 0000000..c880428
--- /dev/null
+++ b/resources/kirmah.desktop
@@ -0,0 +1,12 @@
+
+[Desktop Entry]
+Name=Kirmah
+Comment=Encryption with symmetric-key algorithm Kirmah
+Version=0.34
+Icon=kirmah
+Exec=kirmah
+Terminal=false
+Type=Application
+StartupNotify=false
+MimeType=
+Categories=System;
diff --git a/resources/kirmah/LICENSE b/resources/kirmah/LICENSE
new file mode 100755
index 0000000..94a9ed0
--- /dev/null
+++ b/resources/kirmah/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/resources/kirmah/glade/kirmah.glade b/resources/kirmah/glade/kirmah.glade
new file mode 100644
index 0000000..031dfa1
--- /dev/null
+++ b/resources/kirmah/glade/kirmah.glade
@@ -0,0 +1,974 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/pixmaps/kirmah/kirmah.png b/resources/pixmaps/kirmah/kirmah.png
new file mode 100644
index 0000000..af40d19
Binary files /dev/null and b/resources/pixmaps/kirmah/kirmah.png differ
diff --git a/resources/pixmaps/kirmah/kirmah_ico.png b/resources/pixmaps/kirmah/kirmah_ico.png
new file mode 100644
index 0000000..c58159b
Binary files /dev/null and b/resources/pixmaps/kirmah/kirmah_ico.png differ
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..1125f83
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,53 @@
+# !/usr/bin/env python
+# -*- coding: utf-8 -*-
+# setup.py
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# software : Kirmah
+# version : 2.17
+# date : 2013
+# licence : GPLv3.0
+# author : a-Sansara <[a-sansara]at[clochardprod]dot[net]>
+# copyright : pluie.org
+#
+# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
+#
+# This file is part of Kirmah.
+#
+# Kirmah is free software (free as in speech) : you can redistribute it
+# and/or modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the License,
+# or (at your option) any later version.
+#
+# Kirmah is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Kirmah. If not, see .
+#
+
+from psr.kirmah import conf
+from distutils.core import setup
+import glob
+import os
+
+# I18N
+I18NFILES = []
+
+for filepath in glob.glob('resources/locale/*/LC_MESSAGES/*.mo'):
+ lang = filepath[len('resources/locale/'):]
+ targetpath = os.path.dirname(os.path.join('share/locale',lang))
+ I18NFILES.append((targetpath, [filepath]))
+
+setup(name = conf.PRG_NAME,
+ version = conf.PRG_VERS,
+ packages = [conf.PRG_PACKAGE],
+ scripts = [conf.PRG_SCRIPT, conf.PRG_CLI_NAME],
+ data_files= [('/usr/share/pixmaps/'+conf.PRG_PACKAGE , glob.glob('resources/pixmaps/'+conf.PRG_PACKAGE+'/*.png')),
+ ('/usr/share/applications' , ['resources/'+conf.PRG_PACKAGE+'.desktop']),
+ ('/usr/share/'+conf.PRG_PACKAGE , glob.glob('resources/'+conf.PRG_PACKAGE+'/LICENSE')),
+ ('/usr/share/'+conf.PRG_PACKAGE+'/glade' , glob.glob('resources/'+conf.PRG_PACKAGE+'/glade/*.glade'))]
+ + I18NFILES
+ )