<commit_before>from args import CommandParser
from config import Config
from config import ConfigError
import os
from sftp import Sftp

def get_files(config, directory='.'):
	file_dict = dict()
	file_list = list()
	for f in os.listdir(directory):
		if config.ignore(f):
			continue
		if os.path.isfile(directory + "/" + f):
			file_list.append(f)
		elif os.path.isdir(directory + "/" + f):
			retrurned_files = get_files(config, directory=directory + "/" + f)
			file_list.append(retrurned_files)
	file_dict[directory] = file_list
	return file_dict

def handle_config_error(e):
	if e.cause is ConfigError.INVALID_NAME_ERROR:
		print "the supplied name is not valid."
	elif e.cause is ConfigError.NO_NAME_ERROR:
		print "A destination name is required."
	elif e.cause is ConfigError.JSON_ERROR:
		print "Config file is not properly formatted."
	exit()


def init(options, config):
	if config.config_file_exists():		#check if the stuff already exists and handle the stuff
		print "config file already exists"
		return
	else:
		config.create_config_template()
		print "Config file created"
		return

def push(options, config):
	def help():
		print "push all tracked files to the remote"
		print "usage: deploy push [<remote] [<options>]\n"
		print "\t-r\t\tremove all files that are not locally tracked NOT FUNCTIONAL"

	if options is None or len(options) == 1:
		if options is not None and options[0] == 'help':
			help()
			return
		else:
			if config.config_file_exists():		# if it does try to use it, show help if
				try:
					if options is None:
						config.load_config(options)
					else:
						config.load_config(options[0])	# error occurs
				except ConfigError, e:
					handle_config_error(e)
				
			else:
				print "No Config file found, use 'deploy init' to create a sample config file."
				return
	file_dict = get_files(config)
	sftp = Sftp(config.get_destination_root(), file_dict)
	sftp.send_files(config.get_user(), config.get_host())

def help():
	print """
usage: deploy cmd
	
	help 		Show this help message
	init 		Start deploy in the current directory
	push 		Push to a repository
		"""

def main(name="deploy"):
	#dest = args.get_destination()
	#init = args.get_init()
	config = Config()
	cParser = CommandParser(name, help_callback=help())
	cParser.add_command('init', 'init help', init, config)
	cParser.add_command('push', 'push help', push, config)
	cParser.parse_args()

	
	"""<commit_msg>Fixed bug where help appears for all commands<commit_after>from args import CommandParser
from config import Config
from config import ConfigError
import os
from sftp import Sftp

def get_files(config, directory='.'):
	file_dict = dict()
	file_list = list()
	for f in os.listdir(directory):
		if config.ignore(f):
			continue
		if os.path.isfile(directory + "/" + f):
			file_list.append(f)
		elif os.path.isdir(directory + "/" + f):
			retrurned_files = get_files(config, directory=directory + "/" + f)
			file_list.append(retrurned_files)
	file_dict[directory] = file_list
	return file_dict

def handle_config_error(e):
	if e.cause is ConfigError.INVALID_NAME_ERROR:
		print "the supplied name is not valid."
	elif e.cause is ConfigError.NO_NAME_ERROR:
		print "A destination name is required."
	elif e.cause is ConfigError.JSON_ERROR:
		print "Config file is not properly formatted."
	exit()


def init(options, config):
	if config.config_file_exists():		#check if the stuff already exists and handle the stuff
		print "config file already exists"
		return
	else:
		config.create_config_template()
		print "Config file created"
		return

def push(options, config):
	def help():
		print "push all tracked files to the remote"
		print "usage: deploy push [<remote] [<options>]\n"
		print "\t-r\t\tremove all files that are not locally tracked NOT FUNCTIONAL"

	if options is None or len(options) == 1:
		if options is not None and options[0] == 'help':
			help()
			return
		else:
			if config.config_file_exists():		# if it does try to use it, show help if
				try:
					if options is None:
						config.load_config(options)
					else:
						config.load_config(options[0])	# error occurs
				except ConfigError, e:
					handle_config_error(e)
				
			else:
				print "No Config file found, use 'deploy init' to create a sample config file."
				return
	file_dict = get_files(config)
	sftp = Sftp(config.get_destination_root(), file_dict)
	sftp.send_files(config.get_user(), config.get_host())

def help():
	print """
usage: deploy cmd
	
	help 		Show this help message
	init 		Start deploy in the current directory
	push 		Push to a repository
		"""

def main(name="deploy"):
	#dest = args.get_destination()
	#init = args.get_init()
	config = Config()
	cParser = CommandParser(name, help_callback=help)
	cParser.add_command('init', 'init help', init, config)
	cParser.add_command('push', 'push help', push, config)
	cParser.parse_args()

	
	"""
{'fraction_non_alphanumeric': 0.10493827160493827, 'fraction_numerical': 0.0012345679012345679, 'mean_word_length': 4.084728033472803, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7269259', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1559, 'n_words': 513}