3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Ruurd A. Reitsma
7 * \author Enrico Forestieri
9 * Full author contact details are available in file CREDITS.
15 #include "filetools.h"
16 #include "qstring_helpers.h"
20 #if defined(__CYGWIN__)
21 #include "support/os_cygwin.cpp"
23 #include "support/os_win32.cpp"
25 #include "support/os_unix.cpp"
28 // Static assert to break compilation on platforms where
29 // int/unsigned int is not 4 bytes. Added to make sure that
30 // e.g., the author hash is always 32-bit.
31 template<bool Condition> struct static_assert_helper;
32 template <> struct static_assert_helper<true> {};
34 dummy = sizeof(static_assert_helper<sizeof(int) == 4>)
41 static string const python2(string const & binary, bool verbose = false)
44 lyxerr << "Examining " << binary << "\n";
46 // Check whether this is a python 2 binary.
47 cmd_ret const out = runCommand(binary + " -V 2>&1");
48 if (out.first < 0 || !prefixIs(out.second, "Python 2"))
52 lyxerr << "Found " << out.second << "\n";
63 string const python(bool reset)
65 // Check whether the first python in PATH is the right one.
66 static string command = python2("python -tt");
68 command = python2("python -tt");
71 if (command.empty()) {
72 // It was not, so check whether we can find it elsewhere in
73 // PATH, maybe with some suffix appended.
74 vector<string> const path = getEnvPath("PATH");
75 vector<string>::const_iterator it = path.begin();
76 vector<string>::const_iterator const end = path.end();
77 lyxerr << "Looking for python v2.x ...\n";
78 for (; it != end; ++it) {
79 QString const dir = toqstr(*it);
80 string const localdir = dir.toLocal8Bit().constData();
82 qdir.setFilter(QDir::Files | QDir::Executable);
83 QStringList list = qdir.entryList(QStringList("python*"));
84 for (int i = 0; i < list.size() && command.empty(); ++i) {
85 string const binary = addName(localdir,
86 list.at(i).toLocal8Bit().constData());
87 command = python2(binary, true);
91 // Default to "python" if no usable binary was found.
92 if (command.empty()) {
93 lyxerr << "Warning: No python v2.x binary found.\n";
97 // Add the -tt switch so that mixed tab/whitespace
98 // indentation is an error