Ejemplo n.º 1
0
 def onend_cmd(self, title, stime, done, outputfile):
     """"""
     s = Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN
     Sys.echo(s, Sys.CLZ_HEAD_LINE)
     Sys.wlog([(s, Const.CLZ_HEAD_SEP)])
     Sys.pstep(title, stime, done, True)
     Sys.echo(s, Sys.CLZ_HEAD_LINE)
     Sys.wlog([(s, Const.CLZ_HEAD_SEP)])
     if done and outputfile is not None:
         Sys.cli_emit_progress(100)
         Sys.echo(' '*5+Sys.realpath(outputfile), Sys.Clz.fgB1, False)
         Sys.echo(' ('+Sys.getFileSize(outputfile)+')', Sys.Clz.fgB3)
         bdata = [(' '*5+Sys.realpath(outputfile), 'io'),(' ('+Sys.getFileSize(outputfile)+')','func')]
         Sys.wlog(bdata)
         Sys.wlog(Sys.dprint())
Ejemplo n.º 2
0
    def onCommandKey(self):
        """"""
        if int(self.o.length) >= 128 and int(self.o.length) <= 4096:
            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 !'
                           ))

                done = Sys.pask('Are you sure to rewrite this file')
                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:
                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), ')'), ))
Ejemplo n.º 3
0
 def onend_cmd(self, title, stime, done, outputfile):
     """"""
     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.cli_emit_progress(100)
         Sys.print(' ' * 5 + Sys.realpath(outputfile), Sys.Clz.fgB1, False)
         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())
Ejemplo n.º 4
0
    def onCommandKey(self):
        """"""
        if int(self.o.length) >= 128 and int(self.o.length) <= 4096 :
            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 !'))

                done   = Sys.pask('Are you sure to rewrite this file')
                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 :
                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),')'),))
Ejemplo n.º 5
0
    def onCommandMerge(self):
        """"""
        done   = True

        if not Sys.g.QUIET : self.parser.print_header()

        if done :
            toPath = None
            try :
                Sys.ptask()

                key    = Io.get_data(self.o.keyfile)
                km     = Kirmah(key)
                kcf    = None
                istar  = True
                try:
                    import tarfile
                    dpath = Sys.dirname(Sys.realpath(self.o.outputfile))+Sys.sep if self.o.outputfile is not None else Sys.dirname(Sys.realpath(self.a[1]))+Sys.sep
                    if self.o.outputfile is None :
                        self.o.outputfile = dpath
                    with tarfile.open(self.a[1], mode='r') as tar:
                        #~ print(dpath)
                        tar.extractall(path=dpath)
                        kcf = None
                        for tarinfo in tar:
                            #~ print(tarinfo.name)
                            if tarinfo.isreg() and tarinfo.name[-4:]=='.kcf':
                                #~ print(dpath+tarinfo.name)
                                kcf = dpath+tarinfo.name
                    if kcf is not None :
                        km.DIR_OUTBOX = dpath
                        toPath = km.mergeFile(kcf, self.o.outputfile)
                except BadKeyException:
                    Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)
                    done = False

                except Exception :
                    istar  = False
                    toPath = km.mergeFile(self.a[1], self.o.outputfile)

                #~ if self.o.outputfile is not None :
                #~ Io.rename(toPath, self.o.outputfile)
                #~ toPath = self.o.outputfile

            except BadKeyException:
                Sys.pwarn((('BadKeyException : ',('wrong key ',Sys.CLZ_WARN_PARAM), ' !'),), False)
                done = False

            except Exception as e :
                done = False
                if Sys.g.DEBUG :
                    print(e)
                elif not Sys.g.QUIET :
                    Sys.pwarn((str(e),))
        if not done :
            if istar :
                with tarfile.open(self.a[1], mode='r') as tar:
                    for tarinfo in tar:
                        Sys.removeFile(dpath+tarinfo.name)

        if not Sys.g.QUIET :
            self.onend_cmd('Kirmah Merge', self.stime, done, toPath)
Ejemplo n.º 6
0
    def onCommandMerge(self):
        """"""
        done = True

        if not Sys.g.QUIET: self.parser.print_header()

        if done:
            toPath = None
            try:
                Sys.ptask()

                key = Io.get_data(self.o.keyfile)
                km = Kirmah(key)
                kcf = None
                istar = True
                try:
                    import tarfile
                    dpath = Sys.dirname(
                        Sys.realpath(self.o.outputfile)
                    ) + Sys.sep if self.o.outputfile is not None else Sys.dirname(
                        Sys.realpath(self.a[1])) + Sys.sep
                    if self.o.outputfile is None:
                        self.o.outputfile = dpath
                    with tarfile.open(self.a[1], mode='r') as tar:
                        #~ print(dpath)
                        tar.extractall(path=dpath)
                        kcf = None
                        for tarinfo in tar:
                            #~ print(tarinfo.name)
                            if tarinfo.isreg() and tarinfo.name[-4:] == '.kcf':
                                #~ print(dpath+tarinfo.name)
                                kcf = dpath + tarinfo.name
                    if kcf is not None:
                        km.DIR_OUTBOX = dpath
                        toPath = km.mergeFile(kcf, self.o.outputfile)
                except BadKeyException:
                    Sys.pwarn((('BadKeyException : ',
                                ('wrong key ', Sys.CLZ_WARN_PARAM), ' !'), ),
                              False)
                    done = False

                except Exception:
                    istar = False
                    toPath = km.mergeFile(self.a[1], self.o.outputfile)

                #~ if self.o.outputfile is not None :
                #~ Io.rename(toPath, self.o.outputfile)
                #~ toPath = self.o.outputfile

            except BadKeyException:
                Sys.pwarn((('BadKeyException : ',
                            ('wrong key ', Sys.CLZ_WARN_PARAM), ' !'), ),
                          False)
                done = False

            except Exception as e:
                done = False
                if Sys.g.DEBUG:
                    print(e)
                elif not Sys.g.QUIET:
                    Sys.pwarn((str(e), ))
        if not done:
            if istar:
                with tarfile.open(self.a[1], mode='r') as tar:
                    for tarinfo in tar:
                        Sys.removeFile(dpath + tarinfo.name)

        if not Sys.g.QUIET:
            self.onend_cmd('Kirmah Merge', self.stime, done, toPath)