View Issue Details

IDProjectCategoryView StatusLast Update
0012594Scribus[All Projects] Generalpublic2015-01-28 11:56
Reporterwilliam Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionwon't fix 
Platformx86_64OSFedoraOS Version20
Product Version 
Target VersionFixed in Version 
Summary0012594: [patch] Add a --python-script command line option to Scribus 1.4.5svn to run a script and exit
DescriptionThese patches add a --python-script command line option to Scribus 1.4.5svn (6 Aug 2014 snapshot).
Scribus will run the script and then exit without user interaction.
The patches are operating system and platform independent, although they have been tested only on Linux.
The patches were written by Juraj Fedel.
The patches in this report are the Scribus 1.4.5svn version of the similar patches for Scribus 1.5.0svn in http://bugs.scribus.net/view.php?id=12572
Steps To ReproduceThe uploaded file scribus14-command-line-6aug14.pat contains patches created by "svn diff".
Apply it with
  patch -p0 < scribus14-command-line-6aug14.pat
and then rebuild Scribus 1.4 as usual.
Additional InformationTo test the patches:
Create a Scribus document with two text frames and save it as mydoc14.sla.
Create an empty Scribus document and save it as empty14.sla.
Create a python script data14.py with the lines below.

import scribus
scribus.openDoc('mydoc14.sla')
scribus.setText('Name', 'Text1') # get 'Name' and 'Address' from database
scribus.setText('Address', 'Text2')
scribus.saveDocAs('mydocnew.sla')
pdf = scribus.PDFfile()
pdf.file = 'output1.pdf'
pdf.save()

Then run the command
  scribus --python-script data14.py empty14.sla
Scribus will run the python script to write text into the two frames, save the document as mydocnew.sla and generate a PDF as output1.pdf.
empty14.sla is untouched but prevents Scribus opening a dialog to create a new document.
TagsNo tags attached.
PatchYes

Relationships

related to 0012572 closedcbradney [patch] Add a --python-script command line option to run a script and exit 

Activities

william

2014-08-08 01:06

updater  

scribus14-command-line-6aug14.pat (7,596 bytes)

william

2014-08-29 03:22

updater  

patch_bundle_v144-25aug14.tar.gz (10,948 bytes)

william

2014-08-29 03:28

updater   ~0033361

I uploaded an improved set of patches for Scribus 1.4 from Juraj as patch_bundle_v144-25aug14.tar.gz

The first patch in the set replaces the original patch to add a '--python-script file' command line option.
The seventh patch adds python functions to save and read PDF options.
The eleventh patch enables the '--no-gui' command line option.
The thirteenth patch moves python errors to stderr when Scribus is run with --no-gui.
The other patches fix problems in Scribus that become apparent when you try to script exporting documents to PDF.

I tested the patches with Scribus 1.4.5svn from August 28, 2014.

0001: Add the '--python-script file' CLI option to run 'file' as python script.
0002: Now help(scribus.newDocument) in python console runs without error.
0003: Translate strings to variable names with unitGetUntranslatedStrFromIndex instead of unitGetStrFromIndex so python scripts are not dependent on the locale.
0004: Fix the help message for scribus.PDFfile.
0005: Fix reading the prefs file. Scribus was opening the wrong file.
0006: Set ScribusMainWindow::ScriptRunning earlier in the initialization process. Scribus was using it before it was initialized.
0007: Add two python commands readPDFOptions(file) and savePDFOptions(file).
0008: Fix errors when reading PDFOptions.
0009: Fix errors in error messages related to reading PDFOptions files.
0010: Escape HTML codes in scripter error messages so error messages enclosed by <> show correctly.
0011: Enable the --no-gui CLI option so 'scribus --no-gui --python-script myscript.py' runs a script and exits without starting the GUI.
0012: Update the python scripter to allow exporting documents in PDF 1.5. Scribus limited the 'version' variable to 14 instead of 15.
0013: Do not show a messagebox when python scripts raise an error.

william

2014-09-02 02:03

updater  

0015-All-in-one-Run-python-script-from-CLI_v144.patch (11,739 bytes)
From 9c2e50d5b390160264f46a5386255aafdf2e53c4 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Sun, 31 Aug 2014 15:56:42 +0200
Subject: [PATCH] All in one: Run python script from CLI

Add the '--python-script file' CLI option to run 'file' as python
script.

Also enable the use of --no-gui CLI option
This option is useful to run a python script and then exit scribus with:
scribus --no-gui --python-script myscript.py
if it is run as:
scribus --python-script myscript.py
then after myscript.py finishes, the GUI is started.

I moved signal appStarted() from scribuscore to scribusapp,
it seems to be better place.
---
 scribus/main_nix.cpp                          |    8 ++---
 scribus/main_win32.cpp                        |    6 ++--
 scribus/plugins/scriptplugin/scriptercore.cpp |   29 +++++++++++-----
 scribus/plugins/scriptplugin/scriptercore.h   |    1 +
 scribus/scribusapp.cpp                        |   46 +++++++++++++++++++-----
 scribus/scribusapp.h                          |    4 ++
 scribus/scribuscore.cpp                       |    5 ---
 scribus/scribuscore.h                         |    5 ---
 8 files changed, 67 insertions(+), 37 deletions(-)

diff --git a/scribus/main_nix.cpp b/scribus/main_nix.cpp
index 03db7e8..0a346d1 100644
--- a/scribus/main_nix.cpp
+++ b/scribus/main_nix.cpp
@@ -76,13 +76,11 @@ int mainApp(int argc, char **argv)
 #endif // QT_VERSION == 0x040400
 #endif // Q_OS_UNIX
 	app.parseCommandLine();
+	int appRetVal=app.init();
+	if (appRetVal==EXIT_FAILURE)
+		return(EXIT_FAILURE);
 	if (app.useGUI)
-	{
-		int appRetVal=app.init();
-		if (appRetVal==EXIT_FAILURE)
-			return(EXIT_FAILURE);
 		return app.exec();
-	}
 	return EXIT_SUCCESS;	
 }
 
diff --git a/scribus/main_win32.cpp b/scribus/main_win32.cpp
index aae1fcc..a2c49e4 100644
--- a/scribus/main_win32.cpp
+++ b/scribus/main_win32.cpp
@@ -108,10 +108,10 @@ int mainApp(ScribusQApp& app)
 	{
 #endif
 		app.parseCommandLine();
-		if (app.useGUI)
+		appRetVal = app.init();
+		if (appRetVal != EXIT_FAILURE)
 		{
-			appRetVal = app.init();
-			if (appRetVal != EXIT_FAILURE)
+			if (app.useGUI)
 				appRetVal = app.exec();
 		}
 #ifndef _DEBUG
diff --git a/scribus/plugins/scriptplugin/scriptercore.cpp b/scribus/plugins/scriptplugin/scriptercore.cpp
index 021951d..7ecfc55 100644
--- a/scribus/plugins/scriptplugin/scriptercore.cpp
+++ b/scribus/plugins/scriptplugin/scriptercore.cpp
@@ -32,6 +32,7 @@ for which a new license (GPL+exception) is in place.
 #include "prefscontext.h"
 #include "prefstable.h"
 #include "prefsmanager.h"
+#include "scribusapp.h" // need it to acces ScQApp->pythonScript
 
 ScripterCore::ScripterCore(QWidget* parent)
 {
@@ -62,6 +63,8 @@ ScripterCore::ScripterCore(QWidget* parent)
 
 	QObject::connect(pcon, SIGNAL(runCommand()), this, SLOT(slotExecute()));
 	QObject::connect(pcon, SIGNAL(paletteShown(bool)), this, SLOT(slotInteractiveScript(bool)));
+
+	QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(slotRunPythonScript()) );
 }
 
 ScripterCore::~ScripterCore()
@@ -228,7 +231,7 @@ void ScripterCore::FinishScriptRun()
 void ScripterCore::runScriptDialog()
 {
 	QString fileName;
-	QString curDirPath = QDir::currentPath();
+	// QString curDirPath = QDir::currentPath();
 	RunScriptDialog dia( ScCore->primaryMainWindow(), m_enableExtPython );
 	if (dia.exec())
 	{
@@ -244,7 +247,7 @@ void ScripterCore::runScriptDialog()
 		}
 		rebuildRecentScriptsMenu();
 	}
-	QDir::setCurrent(curDirPath);
+	// QDir::setCurrent(curDirPath);
 	FinishScriptRun();
 }
 
@@ -298,7 +301,7 @@ void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
 		global_state = PyThreadState_Get();
 		state = Py_NewInterpreter();
 		// Chdir to the dir the script is in
-		QDir::setCurrent(fi.absolutePath());
+		// QDir::setCurrent(fi.absolutePath());
 		// Init the scripter module in the sub-interpreter
 		initscribus(ScCore->primaryMainWindow());
 	}
@@ -343,11 +346,9 @@ void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
 		// into a StringIO buffer for later extraction.
 		cm        += QString("except:\n");
 		cm        += QString("    import traceback\n");
-		cm        += QString("    import scribus\n");                  // we stash our working vars here
-		cm        += QString("    scribus._f=cStringIO.StringIO()\n");
-		cm        += QString("    traceback.print_exc(file=scribus._f)\n");
-		cm        += QString("    _errorMsg = scribus._f.getvalue()\n");
-		cm        += QString("    del(scribus._f)\n");
+		cm        += QString("    _errorMsg = traceback.format_exc()\n");
+		if (!ScCore->usingGUI())
+			cm += QString("    traceback.print_exc()\n");
 		// We re-raise the exception so the return value of PyRun_StringFlags reflects
 		// the fact that an exception has ocurred.
 		cm        += QString("    raise\n");
@@ -372,7 +373,7 @@ void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
 				qDebug("Exception was:");
 				PyErr_Print();
 			}
-			else
+			else if (ScCore->usingGUI())
 			{
 				QString errorMsg = PyString_AsString(errorMsgPyStr);
 				// Display a dialog to the user with the exception
@@ -404,6 +405,16 @@ void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
 	enableMainWindowMenu();
 }
 
+// needed for running script from CLI - this is activated by signal ScribusQApp::appStarted()
+void ScripterCore::slotRunPythonScript()
+{
+	if (!ScQApp->pythonScript.isNull())
+	{
+		slotRunScriptFile(ScQApp->pythonScript, true);
+		FinishScriptRun();
+	}
+}
+
 void ScripterCore::slotRunScript(const QString Script)
 {
 	// Prevent two scripts to be run concurrently or face crash!
diff --git a/scribus/plugins/scriptplugin/scriptercore.h b/scribus/plugins/scriptplugin/scriptercore.h
index 47e96ac..aac3a4b 100644
--- a/scribus/plugins/scriptplugin/scriptercore.h
+++ b/scribus/plugins/scriptplugin/scriptercore.h
@@ -39,6 +39,7 @@ public slots:
 	void StdScript(QString filebasename);
 	void RecentScript(QString fn);
 	void slotRunScriptFile(QString fileName, bool inMainInterpreter = false);
+	void slotRunPythonScript(); // needed for running python script from CLI
 	void slotRunScript(const QString Script);
 	void slotInteractiveScript(bool);
 	void slotExecute();
diff --git a/scribus/scribusapp.cpp b/scribus/scribusapp.cpp
index b9c9d75..342b265 100644
--- a/scribus/scribusapp.cpp
+++ b/scribus/scribusapp.cpp
@@ -61,6 +61,7 @@ for which a new license (GPL+exception) is in place.
 #define ARG_SWAPDIABUTTONS "--swap-buttons"
 #define ARG_PREFS "--prefs"
 #define ARG_UPGRADECHECK "--upgradecheck"
+#define ARG_PYTHONSCRIPT "--python-script"
 
 #define ARG_VERSION_SHORT "-v"
 #define ARG_HELP_SHORT "-h"
@@ -75,6 +76,7 @@ for which a new license (GPL+exception) is in place.
 #define ARG_SWAPDIABUTTONS_SHORT "-sb"
 #define ARG_PREFS_SHORT "-pr"
 #define ARG_UPGRADECHECK_SHORT "-u"
+#define ARG_PYTHONSCRIPT_SHORT "-py"
 
 // Qt wants -display not --display or -d
 #define ARG_DISPLAY_QT "-display"
@@ -170,10 +172,9 @@ void ScribusQApp::parseCommandLine()
 		uc.fetch();
 	}
 	//Dont run the GUI init process called from main.cpp, and return
-	if (!header)
-		useGUI=true;
-	else
-		return;
+	if (header)
+		std::exit(EXIT_SUCCESS);
+	useGUI = true;
 	//We are going to run something other than command line help
 	for(int i = 1; i < argc(); i++) {
 		arg = argv()[i];
@@ -210,14 +211,27 @@ void ScribusQApp::parseCommandLine()
 					std::cout << tr("File %1 does not exist, aborting.").arg(prefsUserFile).toLocal8Bit().data() << std::endl;
 				}
 				showUsage();
-				useGUI=false;
-				return;
+				std::exit(EXIT_FAILURE);
 			} else {
 				++i;
 			}
 		} else if (strncmp(arg.toLocal8Bit().data(),"-psn_",4) == 0)
 		{
 			// Andreas Vox: Qt/Mac has -psn_blah flags that must be accepted.
+		} else if (arg == ARG_PYTHONSCRIPT || arg == ARG_PYTHONSCRIPT_SHORT) {
+			pythonScript = QFile::decodeName(argv()[i + 1]);
+			if (!QFileInfo(pythonScript).exists()) {
+				showHeader();
+				if (pythonScript.left(1) == "-" || pythonScript.left(2) == "--") {
+					std::cout << tr("Invalid argument: ").toLocal8Bit().data() << pythonScript.toLocal8Bit().data() << std::endl;
+				} else {
+					std::cout << tr("File %1 does not exist, aborting.").arg(pythonScript).toLocal8Bit().data() << std::endl;
+				}
+				showUsage();
+				std::exit(EXIT_FAILURE);
+			} else {
+				++i;
+			}
 		} else {
 			fileName = QFile::decodeName(argv()[i]);
 			if (!QFileInfo(fileName).exists()) {
@@ -228,8 +242,7 @@ void ScribusQApp::parseCommandLine()
 					std::cout << tr("File %1 does not exist, aborting.").arg(fileName).toLocal8Bit().data() << std::endl;
 				}
 				showUsage();
-				useGUI=false;
-				return;
+				std::exit(EXIT_FAILURE);
 			}
 			else
 			{
@@ -249,8 +262,20 @@ int ScribusQApp::init()
 	processEvents();
 	ScCore->init(useGUI, swapDialogButtonOrder, filesToLoad);
 	int retVal=EXIT_SUCCESS;
-	if (useGUI)
+	/* TODO:
+	 * When Scribus is truly able to run without GUI
+	 * we should uncomment if (useGUI)
+	 * and delete if (true)
+	 */
+	// if (useGUI)
+	if (true)
 		retVal=ScCore->startGUI(showSplash, showFontInfo, showProfileInfo, lang, prefsUserFile);
+
+	// A hook for plugins and scripts to trigger on. Some plugins and scripts
+	// require the app to be fully set up (in particular, the main window to be
+	// built and shown) before running their setup.
+	emit appStarted();
+
 	return retVal;
 }
 
@@ -428,7 +453,8 @@ void ScribusQApp::showUsage()
 	printArgLine(ts, ARG_SWAPDIABUTTONS_SHORT, ARG_SWAPDIABUTTONS, tr("Use right to left dialog button ordering (eg. Cancel/No/Yes instead of Yes/No/Cancel)") );
 	printArgLine(ts, ARG_UPGRADECHECK_SHORT, ARG_UPGRADECHECK, tr("Download a file from the Scribus website and show the latest available version.") );
 	printArgLine(ts, ARG_VERSION_SHORT, ARG_VERSION, tr("Output version information and exit") );
-	
+	printArgLine(ts, ARG_PYTHONSCRIPT_SHORT, QString(QString(ARG_PYTHONSCRIPT) + QString(" ") + tr("filename")).toLocal8Bit().constData(), tr("Run filename in Python scripter") );
+	printArgLine(ts, ARG_NOGUI_SHORT, ARG_NOGUI, tr("Do not start GUI") );
 	
 #if defined(_WIN32) && !defined(_CONSOLE)
 	printArgLine(ts, ARG_CONSOLE_SHORT, ARG_CONSOLE, tr("Display a console window") );
diff --git a/scribus/scribusapp.h b/scribus/scribusapp.h
index 9048328..e532976 100644
--- a/scribus/scribusapp.h
+++ b/scribus/scribusapp.h
@@ -67,6 +67,7 @@ class SCRIBUS_API ScribusQApp : public QApplication
 		bool neverSplashExists();
 		const QString& currGUILanguage() {return GUILang;};
 		ScDLManager* dlManager() { return m_scDLMgr; }
+		QString pythonScript; // script to be run in python from CLI
 
 	public slots:
 
@@ -107,6 +108,9 @@ class SCRIBUS_API ScribusQApp : public QApplication
 
 	protected:
 		virtual bool event(QEvent *event);
+
+	signals:
+		void appStarted();
 };
 
 #endif
diff --git a/scribus/scribuscore.cpp b/scribus/scribuscore.cpp
index 1222516..21ee616 100644
--- a/scribus/scribuscore.cpp
+++ b/scribus/scribuscore.cpp
@@ -142,11 +142,6 @@ int ScribusCore::startGUI(bool showSplash, bool showFontInfo, bool showProfileIn
 	{
 		scribus->slotRaiseOnlineHelp();
 	}
-
-	// A hook for plugins and scripts to trigger on. Some plugins and scripts
-	// require the app to be fully set up (in particular, the main window to be
-	// built and shown) before running their setup.
-	emit appStarted();
 	
 	return EXIT_SUCCESS;
 }
diff --git a/scribus/scribuscore.h b/scribus/scribuscore.h
index a9e0591..6511509 100644
--- a/scribus/scribuscore.h
+++ b/scribus/scribuscore.h
@@ -141,11 +141,6 @@ protected:
 	bool m_HaveGS;
 	bool m_HavePngAlpha;
 	bool m_HaveTiffSep;
-	
-	
-signals:
-	void appStarted();
-
 };
 
 /*
-- 
1.7.2.3

william

2014-09-02 02:06

updater   ~0033449

Juraj has a new patch 0015 that replaces and obsoletes patches 0001, 0011 and 0013. This patch is cleaner and works with the current SVN source.

0015-All-in-one-Run-python-script-from-CLI_v144.patch

Also, see http://bugs.scribus.net/view.php?id=12572#c33448 about the purpose of the patch 0003: Translate strings to variable names with unitGetUntranslatedStrFromIndex instead of unitGetStrFromIndex so python scripts are not dependent on the locale.

william

2014-09-21 17:13

updater  

monster_beheaded_v144-20sep14.tar.gz (9,553 bytes)

william

2014-09-21 17:16

updater   ~0033789

Juraj has provided an updated set of patches that divides his patches into smaller pieces and includes additional bug fixes. It is attached as monster_beheaded_v144-20sep14.tar.gz and the README is below.

---

To ease reviewing this issue, I have split it into several smaller
patches. Thank you Kunda for inspiring link:
http://webchick.net/please-stop-eating-baby-kittens
Hopefully few kittens will be saved by this :)

Since I am not able to join the eventual IRC session, here follows
detailed descriptions of all patches. You should forget about all previous
unapplied patches and consider only the patches in this archive.

0001-Run-python-script-from-CLI.patch

    Script can be run on Scribus startup with CLI option (-py, --python-script).

    How is it implemented?
    It adds code for parsing CLI options and
    in file scriptercore.cpp there is a new function:
    void ScripterCore::slotRunPythonScript()
    which is connected to the appStarted() signal emitted during Scribus
    initialization.

    The script is executed in the main interpreter. Originally it used
    a sub-interpreter, but I changed my mind so that it now closes the
    feature request 9331 (http://bugs.scribus.net/view.php?id=9331).
    Also if a script is executed in a sub-interpreter, the working directory is
    temporarily changed so it is possible only to execute a script successfully
    that is specified by an absolute path (e.g. ../script.py will not
    work). When a script is executed in the main interpreter, this restriction
    does not apply (please do not enforce directory changes for the main
    interpreter also, now that I have pointed this out :).

    After the script is executed, Scribus continues running with a GUI.

    To think about:
    In file scribus/plugins/scriptplugin/scriptercore.h
    there are now a few slots with similar names (mine included):
        void slotRunScriptFile(QString fileName, bool inMainInterpreter = false);
        void slotRunPythonScript(); // needed for running python script from CLI
        void slotRunScript(const QString Script);
        void runStartupScript();
    It is starting to be confusing (or already is :) which slot is used for
    what purpose. Maybe some renaming could help here (or some short
    comments). I realize that the names for new slots are not chosen well.
    Since I am not very versed in English I can only suggest a few
    alternatives and leave decision to somebody else.
    Instead of 'slotRunPythonScript' we could use one of:
    slotRunCLIPythonScript
    slotCLIPythonScript
    cliPythonScript
    slotRunCLIScript
    slotCLIScript
    cliScript
    runCLIScript


0002-Enable-to-run-Scribus-without-GUI.patch

    With this patch, Scribus does not continue with a GUI after initialization
    if the -g or --no-gui CLI option is used.
    This is most useful when Scribus is run with the --python-script option so
    that when the python script ends, Scribus ends too without the need for
    the user to close the main window manually.

    During Scribus initialization in function
    void ScribusQApp::parseCommandLine()
    if an error is detected, Scribus exits right away instead of
    needlessly setting useGUI=false and returning to mainApp().

    This behavior will enable running the GUI from function
    int mainApp(int argc, char **argv)
    only if needed.

    One controversial point in this patch is in function
    int ScribusQApp::init()
    where 'if (true)' is used instead of 'if (useGUI)'.
    There seems to be no easy solution to this.

    So, in fact Scribus does need the GUI to run,
    but it can be run without user interaction.


0003-Move-appStarted-signal-from-scribuscore.cpp-into-scr.patch

    Move appStarted() signal from scribuscore.cpp into scribusapp.cpp

    Currently appStarted() signal is emitted from ScribusCore::startGUI()
    which should be called only if the GUI is used. With this change signal
    will be emitted even if the GUI is not used.

    I was tempted to change the signature of this signal to
    void appStarted(bool useGUI);
    but resisted, leaving this change to developers if they find it useful.

    Since appStarted() signal is not used anywhere, this change should be
    painless.


0004-Do-not-show-messagebox-when-python-script-raise-an-e.patch

    Do not show a messagebox when a python script raises an error.

    When python raises an error and app.useGUI is false, the error message
    is printed on stderr instead of being displayed in a messagebox that
    requires user intervention to close.

    The above statement is valid only for _python_ errors (e.g. syntax errors
    or errors raised by the scripter) not for Scribus functions that pop up
    a messagebox on errors.


0005-Simplify-python-code.patch

    This patch does not change any functionality. It just does the same
    job with less/simpler code.

    While I was editing the previous patch, I saw an opportunity and seized it.

    This is definitely a 'context switching' element, perhaps few kittens
    has been eaten by this :)


0006-Do-not-change-working-directory-when-script-is-execu.patch

    Do not change the working directory when a script is executed.

    To be honest, this patch is not required when running CLI script in the main
    interpreter. It was introduced before, when I was using a sub-interpreter
    instead of the main interpreter. At that time it enabled the possibility of
    running a python script that is not in the current working directory e.g.
    you could run:
    scribus-1.4.4 -py subdirectory/script.py
    Without the patch, above command would fail.

    In the process of changing to use the main interpreter instead of
    a sub-interpreter, I failed to notice that this patch is not needed
    any more, therefore it was left here.

    Why do I think that changing directory is not good anyway?
    With introduction of --python-script CLI option, Scribus can be perceived
    as a special python interpreter that has one extra module available
    (import scribus). I would be very surprised to find an interpreter for any
    language that changes its working directory into the directory where the
    executed script is located.

    I do realize that some scripts in use may be broken by applying this
    patch, but I think those scripts should be adopted/changed instead.

    If you are not convinced by my arguments for applying this patch, please
    consider the fact that the working directory is changed in function
    void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
    while it is changed back to its previous value in function
    void ScripterCore::runScriptDialog()
    I would prefer to move corresponding code from runScriptDialog() into
    the slotRunScriptFile() function.


0007-Do-not-use-and-xB0-as-identifier-in-python.patch

    Do not use % and \xB0 as identifier in python.

    These characters are inaccessible in python as identifiers anyway
    so either don't create them or replace them similarly as 'in' -> 'inch'
    Here I choose to omit them for simplicity.

    Also it is not wise to use translated string as variable names in
    programming (python scripts can break depending on setting of the locale)
    therefore use unitGetUntranslatedStrFromIndex instead of unitGetStrFromIndex


             1) If you open the python scripting console with Script -> Show
             Console and then run
               help(scribus)
             you get the python error

             Traceback (most recent call last):
               File "<console>", line 1, in <module>
               File "/usr/lib64/python2.7/site.py", line 459, in __call__
                 return pydoc.help(*args, **kwds)
               File "/usr/lib64/python2.7/pydoc.py", line 1745, in __call__
                 self.help(request)
               File "/usr/lib64/python2.7/pydoc.py", line 1792, in help
                 else: doc(request, 'Help on %s:')
               File "/usr/lib64/python2.7/pydoc.py", line 1529, in doc
                 pager(render_doc(thing, title, forceload))
               File "/usr/lib64/python2.7/pydoc.py", line 1524, in render_doc
                 return title % desc + '\n\n' + text.document(object, name)
               File "/usr/lib64/python2.7/pydoc.py", line 326, in document
                 if inspect.ismodule(object): return self.docmodule(*args)
               File "/usr/lib64/python2.7/pydoc.py", line 1113, in docmodule
                 result = result + self.section('DATA', join(contents, '\n'))
             UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position
             4810: invalid start byte

             2) If you run the commands
               import scribus
               print scribus.cm
               print scribus.mm
             it works in English but gets errors in some other languages.
             See the attached errtest.py script.

             # Test variable name translations
             #
             # This script is a test case for patch 0003
             # in http://bugs.scribus.net/view.php?id=12572 [^] (1.5)
             # and http://bugs.scribus.net/view.php?id=12594 [^] (1.4)
             #
             # You can run this script from the command line
             # (if you have applied the command line patches)
             # or from the Scripter menu item.
             #
             # This script runs OK with English strings:
             # scribus-1.4.4 -g -py errtest.py -l en
             # 0.0352777777778
             # 0.352777777778
             #
             # The script fails with Russian strings:
             # scribus-1.4.4 -g -py errtest.py -l ru
             # 0.0352777777778
             # Traceback (most recent call last):
             # File "<string>", line 8, in <module>
             # File "errtest.py", line 3, in <module>
             # print scribus.mm
             # AttributeError: 'module' object has no attribute 'mm'
             #
             # The script fails with a different error with Ukrainian strings:
             # scribus-1.4.4 -g -py errtest.py -l uk
             # Traceback (most recent call last):
             # File "<string>", line 8, in <module>
             # File "errtest.py", line 2, in <module>
             # print scribus.cm
             # AttributeError: 'module' object has no attribute 'cm'



And finally for everyone who reads this far, here is one nugget not
presented before. With only two lines of edited code it prevents one
crash and closes two bugs :)

0008-Run-startup-script-only-after-Scribus-is-fully-initi.patch

    Run startup script only after Scribus is fully initialized.

    This patch will close issues 0011336 and 0008552

    Note that this patch could be applied without the rest of the patches
    included in this set. In that case, it should be modified.
    Change
        QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(runStartupScript()) );
    to
        QObject::connect(ScCore, SIGNAL(appStarted()) , this, SLOT(runStartupScript()) );

jghali

2014-10-29 19:45

administrator   ~0034171

Imo these changes are too big for 1.4.x, so I'd prefer not apply these kind of patch to a stable version.

Kunda

2014-10-30 13:17

manager   ~0034174

jghali, can we make another branch with for 1.4.5 for folks who'd like to utilize this but can't due to hardware restrictions ?

Kunda

2015-01-15 13:35

manager   ~0034367

Status? Is this a 'wontfix' ?

Kunda

2015-01-28 11:55

manager   ~0034389

Last edited: 2015-01-28 11:56

View 4 revisions

Since 1.4.5 has been released and as per jghali's comment in 0012594:0034171 ... assigning this is a 'wontfix'. Sorry Juraj and William. Thanks so much for the effort.

Issue History

Date Modified Username Field Change
2014-08-08 01:06 william New Issue
2014-08-08 01:06 william File Added: scribus14-command-line-6aug14.pat
2014-08-08 04:21 Kunda Relationship added related to 0012572
2014-08-09 06:04 christoph_s Assigned To => jghali
2014-08-09 06:04 christoph_s Status new => assigned
2014-08-09 20:36 jghali Project Contributor Builds => Scribus
2014-08-29 03:22 william File Added: patch_bundle_v144-25aug14.tar.gz
2014-08-29 03:28 william Note Added: 0033361
2014-09-02 02:03 william File Added: 0015-All-in-one-Run-python-script-from-CLI_v144.patch
2014-09-02 02:06 william Note Added: 0033449
2014-09-21 17:13 william File Added: monster_beheaded_v144-20sep14.tar.gz
2014-09-21 17:16 william Note Added: 0033789
2014-10-24 22:57 Kunda Patch => Yes
2014-10-29 01:37 Kunda Sticky Issue No => Yes
2014-10-29 19:45 jghali Note Added: 0034171
2014-10-30 13:17 Kunda Note Added: 0034174
2015-01-15 13:35 Kunda Note Added: 0034367
2015-01-28 11:55 Kunda Note Added: 0034389
2015-01-28 11:55 Kunda Status assigned => closed
2015-01-28 11:55 Kunda Resolution open => won't fix
2015-01-28 11:55 Kunda Sticky Issue Yes => No
2015-01-28 11:56 Kunda Note Edited: 0034389 View Revisions
2015-01-28 11:56 Kunda Note Edited: 0034389 View Revisions
2015-01-28 11:56 Kunda Note Edited: 0034389 View Revisions