r23978 by jghali - #16210: Provide a way to get the current script path

scribus-commit scribus-commit at lists.scribus.net
Fri Aug 14 02:48:44 UTC 2020


Author: jghali
Date: Fri Aug 14 02:48:44 2020
New Revision: 23978

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23978
Log:
#16210: Provide a way to get the current script path

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

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23978&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp	Fri Aug 14 02:48:44 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 = io.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