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.
14 #include "filetools.h"
15 #include "qstring_helpers.h"
19 #if defined(__CYGWIN__)
20 #include "support/os_cygwin.cpp"
22 #include "support/os_win32.cpp"
24 #include "support/os_unix.cpp"
27 // Static assert to break compilation on platforms where
28 // int/unsigned int is not 4 bytes. Added to make sure that
29 // e.g., the author hash is always 32-bit.
30 template<bool Condition> struct static_assert_helper;
31 template <> struct static_assert_helper<true> {};
33 dummy = sizeof(static_assert_helper<sizeof(int) == 4>)
40 static string const python2(string const & binary, bool verbose = false)
43 lyxerr << "Examining " << binary << "\n";
45 // Check whether this is a python 2 binary.
46 cmd_ret const out = runCommand(binary + " -V 2>&1");
47 if (out.first < 0 || !prefixIs(out.second, "Python 2"))
51 lyxerr << "Found " << out.second << "\n";
58 // Check whether the first python in PATH is the right one.
59 static string command = python2("python -tt");
61 if (command.empty()) {
62 // It was not, so check whether we can find it elsewhere in
63 // PATH, maybe with some suffix appended.
64 vector<string> const path = getEnvPath("PATH");
65 vector<string>::const_iterator it = path.begin();
66 vector<string>::const_iterator const end = path.end();
67 lyxerr << "Looking for python v2.x ...\n";
68 for (; it != end; ++it) {
69 QString const dir = toqstr(*it);
70 string const localdir = dir.toLocal8Bit().constData();
72 qdir.setFilter(QDir::Files | QDir::Executable);
73 QStringList list = qdir.entryList(QStringList("python*"));
74 for (int i = 0; i < list.size() && command.empty(); ++i) {
75 string const binary = addName(localdir,
76 list.at(i).toLocal8Bit().constData());
77 command = python2(binary, true);
81 // Default to "python" if no usable binary was found.
82 if (command.empty()) {
83 lyxerr << "Warning: No python v2.x binary found.\n";
87 // Add the -tt switch so that mixed tab/whitespace
88 // indentation is an error