<commit_before>#! /usr/bin/env python3
########################################
########################################
##
##  Copyright (C) 2014 Korovasoft, Inc.
##
##  File:
##      \file build.py
##
##  Description:
##      \brief Python build script.
##
##  Author:
##      \author <NAME>
##
########################################
########################################


#
# Imports:
#
import subprocess
from os import path, getcwd, mkdir, chdir
from sys import exit, argv
from platform import system
from time import time
from datetime import datetime
from shutil import rmtree



#
# Print logfile to stdout function:
#
def displayLog(logFile):

	# Open file and print it to stdout:
	with open(logFile, 'r') as fin:
		print(fin.read())



#
# Build function: Unix
#
def unixBuild(log):

	print('Starting UNIX build...')
	print('')


	# Run make:
	print("Running 'make'... ", end='')
	returnCode = subprocess.call(["make"], stdout=log, stderr=subprocess.STDOUT)
	
	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make test:
	print("Running 'make test'... ", end='')
	returnCode = subprocess.call(["make", "test"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make doc:
	print("Running 'make doc'... ", end='')
	returnCode = subprocess.call(["make", "doc"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make install:
	print("Running 'make install'... ", end='')
	returnCode = subprocess.call(["make", "install"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')



#
# Build function: Windows
#
def windowsBuild(log):
	print('Starting Windows build...')
	print('')

  
	# Run msbuild:
	print("Running 'msbuild'... ", end='')
	returnCode = subprocess.call(["msbuild", "ALL_BUILD.vcxproj"], stdout=log, stderr=subprocess.STDOUT)
	
	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')



#
# Main function:
#
def main():

	# Start time for script:
	startTime = time()

	# Get timestamp:
	timeStamp = datetime.fromtimestamp(time()).strftime('%Y-%m-%d_%H-%M-%S')

	# Get current path:
	currentPath = path.abspath(getcwd())

	# Get script path:
	scriptPath = path.abspath(path.dirname(argv[0]))

	# Get OS:
	localOS = system()

	# Create build directories and cd into them:
	buildRoot = path.join(currentPath, 'local-build_' + timeStamp)
	buildFiles = path.join(buildRoot, 'build_files')
	installFiles = path.join(buildRoot, 'install_files')
	mkdir(buildRoot)
	mkdir(buildFiles)
	mkdir(installFiles)<commit_msg>Working on command line arg parsing for build script.<commit_after>#! /usr/bin/env python3
########################################
########################################
##
##  Copyright (C) 2014 Korovasoft, Inc.
##
##  File:
##      \file build.py
##
##  Description:
##      \brief Python build script.
##
##  Author:
##      \author <NAME>erry
##
########################################
########################################


#
# Imports:
#
import argparse, subprocess
from os import path, getcwd, mkdir, chdir
from sys import exit, argv
from platform import system
from time import time
from datetime import datetime
from shutil import rmtree



#
# Print logfile to stdout function:
#
def displayLog(logFile):

	# Open file and print it to stdout:
	with open(logFile, 'r') as fin:
		print(fin.read())



#
# Build function: Unix
#
def unixBuild(log):

	print('Starting UNIX build...')
	print('')


	# Run make:
	print("Running 'make'... ", end='')
	returnCode = subprocess.call(["make"], stdout=log, stderr=subprocess.STDOUT)
	
	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make test:
	print("Running 'make test'... ", end='')
	returnCode = subprocess.call(["make", "test"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make doc:
	print("Running 'make doc'... ", end='')
	returnCode = subprocess.call(["make", "doc"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')


	# Run make install:
	print("Running 'make install'... ", end='')
	returnCode = subprocess.call(["make", "install"], stdout=log, stderr=subprocess.STDOUT)

	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')



#
# Build function: Windows
#
def windowsBuild(log):
	print('Starting Windows build...')
	print('')

  
	# Run msbuild:
	print("Running 'msbuild'... ", end='')
	returnCode = subprocess.call(["msbuild", "ALL_BUILD.vcxproj"], stdout=log, stderr=subprocess.STDOUT)
	
	if returnCode != 0:
		print('ERROR!!! Please see log file for details: ' + log.name)
		displayLog(log.name)
		exit(1)

	print('done!')



#
# Main function:
#
def main():

	# Start time for script:
	startTime = time()


	#
	# Argument parsing:
	#
	parser = argparse.ArgumentParser()
	parser.add_argument("-c", "--clean", help="Remove all directories matching 'local-build_*', then exit.", action="store_true")
	parser.add_argument("-k", "--keep-build", help="Keep build directory, do not delete.", action="store_true")
	parser.add_argument("-v", "--verbose", help="Provide verbose output.", action="store_true")
	args = parser.parse_args()



	#
	# Clean build directories if clean specified:
	#
	if args.clean:
		#rmtree('local-build_*')
		print("Removed all build directories matching 'local-build_*'.")
		exit(0)


	# Get timestamp:
	timeStamp = datetime.fromtimestamp(time()).strftime('%Y-%m-%d_%H-%M-%S')

	# Get current path:
	currentPath = path.abspath(getcwd())

	# Get script path:
	scriptPath = path.abspath(path.dirname(argv[0]))

	# Get OS:
	localOS = system()

	# Create build directories and cd into them:
	buildRoot = path.join(currentPath, 'local-build_' + timeStamp)
	buildFiles = path.join(buildRoot, 'build_files')
	installFiles = path.join(buildRoot, 'install_files')
	mkdir(buildRoot)
	mkdir(buildFiles)
	mkdir(installFiles)
{'fraction_non_alphanumeric': 0.20469243495262446, 'fraction_numerical': 0.004963152353737404, 'mean_word_length': 4.5095277547638775, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '578019', 'n_tokens_mistral': 2365, 'n_tokens_neox': 2186, 'n_words': 577}