Esempio n. 1
0
 def validateArguments(commands, values):
     for key in commands.keys():
         if key not in values:
             err = "For subscription maintenance; '%s' is not a valid argument" % (
                 key)
             raise CL.ArgError(err)
     return
Esempio n. 2
0
 def __validateCommands(self):
     if 'runner' not in self.commands:
         raise CL.ArgError(
             "Must specify a 'runner' flag for uEngine script execution")
     if 'operation' in self.commands:
         raise CL.ArgError(
             "Cannot specify an 'operation' flag for uEngine script execution"
         )
     if 'file' in self.commands:
         raise CL.ArgError(
             "Cannot specify a 'file' flag for uEngine script execution")
     if 'command' in self.commands:
         raise CL.ArgError(
             "Cannot specify an 'command' flag for uEngine script execution"
         )
     return 0
Esempio n. 3
0
 def validateOption(operation, key, values):
     if key in self.commands and not validArgument(
             self.commands.get(key), values):
         err = "For subscription maintenance; '%s' operation requires '%s' to be one of %s" % (
             mode, operation, key, values)
         raise CL.ArgError(err)
     return
Esempio n. 4
0
    def __readCommandLine(self):
        # parse the command line
        cl = CL.CommandLine('textdb', config.flags, True)
        args = self.__correctVersionRequest(sys.argv)
        cl.setArgs(args[1:])
        cl.parse()

        self.commands = cl.getCommands()
        try:
            self.__checkCommandCount()
            if self.__hasSubOperations():
                self.__correctSubOpCommandLine()
        except Exception, e:
            raise CL.ArgError(
                "Invalid command line - contains inappropriate combination of operations",
                e)
Esempio n. 5
0
 def __readCommandLine(self):
     # parse the command line
     cl = CL.CommandLine(self.name,config.flags)
     if self.args != None:
         cl.setArgs(self.args)
     else:
         cl.setArgs(sys.argv[1:])
     
     cl.parse()
     if cl.isHelp():
         cl.usage()
         return 1
     
     cl.mergeListsToString()
     self.commands = cl.getCommands()
     
     return self.__validateArgs()
Esempio n. 6
0
 def __checkCommandCount(self):
     if self.commands == None:
         raise CL.ArgError(
             "Invalid command count - NULL command line provided.")
     count = len(self.commands)
     if count == 0:
         raise CL.ArgError(
             "Invalid command count - Empty command line provided.")
     elif count == 1:
         for key in self.commands.keys():
             length = len(self.commands.get(key))
             if key == CL.HELP_KEY:
                 return
             elif key is CL.DEFAULT_KEY:
                 if length < 2:
                     raise CL.ArgError(
                         "Invalid command count - legacy command requires argument"
                     )
             elif key in config.mergeData:
                 return
             else:
                 # determine if the command has 1 ... n args
                 args = config.message.get(
                     key, {})[config.MSG_ARGS][config.MSG_VALUE]
                 if args == -1:
                     if length == 0:
                         raise CL.ArgError(
                             "Invalid command count - '" + key +
                             "' requires at least one argument")
                 else:
                     if args == -2:
                         return
                     elif length != args:
                         raise CL.ArgError("Invalid command count - '" +
                                           key + "' requires " + str(args) +
                                           " args, " + str(length) +
                                           " supplied")
         return
     for command in self.commands.keys():
         try:
             config.mayJoin.index(command)
         except:
             raise CL.ArgError(
                 "Invalid command count - JOIN command includes invalid option(s)"
             )
     return
Esempio n. 7
0
    def __validateArgs(self):
        # private validation functions
        def promptForOK(command,text):
            io = IO.InputOutput()
            msg = "'%s' operation as requested will %s" % (command,text)
            io.writeln(sys.stdout,msg)
            msg = "Confirm operation [Y|N]: "
            io.write(sys.stdout,msg)
            resp = io.readln(sys.stdin)
            return 'Y' == resp.upper()
            
        def validateOption(operation,key,values):
            if key in self.commands and not validArgument(self.commands.get(key),values):
                err = "For subscription maintenance; '%s' operation requires '%s' to be one of %s" % (mode, operation, key, values)
                raise CL.ArgError(err)
            return
        def validateArguments(commands,values):
            for key in commands.keys():
                if key not in values:
                    err = "For subscription maintenance; '%s' is not a valid argument" % (key)
                    raise CL.ArgError(err)
            return
        def validArgument(name,values):
            try:
                values.index(name)
                return True
            except:
                return False
        def countArgs(vals,cmds):
            cnt = 0
            for cmd in vals:
                if cmd in cmds:
                    cnt += 1
            return cnt

        # validate the operation
        if 'operation' not in self.commands:
            raise CL.ArgError("For subscription maintenance; must specify operation")
        else:
            oper = self.commands.get('operation')
            if not validArgument(oper,config.operations):
                raise CL.ArgError("For subscription maintenance; '" + oper +"' is not a valid operation")
        
        # common validation rules
        if 'substitution' in self.commands and 'file' in self.commands:
            raise CL.ArgError("For subscription maintenance; cannot specify substitution values for an external script.")
        if 'command' in self.commands and 'file' not in self.commands:
            raise CL.ArgError("For subscription maintenance; cannot specify command line arguments without specifying an external script")
        
        # operation validation rules
        # per operation validation rules
        oper = self.commands.get('operation')
        if oper == 'add':
            if 'update' in self.commands:
                raise CL.ArgError("For subscription maintenance; update values are invalid for 'add' operation")
            if 'index' in self.commands:
                raise CL.ArgError("For subscription maintenance; index specification is invalid for 'add' operation")
            cnt = countArgs(config.addread,self.commands)
            if cnt < 3:
                raise CL.ArgError("For subscription maintenance; 'add' operation requires all of " + str(config.addread))
            
            try:
                if 'runner' in self.commands and self.commands['runner'] == 'pil':
                    self.commands['runner'] = 'ldad'
                    
                if 'type' in self.commands and self.commands['type'] == 'pil':
                    self.commands['type'] = 'ldad'
                
                validateOption('add','runner',config.runners)
                validateOption('add','type',config.triggers)
            except:
                raise
        
        elif oper == 'read':
            if 'update' in self.commands:
                raise CL.ArgError("For subscription maintenance; update values are invalid for 'read' operation")
            if 'index' in self.commands:
                raise CL.ArgError("For subscription maintenance; index specification is invalid for 'read' operation")
            cnt = countArgs(config.addread,self.commands)
            if cnt == 0:
                raise CL.ArgError("For subscription maintenance; 'read' must specify a one of " + str(config.addread))

            try:
                if 'runner' in self.commands and self.commands['runner'] == 'pil':
                    self.commands['runner'] = 'ldad'
                    
                if 'type' in self.commands and self.commands['type'] == 'pil':
                    self.commands['type'] = 'ldad'
                
                validateOption('read','runner',config.runners)
                validateOption('read','type',config.triggers)
            except:
                raise
        
        elif oper == 'delete':
            # need to validate naked delete -- subscription -o delete
            if len(self.commands) == 1:
                ok = promptForOK(oper,"clear the entire subscriptions table")
                if not ok:
                    return 1
            # verify that commands with 'index' have no additional arguments.
            if 'index' in self.commands and len(self.commands) != 2:
                raise CL.ArgError("For subscription maintenance; 'delete' operation with an 'index' option cannot have additional options")

            if 'update' in self.commands:
                raise CL.ArgError("For subscription maintenance; update values are invalid for 'delete' operation")

            try:
                if 'runner' in self.commands and self.commands['runner'] == 'pil':
                    self.commands['runner'] = 'ldad'
                    
                if 'type' in self.commands and self.commands['type'] == 'pil':
                    self.commands['type'] = 'ldad'
                
                if 'trigger' in self.commands:
                    validateOption('delete','runner',config.runners)
                    validateOption('delete','type',config.triggers)
            except:
                raise

        elif oper == 'update':
            if 'index' not in self.commands:
                raise CL.ArgError("For subscription maintenance; index specification is required for 'update' operation")
            if 'update' not in self.commands:
                raise CL.ArgError("For subscription maintenance; update values are required for 'update' operation")
            try:
                validateArguments(self.commands,config.update)
            except:
                raise
        else:
            raise CL.ArgError("For subscription maintenance; " + oper + " is not a valid operation")
        return 0