Exemplo n.º 1
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)
Exemplo n.º 2
0
 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])
Exemplo n.º 3
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)
Exemplo n.º 4
0
 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])