From c7e67a70b4fc30dbcf23f2d96c8a0a82cefe2cb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Sverre=20Lien=20Sell=C3=A6g?= Date: Tue, 8 Sep 2020 00:06:57 +0200 Subject: [PATCH] handle creation of plugins directory if it doesn't exist, remove calls to terminal as it might not have been loaded yet at this point --- src/plugins.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/plugins.cc b/src/plugins.cc index ceaf995..be649b9 100644 --- a/src/plugins.cc +++ b/src/plugins.cc @@ -24,8 +24,22 @@ Plugins::~Plugins() { } void Plugins::load() { + const auto &plugin_path = Config::get().plugins.path; + + boost::system::error_code ec; + if(!boost::filesystem::exists(plugin_path, ec)) { + ec.clear(); + boost::filesystem::create_directories(plugin_path, ec); + } + + if(ec) { + std::cerr << ec.message() << std::endl; + return; + } + boost::filesystem::directory_iterator end_it; - for(boost::filesystem::directory_iterator it(Config::get().plugins.path); it != end_it; it++) { + + for(boost::filesystem::directory_iterator it(plugin_path); it != end_it; it++) { auto module_name = it->path().stem().string(); if(module_name.empty()) continue; @@ -35,10 +49,10 @@ void Plugins::load() { if((is_directory && !is_pycache) || has_py_extension) { try { auto module = py::module::import(module_name.c_str()); - Terminal::get().print("Loading plugin ´" + module_name + "´\n"); } catch(py::error_already_set &error) { - Terminal::get().print("Error loading plugin `" + module_name + "`:\n" + error.what() + "\n"); + std::cerr << "Error loading plugin `" << module_name << "`:\n" + << error.what() << "\n"; } } }