def execute(self, executable, properties): script = executable['script'] cp = Properties() cp.set_property('database', executable['database']) if 'environment' in properties.keys(): cp.set_property('environment', properties.get_property('environment')) if 'previous' in properties.keys(): cp.set_property('previous', properties.get_property('previous')) stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "mysql --show-warnings --host=" + executable[ 'host'] + " --user="******" --password="******" " + executable['database'] call = CallFactory.new_call(statement) call['stdin'] = script_reader call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)
def execute(self, executable, properties): script = executable['script'] cp = Properties() cp.set_property('database', executable['database']) if 'schema' in executable.keys(): cp.set_property('schema', executable['schema']) if 'environment' in properties.keys(): cp.set_property('environment', properties.get_property('environment')) if 'previous' in properties.keys(): cp.set_property('previous', properties.get_property('previous')) stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() #script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "sqlcmd -b -S " + executable['host'] + " -U " + executable[ 'username'] + ' -P ' + executable['password'] + " -d " + executable[ 'database'] + " -i " + tmp.get_url() call = CallFactory.new_call(statement) call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)
def testCheckVersion(self): script = File("checkversion.sql") properties = Properties() properties.set_property('name', 'app_prop') properties.set_property('previous', '1.0.0') stream = PreProcessor.parse(script, properties) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = "mysql --show-warnings --host=localhost --user=apps --password=apps acme" call = CallFactory.new_call(statement) call['stdin'] = script_reader call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) print "result", result
def testProcessor(self): script = File("drop_tables.sql") properties = Properties() properties.set_property('database', 'orcl') stream = PreProcessor.parse(script, properties) self.assertEqual(stream, 'orcl', "invalid transformation")
def execute(self, executable, properties): """ Execute the script provided by `executable` on the target server. :type executable: dict :param executable: Should contain the following keys and values: * **host**: The address of the server to connect to; * **port**: Server port to connect to; * **database**: The database name; * **schema**: The schema to use; * **username**: Database username; * **password**: Database user password; * **script**: Path to the script to execute. :type properties: noora.system.Properties.Properties :param properties: A Noora project properties instance """ script = executable['script'] cp = dict() cp['database'] = executable['database'] if 'schema' in executable.keys(): cp['schema'] = executable['schema'] if 'environment' in properties.keys(): cp['environment'] = properties.get('environment') if 'previous' in properties.keys(): cp['previous'] = properties.get('previous') stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() # FIXME: remove? #script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') # FIXME: rewrite with format statement = "sqlcmd -b -S {host},{port} -U {user} -P {passwd} -d {db} -i {url}".format( host=executable['host'], port=executable.get('port') or 1433, user=executable['username'], passwd=executable['password'], db=executable['database'], url=tmp.get_url(), ) call = CallFactory.new_call(statement) call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)
def execute(self, executable, properties): """ Execute the script provided by `executable` on the target server. :type executable: dict :param executable: Should contain the following keys and values: * **host**: The address of the server to connect to; * **port**: Server port to connect to; * **database**: The database name; * **username**: Database username; * **password**: Database user password; * **script**: Path to the script to execute. :type properties: noora.system.Properties.Properties :param properties: A Noora project properties instance """ script = executable['script'] cp = { 'database': executable['database'], 'username': executable['username'].split('@')[0] } if 'environment' in properties.keys(): cp['environment'] = properties.get('environment') if 'previous' in properties.keys(): cp['previous'] = properties.get('previous') stream = PreProcessor.parse(script, cp) tmp = File("tmp.sql") f = open(tmp.get_url(), 'w') f.write(stream) f.close() script_reader = open(tmp.get_url()) feedback = File('feedback.log') feedback_writer = open(feedback.get_url(), 'w') statement = \ "PGPASSWORD={passwd} psql -h {host} -p {port} -U {user} -d {db} " \ "-v ON_ERROR_STOP=1".format( host=executable['host'], port=executable.get('port'), user=executable['username'], passwd=executable['password'], db=executable['database'], ) call = CallFactory.new_call(statement) call['stdin'] = script_reader call['stdout'] = feedback_writer call['stderr'] = feedback_writer result = Shell.execute(call) self.set_result(result)