コード例 #1
0
ファイル: gui.py プロジェクト: pluie-org/imprastorage
 def on_start(self):
     """"""
     Sys.g.GUI_PRINT_STDOUT = False
     Sys.g.GUI              = True
     init(conf.PRG_NAME, False, Sys.getpid(), True, Const.LOG_ALL)
     self.conf        = ImpraConf(KiniFile('impra2.ini'))
     self.populate_profiles()
     self.populate_config()
     self.taskLabel     = ImpraThread.TASK_LABEL
     self.taskStock     = ImpraThread.TASK_STOCK
     self.progressbar   = self.get('progressbar1')
     self.textview      = self.get('textview1')
     try :
         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' if Sys.isUnix() else 'Lucida Conosle 11'))
     except :
         pass
     self.textbuffer    = self.textview.get_buffer()
     self.tags          = self.buildTxtTags(self.textbuffer)
     self.initWidgetByThread('impra-1', self.textview, self.textbuffer, self.progressbar, self.tags)
     self.initWidgetByThread('MainThread', self.textview, self.textbuffer, self.progressbar, self.tags)
     self.tree          = self.get('treeview1')
     self.tree.connect('row-activated', self.on_row_select)
     self.tree.get_selection().connect('changed', self.on_tree_selection_changed)
     self.launch_thread(self.on_ended)
     
     self.searchCatg    = self.get('comboboxtext1')
     self.searchUser    = self.get('comboboxtext4')
     self.searchAccount = self.get('comboboxtext5')
     self.filterIds     = None
     self.index         = None
     self.taskList      = {}
     self.threads_work  = [False, False]
コード例 #2
0
ファイル: app.py プロジェクト: pluie-org/imprastorage
 def __init__(self, debug=False, color=True, loglvl=Const.LOG_NEVER):
     """"""
     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)
コード例 #3
0
ファイル: app.py プロジェクト: manojsingh-ceh/Kirmah
 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)
コード例 #4
0
ファイル: mproc.py プロジェクト: pluie-org/imprastorage
    def __init__(self, appname, debug, gui, color, loglvl, ppid, event, id, wp, delay, task, *args, **kwargs):
        def mptask(id, *args, **kwargs):
            Sys.sendMainProcMsg(Manager.MSG_INIT, None)
            otask = task(id=id, event=event, *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
        # initialize child process event with parent process event
        Sys.g.MPEVENT = event
        if delay : Sys.sleep(delay)
        mptask(id, *args, **kwargs)
コード例 #5
0
ファイル: cli.py プロジェクト: pluie-org/imprastorage
    def __init__(self, path, remote=False, rwargs=None, thread=None, loglvl=Const.LOG_ALL):
        """"""
        AbstractCli.__init__(self, conf, self)

        Cli.HOME   = conf.DEFVAL_USER_PATH
        Cli.DIRKEY = Cli.HOME+'.'+conf.PRG_NAME.lower()+Sys.sep
        if not Sys.isUnix() :
            Cli.CHQ    = '"'
            Cli.HOME   = 'C:'+Sys.sep+conf.PRG_NAME.lower()+Sys.sep
            Cli.DIRKEY = self.HOME+'keys'+Sys.sep
        Sys.mkdir_p(Cli.DIRKEY)

        gpData = OptionGroup(self.parser, '')
        gpData = OptionGroup(self.parser, '')
        gpConf = OptionGroup(self.parser, '')
        
        gpData.add_option('-c', '--category'      , action='store',       metavar='CATG            ')
        gpData.add_option('-u', '--user'          , action='store',       metavar='OWNER           ')
        gpData.add_option('-l', '--label'         , action='store',       metavar='LABEL           ')
        gpData.add_option('-o', '--order'         , action='store',       metavar='ORDER           '  , default='ID')
        gpData.add_option('-O', '--order-inv'     , action='store',       metavar='ORDER_INVERSE   ')
        gpData.add_option('-a', '--account'       , action='store',       metavar='ACCOUNT         ')
        self.parser.add_option_group(gpData)        

        gpConf.add_option('-V', '--view'          , action='store'                                  )
        gpConf.add_option('-L', '--load'          , action='store'                                  )
        gpConf.add_option('-S', '--save'          , action='store'                                  )
        gpConf.add_option('-C', '--check'         , action='store'                                  )
        gpConf.add_option('-H', '--set-host'      , action='store',       metavar='HOST            ')
        gpConf.add_option('-U', '--set-user'      , action='store',       metavar='USER            ')
        gpConf.add_option('-X', '--set-pass'      , action='store',       metavar='PASS            ')
        gpConf.add_option('-P', '--set-port'      , action='store',       metavar='PORT            ')
        gpConf.add_option('-N', '--set-name'      , action='store',       metavar='NAME            ')
        gpConf.add_option('-M', '--set-multi'     , action='store',       metavar='PROFILE         ')
        gpConf.add_option('-R', '--remove-multi'  , action='store',       metavar='PROFILE         ')
        gpConf.add_option('-B', '--set-boxname'   , action='store',       metavar='BOXNAME         ')
        gpConf.add_option('-K', '--gen-key'       , action='store_true',  default=False)
        self.parser.add_option_group(gpConf)

        # rewrite argv sended by remote
        if rwargs is not None :
            import sys
            sys.argv = rwargs

        (o, a) = self.parser.parse_args()

        Sys.g.QUIET      = o.quiet
        Sys.g.THREAD_CLI = thread
        Sys.g.GUI        = thread is not None

        init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)
        Const.LINE_SEP_LEN = 120

        if not a:
            try :
                if not o.help or not o.version:
                    self.parser.error_cmd(('no command specified',), True)
                else :
                    Sys.clear()
                    Cli.print_help()
            except :
                if not o.version :
                    self.parser.error_cmd(('no command specified',), True)
                else :
                    Cli.print_header()

        else:
            if a[0] == 'help':
                Sys.clear()
                Cli.print_help()

            elif a[0] in ['add','conf','import','info', 'edit','export','get','list','remove','search'] :
                app = CliApp(self.HOME, path, self.parser, Cli, a, o)

                if a[0]=='add':
                    app.onCommandAdd()
                elif a[0]=='conf':
                    app.onCommandConf()
                elif a[0]=='info':
                    app.onCommandInfo()
                elif a[0]=='import':
                    app.onCommandImport()
                elif a[0]=='edit':
                    app.onCommandEdit()
                elif a[0]=='export':
                    app.onCommandExport()
                elif a[0]=='get':
                    app.onCommandGet()
                elif a[0]=='list':
                    app.onCommandList()
                elif a[0]=='remove':
                    app.onCommandRemove()
                elif a[0]=='search':
                    app.onCommandSearch()
                    
                Sys.dprint('PUT END SIGNAL')
                if Sys.g.LOG_QUEUE is not None :
                    Sys.g.LOG_QUEUE.put(Sys.g.SIGNAL_STOP)

            else :
                self.parser.error_cmd((('unknow command ',(a[0],Sys.Clz.fgb3)),), True)

        if not o.quiet : Sys.dprint()
コード例 #6
0
ファイル: cli.py プロジェクト: pluie-org/imprastorage
    def __init__(self, path, remote=False, rwargs=None, thread=None, loglvl=Const.LOG_DEFAULT):
        """"""
        AbstractCli.__init__(self, conf, self)

        Cli.HOME = conf.DEFVAL_USER_PATH
        Cli.DIRKEY = Cli.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(Cli.DIRKEY)

        gpData = OptionGroup(self.parser, "")
        gpData.add_option("-a", "--fullcompress", action="store_true")
        gpData.add_option("-z", "--compress", action="store_true")
        gpData.add_option("-Z", "--nocompress", action="store_true")
        gpData.add_option("-r", "--random", action="store_true")
        gpData.add_option("-R", "--norandom", action="store_true")
        gpData.add_option("-m", "--mix", action="store_true")
        gpData.add_option("-M", "--nomix", action="store_true")
        gpData.add_option("-j", "--multiprocess", action="store")
        gpData.add_option("-k", "--keyfile", action="store")
        gpData.add_option("-l", "--length", action="store", default=1024)
        gpData.add_option("-p", "--parts", action="store", default=22)
        gpData.add_option("-o", "--outputfile", action="store")
        self.parser.add_option_group(gpData)

        # rewrite argv sended by remote
        if rwargs is not None:
            import sys

            sys.argv = rwargs

        (o, a) = self.parser.parse_args()

        Sys.g.QUIET = o.quiet
        Sys.g.THREAD_CLI = thread
        Sys.g.GUI = thread is not None

        init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)

        if not a:
            try:
                if not o.help or not o.version:
                    self.parser.error_cmd(("no command specified",), True)
                else:
                    Sys.clear()
                    Cli.print_help()
            except:
                if not o.version:
                    self.parser.error_cmd(("no command specified",), True)
                else:
                    Cli.print_header()

        else:
            if a[0] == "help":
                Sys.clear()
                Cli.print_help()

            elif a[0] in ["key", "enc", "dec", "split", "merge"]:

                app = CliApp(self.HOME, path, self, a, o)

                if a[0] == "key":
                    app.onCommandKey()
                else:
                    if not len(a) > 1:
                        self.parser.error_cmd((("an ", ("inputFile", Sys.Clz.fgb3), " is required !"),), True)
                    elif not Io.file_exists(a[1]):
                        self.parser.error_cmd((("the file ", (a[1], Sys.Clz.fgb3), " doesn't exists !"),), True)

                    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.parser.error_cmd((("unknow command ", (a[0], Sys.Clz.fgb3)),), True)

        if not o.quiet:
            Sys.dprint()
コード例 #7
0
ファイル: app.py プロジェクト: pluie-org/imprastorage
    def run(self):
        """"""
        self.cancelled = False
        self.evtStop.clear()
        Sys.g.THREAD_CLI       = self
        Sys.g.GUI              = True
        Sys.g.GUI_PRINT_STDOUT = True
        done                   = False
        self.can_retry         = True
        init(conf.PRG_NAME, Sys.g.DEBUG, loglvl=Const.LOG_APP)        
        try :
            if self.impst is None :
                
                label = ' [[ INIT IMPRASTORAGE ]] '
                label = ' '+'~'*((Const.LINE_SEP_LEN-len(label))//2-1)+label+'~'*((Const.LINE_SEP_LEN-len(label))//2-1)+' '
                Sys.pwlog([(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0     , True),
                           (label.ljust(Const.LINE_SEP_LEN, ' ')   , Const.CLZ_INIT  , True),
                           (Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0     , True)])
                
                self.impst = ImpraStorage(self.conf, wkdir='.'+Sys.sep+'wk'+Sys.sep)

            done = True
        except Exception as e :
            self.emit('needconfig')
            raise e
        self.emit('indexrefreshed', done)
        if done :        
            while not self.evtStop.is_set() or not self.cancelled:
                with self.condition :
                    self.condition.wait_for(lambda : not self.taskQueue.empty(), 2)
                    
                    if self.can_retry and self.impst.hasBackupAddMap():
                        self.emit('hasaddretry')
                        self.can_retry = False
                    
                    if not self.taskQueue.empty():
                        task, params, idtask = self.taskQueue.get_nowait()
                        label = ' [[ TASK '+str(idtask)+' : '+self.TASK_LABEL[task].upper()+' ]] '
                        label = ' '+'>'*((Const.LINE_SEP_LEN-len(label))//2-1)+label+'<'*((Const.LINE_SEP_LEN-len(label))//2-1)+' '
                        Sys.pwlog([(Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0     , True),
                                   (label.ljust(Const.LINE_SEP_LEN, ' ')   , Const.CLZ_ACTION, True),
                                   (Const.LINE_SEP_CHAR*Const.LINE_SEP_LEN , Const.CLZ_0     , True)])
                        
                        try:
                            if task is self.TASK_WAIT :
                                print('wait')
                                Sys.sleep(params)
                            elif task is self.TASK_GET:
                                #~ mg        = Manager(self.taskGet, 1, None, Sys.g.MPEVENT, uid=params)
                                #~ mg.run()
                                #~ self.emit('fileget', True, '')
                                #~ Thread(target=self.taskGet, name='impra-1', kwargs={'uid':params}).start()
                                print(params)
                                self.taskGet(params)
                            elif task is self.TASK_ADD:
                                self.taskAdd(params)
                            elif task is self.TASK_ADD_RETRY:
                                self.taskAddRetry(params)
                            elif task is self.TASK_REFRESH:
                                self.taskRefresh(params)
                            elif task is self.TASK_INFOS:
                                self.taskInfos(params)
                            elif task is self.TASK_REMOVE:
                                self.taskRemove(params)
                            elif task is self.TASK_EDIT:
                                self.taskEdit(params)
                            self.taskQueue.task_done()

                        except self.impst.SocketError() as e :
                            Sys.pwarn((('ImpraThread.run : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),))
                            self.impst.reconnect()

                        except Exception as e:
                            print(type(e))
                            Sys.pwarn((('ImpraThread.run : ',(str(e),Sys.CLZ_WARN_PARAM), ' !'),))                            
                    else :
                        """"""
                Sys.sleep(0.5)
        self.emit('completed')
コード例 #8
0
    def __init__(self,
                 path,
                 remote=False,
                 rwargs=None,
                 thread=None,
                 loglvl=Const.LOG_DEFAULT):
        """"""
        AbstractCli.__init__(self, conf, self)

        Cli.HOME = conf.DEFVAL_USER_PATH
        Cli.DIRKEY = Cli.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(Cli.DIRKEY)

        gpData = OptionGroup(self.parser, '')
        gpData.add_option('-a', '--fullcompress', action='store_true')
        gpData.add_option('-z', '--compress', action='store_true')
        gpData.add_option('-Z', '--nocompress', action='store_true')
        gpData.add_option('-r', '--random', action='store_true')
        gpData.add_option('-R', '--norandom', action='store_true')
        gpData.add_option('-m', '--mix', action='store_true')
        gpData.add_option('-M', '--nomix', action='store_true')
        gpData.add_option('-j', '--multiprocess', action='store')
        gpData.add_option('-k', '--keyfile', action='store')
        gpData.add_option('-l', '--length', action='store', default=1024)
        gpData.add_option('-p', '--parts', action='store', default=22)
        gpData.add_option('-o', '--outputfile', action='store')
        self.parser.add_option_group(gpData)

        # rewrite argv sended by remote
        if rwargs is not None:
            import sys
            sys.argv = rwargs

        (o, a) = self.parser.parse_args()

        Sys.g.QUIET = o.quiet
        Sys.g.THREAD_CLI = thread
        Sys.g.GUI = thread is not None

        init(conf.PRG_NAME, o.debug, remote, not o.no_color, loglvl)

        if not a:
            try:
                if not o.help or not o.version:
                    self.parser.error_cmd(('no command specified', ), True)
                else:
                    Sys.clear()
                    Cli.print_help()
            except:
                if not o.version:
                    self.parser.error_cmd(('no command specified', ), True)
                else:
                    Cli.print_header()

        else:
            if a[0] == 'help':
                Sys.clear()
                Cli.print_help()

            elif a[0] in ['key', 'enc', 'dec', 'split', 'merge']:

                app = CliApp(self.HOME, path, self, a, o)

                if a[0] == 'key':
                    app.onCommandKey()
                else:
                    if not len(a) > 1:
                        self.parser.error_cmd(
                            (('an ', ('inputFile', Sys.Clz.fgb3),
                              ' is required !'), ), True)
                    elif not Io.file_exists(a[1]):
                        self.parser.error_cmd(
                            (('the file ',
                              (a[1], Sys.Clz.fgb3), ' doesn\'t exists !'), ),
                            True)

                    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.parser.error_cmd(
                    (('unknow command ', (a[0], Sys.Clz.fgb3)), ))

        if not o.quiet: Sys.dprint()