symlinks_install (OSX): update library search paths in shell scripts for easier python support
parent
ad29ce0cd9
commit
bc42717371
|
@ -1,14 +1,21 @@
|
|||
\section{Python integration}
|
||||
\label{sec:python}
|
||||
A recent feature of Mitsuba is a simple Python interface to the renderer API.
|
||||
A recent feature of Mitsuba is a Python interface to the renderer API.
|
||||
While the interface is still limited at this point, it can already be
|
||||
used for many useful purposes. To access the API, start your Python
|
||||
interpreter and enter
|
||||
\begin{python}
|
||||
import mitsuba
|
||||
\end{python}
|
||||
\paragraph{Mac OS:}
|
||||
For this to work on MacOS X, you will first have to run the ``\emph{Apple
|
||||
Menu}$\to$\emph{Command-line access}'' menu item from within Mitsuba.
|
||||
In the unlikely case that you run into shared library loading issues (this is
|
||||
taken care of by default), you may have to set the \code{LD\_LIBRARY\_PATH}
|
||||
environment variable before starting Python so that it points to where the
|
||||
Mitsuba libraries are installed (e.g. the \code{Mitsuba.app/Contents/Frameworks}
|
||||
directory).
|
||||
\paragraph{Windows and Linux:}
|
||||
On Windows and \emph{non-packaged} Linux builds, you may have to explicitly
|
||||
specify the required extension search path before issuing the \code{import} command, e.g.:
|
||||
\begin{python}
|
||||
|
@ -29,6 +36,9 @@ os.environ['PATH'] = 'path-to-mitsuba-directory' + os.pathsep + os.environ['PATH
|
|||
|
||||
import mitsuba
|
||||
\end{python}
|
||||
In rare cases when running on Linux, it may also be necessary to set the
|
||||
\code{LD\_LIBRARY\_PATH} environment variable before starting Python so that it
|
||||
points to where the Mitsuba core libraries are installed.
|
||||
|
||||
For an overview of the currently exposed API subset, please refer
|
||||
to the following page: \url{http://www.mitsuba-renderer.org/api/group__libpython.html}.
|
||||
|
@ -64,8 +74,8 @@ classes, function, or entire namespaces when running an interactive Python shell
|
|||
...
|
||||
\end{shell}
|
||||
The docstrings list the currently exported functionality, as well as C++ and Python signatures, but they
|
||||
don't document what these functions actually do. The web API documentation is the preferred source for
|
||||
this information.
|
||||
don't document what these functions actually do. The web API documentation is
|
||||
the preferred source of this information.
|
||||
|
||||
\subsection{Basics}
|
||||
Generally, the Python API tries to mimic the C++ API as closely as possible.
|
||||
|
|
|
@ -1593,7 +1593,7 @@ void MainWindow::on_actionStartServer_triggered() {
|
|||
|
||||
void MainWindow::on_actionEnableCommandLine_triggered() {
|
||||
if (QMessageBox::question(this, tr("Enable command line access"),
|
||||
tr("<p>If you proceed, Mitsuba will create symbolic links in <tt>/usr/bin</tt> and <tt>/Library/Python/{2.6,2.7}/site-packages</tt>, "
|
||||
tr("<p>If you proceed, Mitsuba will create symbolic links in <tt>/usr/bin</tt> and <tt>/Library/Python/{2.6,2.7}/site-packages</tt>, as well as an entry in .bashrc, "
|
||||
"which enable command line and Python usage. Note that you will have to "
|
||||
"repeat this process every time the Mitsuba application is moved.</p>"
|
||||
"<p>Create links?</p>"),
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <AuthorizationTags.h>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace mitsuba {
|
||||
extern std::string __mts_bundlepath();
|
||||
|
@ -30,7 +31,10 @@ bool create_symlinks() {
|
|||
}
|
||||
std::string bundlePath = mitsuba::__mts_bundlepath();
|
||||
std::string path = bundlePath + "/Contents/MacOS/symlinks_install";
|
||||
char *args[] = { const_cast<char *>(bundlePath.c_str()), NULL };
|
||||
std::ostringstream oss;
|
||||
oss << getuid();
|
||||
std::string uid = oss.str();
|
||||
char *args[] = { const_cast<char *>(bundlePath.c_str()), const_cast<char *>(uid.c_str()), NULL };
|
||||
FILE *pipe = NULL;
|
||||
flags = kAuthorizationFlagDefaults;
|
||||
status = AuthorizationExecuteWithPrivileges(ref, const_cast<char *>(path.c_str()), flags, args, &pipe);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/param.h>
|
||||
#include <pwd.h>
|
||||
|
||||
void installPython(const char *basedir, const char *version) {
|
||||
char fname[MAXPATHLEN];
|
||||
|
@ -23,6 +24,22 @@ void installPython(const char *basedir, const char *version) {
|
|||
fclose(f);
|
||||
}
|
||||
|
||||
void appendShellConfig(const char *basedir, const char *target, const char *fmt, const char *dir) {
|
||||
char fname[MAXPATHLEN];
|
||||
snprintf(fname, sizeof(fname), "%s/%s", basedir, target);
|
||||
|
||||
if (access(fname, R_OK) < 0)
|
||||
return;
|
||||
|
||||
FILE *f = fopen(fname, "a");
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
fprintf(f, fmt, dir);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void install(const char *basedir, const char *name) {
|
||||
char fname[MAXPATHLEN];
|
||||
FILE *f;
|
||||
|
@ -51,11 +68,11 @@ void install(const char *basedir, const char *name) {
|
|||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Incorrect number of arguments!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
if (setuid(0) != 0) {
|
||||
fprintf(stderr, "setuid(): failed!\n");
|
||||
return -1;
|
||||
|
@ -68,6 +85,11 @@ int main(int argc, char **argv) {
|
|||
install(argv[1], "mtsimport");
|
||||
installPython(argv[1], "2.6");
|
||||
installPython(argv[1], "2.7");
|
||||
struct passwd *pw = getpwuid(atoi(argv[2]));
|
||||
|
||||
appendShellConfig(pw->pw_dir, ".bashrc", "\nexport LD_LIBRARY_PATH=%s/Contents/Frameworks:$LD_LIBRARY_PATH\n", argv[1]);
|
||||
appendShellConfig(pw->pw_dir, ".zshrc", "\nexport LD_LIBRARY_PATH=%s/Contents/Frameworks:$LD_LIBRARY_PATH\n", argv[1]);
|
||||
appendShellConfig(pw->pw_dir, ".cshrc", "\nsetenv LD_LIBRARY_PATH %s/Contents/Frameworks:${LD_LIBRARY_PATH}\n", argv[1]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue