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.")
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.")
def testPropertyLoader(self): properties = Properties() propertyLoader = PropertyLoader(properties) fileReader = self.getFileReader("test.conf") propertyLoader.load(fileReader) self.assertEqual(properties.size(), 4, "invalid size") property = properties.getProperty("ORACLE_USERS") self.assertEqual(len(eval(property.getValue())), 2, "invalid size")
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")
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.")
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)
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)
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)
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()
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)
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)
def findByType(self, type): plugins = self.getPlugins() 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()
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())
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())
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")
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)
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."
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)
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 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)
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())
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)
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)