<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import readline
import sys
import os
import shutil
import re
import subprocess
import tempfile
import termios
import fcntl

_SWIFT_RELEASES = {
	"fc261045a5": { "name": "DEV-02-25", "works": False },
	"24a0c3de75": { "name": "DEV-03-01", "works": False },
	"3.0-dev": { "name": "DEV_3.0-UNKNOWN", "works": False },
	"2.2-dev": { "name": "DEV_2.2", "works": False },
    "3.0": { "name": "3.0-RELEASE", "works": False },
    "3.0.1": { "name": "3.0.1-RELEASE", "works": False },
    "3.0.2": { "name": "3.0.2-RELEASE", "works": False },
    "3.1": { "name": "3.1-RELEASE", "works": True }
}

BINARY_NAME = "swift-express"

def run_command(name, params=[], cwd=None, shell=False):
  if shell:
    subprocess.check_call(name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd, shell=shell)
  else:
    run_params = [name]
    run_params.extend(params)
    subprocess.check_call(run_params, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd, shell=shell)

def ask_bool_question(question):
	sys.stdout.write(question)
	sys.stdout.write(" [y/n]: ")

	fd = sys.stdin.fileno()
	oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
	fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

	while True:
		try:
			response = unicode(sys.stdin.read(1)).lower()
			if response == "y" or response == "n":
				break
		except IOError: pass

	fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
	return response == "y"

def read_path():
	return raw_input("--> ").strip()

def get_swift_release(swift_bin_path):
	result = subprocess.check_output([swift_bin_path, "-version"])
	m = re.search("swift\s+([a-z0-9]+)\)", result, re.I)
	if m is not None:
		release = _SWIFT_RELEASES.get(m.group(1))
		if release is not None:
			print "Swift release is:", release["name"]
			return release
		m = re.search("version\s+([0-9a-z\.\-]+)", result, re.I)
		if m is not None:
			release = _SWIFT_RELEASES.get(m.group(1))
			if release is not None:
				print "Swift release is: ", release["name"]
			else:
				print "Can't detect Swift release"
			return release
	print "Can't detect Swift release"
	return None

def get_swift_path():
	try:
		path = subprocess.check_output(["which", "swift"]).strip("\n")
		print "Found Swift binary in:", path
		return path<commit_msg>Added swift versions. Fixed version check<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import readline
import sys
import os
import shutil
import re
import subprocess
import tempfile
import termios
import fcntl

_SWIFT_RELEASES = {
	"fc261045a5": { "name": "DEV-02-25", "works": False },
	"24a0c3de75": { "name": "DEV-03-01", "works": False },
	"3.0-dev": { "name": "DEV_3.0-UNKNOWN", "works": False },
	"2.2-dev": { "name": "DEV_2.2", "works": False },
	"2.2.1-dev": { "name": "DEV_2.2.1", "works": False },
	"3.0": { "name": "3.0-RELEASE", "works": False },
	"3.0.1": { "name": "3.0.1-RELEASE", "works": False },
	"3.0.2": { "name": "3.0.2-RELEASE", "works": False },
	"3.1": { "name": "3.1-RELEASE", "works": True }
}

BINARY_NAME = "swift-express"

def run_command(name, params=[], cwd=None, shell=False):
  if shell:
    subprocess.check_call(name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd, shell=shell)
  else:
    run_params = [name]
    run_params.extend(params)
    subprocess.check_call(run_params, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, cwd=cwd, shell=shell)

def ask_bool_question(question):
	sys.stdout.write(question)
	sys.stdout.write(" [y/n]: ")

	fd = sys.stdin.fileno()
	oldflags = fcntl.fcntl(fd, fcntl.F_GETFL)
	fcntl.fcntl(fd, fcntl.F_SETFL, oldflags | os.O_NONBLOCK)

	while True:
		try:
			response = unicode(sys.stdin.read(1)).lower()
			if response == "y" or response == "n":
				break
		except IOError: pass

	fcntl.fcntl(fd, fcntl.F_SETFL, oldflags)
	return response == "y"

def read_path():
	return raw_input("--> ").strip()

def get_swift_release(swift_bin_path):
	result = subprocess.check_output([swift_bin_path, "-version"])
	m = re.search("swift\s+([a-z0-9]+)\)", result, re.I)
	if m is not None:
		release = _SWIFT_RELEASES.get(m.group(1))
		if release is not None:
			print "Swift release is:", release["name"]
			return release
	m = re.search("version\s+([0-9a-z\.\-]+)", result, re.I)
	if m is not None:
		release = _SWIFT_RELEASES.get(m.group(1))
		if release is not None:
			print "Swift release is: ", release["name"]
		else:
			print "Can't detect Swift release"
		return release
	print "Can't detect Swift release"
	return None

def get_swift_path():
	try:
		path = subprocess.check_output(["which", "swift"]).strip("\n")
		print "Found Swift binary in:", path
		return path
{'fraction_non_alphanumeric': 0.18248789728478215, 'fraction_numerical': 0.025257840454641127, 'mean_word_length': 4.2105263157894735, 'pattern_counts': {'":': 53, '<': 3, '<?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': '4185746', 'n_tokens_mistral': 1991, 'n_tokens_neox': 1873, 'n_words': 429}