<commit_before>import time
import os
import subprocess


class Server_Config:
    values = {}

    def __init__(self):
        thefile = "/etc/irods/server.config"
        if os.path.isfile(thefile):
                cfg_file = thefile
        else:
                cfg_file = os.path.dirname(
                    os.path.dirname(os.path.realpath(__file__))) + "/iRODS/server/config/server.config"
        self.capture(cfg_file, ' ')

        thefile = "/var/lib/irods/.odbc.ini"
        if os.path.isfile(thefile):
                cfg_file = thefile
        else:
                cfg_file = os.environ['HOME'] + "/.odbc.ini"
        self.capture(cfg_file, '=')

    def capture(self, cfg_file, sep):
        # NOTE:: we want to make this programmatically detected
        cfg_file = os.path.abspath(cfg_file)
        f = open(cfg_file, 'r')
        try:
            for i, row in enumerate(f):
                columns = row.split(sep)
                # print columns
                col_0 = columns[0]
                if(col_0[0] == '#'):
                    continue
                elif len(columns) > 1:
                    self.values[columns[0] .rstrip()] = columns[1].rstrip()
        finally:
            f.close()

    def get_db_pass(self):
        db_key = self.values['DBKey']
        db_obf_pass = self.values['DBPassword']
        run_str = "iadmin dspass '" + db_obf_pass + "' " + db_key
        p = subprocess.Popen(run_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (db_pass, db_err) = p.communicate()
        return db_pass.split(":")[1].rstrip()

    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    # POSTGRES
    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    def exec_pgsql_cmd(self, sql):
        sql = sql.strip()
        if( not sql.endswith( ';' ) ):
            sql = sql + ";"

        sqlfile = "tmpsqlfile"
        f = open(sqlfile, 'w+')
        f.write(sql)
        f.close()
        (returncode, myout, myerr) = self.exec_pgsql_file(sqlfile)
        os.unlink(sqlfile)

    def exec_pgsql_file(self, sql):
        fbp = os.path.dirname(
            os.path.realpath(__file__)) + "/find_bin_postgres.sh"
        if( not os.path.isfile(fbp) ):
                fbp = os.path.dirname( os.path.dirname(
                        os.path.realpath(__file__))) + "/plugins/database/packaging/find_bin_postgres.sh"
        p = subprocess.Popen(
            fbp,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        sqlclient = ""
        for line in p.stdout:
            sqlclient = line.decode('utf-8').rstrip() + "/psql"
        retval = p.wait()
        if retval != 0:
            print("find_bin_postgres.sh failed")
            return

        db_host = self.values['Servername']
        db_port = self.values['Port']
        db_name = self.values['Database']
        if db_host == 'localhost':
            run_str = sqlclient + \
            " -p " + db_port + \
            " " + db_name + \
            " < " + sql
        else:
            run_str = sqlclient + \
            " -h " + db_host + \
            " -p " + db_port + \
            " " + db_name + \
            " < " + sql

        p = subprocess.Popen(
            run_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (myout, myerr) = p.communicate()
        return (p.returncode, myout, myerr)

    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    # MYSQL
    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    def exec_mysql_cmd(self, sql):
        sql = sql.strip()
        if( not sql.endswith( ';' ) ):
            sql = sql + ";"

        sqlfile = "tmpsqlfile"
        f = open(sqlfile, 'w+')
        f.write(sql)
        f.close()
        (returncode, myout, myerr) = self.exec_mysql_file(sqlfile)
        os.unlink(sqlfile)

    def exec_mysql_file(self, sql):
        fbp = os.path.dirname(
            os.path.realpath(__file__)) + "/find_bin_mysql.sh"
        p = subprocess.Popen(
            fbp,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        sqlclient = ""
        for line in p.stdout:
            sqlclient = line.decode('utf-8').rstrip() + "/mysql"
        retval = p.wait()
        if retval != 0:
            print("find_bin_mysql.sh failed")
            return

        db_host = self.values['Servername']
        db_port = self.values['Port']
        db_name = self.values['Database']<commit_msg>[#2228] add missing return statements to PGSQL and MySQL<commit_after>import time
import os
import subprocess


class Server_Config:
    values = {}

    def __init__(self):
        thefile = "/etc/irods/server.config"
        if os.path.isfile(thefile):
                cfg_file = thefile
        else:
                cfg_file = os.path.dirname(
                    os.path.dirname(os.path.realpath(__file__))) + "/iRODS/server/config/server.config"
        self.capture(cfg_file, ' ')

        thefile = "/var/lib/irods/.odbc.ini"
        if os.path.isfile(thefile):
                cfg_file = thefile
        else:
                cfg_file = os.environ['HOME'] + "/.odbc.ini"
        self.capture(cfg_file, '=')

    def capture(self, cfg_file, sep):
        # NOTE:: we want to make this programmatically detected
        cfg_file = os.path.abspath(cfg_file)
        f = open(cfg_file, 'r')
        try:
            for i, row in enumerate(f):
                columns = row.split(sep)
                # print columns
                col_0 = columns[0]
                if(col_0[0] == '#'):
                    continue
                elif len(columns) > 1:
                    self.values[columns[0] .rstrip()] = columns[1].rstrip()
        finally:
            f.close()

    def get_db_pass(self):
        db_key = self.values['DBKey']
        db_obf_pass = self.values['DBPassword']
        run_str = "iadmin dspass '" + db_obf_pass + "' " + db_key
        p = subprocess.Popen(run_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (db_pass, db_err) = p.communicate()
        return db_pass.split(":")[1].rstrip()

    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    # POSTGRES
    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    def exec_pgsql_cmd(self, sql):
        sql = sql.strip()
        if( not sql.endswith( ';' ) ):
            sql = sql + ";"

        sqlfile = "tmpsqlfile"
        f = open(sqlfile, 'w+')
        f.write(sql)
        f.close()
        (returncode, myout, myerr) = self.exec_pgsql_file(sqlfile)
        os.unlink(sqlfile)
        return (returncode, myout, myerr)

    def exec_pgsql_file(self, sql):
        fbp = os.path.dirname(
            os.path.realpath(__file__)) + "/find_bin_postgres.sh"
        if( not os.path.isfile(fbp) ):
                fbp = os.path.dirname( os.path.dirname(
                        os.path.realpath(__file__))) + "/plugins/database/packaging/find_bin_postgres.sh"
        p = subprocess.Popen(
            fbp,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        sqlclient = ""
        for line in p.stdout:
            sqlclient = line.decode('utf-8').rstrip() + "/psql"
        retval = p.wait()
        if retval != 0:
            print("find_bin_postgres.sh failed")
            return

        db_host = self.values['Servername']
        db_port = self.values['Port']
        db_name = self.values['Database']
        if db_host == 'localhost':
            run_str = sqlclient + \
            " -p " + db_port + \
            " " + db_name + \
            " < " + sql
        else:
            run_str = sqlclient + \
            " -h " + db_host + \
            " -p " + db_port + \
            " " + db_name + \
            " < " + sql

        p = subprocess.Popen(
            run_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        (myout, myerr) = p.communicate()
        return (p.returncode, myout, myerr)

    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    # MYSQL
    # =-=-=-=-=-=-=-=-=-=-=-=-=-
    def exec_mysql_cmd(self, sql):
        sql = sql.strip()
        if( not sql.endswith( ';' ) ):
            sql = sql + ";"

        sqlfile = "tmpsqlfile"
        f = open(sqlfile, 'w+')
        f.write(sql)
        f.close()
        (returncode, myout, myerr) = self.exec_mysql_file(sqlfile)
        os.unlink(sqlfile)
        return (returncode, myout, myerr)

    def exec_mysql_file(self, sql):
        fbp = os.path.dirname(
            os.path.realpath(__file__)) + "/find_bin_mysql.sh"
        p = subprocess.Popen(
            fbp,
            shell=True,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)

        sqlclient = ""
        for line in p.stdout:
            sqlclient = line.decode('utf-8').rstrip() + "/mysql"
        retval = p.wait()
        if retval != 0:
            print("find_bin_mysql.sh failed")
            return

        db_host = self.values['Servername']
        db_port = self.values['Port']
        db_name = self.values['Database']
{'fraction_non_alphanumeric': 0.15125768585802124, 'fraction_numerical': 0.0031302403577417553, 'mean_word_length': 1.5968069666182874, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 5, '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': '2730226', 'n_tokens_mistral': 2999, 'n_tokens_neox': 2881, 'n_words': 513}