@@ -278,6 +278,50 @@ sys.argv.append("energyplus")
278278 cmd += R"python(
279279from eplaunch.tk_runner import main_gui
280280main_gui()
281+ )python" ;
282+ // std::cout << "Trying to execute this python snippet: " << std::endl << cmd << std::endl;
283+ engine.exec (cmd);
284+ exit (0 );
285+ });
286+
287+ auto *updaterSubCommand = auxiliaryToolsSubcommand->add_subcommand (" updater" , " IDF Version Updater" );
288+ updaterSubCommand->add_option (" args" , python_fwd_args, " Extra Arguments forwarded to IDF Version Updater" )->option_text (" ARG ..." );
289+ updaterSubCommand->positionals_at_end (true );
290+ updaterSubCommand->footer (" You can pass extra arguments after the updater keyword, they will be forwarded to IDF Version Updater." );
291+
292+ updaterSubCommand->callback ([&state, &python_fwd_args] {
293+ EnergyPlus::Python::PythonEngine engine (state);
294+ // There's probably better to be done, like instantiating the pythonEngine with the argc/argv then calling PyRun_SimpleFile but whatever
295+ std::string cmd = R"python( import sys
296+ sys.argv.clear()
297+ sys.argv.append("energyplus")
298+ )python" ;
299+ for (const auto &arg : python_fwd_args) {
300+ cmd += fmt::format (" sys.argv.append(\" {}\" )\n " , arg);
301+ }
302+
303+ fs::path programDir = FileSystem::getParentDirectoryPath (FileSystem::getAbsolutePath (FileSystem::getProgramPath ()));
304+ fs::path const pathToPythonPackages = programDir / " python_lib" ;
305+ std::string sPathToPythonPackages = std::string (pathToPythonPackages.string ());
306+ std::replace (sPathToPythonPackages .begin (), sPathToPythonPackages .end (), ' \\ ' , ' /' );
307+ cmd += fmt::format (" sys.path.insert(0, \" {}\" )\n " , sPathToPythonPackages );
308+
309+ std::string tclConfigDir;
310+ for (auto &p : std::filesystem::directory_iterator (pathToPythonPackages)) {
311+ if (p.is_directory ()) {
312+ std::string dirName = p.path ().filename ().string ();
313+ if (dirName.find (" tcl" , 0 ) == 0 && dirName.find (" ." , 0 ) > 0 ) {
314+ tclConfigDir = dirName;
315+ break ;
316+ }
317+ }
318+ }
319+ cmd += " from os import environ\n " ;
320+ cmd += fmt::format (" environ[\' TCL_LIBRARY\' ] = \" {}/{}\"\n " , sPathToPythonPackages , tclConfigDir);
321+
322+ cmd += R"python(
323+ from energyplus_transition.runner import main_gui
324+ main_gui(True)
281325)python" ;
282326 // std::cout << "Trying to execute this python snippet: " << std::endl << cmd << std::endl;
283327 engine.exec (cmd);
0 commit comments