<commit_before>import os
import os.path
import stat
import glob

import platform
import tempfile

from time import sleep

import zip
import backend

from compiler import *
from sandbox import *

import smtplib
from email.mime.text import MIMEText

import configparser

import copy

parser = configparser.ConfigParser()
parser.read("../halite.ini")

RUN_GAME_FILE_NAME = "runGame.sh"
HALITE_EMAIL = "<EMAIL>"
HALITE_EMAIL_PASSWORD = parser["email"]["password"]

def makePath(path):
	"""Deletes anything residing at path, creates path, and chmods the directory"""
	if os.path.exists(path):
		shutil.rmtree(path)
	os.makedirs(path)
	os.chmod(path, 0o777)

def sendEmail(subject, body, recipient):
	print("Sending email")

	msg = MIMEText(body, "html")
	msg['Subject'] = subject
	msg['From'] = HALITE_EMAIL
	msg['To'] = recipient

	s = smtplib.SMTP('smtp.gmail.com:587')
	s.ehlo()
	s.starttls();
	s.login(HALITE_EMAIL, HALITE_EMAIL_PASSWORD)
	s.sendmail(HALITE_EMAIL, [recipient], msg.as_string())
	s.quit()


def executeCompileTask(user, backend):
	"""Downloads and compiles a bot. Posts the compiled bot files to the manager."""
	print("Compiling a bot with userID %s" % (user["userID"]))

	workingPath = "workingPath"
	makePath(workingPath)
	botPath = backend.storeBotLocally(int(user["userID"]), workingPath)
	zip.unpack(botPath)

	while len([name for name in os.listdir(workingPath) if os.path.isfile(name)]) == 0 and len(glob.glob(os.path.join(workingPath, "*"))) == 1:
		singleFolder = glob.glob(os.path.join(workingPath, "*"))[0]
		for filename in os.listdir(singleFolder):
    			shutil.move(os.path.join(singleFolder, filename), os.path.join(workingPath, filename))
		os.rmdir(singleFolder)

	language, errors = compile_anything(workingPath)
	didCompile = True if errors == None else False

	if didCompile:
		print("Bot did compile")
		zip.zipFolder(workingPath, os.path.join(workingPath, user["userID"]+".zip"))
		backend.storeBotRemotely(int(user["userID"]), os.path.join(workingPath, user["userID"]+".zip"))<commit_msg>Add buffer folder to recursive delteing of folders at worker compile<commit_after>import os
import os.path
import stat
import glob

import platform
import tempfile

from time import sleep

import zip
import backend

from compiler import *
from sandbox import *

import smtplib
from email.mime.text import MIMEText

import configparser

import copy

parser = configparser.ConfigParser()
parser.read("../halite.ini")

RUN_GAME_FILE_NAME = "runGame.sh"
HALITE_EMAIL = "<EMAIL>"
HALITE_EMAIL_PASSWORD = parser["email"]["password"]
SECRET_FOLDER = parser["hce"]["secretFolder"]

def makePath(path):
	"""Deletes anything residing at path, creates path, and chmods the directory"""
	if os.path.exists(path):
		shutil.rmtree(path)
	os.makedirs(path)
	os.chmod(path, 0o777)

def sendEmail(subject, body, recipient):
	print("Sending email")

	msg = MIMEText(body, "html")
	msg['Subject'] = subject
	msg['From'] = HALITE_EMAIL
	msg['To'] = recipient

	s = smtplib.SMTP('smtp.gmail.com:587')
	s.ehlo()
	s.starttls();
	s.login(HALITE_EMAIL, HALITE_EMAIL_PASSWORD)
	s.sendmail(HALITE_EMAIL, [recipient], msg.as_string())
	s.quit()


def executeCompileTask(user, backend):
	"""Downloads and compiles a bot. Posts the compiled bot files to the manager."""
	print("Compiling a bot with userID %s" % (user["userID"]))

	workingPath = "workingPath"
	makePath(workingPath)
	botPath = backend.storeBotLocally(int(user["userID"]), workingPath)
	zip.unpack(botPath)

	while len([name for name in os.listdir(workingPath) if os.path.isfile(name)]) == 0 and len(glob.glob(os.path.join(workingPath, "*"))) == 1:
		singleFolder = glob.glob(os.path.join(workingPath, "*"))[0]
		bufferFolder = os.path.join(workingPath, SECRET_FOLDER)
		for filename in os.listdir(singleFolder):
    			shutil.move(os.path.join(singleFolder, filename), os.path.join(bufferFolder, filename))
		os.rmdir(singleFolder)
		
		for filename in os.listdir(bufferFolder):
    			shutil.move(os.path.join(bufferFolder, filename), os.path.join(workingPath, filename))

	language, errors = compile_anything(workingPath)
	didCompile = True if errors == None else False

	if didCompile:
		print("Bot did compile")
		zip.zipFolder(workingPath, os.path.join(workingPath, user["userID"]+".zip"))
		backend.storeBotRemotely(int(user["userID"]), os.path.join(workingPath, user["userID"]+".zip"))
{'fraction_non_alphanumeric': 0.1393160431489557, 'fraction_numerical': 0.004590314436538903, 'mean_word_length': 5.704615384615384, 'pattern_counts': {'":': 0, '<': 5, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6464252', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1503, 'n_words': 350}