<commit_before>/**
*
* Load the windows for a space.
*
* @author <NAME> <<EMAIL>>
* @method boot
* @memberof controller/space
* @param {object} config The global configuraton.
* @param {object} input The configuration for the space.
* @returns {boolean} Fail/success state.
*
**/
module.exports = function() {
	'use strict';

	// Wrap the Function.
	return function(config, input) {
		// Store the concatenated AppleScript template.
		var appleScript = '';

		// @todo remove
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setSpace.applescript')).toString();
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setSpaceIndex.applescript')).toString();
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setWindow.applescript')).toString();

		// The starting column for the grid.
		var column = -1;

		// The starting row for the grid.
		var row = 0;

		// Reference the `tmp` directory.
		var tmpDirectory = path.join(__dirname, '..', '..', 'tmp');

		// Generate a temporary directory for the instance.
		var instanceDirectory = path.join(tmpDirectory, nodeUuid.v4());

		// If the `tmp` directory doesn't exist, then create it.
		if (fs.existsSync(tmpDirectory) === false) {
			// Create the directory.
			fs.mkdirSync(tmpDirectory);
		}

		// Create the temporary directory for the instance.
		fs.mkdirSync(instanceDirectory);


		// @todo ok so this we need to fetch when the space changes apparently...
		var resolution = _.screenResolution();


		var windowHeight = Math.floor(resolution.height / input.row.max);

		var windowWidth = Math.floor(resolution.width / input.column.max);

		// Iterate through each of the windows and open them on the specific space.
		input.window.forEach(function(value, index) {
			// @todo if application is missing throw a error

			if (column < input.column.max - 1) {
				column++;
			}

			
			else {
				row++;
				column = 0;
			}

			var left = (column * (resolution.width / input.column.max));
			var top = (row * (resolution.height / input.row.max));

			if (input.column.max > 1 && column == input.column.max - 1 && input.column.spacing) {
				left += input.column.spacing;
			}

			if (input.row.max > 1 && row == input.row.max - 1 && input.row.spacing) {
				top += input.row.spacing;
			}

			if (input.row.max > 1) {
				windowHeight -= input.row.spacing;
			}

			if (input.column.max > 1) {
				windowWidth -= input.column.spacing;
			}

			// Append a new line.
			appleScript += '\n';

			// Append a comment for the new `setWindow` routine.
			appleScript += '-- ' + value.application;

			// Append the `title` for the window.
			appleScript += value.title ? ' - ' + value.title : '';

			// Append the `description` for the window.
			appleScript += value.description ? ' - ' + value.description : '';

			// Append a new line.
			appleScript += '\n';

			// Append the `setWindow` routine.
			appleScript += _.appleScriptRoutineCall('setWindow', [
				value.application,
				config.delay,
				value.osascript.join(' & '),
				value.osascriptPre.join(' & '),
				value.osascriptPost.join(' & '),
				input.space,
				value.shell.join(';'),
				value.shellPre.join(';'),
				value.shellPost.join(';'),
				windowHeight,
				windowWidth,
				left,
				top
			]);
		});

		var d = path.join(instanceDirectory, 'window.applescript');
		fs.writeFileSync(d, appleScript);

		try {
			_.exec('osascript ' + d);
		} catch (e) {
			log.error('command failed');
		}

		// Remove the temporary directory.
		//_.exec('rm -r ' + instanceDirectory);
	};
};<commit_msg>Cleaning code.<commit_after>/**
*
* Load the windows for a space.
*
* @author <NAME> <<EMAIL>>
* @method boot
* @memberof controller/space
* @param {object} config The global configuraton.
* @param {object} input The configuration for the space.
* @returns {boolean} Fail/success state.
*
**/
module.exports = function() {
	'use strict';

	// Wrap the Function.
	return function(config, input) {
		// Store the concatenated AppleScript template.
		var appleScript = '';

		// @todo remove
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setSpace.applescript')).toString();
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setSpaceIndex.applescript')).toString();
		appleScript += fs.readFileSync(path.join(__dirname, '..', '..', 'applescript', 'setWindow.applescript')).toString();

		// The starting column for the grid.
		var column = -1;

		// The starting row for the grid.
		var row = 0;

		// Reference the `tmp` directory.
		var tmpDirectory = path.join(__dirname, '..', '..', 'tmp');

		// Generate a temporary directory for the instance.
		var instanceDirectory = path.join(tmpDirectory, nodeUuid.v4());

		// If the `tmp` directory doesn't exist, then create it.
		if (fs.existsSync(tmpDirectory) === false) {
			// Create the directory.
			fs.mkdirSync(tmpDirectory);
		}

		// Create the temporary directory for the instance.
		fs.mkdirSync(instanceDirectory);


		// @todo ok so this we need to fetch when the space changes apparently...
		var resolution = _.screenResolution();

		// Iterate through each of the windows and open them on the specific space.
		input.window.forEach(function(value) {
			// If the `application` property is missing, then skip the iteration.
			if (_.isEmpty(value.application) === true) {
				// Throw a error to console.
				log.error('No application name specified for window! Skipping.', value);

				// Skip the iteration..
				return;
			}

			var windowHeight = 0;
			var windowWidth = 0;
			var windowX = 0;
			var windowY = 0;

			// Process the grid if the maximum number of columns/rows aren't set to `0`.
			if (input.column.max > 0 && input.row.max > 0) {


				// @todo
				windowHeight = Math.floor(resolution.height / input.row.max);

				windowWidth = Math.floor(resolution.width / input.column.max);



				// Increment the column before the row.
				if (column < input.column.max - 1) {
					column++;
				}

				// If the columns have exhausted, then increment the row.
				else {
					// Increment the row.
					row++;

					// Reset the column.
					column = 0;
				}

				// Adjust the X position of the window.
				windowX = column * (resolution.width / input.column.max);

				// Adjust the Y position of the window.
				windowY = row * (resolution.height / input.row.max);

				// If column spacing is enabled, then adjust the window.
				if (input.column.spacing > 0 && input.column.max > 1) {
					// Only adjust the X position, if it's not the first column.
					if (column > 1) {
						windowX += input.column.spacing;
					}

					// Adjust the window width.
					windowWidth -= input.column.spacing;
				}

				// If row spacing is enabled, then adjust the window.
				if (input.row.spacing > 0 && input.row.max > 1) {
					// Only adjust the Y position, if it's not the first row.
					if (row > 1) {
						windowY += input.row.spacing;
					}

					// Adjust the window height.
					windowHeight -= input.row.spacing;
				}

				if (input.column.max > 1) {
					windowWidth -= input.column.spacing;
				}
			}

			// Append a new line.
			appleScript += '\n';

			// Append a comment for the new `setWindow` routine.
			appleScript += '-- ' + value.application;

			// Append the `title` for the window.
			appleScript += value.title ? ' - ' + value.title : '';

			// Append the `description` for the window.
			appleScript += value.description ? ' - ' + value.description : '';

			// Append a new line.
			appleScript += '\n';

			// Append the `setWindow` routine.
			appleScript += _.appleScriptRoutineCall('setWindow', [
				value.application,
				config.delay,
				value.osascript.join(' & '),
				value.osascriptPre.join(' & '),
				value.osascriptPost.join(' & '),
				input.space,
				value.shell.join(';'),
				value.shellPre.join(';'),
				value.shellPost.join(';'),
				windowHeight,
				windowWidth,
				windowX,
				windowY
			]);
		});

		var appleScriptFile = path.join(instanceDirectory, 'window.applescript');
		fs.writeFileSync(appleScriptFile, appleScript);

		// Attempt to invoke the batch script.
		try {
			// Invoke the AppleScript.
			_.exec('osascript ' + appleScriptFile);
		}

		// Catch any exceptions.
		catch (exception) {
			// Throw a error to console.
			log.error('Building of space failed.', exception);
		}

		// Remove the temporary directory.
		_.exec('rm -r ' + instanceDirectory);
	};
};
{'fraction_non_alphanumeric': 0.14898632720414898, 'fraction_numerical': 0.003536067892503536, 'mean_word_length': 2.806639748766263, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 22, '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': '2725309', 'n_tokens_mistral': 3139, 'n_tokens_neox': 2599, 'n_words': 747}