<commit_before>import os
import inspect
import subprocess
from django.template import Template
from django.template import Context
from arches.management.commands import utils
import re

postgres_version = subprocess.check_output(["psql", "--version"])
pattern = re.compile(r'\s\d+.\d*.\d*')
matches = pattern.findall(postgres_version)
psqlversionmatch = matches[0]
split = (psqlversionmatch.split('.'))  # major[9].minor[2].patch[0]

# add "0" place holders
if len(split) < 2:  # e.g 9 > 9.0
    split.append(0)
if len(split) < 3:  # e.g 9.1 > 9.1.0
    split.append(0)


def create_sqlfile(database_settings, path_to_file):
    context = Context(database_settings)
    if (split[0] >= 9) & (split[1] >= 2) & (split[2] >= 0):  # 9.2.0 or above
        context['PID'] = "pid"
    else:
        context['PID'] = "procpid"

    t = Template(
	"SELECT pg_terminate_backend({{ PID }}) from pg_stat_activity where datname='{{ NAME }}';\n"
	"\n"

	"DROP DATABASE IF EXISTS {{ NAME }};\n"
	"\n"

	"CREATE DATABASE {{ NAME }}\n"
	"  WITH ENCODING='UTF8'\n"
	"       OWNER={{ USER }}\n"
	"       CONNECTION LIMIT=-1;\n"
	"\n"
	)
    utils.write_to_file(path_to_file, t.render(context))
<commit_msg>Updated files to make Arches compatible with up-to-date versions of Postgres.<commit_after>import os
import inspect
import subprocess
from django.template import Template
from django.template import Context
from arches.management.commands import utils
import re

postgres_version = subprocess.check_output(["psql", "--version"])
pattern = re.compile(r'\s\d+.\d*.\d*')
matches = pattern.findall(postgres_version)
<<<<<<< HEAD
psqlversionmatch = matches[0]
split = (psqlversionmatch.split('.'))  # major[9].minor[2].patch[0]

# add "0" place holders
if len(split) < 2:  # e.g 9 > 9.0
    split.append(0)
if len(split) < 3:  # e.g 9.1 > 9.1.0
    split.append(0)


def create_sqlfile(database_settings, path_to_file):
    context = Context(database_settings)
    if (split[0] >= 9) & (split[1] >= 2) & (split[2] >= 0):  # 9.2.0 or above
=======
psqlversionmatch = matches[0] 
split = (psqlversionmatch.split('.'))#major[9].minor[2].patch[0]

#add "0" place holders
if len(split) < 2:#e.g 9 > 9.0
    split.append(0)
if len(split) < 3:#e.g 9.1 > 9.1.0
    split.append(0)

def create_sqlfile(database_settings, path_to_file):
    context = Context(database_settings)
    if (split[0] >= 9) & (split[1] >= 2) & (split[2] >= 0):#9.2.0 or above
>>>>>>> b6b2501b124b119956ed0de98cc27a617ea52fc8
        context['PID'] = "pid"
    else:
        context['PID'] = "procpid"

    t = Template(
	"SELECT pg_terminate_backend({{ PID }}) from pg_stat_activity where datname='{{ NAME }}';\n"
	"\n"

	"DROP DATABASE IF EXISTS {{ NAME }};\n"
	"\n"

	"CREATE DATABASE {{ NAME }}\n"
	"  WITH ENCODING='UTF8'\n"
	"       OWNER={{ USER }}\n"
	"       CONNECTION LIMIT=-1;\n"
	"\n"
	)
    utils.write_to_file(path_to_file, t.render(context))

{'fraction_non_alphanumeric': 0.16993681410043232, 'fraction_numerical': 0.035583638177585634, 'mean_word_length': 3.291012838801712, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 25, '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': '223684', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1133, 'n_words': 252}