Example #1
0
 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)
Example #2
0
 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)
Example #3
0
 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)
             k = KeyGen(conf.DEFVAL_UKEY_LENGHT)
             print(k)
             content = k.key
             print('content')
             Io.set_data(kpath, content)
             print('set content')
     self.selectKey(kpath)
Example #4
0
    def getFileParts(self, row, ids):
        """"""
        done = False
        if len(ids) >= row[self.idxu.index.PARTS]:
            for i, uid in enumerate(ids):
                d = Sys.datetime.now()
                self.idxu.ih.getAttachment(uid, self.inbox, True)

                Sys.pwlog(
                    [
                        (" part ", Const.CLZ_0),
                        (str(i + 1).rjust(2, " "), Const.CLZ_2),
                        (" / ", Const.CLZ_0),
                        (str(len(ids)), Const.CLZ_3),
                        (" downloaded in ", Const.CLZ_0),
                        (Sys.getDelta(d), Const.CLZ_4, True),
                    ]
                )

                Sys.cli_emit_progress(int((i + 1) * 100 / len(ids)))
                Sys.sleep(0.5)

            Sys.mkdir_p(self.deploy + row[self.idxu.index.CATG])
            Sys.cli_emit_progress(100)
Example #5
0
    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()
Example #6
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)),), True)

        if not o.quiet:
            Sys.dprint()
Example #7
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])
Example #8
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])
Example #9
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()