<commit_before>colors	= require "colors"
ftp		= require "ftp"
fs 		= require "fs"
YAML 	= require "yamljs"
Signal	= require "signals"
exec	= require("child_process").exec
argv 	= require("optimist").argv


module.exports = class Deploy

	server 			: null

	local_hash		: null
	remote_hash		: null
	connection		: null

	connections 	: []
	toUpload		: []
	toDelete		: []
	dirCreated		: {}

	completed 		: null

	constructor: (@server = "default") ->
		@completed = new Signal()

		# Load the config file
		fs.readFile "gploy.yaml", (error, data) =>
			if error
				return console.log "Error:".bold.red, "The file \"gploy.yaml\" could not be found."
				process.exit(code=0)

			# Set the config file based on the arguments
			# If no arguments were found, use the "default" setup
			@config = YAML.parse(data.toString())[@server]
			unless @config
				return console.log "Error:".bold.red, "We couldn't find the settings for " + "#{@server}".bold.red
				process.exit(code=0)
			
			# Call git
			@setupGit()

	setupGit: ->
		console.log "Connecting to ".bold.yellow + "#{@server}".bold.underline.yellow + "...".bold.yellow

		# Get the HEAD hash id so we can compare to the hash on the server
		exec "git log --pretty=format:'%H' -n 1", (error, stdout, stderr) =>
			return console.log "This is not a valid .git repository.".bold.red if error
			@local_hash	= stdout

			# Call the FTP
			@setupFTP()

	setupFTP: ->
		# Create a new instance of the FTP
		@connection = new ftp()
		@connection.on "error", => return console.log "Connection failed.".bold.red
		@connection.on "ready", =>
			@connections.push @connection

			# Once is connected, check the revision files
			@checkRevision()

		# Connect using the config information
		@connection.connect
			host		: @config.host
			port		: @config.port
			user		: @config.user
			password	: @config.pass

	setupMultipleFTP: ->
		con = new ftp()<commit_msg>Updated the logs #gploy #default #stage #live<commit_after>colors	= require "colors"
ftp		= require "ftp"
fs 		= require "fs"
YAML 	= require "yamljs"
Signal	= require "signals"
exec	= require("child_process").exec
argv 	= require("optimist").argv


module.exports = class Deploy

	server 			: null

	local_hash		: null
	remote_hash		: null
	connection		: null

	connections 	: []
	toUpload		: []
	toDelete		: []
	dirCreated		: {}

	completed 		: null

	constructor: (@server = "default") ->
		@completed = new Signal()

		# Load the config file
		fs.readFile "gploy.yaml", (error, data) =>
			if error
				return console.log "Error:".bold.red, "The file \"gploy.yaml\" could not be found."
				process.exit(code=0)

			# Set the config file based on the arguments
			# If no arguments were found, use the "default" setup
			@config = YAML.parse(data.toString())[@server]
			unless @config
				return console.log "Error:".bold.red, "We couldn't find the settings for " + "#{@server}".bold.red
				process.exit(code=0)
			
			# Call git
			@setupGit()

	setupGit: ->
		console.log "Connecting to ".bold.yellow + "#{@server}".bold.underline.yellow + "...".bold.yellow

		# Get the HEAD hash id so we can compare to the hash on the server
		exec "git log --pretty=format:'%H' -n 1", (error, stdout, stderr) =>
			return console.log "This is not a valid .git repository.".bold.red if error
			@local_hash	= stdout

			# Call the FTP
			@setupFTP()

	setupFTP: ->
		# Create a new instance of the FTP
		@connection = new ftp()
		@connection.on "error", =>
			console.log "Connection failed.".bold.red
			@completed.dispatch()
			return
		@connection.on "ready", =>
			@connections.push @connection

			# Once is connected, check the revision files
			@checkRevision()

		# Connect using the config information
		@connection.connect
			host		: @config.host
			port		: @config.port
			user		: @config.user
			password	: <PASSWORD>

	setupMultipleFTP: ->
		con = new ftp()
{'fraction_non_alphanumeric': 0.13136798551848977, 'fraction_numerical': 0.0015515903801396431, 'mean_word_length': 3.2273224043715847, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 20, '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': '1953736', 'n_tokens_mistral': 1488, 'n_tokens_neox': 1276, 'n_words': 392}