<commit_before>#!/usr/bin/env python
import os
import subprocess
from string import Template
from .command import Command


def _connection_string(dbms, connection, user, password):
    if dbms.lower() == 'oracle':
        return user + '/' + password + '@' + connection


def _sql_script(file_path):
    file = open(file_path, 'r')
    script = file.read()
    script += '\nshow error'
    return script


class RunSqlScript(Command):

    def add_arguments(self, parser):
        parser.add_argument(
            '-s', '--dbms',
            type=str,
            required=True,
            help='oracle or mssql')

        parser.add_argument(
            '-d', '--directory',
            type=str,
            required=True,
            help='Directory containing script')

        parser.add_argument(
            '-f', '--file',
            type=str,
            required=True,
            help='Script file name')

        parser.add_argument(
            '-c', '--connection',
            type=str,
            required=True,
            help='db connection string')

        parser.add_argument(
            '-u', '--user',
            type=str,
            required=True,
            help='Database user')

        parser.add_argument(
            '-p', '--password',
            type=str,
            required=True,
            help='Password')

    def _runScript(self, file_path, dbms, connection):
        script = _sql_script(file_path)

        os.chdir(os.path.dirname(file_path))

        process = subprocess.Popen(
            ['sqlplus', '-S', '-L', connection],
            stdin=subprocess.PIPE,
            stderr=subprocess.PIPE)
        process.stdin.write(script.encode('utf-8'))
        process.stdin.close()
        process.wait()

    def execute(self):
        file_path = os.path.join(self.args.directory, self.args.file)

        message = Template(
            'Matador: Executing ${file} against ${connection} \n')
        substitutions = {
            'file': os.path.basename(file_path),
            'connection': self.args.connection
        }
        self._logger.info(message.substitute(substitutions))
<commit_msg>Add condition on dbms to run script method<commit_after>#!/usr/bin/env python
import os
import subprocess
from string import Template
from .command import Command


def _connection_string(dbms, connection, user, password):
    if dbms.lower() == 'oracle':
        return user + '/' + password + '@' + connection


def _sql_script(file_path):
    file = open(file_path, 'r')
    script = file.read()
    script += '\nshow error'
    return script


class RunSqlScript(Command):

    def add_arguments(self, parser):
        parser.add_argument(
            '-s', '--dbms',
            type=str,
            required=True,
            help='oracle or mssql')

        parser.add_argument(
            '-d', '--directory',
            type=str,
            required=True,
            help='Directory containing script')

        parser.add_argument(
            '-f', '--file',
            type=str,
            required=True,
            help='Script file name')

        parser.add_argument(
            '-c', '--connection',
            type=str,
            required=True,
            help='db connection string')

        parser.add_argument(
            '-u', '--user',
            type=str,
            required=True,
            help='Database user')

        parser.add_argument(
            '-p', '--password',
            type=str,
            required=True,
            help='Password')

    def _runScript(self, file_path, dbms, connection):
        script = _sql_script(file_path)

        os.chdir(os.path.dirname(file_path))

        if dbms.lower() == 'oracle':
            process = subprocess.Popen(
                ['sqlplus', '-S', '-L', connection],
                stdin=subprocess.PIPE,
                stderr=subprocess.PIPE)
            process.stdin.write(script.encode('utf-8'))
            process.stdin.close()
            process.wait()

    def execute(self):
        file_path = os.path.join(self.args.directory, self.args.file)

        message = Template(
            'Matador: Executing ${file} against ${connection} \n')
        substitutions = {
            'file': os.path.basename(file_path),
            'connection': self.args.connection
        }
        self._logger.info(message.substitute(substitutions))

{'fraction_non_alphanumeric': 0.12766924125397547, 'fraction_numerical': 0.00045433893684688776, 'mean_word_length': 1.8170185540627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7235197', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1218, 'n_words': 262}