def run():
	# if an input path is provided
	if len(sys.argv[1:]) and sys.argv[1][0] != '-': # skip if it looks like an option
		baseFolderPath = sys.argv[1]

		if baseFolderPath[-1] == '/':  # remove last slash if present
			baseFolderPath = baseFolderPath[:-1]

		# make sure the path is valid
		if not os.path.isdir(baseFolderPath):
			print >> sys.stderr, "ERROR: Invalid input folder\n\t%s" % baseFolderPath
			return

	# if an input path is not provided, use the current directory
	else:
		baseFolderPath = os.getcwd()

	# Load the options
	try:
		options = getOptions(baseFolderPath)
	except:
		return
	
	# Get paths to fonts and instances file
	fontPathsList, instancesFilePath = getFontPaths(baseFolderPath)
	
	if not len(fontPathsList):
		print >> sys.stderr, "ERROR: No UFO fonts were found in the path below\n\t%s" % baseFolderPath
		return

	# Handle the instances file
	if not instancesFilePath:
		print >> sys.stderr, "ERROR: Could not find the file named '%s' in the path below\n\t%s" % (kInstancesDataFileName, baseFolderPath)
		return
	print "Parsing %s file..." % kInstancesDataFileName
	try:
		instancesList = readInstanceFile(instancesFilePath)
	except:
		print >> sys.stderr, "ERROR: Error parsing file or file is empty."
		return

	# Check the UFO file names
	masterIndexes = []
	for ufoPath in fontPathsList:
		fileNameNoExtension, fileExtension = os.path.splitext(ufoPath)
		masterNumber = fileNameNoExtension.split('_')[-1]
		
		if masterNumber.isdigit():
			masterIndexes.append(int(masterNumber))
	if masterIndexes != range(len(fontPathsList)):
		print >> sys.stderr, "ERROR: The UFO master files are not named properly"
		return
	
	# Check the number of UFOs against the number of axes in the instances file
	axisNum = int(math.log(len(masterIndexes), 2))
	for i in range(len(instancesList)):
		instanceDict = instancesList[i]
		axisVal = instanceDict[kCoordsKey] # Get AxisValues strings
		if axisNum != len(axisVal):
			print 'ERROR:  The %s value for the instance named %s in the %s file is not compatible with the number of axis in the MM source font.' % (kCoordsKey, instanceDict[kFontName], kInstancesDataFileName)
			return

	# Get the path to the output folder
	try:
		outputDirPath = options.outputPath
		if not os.path.isdir(outputDirPath):
			print >> sys.stderr, "ERROR: Invalid output folder\n\t%s" % outputDirPath
			return
	except AttributeError: # use the current folder to output the instances
		outputDirPath = baseFolderPath

	t1 = time.time()

	print "Reading %d UFO files..." % len(fontPathsList)
	ufoMasters = [OpenFont(ufoPath) for ufoPath in fontPathsList]	

	totalInstances = len(instancesList)
	print "Generating %d instances..." % totalInstances
	for i in range(totalInstances):
		makeInstance((i+1, totalInstances), ufoMasters, instancesList[i], outputDirPath, options)

	t2 = time.time()
	elapsedSeconds = t2-t1
	
	if (elapsedSeconds/60) < 1:
		print 'Completed in %.1f seconds.' % elapsedSeconds
	else:
		print 'Completed in %.1f minutes.' % (elapsedSeconds/60)
dataset/ETHPy150Open adobe-type-tools/python-scripts/UFOInstanceGenerator.py/run/original