r23979 by jghali - #16210: Provide a way to get the current script path (also for legacy Python 2.x scripter)

scribus-commit scribus-commit at lists.scribus.net
Fri Aug 14 03:01:54 UTC 2020


Author: jghali
Date: Fri Aug 14 03:01:54 2020
New Revision: 23979

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23979
Log:
#16210: Provide a way to get the current script path (also for legacy Python 2.x scripter)

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptercore.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23979&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptercore.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptercore.cpp	Fri Aug 14 03:01:54 2020
@@ -286,6 +286,7 @@
 	{
 		// Path separators need to be escaped on Windows
 		QString escapedAbsPath  = QDir::toNativeSeparators(fi.absolutePath()).replace("\\", "\\\\");
+		QString escapedAbsFilePath  = QDir::toNativeSeparators(fi.absoluteFilePath()).replace("\\", "\\\\");
 		QString escapedFileName = QDir::toNativeSeparators(fileName).replace("\\", "\\\\");
 		// FIXME: If filename contains chars outside 7bit ascii, might be problems
 		PyObject* globals = PyModule_GetDict(m);
@@ -301,6 +302,8 @@
 		// Replace sys.stdin with a dummy StringIO that always returns
 		// "" for read
 		cm        += QString("sys.stdin = cStringIO.StringIO()\n");
+		// Provide script path to the interpreter
+		cm        += QString("__file__ = \"%1\"\n").arg(escapedAbsFilePath);
 		// tell the script if it's running in the main intepreter or a subinterpreter
 		cm        += QString("import scribus\n");
 		if (inMainInterpreter)




More information about the scribus-commit mailing list