#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, argparse, os.path

class ConfigurationGenerator:


	def __init__(self):
		self.output_list=[]
		self.corp_names_list=[]
		self.operators_names_list=[]
	
	
	def generate_configuration(self, builder, corpuses, operators, reader, out_dir, tagset, interval, pos, isMain=False):
		self.output_list=[]
		self.corp_names_list=[]
		self.operators_names_list=[]

		corp_list=corpuses
		oper_list=operators
		output=""
		if type(corp_list).__name__!='list':
			corp_list=[corp_list]
		if type(oper_list).__name__!='list':
			oper_list=[oper_list]

		for corpus in corp_list:
			first_part = builder+" -t " + tagset + " -r " + reader + " -d " + str(interval) + " -a " +str( pos) + " -c " + corpus 
		
			corpus_name = os.path.basename(corpus)
			self.corp_names_list.append(corpus_name)
			for operator in oper_list:
				operator_name = os.path.splitext(os.path.basename(operator))[0]
				self.operators_names_list.append(operator_name)
				self.output_list.append(corpus_name + "_"+ operator_name )
				if not os.path.exists(os.path.join(out_dir,"tuples")):
					os.mkdir(os.path.join(out_dir,"tuples"))
				sec_part = first_part + " --operator " + operator + " -o " + os.path.join(out_dir, "tuples/" + corpus_name + "_"+ operator_name + ".tuples")
				if isMain:
					print sec_part
				output+=sec_part + "\n"
		return output
	
	def get_files_list(self):
		return self.output_list

