Exemple #1
0
    def testFileExtensionFilter(self):

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

        excludedExtensions = properties.getPropertyValues(
            'EXCLUDED_EXTENSIONS')
        self.assertEquals(excludedExtensions, ['bak', '~', 'pyc', 'log'],
                          "'bak', '~', 'pyc', 'log' expected")

        filters = Filters()
        for excludedExtension in excludedExtensions:
            ef = File("*." + excludedExtension)
            ff = FileExtensionFilter(ef)
            filters.add(ff)

        file = File('install.sql')
        self.assertEquals(filters.accept(file), False,
                          "install.sql is in filter.")

        file = File('install.pyc')
        self.assertEquals(filters.accept(file), True,
                          "install.pyc is not in filter.")
Exemple #2
0
    def testFileFilter(self):

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

        excludedFiles = properties.getPropertyValues('EXCLUDED_FILES')
        self.assertEquals(excludedFiles, ['install.sql'],
                          "install.sql expected")

        # install.sql is an excluded file.
        filters = Filters()
        for excludedFile in excludedFiles:
            ef = File(excludedFile)
            ff = FileFilter(ef)
            filters.add(ff)

        file = File('test.sql')
        self.assertEquals(filters.accept(file), False,
                          "test.sql is in filter.")

        file = File('install.sql')
        self.assertEquals(filters.accept(file), True,
                          "install.sql is not in filter.")
Exemple #3
0
    def testFileFolderFilter(self):

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

        excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS')
        self.assertEquals(excludedFolders, ['.svn', 'hotfix'],
                          "'.svn', 'hotfix' expected")

        filters = Filters()
        for excludedFolder in excludedFolders:
            ef = File(excludedFolder)
            ff = FileFolderFilter(ef)
            filters.add(ff)
        file = File(NOORA_DIR + os.sep + 'org/noora/plugin/mysql/drop/.svn')
        self.assertEquals(filters.accept(file), True, ".svn is in filter.")
        file = File('.svn')
        self.assertEquals(filters.accept(file), True, ".svn is in filter.")
Exemple #4
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."
  def execute(self, commandLine, properties):
    
    version = commandLine.getOptionValue('-v')

    configFile = File(Path.path(properties.getPropertyValue('current.dir'),properties.getPropertyValue('project.file')))
    if configFile.exists()==False:      
      client = commandLine.getOptionValue('-c')
      username = commandLine.getOptionValue('-u')
      password = commandLine.getOptionValue('-p')
      workspace = commandLine.getOptionValue('-w')

      #create project.conf
      templateFolder = Path.path(properties.getPropertyValue('plugin.dir'),'tripolis','generate','templates')
      templateFile = File(Path.path(properties.getPropertyValue('plugin.dir'),'tripolis','generate','templates',properties.getPropertyValue('project.file')))
      reader = FileReader(templateFile)
      stream = reader.read()
      stream=stream.replace('{client}',client)
      stream=stream.replace('{username}',username)
      stream=stream.replace('{password}',password)
      stream=stream.replace('{workspace}',workspace)
      
      configFile = File(Path.path(properties.getPropertyValue('current.dir'),properties.getPropertyValue('project.file')))
      writer = FileWriter(configFile)
      writer.write(stream)
      writer.close()

    # create the project folder
    versionDir = Path.path(properties.getPropertyValue('current.dir'), version)
    os.makedirs(versionDir)

    direct_email_type = commandLine.getOptionValue('-d')
    directEmailTypeDir = Path.path(properties.getPropertyValue('current.dir'), version, direct_email_type)
    os.makedirs(directEmailTypeDir)

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

    environments = project_conf.getPropertyValues('ENVIRONMENTS')
    for environment in environments:
      os.mkdir(Path.path(properties.getPropertyValue('current.dir'), version, direct_email_type, environment))
    #
    #
    # # 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('DIRECT_EMAIL_TYPES')   # add to project.cong
    # 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 "+version+" created."
    
Exemple #6
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)