Ejemplo n.º 1
0
    def testUpdatePass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty(
            "plugin.dir",
            NOORA_DIR + os.sep + "org" + os.sep + "noora" + os.sep + "plugin")
        properties.setProperty("current.dir", os.path.abspath('.'))
        properties.setProperty(
            "alter.dir",
            properties.getPropertyValue("current.dir") + os.sep + "alter")
        properties.setProperty(
            "create.dir",
            properties.getPropertyValue("current.dir") + os.sep + "create")

        #connectable=MysqlConnector()
        updatePlugin = UpdatePlugin()
        print(updatePlugin.getRevision())
        options = updatePlugin.getOptions(properties)

        arguments = ['-h=localhost', '-e=dev', '-v=1.0.1']
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        updatePlugin.execute(commandLine, properties)
Ejemplo n.º 2
0
    def testProcessor(self):

        script = File("drop_tables.sql")
        scriptReader = FileReader(script)

        properties = Properties()
        properties.setProperty('database', 'orcl')

        parser = Parser(scriptReader, properties)
        preProcessor = PreProcessor()
        stream = preProcessor.parse(parser)
        self.assertEqual(stream, 'orcl', "invalid transformation")
Ejemplo n.º 3
0
  def testVersionLoader(self):
    
    properties = Properties()        
    propertyLoader = PropertyLoader(properties)        

    file = File("myproject.conf")
    fileReader = FileReader(file) 
    propertyLoader.load(fileReader)
    
    properties.setProperty("current.dir", os.path.abspath('.'))
    properties.setProperty("project.file", "myproject.conf")
    properties.setProperty("alter.dir",Path.path(properties.getPropertyValue("current.dir"),"alter"))
    properties.setProperty("create.dir",Path.path(properties.getPropertyValue("current.dir"),"create"))
    print "current.dir",properties.getPropertyValue("current.dir")
    #print "alter.dir",properties.getPropertyValue("alter.dir")
    #print "default_version :" + properties.getPropertyValues("DEFAULT_VERSION")
    
    
    # a File object is not a Version object
    # 
    versions = Versions()
    versionLoader = VersionLoader(versions)
    versionLoader.load(properties)
    versions.sort()
    #versions.sort()
    #print "versions",versions.getVersions()
    v = Version('1.0.1')
    print versions.previous(v).getValue()
    
    print versions.last().toString()
    print versions.next().toString()
    
    versionGuesser=VersionGuesser(properties, versions)
    nextVersion = versionGuesser.guess(None).toString()
    print versionGuesser.toFolder(nextVersion)
Ejemplo n.º 4
0
    def testOracleConnector(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("project.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("noora.script.dir",
                               NOORA_DIR + os.sep + 'scripts')

        connector = OracleConnector()
        execute = ExecuteFactory.newOracleExecute()
        execute.setHost('orcl')
        execute.setUsername('apps')
        execute.setPassword('apps')
        file = File('application_properties.sql')
        execute.setScript(file)

        connector.execute(execute, properties)
Ejemplo n.º 5
0
    def testDropPass(self):

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

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)

        #connectable=MysqlConnector()
        dropPlugin = DropPlugin()
        options = dropPlugin.getOptions(properties)

        arguments = ['-h=localhost', '-d=orcl', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)

        dropPlugin.execute(commandLine, properties)
Ejemplo n.º 6
0
    def testCreatePass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)

        #connectable=MysqlConnector()
        createPlugin = CreatePlugin()
        print(createPlugin.getRevision())
        options = createPlugin.getOptions(properties)

        arguments = ['-h=localhost', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        createPlugin.execute(commandLine, properties)
Ejemplo n.º 7
0
    def testXmlFileReader(self):
        file = File("project.xml")
        fileReader = XmlFileReader(file)
        stream = fileReader.read()

        properties = Properties()
        root = stream.getroot()
        for element in self.getElement(root):
            property = properties.getProperty(element[0])
            if property != None:

                value = property.getValue()
                property.setValue(value + ',' + str(element[1]))
            else:
                properties.setProperty(element[0], str(element[1]))
            print element
        #for index in range(root.__len__()):
        #  print root.__getitem__(index)

        #for element in stream.iter():
        #  if element.__len__()!=0:
        #    for index in range(element.__len__()):
        #      print element.__getitem__(index)

        print "------------------"
        #for element in stream.iter():

        #  if element.text != None:
        #    if element.text.strip()!="":
        #      #print element.tag,"-->","'"+element.text+"'"
        #      properties.setProperty(element.tag, element.text)
        #    else:
        #      pass
        #print element.tag
        fileReader.close()
        print "properties.size:", properties.size()
        for property in properties.list():
            print property.getKey(), "-->", property.getValue()
Ejemplo n.º 8
0
    def testDropPluginPass(self):

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

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("project.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("noora.script.dir",
                               NOORA_DIR + os.sep + "scripts")

        connectable = OracleConnectorStub()
        dropPlugin = PluginFactory.newOracleDropPlugin(connectable)
        options = dropPlugin.getOptions(properties)

        arguments = ['-s=orcl', '-e=dev']
        parser = Parser()
        commandLine = parser.parse(options, arguments)

        dropPlugin.execute(commandLine, properties)
Ejemplo n.º 9
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)
Ejemplo n.º 10
0
    def testGenerateUpdateGuess(self):
        properties = Properties()
        properties.setProperty("noora.dir", NOORA_DIR)
        properties.setProperty("plugin.dir",
                               Path.path(NOORA_DIR, "org", "noora", "plugin"))
        properties.setProperty("current.dir",
                               Path.path(os.path.abspath('.'), 'example'))
        properties.setProperty(
            "alter.dir",
            Path.path(properties.getPropertyValue("current.dir"), "alter"))
        properties.setProperty(
            "create.dir",
            Path.path(properties.getPropertyValue("current.dir"), "create"))
        properties.setProperty("project.file", "myproject.conf")

        #connectable=MysqlConnector()
        generatePlugin = GeneratePlugin()
        print(generatePlugin.getRevision())
        options = generatePlugin.getOptions(properties)

        arguments = []
        parser = Parser()
        commandLine = parser.parse(options, arguments)
        parser.checkRequiredOptions()
        parser.checkRequiredArguments()
        generatePlugin.execute(commandLine, properties)
Ejemplo n.º 11
0
 def execute(self, executable, properties):
   
     
   cp = Properties()
   cp.setProperty('database', executable.getDatabase())
   cp.setProperty('environment', properties.getPropertyValue('environment'))    
   cp.setProperty('previous', properties.getPropertyValue('previous'))  
   
   feedback = File('feedback.log')
   feedbackWriter = FileWriter(feedback) 
   
   startupInfo = StartupInfoFactory.newStartupInfo()      
   
   cp = Properties()
   cp.setProperty(Processor.STDERR, feedbackWriter)
   cp.setProperty(Processor.STDIN, None)
   cp.setProperty(Processor.STDOUT, feedbackWriter)
   cp.setProperty(Processor.STARTUPINFO, startupInfo)
   cp.setProperty(Processor.ARGUMENT, ["psql",
                                       "--host="+executable.getHost(),
                                       "--port="+executable.getPort(),
                                       "-U", executable.getUsername(),
                                       "-w",
                                       "-d", executable.getDatabase(),
                                       "-f", executable.getScript()])
   cp.setProperty(Processor.SHELL, False)
   psqlCall= Call(cp)
         
   processor = Processor()
   processorResult = processor.call(psqlCall)
   self.setProcessorResult(processorResult)
        
   logger = logging.getLogger('NoOraLogger')
   logger.info(executable.getScript())
Ejemplo n.º 12
0
    def execute(self, commandLine, properties):

        project = commandLine.getOptionValue('-pr')
        version = commandLine.getOptionValue('-v')

        configFile = File(
            Path.path(properties.getPropertyValue('current.dir'),
                      properties.getPropertyValue('project.file')))
        if configFile.exists() == False:
            #project = commandLine.getOptionValue('-pr')
            host = commandLine.getOptionValue('-h')
            port = commandLine.getOptionValue('-p')
            database = commandLine.getOptionValue('-d')
            username = commandLine.getOptionValue('-u')
            #password = commandLine.getOptionValue('-p')
            #version = commandLine.getOptionValue('-v')

            # create the project folder
            os.makedirs(project)

            #create project.conf
            templateFolder = Path.path(
                properties.getPropertyValue('plugin.dir'), 'postgresql',
                'generate', 'templates')
            templateFile = File(
                Path.path(properties.getPropertyValue('plugin.dir'),
                          'postgresql', 'generate', 'templates',
                          properties.getPropertyValue('project.file')))
            reader = FileReader(templateFile)
            stream = reader.read()
            stream = stream.replace('{host}', host)
            stream = stream.replace('{port}', port)
            stream = stream.replace('{database}', database)
            stream = stream.replace('{username}', username)
            #stream=stream.replace('{password}',password)
            stream = stream.replace('{version}', version)

            configFile = File(
                Path.path(properties.getPropertyValue('current.dir'), project,
                          properties.getPropertyValue('project.file')))
            writer = FileWriter(configFile)
            writer.write(stream)
            writer.close()

        alterDir = Path.path(properties.getPropertyValue('current.dir'),
                             project, 'alter')
        createDir = Path.path(properties.getPropertyValue('current.dir'),
                              project, 'create')

        # load project.conf
        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        fileReader = FileReader(configFile)
        propertyLoader.load(fileReader)

        properties.setProperty("alter.dir", alterDir)
        properties.setProperty("create.dir", createDir)

        # resolve the version folder
        # create the version folder

        versions = Versions()
        versionLoader = VersionLoader(versions)
        versionLoader.load(properties)
        versions.sort()
        #print versions.list()
        versionGuesser = VersionGuesser(properties, versions)
        nextVersion = versionGuesser.guess(version).toString()
        versionFolder = versionGuesser.toFolder(nextVersion)

        databases = properties.getPropertyValues('DATABASES')
        versionDatabase = properties.getPropertyValues('VERSION_DATABASE')
        defaultVersion = properties.getPropertyValues('DEFAULT_VERSION')
        environments = properties.getPropertyValues('ENVIRONMENTS')
        objects = properties.getPropertyValues('CREATE_OBJECTS')

        # create the version folder
        os.makedirs(versionFolder)

        for database in databases:

            # create the scheme folder
            databaseFolder = versionFolder + os.sep + database
            os.mkdir(databaseFolder)

            # create the dat folder
            datFolder = Path.path(databaseFolder, 'dat')
            os.mkdir(datFolder)

            # create the version script in the dat folder
            if database == versionDatabase:
                versionFile = File(Path.path(datFolder, "version.sql"))
                versionFileWriter = FileWriter(versionFile)

                if nextVersion == defaultVersion:
                    stream = properties.getPropertyValues(
                        'VERSION_INSERT_STATEMENT')
                else:
                    stream = properties.getPropertyValues(
                        'VERSION_UPDATE_STATEMENT')

                stream = stream.replace('<version>', nextVersion)

                versionFileWriter.write(stream)
                versionFileWriter.close()

                #sqlScript=self.getSqlVersionStatement(versions, version)
                #projectHelper.writeFile(datFolder+os.sep+'version.sql', sqlScript)

            # create the environment folders in the dat folder
            for environment in environments:

                os.mkdir(Path.path(datFolder, environment))

                # create the environment script in the dat folder.
                if database == versionDatabase and nextVersion == defaultVersion:
                    environmentFile = File(
                        Path.path(datFolder, environment, 'environment.sql'))
                    environmentFileWriter = FileWriter(environmentFile)
                    stream = properties.getPropertyValues(
                        'ENVIRONMENT_INSERT_STATEMENT')
                    stream = stream.replace('<environment>', environment)

                    environmentFileWriter.write(stream)
                    environmentFileWriter.close()

                    #sqlScript=self.getSqlEnvironmentStatement(environment)
                    #projectHelper.writeFile(datFolder+os.sep+environment+os.sep+'environment.sql', sqlScript)

            # create the ddl folder
            ddlFolder = Path.path(databaseFolder, 'ddl')
            os.mkdir(ddlFolder)

            # create the object folders in the ddl folder
            for object in objects:
                os.mkdir(Path.path(ddlFolder, object))

            # create the template code on create.
            if database == versionDatabase and nextVersion == defaultVersion:
                for object in objects:
                    objectFolder = Path.path(templateFolder, object)
                    objectFile = File(objectFolder)
                    if objectFile.exists():
                        files = Files.list(objectFile)
                        for file in files:
                            fileReader = FileReader(file)
                            stream = fileReader.read()
                            fileReader.close()

                            target = File(
                                Path.path(ddlFolder, object, file.getName()))
                            targetWriter = FileWriter(target)
                            targetWriter.write(stream)
                            targetWriter.close()

        print "version " + nextVersion + " created."
Ejemplo n.º 13
0
 def testProperties(self):
     properties = Properties()
     properties.setProperty("application.version", "1.0.0")
     self.assertEqual(properties.size(), 1, "invalid size")
     properties.clear()
     self.assertEqual(properties.size(), 0, "invalid size")
Ejemplo n.º 14
0
        for plugin in plugins:
            if plugin.getType().lower() == type.lower():
                return plugin


def getRevision(app):
    print "noora version '" + app.getVersion() + "'"
    print "noora runtime (build " + app.getVersion() + "_" + app.getRevision(
    ).split(":")[1].rstrip("$").strip() + ")"


if __name__ == "__main__":

    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')
    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)
Ejemplo n.º 15
0
    def execute(self, executable, properties):

        script = executable.getScript()

        feedback = File('feedback.log')
        feedbackWriter = FileWriter(feedback)

        startupInfo = StartupInfoFactory.newStartupInfo()
        template = properties.getPropertyValue(
            "noora.script.dir") + os.sep + "template.sql"

        cp = Properties()
        cp.setProperty(Processor.STDERR, feedbackWriter)
        cp.setProperty(Processor.STDIN, None)
        cp.setProperty(Processor.STDOUT, feedbackWriter)
        cp.setProperty(Processor.STARTUPINFO, startupInfo)

        cp.setProperty(Processor.ARGUMENT, [
            "sqlplus", "-l", "-s",
            executable.getUsername() + "/" + executable.getPassword() + '@' +
            executable.getHost(), "@ " + template,
            script.getAbsolutePath() + os.sep + script.getName()
        ])
        cp.setProperty(Processor.SHELL, False)
        oracleCall = Call(cp)

        processor = Processor()
        processor.call(oracleCall)

        logger = logging.getLogger('NoOraLogger')
        logger.info(executable.getScript())
Ejemplo n.º 16
0
    def execute(self, executable, properties):

        script = executable.getScript()
        scriptReader = FileReader(script)

        cp = Properties()
        cp.setProperty('database', executable.getDatabase())
        cp.setProperty('environment',
                       properties.getPropertyValue('environment'))
        cp.setProperty('previous', properties.getPropertyValue('previous'))
        parser = Parser(scriptReader, cp)
        preProcessor = PreProcessor()
        stream = preProcessor.parse(parser)

        tmp = File("tmp.sql")
        tmpWriter = FileWriter(tmp)
        tmpWriter.write(stream)
        tmpWriter.close()

        scriptReader = FileReader(tmp)

        feedback = File('feedback.log')
        feedbackWriter = FileWriter(feedback)

        startupInfo = StartupInfoFactory.newStartupInfo()

        cp = Properties()
        cp.setProperty(Processor.STDERR, feedbackWriter)
        cp.setProperty(Processor.STDIN, scriptReader)
        cp.setProperty(Processor.STDOUT, feedbackWriter)
        cp.setProperty(Processor.STARTUPINFO, startupInfo)
        cp.setProperty(Processor.ARGUMENT, [
            "mysql", "--show-warnings", "--host=" + executable.getHost(),
            "--user="******"--password=" + executable.getPassword(),
            executable.getDatabase()
        ])
        cp.setProperty(Processor.SHELL, False)
        mysqlCall = Call(cp)

        processor = Processor()
        processorResult = processor.call(mysqlCall)
        self.setProcessorResult(processorResult)

        logger = logging.getLogger('NoOraLogger')
        logger.info(executable.getScript())
Ejemplo n.º 17
0
    def execute(self, mysqlHost, mysqlDatabase, mysqlUser, mysqlPasswd,
                mysqlScript, paramA, paramB, ignoreErrors):
        #try:

        script = File(mysqlScript)
        scriptReader = FileReader(script)

        properties = Properties()
        properties.setProperty('database', mysqlDatabase)
        parser = Parser(scriptReader, properties)
        preProcessor = PreProcessor()
        stream = preProcessor.parse(parser)

        tmp = File("tmp.sql")
        tmpWriter = FileWriter(tmp)
        tmpWriter.write(stream)
        tmpWriter.close()

        scriptReader = FileReader(tmp)

        feedback = File('feedback.log')
        feedbackWriter = FileWriter(feedback)

        startupInfo = StartupInfoFactory.newStartupInfo()

        properties = Properties()
        properties.setProperty(Processor.STDERR, feedbackWriter)
        properties.setProperty(Processor.STDIN, scriptReader)
        properties.setProperty(Processor.STDOUT, feedbackWriter)
        properties.setProperty(Processor.STARTUPINFO, startupInfo)
        properties.setProperty(Processor.ARGUMENT, [
            "mysql", "--host=" + str(mysqlHost), "--user="******"--password=" + str(mysqlPasswd),
            str(mysqlDatabase)
        ])
        properties.setProperty(Processor.SHELL, False)
        mysqlCall = Call(properties)

        processor = Processor()
        processor.call(mysqlCall)

        logger = logging.getLogger('NoOraLogger')
        logger.info(mysqlScript)
Ejemplo n.º 18
0
    def testZipPass(self):

        properties = Properties()
        propertyLoader = PropertyLoader(properties)
        file = File("myproject.conf")
        fileReader = FileReader(file)
        propertyLoader.load(fileReader)

        properties.setProperty("current.dir", os.path.abspath('.'))
        properties.setProperty(
            "alter.dir",
            properties.getPropertyValue("current.dir") + os.sep + "alter")
        properties.setProperty(
            "create.dir",
            properties.getPropertyValue("current.dir") + os.sep + "create")

        versions = Versions()
        versionLoader = VersionLoader(versions)
        versionLoader.load(properties)
        versions.sort()
        #print versions.list()
        versionGuesser = VersionGuesser(properties, versions)
        version = versionGuesser.toFolder('1.0.0')

        currentFile = File(os.path.abspath('.'))
        current = Path.path(currentFile.getPath(), currentFile.getName())

        targetPath = Path.path(current, 'target')
        targetFile = File(targetPath)
        if not targetFile.exists():
            os.makedirs(targetPath)

        zipHandle = ZipFile(
            targetPath + os.sep + 'example_' + version + '.zip', 'w')

        excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS')

        files = Files.list(currentFile, True)

        filters = Filters()

        excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS')
        for excludedFolder in excludedFolders:
            ef = File(excludedFolder)
            ff = FileFolderFilter(ef)
            filters.add(ff)

        for file in files:

            result = False
            for excludedFolder in excludedFolders:
                if excludedFolder in file.getPath() + file.getName():
                    result = True
                    break

            #if filters.accept(file)==False:
            if not result:
                source = Path.path(file.getPath(), file.getName())
                target = source.replace(current, '')
                print file.getPath(), file.getName()

                zipHandle.write(source, target, zipfile.ZIP_DEFLATED)