Merge lp:~dmitry-zhulanov/inkscape/xverbs-bugfixes into lp:~inkscape.dev/inkscape/trunk

Proposed by Dmitry Zhulanov
Status: Merged
Merged at revision: 15726
Proposed branch: lp:~dmitry-zhulanov/inkscape/xverbs-bugfixes
Merge into: lp:~inkscape.dev/inkscape/trunk
Diff against target: 184 lines (+50/-19)
1 file modified
src/main-cmdlinexact.cpp (+50/-19)
To merge this branch: bzr merge lp:~dmitry-zhulanov/inkscape/xverbs-bugfixes
Reviewer Review Type Date Requested Status
Patrick Storz Approve
Review via email: mp+325034@code.launchpad.net

Description of the change

xverbs related bugs fixed:
checking if .svg file exists before open.
handle .svg files relative to .yaml
add filename to "yaml not found" message

To post a comment you must log in.
Revision history for this message
Patrick Storz (ede123) wrote :

Thanks for the fixes!

One new issue I just discovered during testing:
- bug #1695606

Some minor stuff:
- "Failed to open file test.yaml" - Could we be more specific? Was the file not found or could it not be parsed (or maybe it even did exist but could not be accessed?)
- "document is not exists" is not proper english.

Revision history for this message
Patrick Storz (ede123) wrote :

Also I'm afraid getDocumentPathRelatedYaml() does not work properly (at least on Windows):

For a files "test.yml" and "test.svg" in inkscape folder:

>inkscape.com --xverbs=test.yaml
document is not exists: .\inkscape/test.svg

>inkscape\inkscape.com --xverbs=inkscape\test.yaml
document is not exists: inkscape\inkscape/test.svg

15705. By Dmitry Zhulanov

abort Inkscape if XFileOpen command fails

15706. By Dmitry Zhulanov

minor fixes

Revision history for this message
Patrick Storz (ede123) wrote :

Forget my last comment, the function is working. I messed up and did in fact reference a non-existing file, sorry.

Revision history for this message
Patrick Storz (ede123) wrote :

Sorry for the constant stream of reports, but I just found another issue, see bug #1695629.

15707. By Dmitry Zhulanov

replace fopen with g_fopen

Revision history for this message
Patrick Storz (ede123) wrote :

Thanks for the fixes, working fine now on Windows 10!

Let me know if I should hold of on merging for some reason, otherwise I think we're all set.

review: Approve
Revision history for this message
Dmitry Zhulanov (dmitry-zhulanov) wrote :

Thank, you for feedback! Please, merge the branch. I don't have any reason to hold merging

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/main-cmdlinexact.cpp'
2--- src/main-cmdlinexact.cpp 2017-05-17 21:00:31 +0000
3+++ src/main-cmdlinexact.cpp 2017-06-04 14:22:41 +0000
4@@ -29,6 +29,7 @@
5 #include "extension/system.h"
6 #include "file.h"
7 #include <glib.h>
8+#include <glib/gstdio.h>
9 #include "sp-root.h"
10 #include "document-undo.h"
11 #include "util/units.h"
12@@ -41,13 +42,14 @@
13 #include <document-undo.h>
14 #include <ui/view/view-widget.h>
15 #include <ui/interface.h>
16-#include <verbs.h>
17+#include <io/sys.h>
18
19 #define DPI_BASE Inkscape::Util::Quantity::convert(1, "in", "px")
20
21 namespace
22 {
23 bool s_verbose = false;
24+Glib::ustring s_yaml_filename("");
25
26 bool createDirForFilename( const std::string &filename )
27 {
28@@ -96,10 +98,33 @@
29 return result;
30 }
31
32+Glib::ustring getDocumentPathRelatedYaml( const Glib::ustring &uri )
33+{
34+ if (g_path_is_absolute (uri.c_str()))
35+ return uri;
36+
37+ gchar *yaml_dirname = g_path_get_dirname(s_yaml_filename.c_str());
38+ gchar *document_path = g_build_filename(yaml_dirname, uri.c_str(), NULL);
39+
40+ Glib::ustring result(document_path);
41+
42+ g_free(document_path);
43+ g_free(yaml_dirname);
44+
45+ return result;
46+}
47+
48 void xFileOpen( const Glib::ustring &uri )
49 {
50+ Glib::ustring document_filename = getDocumentPathRelatedYaml(uri);
51+
52+ if (!Inkscape::IO::file_test(document_filename.c_str(), (GFileTest)(G_FILE_TEST_EXISTS))) {
53+ printf("SVG document does not exist: %s\n", document_filename.c_str());
54+ exit(1);
55+ }
56+
57 if (s_verbose) {
58- printf("open %s\n", uri.c_str());
59+ printf("open %s\n", document_filename.c_str());
60 fflush(stdout);
61 }
62
63@@ -114,11 +139,11 @@
64 SPDocument *doc = NULL;
65 Inkscape::Extension::Extension *key = NULL;
66 try {
67- doc = Inkscape::Extension::open(key, uri.c_str());
68+ doc = Inkscape::Extension::open(key, document_filename.c_str());
69 } catch (std::exception &e) {
70 doc = NULL;
71 std::string exeption_mgs = e.what();
72- printf("Error: open %s:%s\n",uri.c_str(), exeption_mgs.c_str() );
73+ printf("Error: open %s:%s\n",document_filename.c_str(), exeption_mgs.c_str() );
74 fflush(stdout);
75 }
76
77@@ -157,31 +182,33 @@
78
79 void xFileSaveAs( Inkscape::ActionContext const & context, const Glib::ustring &uri )
80 {
81+ Glib::ustring document_filename = getDocumentPathRelatedYaml(uri);
82 SPDocument *doc = context.getDocument();
83 if (s_verbose) {
84- printf("save as %s\n", uri.c_str());
85+ printf("save as %s\n", document_filename.c_str());
86 fflush(stdout);
87 }
88
89- if( createDirForFilename( uri )) {
90+ if( createDirForFilename( document_filename )) {
91 Inkscape::Extension::save(
92 Inkscape::Extension::db.get("org.inkscape.output.svg.inkscape"),
93- doc, uri.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
94+ doc, document_filename.c_str(), false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS);
95 if (s_verbose) {
96- printf("save done: %s\n", uri.c_str() );
97+ printf("save done: %s\n", document_filename.c_str() );
98 fflush(stdout);
99 }
100 }
101 else {
102- printf("can't create dirs for filename %s\n", uri.c_str() );
103+ printf("can't create dirs for filename %s\n", document_filename.c_str() );
104 fflush(stdout);
105 }
106 }
107
108 void xFileExportPNG( Inkscape::ActionContext const & context, const Glib::ustring &uri )
109 {
110+ Glib::ustring document_filename = getDocumentPathRelatedYaml(uri);
111 if (s_verbose) {
112- printf("export png %s\n", uri.c_str());
113+ printf("export png %s\n", document_filename.c_str());
114 fflush(stdout);
115 }
116
117@@ -204,27 +231,27 @@
118
119 SPNamedView *nv = desktop->getNamedView();
120
121- ExportResult status = sp_export_png_file(doc, uri.c_str(),
122+ ExportResult status = sp_export_png_file(doc, document_filename.c_str(),
123 Geom::Rect(Geom::Point(0,0), Geom::Point(width, height)), png_width, png_height, dpi, dpi,
124 nv->pagecolor, 0, 0, TRUE);
125 }
126
127-void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &uri )
128+void xSelectElement( Inkscape::ActionContext const & context, const Glib::ustring &element_name )
129 {
130 if (context.getDocument() == NULL || context.getSelection() == NULL) {
131 return;
132 }
133
134 if (s_verbose) {
135- printf("select element: %s\n", uri.c_str());
136+ printf("select element: %s\n", element_name.c_str());
137 fflush(stdout);
138 }
139
140 SPDocument * doc = context.getDocument();
141- SPObject * obj = doc->getObjectById(uri);
142+ SPObject * obj = doc->getObjectById(element_name);
143
144 if (obj == NULL) {
145- printf(_("Unable to find node ID: '%s'\n"), uri.c_str());
146+ printf(_("Unable to find node ID: '%s'\n"), element_name.c_str());
147 fflush(stdout);
148 return;
149 }
150@@ -233,7 +260,7 @@
151 selection->add(obj);
152
153 if (s_verbose) {
154- printf("select done %s\n", uri.c_str());
155+ printf("select done %s\n", element_name.c_str());
156 fflush(stdout);
157 }
158 }
159@@ -291,11 +318,13 @@
160 {
161 verbs_list_t verbs_list;
162
163- FILE *fh = fopen(yaml_filename, "r");
164+ FILE *fh = g_fopen(yaml_filename, "r");
165 if(fh == NULL) {
166- printf("Failed to open file!\n");
167+ printf("Failed to read from file %s\n", yaml_filename);
168 fflush(stdout);
169- return verbs_list;
170+
171+ // exit with error
172+ exit(1);
173 }
174
175 yaml_parser_t parser;
176@@ -437,6 +466,8 @@
177 void
178 CmdLineXAction::createActionsFromYAML( gchar const *yaml_filename )
179 {
180+ s_yaml_filename = Glib::ustring(yaml_filename);
181+
182 verbs_list_t verbs_list = parseVerbsYAMLFile(yaml_filename);
183
184 typedef std::map<std::string,int> undo_labels_map_t;