#!/usr/bin/env python

if __file__[-13:] == "/bin/scaffold" or __file__[-13:] == "\\bin\\scaffold":
	import os, sys
	print("Using test source code from", os.path.dirname(__file__)[0:-3])
	sys.path.insert(0, os.path.dirname(__file__)[0:-3])
import configparser
import builtins
import argparse
import scaffold
from scaffold.config import ScaffoldIniConfig
from scaffold.scaffold import Scaffold

##
## This is the high-level API: It receives a command from the CLI, which is translated
## to the scaffold python package and executed.
##

# Parse the command line arguments.

parser = argparse.ArgumentParser()

parser.add_argument("-c", "--config",
	help="Specify the path of the configuration .ini file.",
	default="{}/configurations/mouse_cerebellum.ini".format(scaffold.__path__[0])
)
parser.add_argument("-v", "--verbose",
	help="Specify the verbosity of the console output",
	action="count",
	default=0
)

subparsers = parser.add_subparsers(
	title='Scaffold tasks',
	description='The scaffold performs multiple seperate tasks. See the list below for available tasks.',
	required=True,
	dest='task'
)

parser_compile = subparsers.add_parser('compile', help='Build a network of neurons in a volume.')
parser_compile.add_argument('-p', action='store_true',help='Plot the created network')

parser_run = subparsers.add_parser('run', help='Run a simulation using a compiled scaffold network.')

cl_args = parser.parse_args()

# Load the .ini configuration
scaffoldConfig = ScaffoldIniConfig(cl_args.config)
scaffoldConfig.verbosity = cl_args.verbose

# Create the scaffold instance
scaffoldInstance = Scaffold(scaffoldConfig)
# Make the scaffoldInstance available in all modules. (Monkey patch during rework)
builtins.scaffoldInstance = scaffoldInstance

if cl_args.task == 'compile':
	scaffoldInstance.compileNetworkArchitecture()
	if cl_args.p:
		scaffoldInstance.plotNetworkCache()

if cl_args.task == 'run':
	# Run the nest script
	pass
