Exemple #1
0
 def testUnrecognizedOption(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   parser = Parser()
       
   try:
     commandLine = parser.parse(options,['-q'])
   except UnrecognizedOptionException as uoe:
     self.assertEquals(uoe.getMessage(), 'unrecognized option -q')
Exemple #2
0
 def testMissingArgument(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   parser = Parser()
   commandLine = parser.parse(options,['-s'])
   
   try:
     parser.checkRequiredArguments()
   except MissingArgumentException as mae:
     self.assertEquals(mae.getMessage(), 'missing argument in option -s')
Exemple #3
0
 def testMissingArgumentValue(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, True, "scheme (user) of the database.")
   option = options.getOption("-s")
   option.setValues(['localhost'])
   parser = Parser()
   
   
   
   try:
     commandLine = parser.parse(options,['-s=orcl'])
     
   except UnrecognizedArgumentException as uae:
     self.assertEquals(uae.getMessage(), 'unrecognized argument orcl')
Exemple #4
0
 def testOptions(self):
   options = Options()
   options.addOption("-?","--help", False, False,  "display help")      
   options.addOption("-s","--sid", True, True, "tnsname (sid) of the database.")
   options.addOption("-u","--user", True, False, "scheme (user) of the database.")
   self.assertEquals(options.size(),3, "invalid number of options")
   parser = Parser()
   commandLine = parser.parse(options,['-s=orcl','--user=apps'])
   
   self.assertEquals(commandLine.hasOption('-s'), True, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-?'), False, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-t'), False, "invalid parameter")
   self.assertEquals(commandLine.hasOption('-u'), True, "invalid parameter")
   self.assertEquals(commandLine.getOptionValues('-s'), ['orcl'], "invalid option value")
   self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value")
   self.assertEquals(commandLine.getOptionValue('-s'), 'orcl', "invalid option value")
Exemple #5
0
class CommandLine:
    def __init__(self):
        self.__options = Options()

    def addOption(self, option):
        self.__options.add(option)

    def hasOption(self, type):
        options = self.__options
        return options.hasOption(type)

    def getOption(self, type):
        options = self.getOptions()
        if options.hasOption(type):
            return options.getOption(type)

    def getOptionValues(self, type, defaultValue=None):
        options = self.getOptions()
        if options.hasOption(type):
            option = options.getOption(type)
            return option.getValues()
        return defaultValue

    def getOptionValue(self, type, defaultValue=None):
        options = self.getOptions()
        if options.hasOption(type):
            option = options.getOption(type)
            return option.getValue()
        return defaultValue

    def getRequiredArguments(self):
        options = self.getOptions()
        return options.getRequiredArguments()

    def getOptions(self):
        return self.__options
Exemple #6
0
    def testNoOraAppPass(self):

        NOORA_DIR = os.path.abspath('.').split('test')[0] + "src"

        sys.path.append(NOORA_DIR)
        CURRENT_DIR = os.path.abspath('.')

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("current.dir", CURRENT_DIR)
        properties.setProperty(
            "plugin.dir",
            NOORA_DIR + os.sep + 'org' + os.sep + 'noora' + os.sep + 'plugin')
        app = NoOraApp()
        file = app.getConfigFile(properties)
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        classLoader = ClassLoader()
        options = Options()
        pluginManager = PluginManager(classLoader, options)
        pluginsProperty = properties.getProperty('PLUGINS')
        pluginManager.load(pluginsProperty)
        options = pluginManager.getOptions()

        arguments = [
            'drop', 'create', 'update', '-h=localhost', '-d=orcl', '-e=dev',
            '-v=1.0.1'
        ]

        parser = Parser()
        commands = parser.parse(options, arguments)

        for command in commands.getOptions().getOptions():
            plugin = pluginManager.findByType(command.getType())

            options = plugin.getOptions(properties)
            commandLine = parser.parse(options, arguments)
            parser.checkRequiredOptions()
            parser.checkRequiredArguments()

            plugin.execute(commandLine, properties)
Exemple #7
0
 def __init__(self):
     self.__options = Options()
Exemple #8
0
 def __init__(self, type, connectable):
   Pluginable.__init__(self, type, connectable)
   self.__options = Options()
   self.setType(type)
   self.setConnector(connectable)    
Exemple #9
0
        NOORA_DIR + os.sep + 'org' + os.sep + 'noora' + os.sep + 'plugin')
    properties.setProperty("project.file", "pgproject.conf")
    properties.setProperty(
        "alter.dir",
        properties.getPropertyValue("current.dir") + os.sep + "alter")
    properties.setProperty(
        "create.dir",
        properties.getPropertyValue("current.dir") + os.sep + "create")

    app = NoOraApp()
    file = app.getConfigFile(properties)
    fileReader = FileReader(file)
    propertyLoader.load(fileReader)

    classLoader = ClassLoader()
    options = Options()
    pluginManager = PluginManager(classLoader, options)
    pluginsProperty = properties.getProperty('PLUGINS')
    pluginManager.load(pluginsProperty)
    options = pluginManager.getOptions()

    #arguments = ['drop','create','update','-h=localhost','-d=orcl','-e=dev','-v=1.0.1']
    arguments = sys.argv[1:]

    parser = Parser()
    commands = parser.parse(options, arguments)

    for command in commands.getOptions().getOptions():

        plugin = pluginManager.findByType(command.getType())