<commit_before>import optparse
import logging
import os.path
import sys

from mirte.core import Manager
from mirte.mirtefile import load_mirteFile

from sarah.order import sort_by_successors

def parse_cmdLine(args):
	""" Parses commandline arguments into options and arguments """
	options = dict()
	rargs = list()
	for arg in args:
		if arg[:2] == '--':
			tmp = arg[2:]
			bits = tmp.split('=', 1)
			if len(bits) == 1:
				bits.append('')
			options[bits[0]] = bits[1]
		else:
			rargs.append(arg)
	return options, rargs

def execute_cmdLine_options(options, m, l):
	""" Applies the instructions given via <options> on the manager <m> """
	opt_lut = dict()
	inst_lut = dict()
	for k, v in options.iteritems():
		bits = k.split('-', 1)
		if len(bits) == 1:
			inst_lut[bits[0]] = v
		else:
			if not bits[0] in opt_lut:
				opt_lut[bits[0]] = list()
			opt_lut[bits[0]].append((bits[1], v))
	inst_list = sort_by_successors(inst_lut.keys(),
			lambda inst: [v for (k,v) in opt_lut.get(inst, ())
					if k in m.modules[inst_lut[inst]].deps])
	for k in reversed(tuple(inst_list)):
		if k in m.insts:
			raise NotImplementedError, \
				"Overwriting instancens not yet supported"
		settings = dict()
		if k in opt_lut:
			for k2, v2 in opt_lut[k]:
				settings[k2] = v2
		m.create_instance(k, inst_lut[k], settings)
	for k in opt_lut:
		if k in inst_lut:
			continue
		for k2, v2 in opt_lut[k]:
			if not k in m.insts:
				raise ValueError, "No such instance %s" % k
			m.change_setting(k, k2, v2)

def main():
	""" Entry-point """
	logging.basicConfig(level=logging.DEBUG,
	    format="%(relativeCreated)d %(levelname)s:%(name)s:%(message)s")
	l = logging.getLogger('mirte')
	options, args = parse_cmdLine(sys.argv[1:])
	m = Manager(l)
	path = args[0] if len(args) > 0 else 'default.mirte'
	load_mirteFile(path, m, logger=l)
	execute_cmdLine_options(options, m, l)
	m.run()
<commit_msg>default.mirte.mirte -> default.mirte<commit_after>import optparse
import logging
import os.path
import sys

from mirte.core import Manager
from mirte.mirtefile import load_mirteFile

from sarah.order import sort_by_successors

def parse_cmdLine(args):
	""" Parses commandline arguments into options and arguments """
	options = dict()
	rargs = list()
	for arg in args:
		if arg[:2] == '--':
			tmp = arg[2:]
			bits = tmp.split('=', 1)
			if len(bits) == 1:
				bits.append('')
			options[bits[0]] = bits[1]
		else:
			rargs.append(arg)
	return options, rargs

def execute_cmdLine_options(options, m, l):
	""" Applies the instructions given via <options> on the manager <m> """
	opt_lut = dict()
	inst_lut = dict()
	for k, v in options.iteritems():
		bits = k.split('-', 1)
		if len(bits) == 1:
			inst_lut[bits[0]] = v
		else:
			if not bits[0] in opt_lut:
				opt_lut[bits[0]] = list()
			opt_lut[bits[0]].append((bits[1], v))
	inst_list = sort_by_successors(inst_lut.keys(),
			lambda inst: [v for (k,v) in opt_lut.get(inst, ())
					if k in m.modules[inst_lut[inst]].deps])
	for k in reversed(tuple(inst_list)):
		if k in m.insts:
			raise NotImplementedError, \
				"Overwriting instancens not yet supported"
		settings = dict()
		if k in opt_lut:
			for k2, v2 in opt_lut[k]:
				settings[k2] = v2
		m.create_instance(k, inst_lut[k], settings)
	for k in opt_lut:
		if k in inst_lut:
			continue
		for k2, v2 in opt_lut[k]:
			if not k in m.insts:
				raise ValueError, "No such instance %s" % k
			m.change_setting(k, k2, v2)

def main():
	""" Entry-point """
	logging.basicConfig(level=logging.DEBUG,
	    format="%(relativeCreated)d %(levelname)s:%(name)s:%(message)s")
	l = logging.getLogger('mirte')
	options, args = parse_cmdLine(sys.argv[1:])
	m = Manager(l)
	path = args[0] if len(args) > 0 else 'default'
	load_mirteFile(path, m, logger=l)
	execute_cmdLine_options(options, m, l)
	m.run()

{'fraction_non_alphanumeric': 0.14726840855106887, 'fraction_numerical': 0.012668250197941409, 'mean_word_length': 4.0, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, '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': '5717406', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1448, 'n_words': 393}