Esempio n. 1
0
    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()).rjust(5,' ')+']', ' '+sign+'(', Log._formatArgs(args), ') '
            if not isChildProc :
                Sys.echo(a , Sys.CLZ_IO  , False)
                Sys.echo(b , Sys.CLZ_PID if  not isChildProc else Sys.CLZ_CPID, False)
                Sys.echo(c , Sys.CLZ_FUNC, False)
                try:
                    Sys.echo(d , Sys.CLZ_ARGS, False)
                except :
                    Sys.echo('?nr_arg?' , Sys.CLZ_ARGS, False)
                    pass
                Sys.echo(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)
Esempio n. 2
0
    def wait_childs(self):
        """"""
        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 :

                    cpid = self.getcpid(msg[self.K_ID])

                    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])

                    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.echo(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])
Esempio n. 3
0
 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')
         self.on_proceed_end(True)
         self.pb.hide()
         self.show_log()
Esempio n. 4
0
 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')
         self.on_proceed_end(True)
         self.pb.hide()
         self.show_log()
Esempio n. 5
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())
Esempio n. 6
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())
Esempio n. 7
0
 def print_header():
     """"""
     a = AbstractCli.printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
     b = AbstractCli.printHeaderTitle(AbstractCli.conf.PRG_CLI_NAME)
     c = AbstractCli.printHeaderPart('version'  ,AbstractCli.conf.PRG_VERS)
     d = AbstractCli.printHeaderPart('author'   ,AbstractCli.conf.PRG_AUTHOR)
     e = AbstractCli.printHeaderPart('license'  ,AbstractCli.conf.PRG_LICENSE)
     f = AbstractCli.printHeaderPart('copyright',AbstractCli.conf.PRG_COPY)
     Sys.echo(' ', Sys.Clz.OFF)
     AbstractCli.printLineSep(Const.LINE_SEP_CHAR,Const.LINE_SEP_LEN)
     Sys.wlog(a)
     Sys.wlog(b + c + d + e + f )
     Sys.wlog(a)
Esempio n. 8
0
    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.parser.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 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 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 :

            try :
                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']:
                    p += frav
                    Io.touch(row[1]+km.EXT,times)
                    Sys.cli_emit_progress(p)
                if self.o.outputfile is not None :
                    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, 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 :
                    print('split exception')
                    print(e)

                    #~ raise e
                elif not Sys.g.QUIET :
                    Sys.pwarn((str(e),))

        if not Sys.g.QUIET:
            Sys.cli_emit_progress(100)
            self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)
Esempio n. 9
0
    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.parser.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 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 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:

            try:
                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']:
                    p += frav
                    Io.touch(row[1] + km.EXT, times)
                    Sys.cli_emit_progress(p)
                if self.o.outputfile is not None:
                    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, 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:
                    print('split exception')
                    print(e)

                    #~ raise e
                elif not Sys.g.QUIET:
                    Sys.pwarn((str(e), ))

        if not Sys.g.QUIET:
            Sys.cli_emit_progress(100)
            self.onend_cmd('Kirmah Split', self.stime, done, self.o.outputfile)