From 19e3a099802d596babf95d84cc4a1ae21dbb347f Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 10 Jul 2014 22:33:20 +0000 Subject: [PATCH] Allow '~/' as alias for user's home directory when importing cti/xml --- interfaces/cython/cantera/ctml_writer.py | 1 + src/base/application.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/interfaces/cython/cantera/ctml_writer.py b/interfaces/cython/cantera/ctml_writer.py index d69b76e61..e117936db 100644 --- a/interfaces/cython/cantera/ctml_writer.py +++ b/interfaces/cython/cantera/ctml_writer.py @@ -2612,6 +2612,7 @@ validate() def convert(filename, outName=None): import os + filename = os.path.expanduser(filename) base = os.path.basename(filename) root, _ = os.path.splitext(base) dataset(root) diff --git a/src/base/application.cpp b/src/base/application.cpp index 18abccee7..53d10f021 100644 --- a/src/base/application.cpp +++ b/src/base/application.cpp @@ -508,6 +508,17 @@ std::string Application::findInputFile(const std::string& name) string inname; std::vector& dirs = inputDirs; + // Expand "~/" to user's home directory, if possible + if (name.find("~/") == 0) { + char* home = getenv("HOME"); // POSIX systems + if (!home) { + home = getenv("USERPROFILE"); // Windows systems + } + if (home) { + return home + name.substr(1, npos); + } + } + if (islash == string::npos && ibslash == string::npos) { size_t nd = dirs.size(); inname = "";