Allow --options to be added by the user in Python
This commit is contained in:
parent
cfd7ffb126
commit
a125f24d29
8 changed files with 42 additions and 4 deletions
|
|
@ -71,6 +71,10 @@ public:
|
|||
std::size_t count;
|
||||
std::size_t sequence;
|
||||
|
||||
explicit parse_context_t(const path& cwd)
|
||||
: current_directory(cwd), master(NULL), scope(NULL),
|
||||
linenum(0), errors(0), count(0), sequence(1) {}
|
||||
|
||||
explicit parse_context_t(shared_ptr<std::istream> _stream,
|
||||
const path& cwd)
|
||||
: stream(_stream), current_directory(cwd), master(NULL),
|
||||
|
|
@ -126,6 +130,9 @@ class parse_context_stack_t
|
|||
std::list<parse_context_t> parsing_context;
|
||||
|
||||
public:
|
||||
void push() {
|
||||
parsing_context.push_front(parse_context_t(filesystem::current_path()));
|
||||
}
|
||||
void push(shared_ptr<std::istream> stream,
|
||||
const path& cwd = filesystem::current_path()) {
|
||||
parsing_context.push_front(parse_context_t(stream, cwd));
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ namespace {
|
|||
catch (const std::exception&) {
|
||||
if (name[0] == '-')
|
||||
add_error_context(_("While parsing option '%1'") << name);
|
||||
|
||||
else
|
||||
add_error_context(_("While parsing environent variable '%1'") << name);
|
||||
throw;
|
||||
|
|
|
|||
|
|
@ -419,10 +419,19 @@ expr_t::ptr_op_t python_interpreter_t::lookup(const symbol_t::kind_t kind,
|
|||
}
|
||||
break;
|
||||
|
||||
case symbol_t::OPTION:
|
||||
case symbol_t::OPTION: {
|
||||
if (option_t<python_interpreter_t> * handler = lookup_option(name.c_str()))
|
||||
return MAKE_OPT_HANDLER(python_interpreter_t, handler);
|
||||
|
||||
string option_name(string("option_") + name);
|
||||
if (is_initialized && main_nspace.has_key(option_name.c_str())) {
|
||||
DEBUG("python.interp", "Python lookup option: " << option_name);
|
||||
|
||||
if (python::object obj = main_nspace.get(option_name.c_str()))
|
||||
return WRAP_FUNCTOR(functor_t(obj, option_name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case symbol_t::PRECOMMAND: {
|
||||
const char * p = name.c_str();
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ session_t::session_t()
|
|||
HANDLER(price_db_).on(none, (path(home_var) / ".pricedb").string());
|
||||
else
|
||||
HANDLER(price_db_).on(none, path("./.pricedb").string());
|
||||
|
||||
parsing_context.push();
|
||||
}
|
||||
|
||||
std::size_t session_t::read_data(const string& master_account)
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ public:
|
|||
explicit session_t();
|
||||
virtual ~session_t() {
|
||||
TRACE_DTOR(session_t);
|
||||
parsing_context.pop();
|
||||
}
|
||||
|
||||
virtual string description() {
|
||||
|
|
|
|||
|
|
@ -508,8 +508,9 @@ void instance_t::option_directive(char * line)
|
|||
*p++ = '\0';
|
||||
}
|
||||
|
||||
if (! process_option(context.pathname.string(), line + 2,
|
||||
*context.scope, p, line))
|
||||
path abs_path(filesystem::absolute(context.pathname,
|
||||
context.current_directory));
|
||||
if (! process_option(abs_path.string(), line + 2, *context.scope, p, line))
|
||||
throw_(option_error, _("Illegal option --%1") << line + 2);
|
||||
}
|
||||
|
||||
|
|
|
|||
14
test/baseline/feat-option_py.test
Normal file
14
test/baseline/feat-option_py.test
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
python
|
||||
def option_pyfirst(context):
|
||||
print "In --pyfirst (from %s)" % context
|
||||
|
||||
def option_pysecond(context, val):
|
||||
print "In --pysecond=%s (from %s)" % (val, context)
|
||||
|
||||
--pyfirst
|
||||
--pysecond Hey
|
||||
|
||||
test reg
|
||||
In --pyfirst (from $sourcepath/test/baseline/feat-option_py.test)
|
||||
In --pysecond=Hey (from $sourcepath/test/baseline/feat-option_py.test)
|
||||
end test
|
||||
5
test/baseline/featoption.py
Normal file
5
test/baseline/featoption.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def option_pyfirst(context):
|
||||
print "In --pyfirst (from %s)" % context
|
||||
|
||||
def option_pysecond(context, val):
|
||||
print "In --pysecond=%sh (from %s)" % (val, context)
|
||||
Loading…
Add table
Reference in a new issue