<commit_before>'use strict';

var Utilities = require('periodicjs.core.utilities'),
	ControllerHelper = require('periodicjs.core.controller'),
	Extensions = require('periodicjs.core.extensions'),
	Connection = require('ssh2'),
	fs = require('fs-extra'),
	path = require('path'),
	async = require('async'),
	CoreUtilities,
	CoreController,
	CoreExtension,
	appSettings,
	mongoose,
	logger,
	replicationconffilepath,
	replicationSettings,
	uploadreplicationdir = path.resolve(process.cwd(), 'content/files/replications'),
	d = new Date(),
	defaultExportFileName = 'dbemptyreplication' + '-' + d.getUTCFullYear() + '-' + d.getUTCMonth() + '-' + d.getUTCDate() + '-' + d.getTime() + '.json';

/**
 * get the replication settings
 * @param  {Function} asyncCallBack
 * @return {Function} async callback asyncCallBack(err,results);
 */
var getReplicationData = function (replicationSettings, asyncCallBack) {
	try {
		var conn = new Connection();
		conn.on('ready', function () {
			console.log('Connection :: ready');
			conn.exec('uptime', function (err, stream) {
				if (err) {
					asyncCallBack(err);
				}
				else {
					stream.on('exit', function (code, signal) {
						console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
						asyncCallBack(null, 'Stream :: exit :: code: ' + code + ', signal: ' + signal);
					}).on('close', function () {
						console.log('Stream :: close');
						conn.end();
					}).on('data', function (data) {
						console.log('STDOUT: ' + data);
					}).stderr.on('data', function (data) {
						console.log('STDERR: ' + data);
					});
				}
			});
		}).connect(replicationSettings);
		conn.on('error', function (err) {
			asyncCallBack(err);
		});
	}
	catch (e) {
		asyncCallBack(e);
	}
};

/**
 * get the replication settings
 * @param  {Function} asyncCallBack
 * @return {Function} async callback asyncCallBack(err,results);
 */
var getReplicationConfig = function (replicateFromEnvironment, asyncCallBack) {
	fs.readJson(replicationconffilepath, function (err, confJson) {
		if (err) {
			asyncCallBack(err, null);
		}
		else {
			try {
				replicationSettings = confJson[replicateFromEnvironment];<commit_msg>working on replication<commit_after>'use strict';

var Utilities = require('periodicjs.core.utilities'),
	ControllerHelper = require('periodicjs.core.controller'),
	Extensions = require('periodicjs.core.extensions'),
	Connection = require('ssh2'),
	fs = require('fs-extra'),
	path = require('path'),
	async = require('async'),
	CoreUtilities,
	CoreController,
	CoreExtension,
	appSettings,
	mongoose,
	logger,
	replicationconffilepath,
	replicationSettings,
	uploadreplicationdir = path.resolve(process.cwd(), 'content/files/replications'),
	d = new Date(),
	defaultExportFileName = 'dbemptyreplication' + '-' + d.getUTCFullYear() + '-' + d.getUTCMonth() + '-' + d.getUTCDate() + '-' + d.getTime() + '.json';

/**
 * get the replication settings
 * @param  {Function} asyncCallBack
 * @return {Function} async callback asyncCallBack(err,results);
 */
var getReplicationData = function (replicationSettings, asyncCallBack) {
	try {
		var conn = new Connection();
		var onShell1 = function () {
			conn.exec('cd /var/www/promise-web-application/current/periodicjs && ls && node index.js --cli --extension dbseed --task export', function (err, stream) {
				stream.on('exit', function (code, signal) {
					console.log('Stream :: exit :: code: ' + code + ', signal: ' + signal);
					asyncCallBack(null, 'Stream :: exit :: code: ' + code + ', signal: ' + signal);
				});
				stream.on('close', function () {
					console.log('Stream :: close');
					// conn.shell('ls');
					conn.end();

				});
				stream.on('data', function (data) {
					console.log('STDOUT: ' + data);
				});
				stream.stderr.on('data', function (data) {
					console.log('STDERR: ' + data);
				});
				stream.on('end', function () {
					conn.end();
				});
			});
			// conn.shell('ls -l', function (err, stream) {
			// 	if (err) {
			// 		asyncCallBack(err);
			// 	}
			// 	stream.on('close', function () {
			// 		console.log('Stream :: close');
			// 		conn.end();
			// 	});
			// 	stream.on('data', function (data) {
			// 		console.log('STDOUT: ' + data);
			// 	});
			// 	stream.stderr.on('data', function (data) {
			// 		console.log('STDERR: ' + data);
			// 	});
			// 	stream.end('cd /var/www/promise-web-application/current/periodicjs && ls');
		});
};
conn.on('ready', function () {
	console.log('Connection :: readys');
	conn.shell(onShell1);
});
conn.connect(replicationSettings);
conn.on('error', function (err) {
	asyncCallBack(err);
});
conn.on('end', function () {
	asyncCallBack(null, 'got replication');
});
}
catch (e) {
	asyncCallBack(e);
}
};

/**
 * get the replication settings
 * @param  {Function} asyncCallBack
 * @return {Function} async callback asyncCallBack(err,results);
 */
var getReplicationConfig = function (replicateFromEnvironment, asyncCallBack) {
	fs.readJson(replicationconffilepath, function (err, confJson) {
		if (err) {
			asyncCallBack(err, null);
		}
		else {
			try {
				replicationSettings = confJson[replicateFromEnvironment];
{'fraction_non_alphanumeric': 0.17997267226234628, 'fraction_numerical': 0.0007807925043919579, 'mean_word_length': 3.824858757062147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '207335', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1655, 'n_words': 327}