summaryrefslogtreecommitdiff
path: root/pyuno/zipcore
diff options
context:
space:
mode:
Diffstat (limited to 'pyuno/zipcore')
-rwxr-xr-xpyuno/zipcore/makefile.mk132
-rw-r--r--pyuno/zipcore/python.cxx303
-rw-r--r--pyuno/zipcore/python.sh65
-rw-r--r--pyuno/zipcore/pyversion.inc28
4 files changed, 528 insertions, 0 deletions
diff --git a/pyuno/zipcore/makefile.mk b/pyuno/zipcore/makefile.mk
new file mode 100755
index 000000000000..06241da2bfdb
--- /dev/null
+++ b/pyuno/zipcore/makefile.mk
@@ -0,0 +1,132 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJNAME=pyuno
+PRJ=..
+
+TARGET=zipcore
+LIBTARGET=NO
+
+.INCLUDE : settings.mk
+.IF "$(L10N_framework)"==""
+UWINAPILIB =
+
+.IF "$(SYSTEM_PYTHON)" == "YES" || "$(GUI)" == "OS2"
+systempython:
+ @echo "Not building python-core because system python is being used"
+.ELSE
+
+.INCLUDE : pyversion.mk
+
+PYDIRNAME=python-core-$(PYVERSION)
+DESTROOT=$(BIN)$/$(PYDIRNAME)
+.IF "$(GUI)" == "UNX"
+PYTHONBINARY=$(BIN)$/python$(EXECPOST).bin
+.ELSE
+.IF "$(COM)" == "GCC"
+PYTHONBINARY=$(DESTROOT)$/bin$/python.bin
+.ELSE
+PYTHONBINARY=$(DESTROOT)$/bin$/python$(EXECPOST)
+.ENDIF
+.ENDIF
+
+FINDLIBFILES_TMP:=$(subst,/,$/ \
+ $(shell @$(FIND) $(SOLARLIBDIR)$/python -type f| $(GREP) -v "\.pyc" |$(GREP) -v "\.py~" |$(GREP) -v .orig | $(GREP) -v _failed))
+FINDLIBFILES=$(subst,$(SOLARLIBDIR)$/python, $(FINDLIBFILES_TMP))
+
+FILES=\
+ $(PYTHONBINARY) \
+ $(foreach,i,$(FINDLIBFILES) $(DESTROOT)$/lib$(i))
+
+.IF "$(OS)" == "WNT"
+APP1TARGET = python
+APP1OBJS = $(OBJFILES) $(SOLARLIBDIR)$/pathutils-obj.obj
+APP1STDLIBS =
+APP1RPATH = BRAND
+OBJFILES = $(OBJ)$/python.obj
+.ENDIF
+
+
+.INCLUDE: target.mk
+
+ALLTAR: \
+ $(BIN)$/$(PYDIRNAME).zip
+
+.IF "$(GUI)" == "UNX"
+ALLTAR : $(BIN)$/python.sh
+$(BIN)$/python.sh : python.sh
+ -rm -f $@
+ cat $? > $@
+ sed 's/%%PYVERSION%%/$(PYVERSION)/g' < $@ > $@.new
+ mv $@.new $@
+ chmod +x $@
+.ENDIF
+
+$(OBJ)$/python.obj: $(OUT)$/inc$/pyversion.hxx
+
+$(OUT)$/inc$/pyversion.hxx: pyversion.inc
+ $(SED) $(USQ)s/@/$(PYVERSION)/g$(USQ) < $< > $@
+
+$(BIN)$/$(PYDIRNAME).zip : $(FILES)
+.IF "$(GUI)" == "UNX"
+.IF "$(OS)" != "MACOSX"
+ cd $(DESTROOT) && find . -name '*$(DLLPOST)' | xargs strip
+.ENDIF
+.ENDIF
+ -rm -f $@
+ cd $(BIN) && zip -r $(PYDIRNAME).zip $(PYDIRNAME)
+
+$(DESTROOT)$/lib$/% : $(SOLARLIBDIR)$/python$/%
+ -$(MKDIRHIER) $(@:d)
+ -rm -f $@
+ cat $< > $@
+
+.IF "$(GUI)"== "UNX"
+$(BIN)$/python$(EXECPOST).bin : $(SOLARBINDIR)$/python$(EXECPOST)
+ -$(MKDIRHIER) $(@:d)
+ -rm -f $@
+ cat $< > $@
+.IF "$(OS)" != "MACOSX"
+ strip $@
+.ENDIF
+ chmod +x $@
+.ELSE
+.IF "$(COM)" == "GCC"
+$(DESTROOT)$/bin$/python.bin : $(SOLARBINDIR)$/python$(EXECPOST)
+.ELSE
+$(DESTROOT)$/bin$/python$(EXECPOST) : $(SOLARBINDIR)$/python$(EXECPOST)
+.ENDIF
+ -$(MKDIRHIER) $(@:d)
+ -rm -f $@
+ cat $< > $@
+.ENDIF
+
+.ENDIF
+.ELSE
+ivo:
+ $(ECHO)
+.ENDIF # L10N_framework
diff --git a/pyuno/zipcore/python.cxx b/pyuno/zipcore/python.cxx
new file mode 100644
index 000000000000..14f629922a1d
--- /dev/null
+++ b/pyuno/zipcore/python.cxx
@@ -0,0 +1,303 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <cstddef>
+#include <stdlib.h>
+#include <wchar.h>
+
+#define WIN32_LEAN_AND_MEAN
+#if defined _MSC_VER
+#pragma warning(push, 1)
+#endif
+#include <windows.h>
+#if defined _MSC_VER
+#pragma warning(pop)
+#endif
+
+#include "tools/pathutils.hxx"
+
+#include "pyversion.hxx"
+
+#define MY_LENGTH(s) (sizeof (s) / sizeof *(s) - 1)
+#define MY_STRING(s) (s), MY_LENGTH(s)
+
+wchar_t * encode(wchar_t * buffer, wchar_t const * text) {
+ *buffer++ = L'"';
+ std::size_t n = 0;
+ for (;;) {
+ wchar_t c = *text++;
+ if (c == L'\0') {
+ break;
+ } else if (c == L'"') {
+ // Double any preceding backslashes as required by Windows:
+ for (std::size_t i = 0; i < n; ++i) {
+ *buffer++ = L'\\';
+ }
+ *buffer++ = L'\\';
+ *buffer++ = L'"';
+ n = 0;
+ } else if (c == L'\\') {
+ *buffer++ = L'\\';
+ ++n;
+ } else {
+ *buffer++ = c;
+ n = 0;
+ }
+ }
+ // The command line will continue with a double quote, so double any
+ // preceding backslashes as required by Windows:
+ for (std::size_t i = 0; i < n; ++i) {
+ *buffer++ = L'\\';
+ }
+ *buffer++ = L'"';
+ return buffer;
+}
+
+#ifdef __MINGW32__
+int main(int argc, char ** argv, char **) {
+#else
+int wmain(int argc, wchar_t ** argv, wchar_t **) {
+#endif
+ wchar_t path[MAX_PATH];
+ DWORD n = GetModuleFileNameW(NULL, path, MAX_PATH);
+ if (n == 0 || n >= MAX_PATH) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t * pathEnd = tools::filename(path);
+ *pathEnd = L'\0';
+ n = GetEnvironmentVariableW(L"UNO_PATH", NULL, 0);
+ if (n == 0) {
+ if (GetLastError() != ERROR_ENVVAR_NOT_FOUND ||
+ !SetEnvironmentVariableW(L"UNO_PATH", path))
+ {
+ exit(EXIT_FAILURE);
+ }
+ }
+ wchar_t bootstrap[MY_LENGTH(L"vnd.sun.star.pathname:") + MAX_PATH] =
+ L"vnd.sun.star.pathname:"; //TODO: overflow
+ wchar_t * bootstrapEnd = tools::buildPath(
+ bootstrap + MY_LENGTH(L"vnd.sun.star.pathname:"), path, pathEnd,
+ MY_STRING(L"fundamental.ini"));
+ if (bootstrapEnd == NULL ||
+ (tools::buildPath(path, path, pathEnd, MY_STRING(L"..\\basis-link"))
+ == NULL))
+ {
+ exit(EXIT_FAILURE);
+ }
+ pathEnd = tools::resolveLink(path);
+ wchar_t path1[MAX_PATH];
+ wchar_t * path1End = tools::buildPath(
+ path1, path, pathEnd, MY_STRING(L"\\program"));
+ if (path1End == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t pythonpath2[MAX_PATH];
+ wchar_t * pythonpath2End = tools::buildPath(
+ pythonpath2, path, pathEnd,
+ MY_STRING(L"\\program\\python-core-" MY_PYVERSION L"\\lib"));
+ if (pythonpath2End == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t pythonpath3[MAX_PATH];
+ wchar_t * pythonpath3End = tools::buildPath(
+ pythonpath3, path, pathEnd,
+ MY_STRING(
+ L"\\program\\python-core-" MY_PYVERSION L"\\lib\\site-packages"));
+ if (pythonpath3End == NULL) {
+ exit(EXIT_FAILURE);
+ }
+#ifdef __MINGW32__
+ wchar_t pythonpath4[MAX_PATH];
+ wchar_t * pythonpath4End = tools::buildPath(
+ pythonpath4, path, pathEnd,
+ MY_STRING(L"\\program\\python-core-" MY_PYVERSION L"\\lib\\lib-dynload"));
+ if (pythonpath4End == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t pythonpath5[MAX_PATH];
+ wchar_t * pythonpath5End = tools::buildPath(
+ pythonpath5, path, pathEnd,
+ MY_STRING(L"\\program\\python-core-" MY_PYVERSION L"\\lib\\lib-dynload"));
+ if (pythonpath5End == NULL) {
+ exit(EXIT_FAILURE);
+ }
+#endif
+ wchar_t pythonhome[MAX_PATH];
+ wchar_t * pythonhomeEnd = tools::buildPath(
+ pythonhome, path, pathEnd,
+ MY_STRING(L"\\program\\python-core-" MY_PYVERSION));
+ if (pythonhomeEnd == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t pythonexe[MAX_PATH];
+ wchar_t * pythonexeEnd = tools::buildPath(
+ pythonexe, path, pathEnd,
+#ifdef __MINGW32__
+ MY_STRING(
+ L"\\program\\python-core-" MY_PYVERSION L"\\bin\\python.bin"));
+#else
+ MY_STRING(
+ L"\\program\\python-core-" MY_PYVERSION L"\\bin\\python.exe"));
+#endif
+ if (pythonexeEnd == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ if (tools::buildPath(path, path, pathEnd, MY_STRING(L"\\ure-link")) == NULL)
+ {
+ exit(EXIT_FAILURE);
+ }
+ pathEnd = tools::resolveLink(path);
+ if (pathEnd == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ pathEnd = tools::buildPath(path, path, pathEnd, MY_STRING(L"\\bin"));
+ if (pathEnd == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ std::size_t clSize = MY_LENGTH(L"\"") + 4 * (pythonexeEnd - pythonexe) +
+ MY_LENGTH(L"\"\0"); //TODO: overflow
+ // 4 * len: each char preceded by backslash, each trailing backslash
+ // doubled
+ for (int i = 1; i < argc; ++i) {
+#ifdef __MINGW32__
+ clSize += MY_LENGTH(L" \"") + 4 * strlen(argv[i]) +
+#else
+ clSize += MY_LENGTH(L" \"") + 4 * wcslen(argv[i]) +
+#endif
+ MY_LENGTH(L"\""); //TODO: overflow
+ }
+ wchar_t * cl = new wchar_t[clSize];
+ if (cl == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ wchar_t * cp = encode(cl, pythonhome);
+ for (int i = 1; i < argc; ++i) {
+ *cp++ = L' ';
+#ifdef __MINGW32__
+ int nNeededWStrBuffSize = MultiByteToWideChar(CP_ACP, 0, argv[i], -1, NULL, 0);
+ WCHAR *buff = new WCHAR[nNeededWStrBuffSize+1];
+ MultiByteToWideChar(CP_ACP, 0, argv[i], -1, buff, nNeededWStrBuffSize);
+ buff[nNeededWStrBuffSize] = 0;
+ cp = encode(cp, buff);
+ delete [] buff;
+#else
+ cp = encode(cp, argv[i]);
+#endif
+ }
+ *cp = L'\0';
+ n = GetEnvironmentVariableW(L"PATH", NULL, 0);
+ wchar_t * orig;
+ if (n == 0) {
+ if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
+ exit(EXIT_FAILURE);
+ }
+ orig = L"";
+ } else {
+ orig = new wchar_t[n];
+ if (orig == NULL ||
+ GetEnvironmentVariableW(L"PATH", orig, n) != n - 1)
+ {
+ exit(EXIT_FAILURE);
+ }
+ }
+ wchar_t * value = new wchar_t[
+ (pathEnd - path) + MY_LENGTH(L";") + (path1End - path1) +
+ (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
+ wsprintfW(value, L"%s;%s%s%s", path, path1, n == 0 ? L"" : L";", orig);
+ if (!SetEnvironmentVariableW(L"PATH", value)) {
+ exit(EXIT_FAILURE);
+ }
+ if (n != 0) {
+ delete [] orig;
+ }
+ delete [] value;
+ n = GetEnvironmentVariableW(L"PYTHONPATH", NULL, 0);
+ if (n == 0) {
+ if (GetLastError() != ERROR_ENVVAR_NOT_FOUND) {
+ exit(EXIT_FAILURE);
+ }
+ orig = L"";
+ } else {
+ orig = new wchar_t[n];
+ if (orig == NULL ||
+ GetEnvironmentVariableW(L"PYTHONPATH", orig, n) != n - 1)
+ {
+ exit(EXIT_FAILURE);
+ }
+ }
+#ifdef __MINGW32__
+ value = new wchar_t[
+ (path1End - path1) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
+ MY_LENGTH(L";") + (pythonpath4End - pythonpath4) +
+ MY_LENGTH(L";") + (pythonpath5End - pythonpath5) +
+ MY_LENGTH(L";") + (pythonpath3End - pythonpath3) +
+ (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
+ wsprintfW(
+ value, L"%s;%s;%s;%s;%s%s%s", path1, pythonpath2, pythonpath4,
+ pythonpath5, pythonpath3,
+ n == 0 ? L"" : L";", orig);
+#else
+ value = new wchar_t[
+ (path1End - path1) + MY_LENGTH(L";") + (pythonpath2End - pythonpath2) +
+ MY_LENGTH(L";") + (pythonpath3End - pythonpath3) +
+ (n == 0 ? 0 : MY_LENGTH(L";") + (n - 1)) + 1]; //TODO: overflow
+ wsprintfW(
+ value, L"%s;%s;%s%s%s", path1, pythonpath2, pythonpath3,
+ n == 0 ? L"" : L";", orig);
+#endif
+ if (!SetEnvironmentVariableW(L"PYTHONPATH", value)) {
+ exit(EXIT_FAILURE);
+ }
+ if (n != 0) {
+ delete [] orig;
+ }
+ delete [] value;
+ if (!SetEnvironmentVariableW(L"PYTHONHOME", pythonhome)) {
+ exit(EXIT_FAILURE);
+ }
+ n = GetEnvironmentVariableW(L"URE_BOOTSTRAP", NULL, 0);
+ if (n == 0) {
+ if (GetLastError() != ERROR_ENVVAR_NOT_FOUND ||
+ !SetEnvironmentVariableW(L"URE_BOOTSTRAP", bootstrap))
+ {
+ exit(EXIT_FAILURE);
+ }
+ }
+ STARTUPINFOW startinfo;
+ ZeroMemory(&startinfo, sizeof (STARTUPINFOW));
+ startinfo.cb = sizeof (STARTUPINFOW);
+ PROCESS_INFORMATION procinfo;
+ if (!CreateProcessW(
+ pythonexe, cl, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, NULL,
+ NULL, &startinfo, &procinfo)) {
+ exit(EXIT_FAILURE);
+ }
+ WaitForSingleObject(procinfo.hProcess,INFINITE);
+ DWORD exitStatus;
+ GetExitCodeProcess(procinfo.hProcess,&exitStatus);
+ exit(exitStatus);
+}
diff --git a/pyuno/zipcore/python.sh b/pyuno/zipcore/python.sh
new file mode 100644
index 000000000000..680c6a241572
--- /dev/null
+++ b/pyuno/zipcore/python.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+# resolve installation directory
+sd_cwd="`pwd`"
+if [ -h "$0" ] ; then
+ sd_basename=`basename "$0"`
+ sd_script=`ls -l "$0" | sed "s/.*${sd_basename} -> //g"`
+ cd "`dirname "$0"`"
+ cd "`dirname "$sd_script"`"
+else
+ cd "`dirname "$0"`"
+fi
+sd_prog=`pwd`
+cd "$sd_cwd"
+
+# Set PATH so that crash_report is found:
+PATH=$sd_prog${PATH+:$PATH}
+export PATH
+
+# Set LD_LIBRARY_PATH so that "import pyuno" finds libpyuno.so:
+LD_LIBRARY_PATH=$sd_prog/../basis-link/program:$sd_prog/../basis-link/ure-link/lib${LD_LIBRARY_PATH+:$LD_LIBRARY_PATH}
+export LD_LIBRARY_PATH
+
+# Set UNO_PATH so that "officehelper.bootstrap()" can find soffice executable:
+: ${UNO_PATH=$sd_prog}
+export UNO_PATH
+
+# Set URE_BOOTSTRAP so that "uno.getComponentContext()" bootstraps a complete
+# OOo UNO environment:
+: ${URE_BOOTSTRAP=vnd.sun.star.pathname:$sd_prog/fundamentalrc}
+export URE_BOOTSTRAP
+
+PYTHONPATH=$sd_prog/../basis-link/program:$sd_prog/../basis-link/program/python-core-%%PYVERSION%%/lib:$sd_prog/../basis-link/program/python-core-%%PYVERSION%%/lib/lib-dynload:$sd_prog/../basis-link/program/python-core-%%PYVERSION%%/lib/lib-tk:$sd_prog/../basis-link/program/python-core-%%PYVERSION%%/lib/site-packages${PYTHONPATH+:$PYTHONPATH}
+export PYTHONPATH
+PYTHONHOME=$sd_prog/../basis-link/program/python-core-%%PYVERSION%%
+export PYTHONHOME
+
+# execute binary
+exec "$sd_prog/../basis-link/program/python.bin" "$@"
diff --git a/pyuno/zipcore/pyversion.inc b/pyuno/zipcore/pyversion.inc
new file mode 100644
index 000000000000..de71214717b4
--- /dev/null
+++ b/pyuno/zipcore/pyversion.inc
@@ -0,0 +1,28 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#define MY_PYVERSION L"@"