def execute(self, commandLine, properties): name = commandLine.getOptionValue('-n') version = commandLine.getOptionValue('-v') current = properties.getPropertyValue('current.dir') versions = Versions() versionLoader = VersionLoader(versions) versionLoader.load(properties) versions.sort() #print versions.list() versionGuesser = VersionGuesser(properties, versions) versionFolder = versionGuesser.toFolder(version) # create the target folder targetPath = Path.path(current, 'target') targetFile = File(targetPath) if not targetFile.exists(): os.makedirs(targetPath) zipFilename = name + '_' + version + '.zip' zipHandle = ZipFile(targetPath + os.sep + zipFilename, 'w') files = Files.list(File(versionFolder), True) for file in files: source = Path.path(file.getPath(), file.getName()) target = source.replace(current, '') zipHandle.write(source, target, zipfile.ZIP_DEFLATED) print zipFilename + ' created.'
def POST(self, hashcode): render = self.getRenderer().getRender() db = self.getPersister().getDatabase() form = self.getForm() #if not form.validates(): # return render.project_edit(project, form) x = web.input(upload={}) folder = File(Path.path('projects',hashcode)) if not folder.exists(): os.makedirs(Path.path(folder.getPath(),folder.getName())) fout = open(Path.path('projects',hashcode ,x.upload.filename),'wb') # creates the file where the uploaded file should be stored fout.write(x.upload.file.read()) # writes the uploaded file to the newly created file. fout.close() # closes the file, u projectFileModel = ProjectFileModel(db) projectFileModel.newProjectFile(hashcode, x.upload.filename) #projectModel = ProjectModel(db) #project = projectModel.getProject(hashcode) #projectModel.updateProject(hashcode, form.d.name) raise web.seeother('/project_edit/'+hashcode)
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 execute(self, commandLine, properties): defaultWorkspace = properties.getPropertyValues('DEFAULT_WORKSPACE') workspace = commandLine.getOptionValue('-w', defaultWorkspace) defaultEnvironment = properties.getPropertyValues( 'DEFAULT_ENVIRONMENT') environment = commandLine.getOptionValue('-e', defaultEnvironment) version = commandLine.getOptionValue('-v') version_in_description = properties.getPropertyValues( 'VERSION_IN_DESCRIPTION') connector = self.getConnector() folder = File(Path.path(os.path.abspath('.'), version)) for directEmailType in Files.list(folder): print "Creating '" + directEmailType.getName( ) + "' emails, using environment '" + environment + "'" executor = ExecuteFactory.newTripolisExecute() executor.setWorkspace(workspace) executor.setDirectEmailType(directEmailType.getName()) if version_in_description == 'Y': executor.setAdditionalDescription(version) # global email objects ConnectionExecutor.execute(connector, executor, properties, directEmailType) # environment specific email objects ConnectionExecutor.execute( connector, executor, properties, File( Path.path(directEmailType.getPath(), directEmailType.getName(), environment))) print "'" + directEmailType.getName() + "' emails created."
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 execute(self, commandLine, properties): ignoreErrors = commandLine.getOptionValue('--ignore-errors', False) host = commandLine.getOptionValue('-h') port = commandLine.getOptionValue('-p') defaultDatabases = properties.getPropertyValues('DATABASES') databases = commandLine.getOptionValues('-d', defaultDatabases) defaultEnvironment = properties.getPropertyValues( 'DEFAULT_ENVIRONMENT') environment = commandLine.getOptionValue('-e', defaultEnvironment) objects = properties.getPropertyValues('CREATE_OBJECTS') connector = self.getConnector() for database in databases: print "creating database '" + database + "' on host '" + host + ":" + port + "' using environment '" + environment + "'" users = properties.getPropertyValues('POSTGRESQL_USERS') user = PropertyHelper.getPostgresqlUser(users, host, port, database) # password is fetched from ~/.pgpass by the psql executable itself #passwd = PropertyHelper.getPostgresqlPasswd(users, host, database) executor = ExecuteFactory.newPostgresqlExecute() executor.setHost(host) executor.setPort(port) executor.setDatabase(database) executor.setIgnoreErrors(ignoreErrors) executor.setPassword(passwd) executor.setUsername(user) for object in objects: # global ddl objects folder = File(self.getCreateDir() + os.sep + database + os.sep + 'ddl' + os.sep + object) ConnectionExecutor.execute(connector, executor, properties, folder) # environment specific ddl objects folder = File(self.getCreateDir() + os.sep + database + os.sep + 'ddl' + os.sep + object + os.sep + environment) ConnectionExecutor.execute(connector, executor, properties, folder) # global dat objects folder = File(self.getCreateDir() + os.sep + database + os.sep + 'dat') ConnectionExecutor.execute(connector, executor, properties, folder) # environment specific dat objects folder = File(self.getCreateDir() + os.sep + database + os.sep + 'dat' + os.sep + environment) ConnectionExecutor.execute(connector, executor, properties, folder) print "database '" + database + "' created."
def getConfigFile(self, properties): currentDir = properties.getPropertyValue("current.dir") projectFile = properties.getPropertyValue("project.file") file = File(currentDir + os.sep + projectFile) if file.exists(): return file nooraDir = properties.getPropertyValue("noora.dir") file = File(nooraDir + os.sep + projectFile) return file
def toPython(ctrlfile): root = ctrlfile.getRoot() htmlfile = File("%s.%s" % (root, 'html')) textfile = File("%s.%s" % (root, 'txt')) try: ctrl = FileReader(ctrlfile).read() html = FileReader(htmlfile).read() text = FileReader(textfile).read() return "%s%shtml=\"\"\"%s\"\"\"%stext=\"\"\"%s\"\"\"" % ( ctrl, os.linesep, html, os.linesep, text) except (OSError, IOError) as e: raise "Reading one of files %s.(py|html|txt) failed: %s" % (root, e)
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 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 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, 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, commandLine, properties): ignoreErrors = commandLine.getOptionValue('--ignore-errors', False) host = commandLine.getOptionValue('-s') defaultSchemes = properties.getPropertyValues('SCHEMES') schemes = commandLine.getOptionValues('-u', defaultSchemes) defaultEnvironment = properties.getProperty('DEFAULT_ENVIRONMENT') environment = commandLine.getOptionValue('-e', defaultEnvironment) objects = properties.getPropertyValues('DROP_OBJECTS') connector = self.getConnector() for scheme in schemes: print "dropping scheme '" + scheme + "' in database '" + host + "' using environment '" + environment + "'" users = properties.getPropertyValues('ORACLE_USERS') user = PropertyHelper.getUser(users, host, scheme) passwd = PropertyHelper.getPasswd(users, host, scheme) executor = ExecuteFactory.newOracleExecute() executor.setHost(host) executor.setIgnoreErrors(ignoreErrors) executor.setPassword(passwd) executor.setUsername(user) for object in objects: folder = File(self.getDropDir(properties) + os.sep + object) ConnectionExecutor.execute(connector, executor, properties, folder) print "scheme '" + scheme + "' dropped."
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 checkEnvironment(self, connector, executor, environment, properties): pluginFolder = properties.getPropertyValue('plugin.dir') properties.setProperty('environment',environment) script = File(pluginFolder+os.sep+'mysql'+os.sep+'update'+os.sep+'checkenvironment.sql') executor.setScript(script) connector.execute(executor, properties) if "(Code 1329)" in connector.getProcessorResult().getResult(): raise InvalidEnvironmentException("invalid environment",environment)
def load(self, list=None): filters = self.getFilters() for item in list: file = File(item) filter = FileFolderFilter(file) filters.add(filter) return filters
def load(self, list = None, filterType): filters = self.getFilters() for item in list: file = File(item) filter = FileExtensionFilter(file) filters.add(filter) return filters
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 testPropertyLoader(self): properties = Properties() propertyLoader = PropertyLoader(properties) file = File("test.conf") fileReader = FileReader(file) 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 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 list(file=None, recursive=False, exclude=None): result = [] if file.exists(): folder = file.getPath() + os.sep + file.getName() fileList = os.listdir(folder) fileList.sort() for fileItem in fileList: pathName = folder + os.sep + fileItem candidateFile = File(pathName) if candidateFile.isFile() and exclude != "file": result.append(candidateFile) if candidateFile.isDirectory() and exclude != "directory": result.append(candidateFile) if candidateFile.isDirectory() and recursive == True: recursiveFiles = Files.list(candidateFile, recursive, exclude) for recursiveFile in recursiveFiles: result.append(recursiveFile) #result.sort() return result
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 testFile(self): file = File('project.conf') self.assertEquals(file.isFile(), True, "is a file expected") self.assertEquals(file.isDirectory(), False, "is not a directory expected") self.assertEquals(file.getName(), 'project.conf', "invalid name") self.assertEquals(file.getPath(), '', "invalid path")
def execute(connector, executor, properties, folder): filters = Filters() excludedFolders = properties.getPropertyValues('EXCLUDED_FOLDERS') for excludedFolder in excludedFolders: ef = File(excludedFolder) ff = FileFolderFilter(ef) filters.add(ff) excludedExtensions = properties.getPropertyValues( 'EXCLUDED_EXTENSIONS') for excludedExtension in excludedExtensions: ef = File("*." + excludedExtension) ff = FileExtensionFilter(ef) filters.add(ff) excludedFiles = properties.getPropertyValues('EXCLUDED_FILES') for excludedFile in excludedFiles: ef = File(excludedFile) ff = FileFilter(ef) filters.add(ff) if folder.isDirectory(): files = Files.list(folder) for file in files: if filters.accept( file) == False and file.isDirectory() == False: url = file.getPath() + os.sep + file.getName() print url # executor = ExecuteFactory.newMysqlExecute() # executor.setHost(host) # executor.setDatabase(database) # executor.setIgnoreErrors(ignoreErrors) # executor.setUsername(user) # executor.setPassword(passwd) executor.setScript(file) connector.execute(executor, properties)
def execute(self, commandLine, properties): #if parameterHelper.hasParameter('-h'): # self.getUsage() # exit(1) ignoreErrors = commandLine.getOptionValue('--ignore-errors', False) host = commandLine.getOptionValue('-h') self.checkBlockedHosts(host, properties) defaultDatabases = properties.getPropertyValues('DATABASES') databases = commandLine.getOptionValues('-d', defaultDatabases) defaultEnvironment = properties.getPropertyValues( 'DEFAULT_ENVIRONMENT') environment = commandLine.getOptionValue('-e', defaultEnvironment) objects = properties.getPropertyValues('DROP_OBJECTS') alias = commandLine.getOptionValue('-a', None) # if an alias is given, only the alias database will be installed, other databases will be ignored. if alias: print "using alias :" + alias databases = [alias] for database in databases: print "dropping database '" + database + "' on host '" + host + "' using environment '" + environment + "'" users = properties.getPropertyValues('MYSQL_USERS') user = PropertyHelper.getUser(users, host, database) passwd = PropertyHelper.getPasswd(users, host, database) connector = self.getConnector() executor = ExecuteFactory.newMysqlExecute() executor.setHost(host) executor.setDatabase(database) executor.setIgnoreErrors(ignoreErrors) executor.setPassword(passwd) executor.setUsername(user) for object in objects: folder = File(self.getDropDir(properties) + os.sep + object) ConnectionExecutor.execute(connector, executor, properties, folder) print "database '" + database + "' dropped."
def load(self, properties): alter = File(properties.getPropertyValue("alter.dir")) if alter.exists(): files = Files() for version in files.list(alter): self.__versions.add(Version(version.getName())) create = File(properties.getPropertyValue("create.dir")) if create.exists(): self.__versions.add( Version(properties.getPropertyValues("DEFAULT_VERSION")))
def checkVersion(self, connector, executor, version, properties): pluginFolder = properties.getPropertyValue('plugin.dir') versions = Versions() versionLoader = VersionLoader(versions) versionLoader.load(properties) versions.sort() #versions.sort() #print "versions",versions.getVersions() v = Version(version) previous = versions.previous(v).getValue() properties.setProperty('previous', previous) script = File(pluginFolder + os.sep + 'mysql' + os.sep + 'update' + os.sep + 'checkversion.sql') executor.setScript(script) connector.execute(executor, properties) if "(Code 1329)" in connector.getProcessorResult().getResult(): raise InvalidVersionException("invalid version", previous)
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)