import os
import sys
from java.io import File

# TODO Move checkParameterName here

class Utils(object):
	"""All the constants necessary for the LineAnalysis scripts."""

	def getCassisDir():
		"""Function allowing the user to extract the right CASSIS directory path"""
		from eu.omp.irap.cassis.properties import Software
		CASSIS_DIR = Software.getCassisPath()
		return CASSIS_DIR

	CASSIS_DIR             = getCassisDir()
	CONTINUUM_DIR          = os.path.join(CASSIS_DIR, "delivery", "continuum")
	TELESCOPE_DIR          = os.path.join(CASSIS_DIR, "delivery", "telescope")
	MANDATORY_PARAMETERS  = ["Fi", 
						     "Tc", "Tf", "Tr",
						     "vlsr", "Vin", 
						     "tau", "fwhm"]
	# The user wants to start from 1 instead if 0
	USER_START_INDEX = 1
	ORDERED_PARAMETER_NAMES  = ["tau", "Vin", "Tr", "fwhm", "Fi", "vlsr", "Tc", "Tf"]

def product(*args):
    """product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
    product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111

    """
    pools = map(tuple, args)
    result = [[]]
    for pool in pools:
        result = [x+[y] for x in result for y in pool]
    for prod in result:
        yield tuple(prod)

