Package: dxf2gcode / 20240509-2

2020-quiet-exit-code.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Description: Return meaningful exit code when converting files in quiet mode
 Otherwise failing conversions might be silently ignored.  This is
 useful for non-interactive conversions, and is used by the
 autopkgtest check in Debian.  A better approach might be to not
 silently catch all Exception in exportShapes() and instead pass them
 to the __main__ code block and report the error there.  I picked this
 approach as it did not require a complete restructure of the code.
Author: Petter Reinholdtsen <pere@debian.org>
Forwarded: no
Reviewed-By: Petter Reinholdtsen <pere@debian.org>
Last-Update: 2022-11-26
---
Index: dxf2gcode-salsa/dxf2gcode.py
===================================================================
--- dxf2gcode-salsa.orig/dxf2gcode.py	2024-05-09 22:50:32.627851399 +0200
+++ dxf2gcode-salsa/dxf2gcode.py	2024-05-09 22:53:05.117258926 +0200
@@ -325,7 +325,7 @@
             # If Cancel was pressed
             if not save_filename:
                 self.unsetCursor()
-                return
+                return 0
 
             # If automatic save paths is checked keep it up to date.
             if g.config.vars.Paths['autosave_path']:
@@ -362,16 +362,18 @@
 
         # Prepare if any exception happens during export
         #try:
-        self.MyPostProcessor.exportShapes(self.filename,
+        retval = self.MyPostProcessor.exportShapes(self.filename,
                                         save_filename,
                                         self.layerContents)
         #except Exception as e:
         #    logger.error(self.tr('Error exporting shapes: %s') % str (e))
+        #    retval = 1
 
         self.unsetCursor()
 
         if g.config.vars.General['write_to_stdout']:
             self.close()
+        return retval
 
     def optimizeAndExportShapes(self, saveas=None, post_pro=None):
         """
@@ -1216,6 +1218,7 @@
     """
     The main function which is executed after program start.
     """
+    retval = 0
     Log = LoggerClass(logger)
 
     g.config = MyConfig()
@@ -1297,8 +1300,9 @@
         window.load()
 
     if options.export_filename is not None:
-        window.exportShapes(None, options.export_filename)
+        retval = window.exportShapes(None, options.export_filename)
 
     if not options.quiet:
         # It's exec_ because exec is a reserved word in Python
-        sys.exit(app.exec_())
+        retval = app.exec_()
+    sys.exit(retval)
diff --git a/dxf2gcode/postpro/postprocessor.py b/dxf2gcode/postpro/postprocessor.py
index 6ace659..812f528 100644
--- a/dxf2gcode/postpro/postprocessor.py
+++ b/dxf2gcode/postpro/postprocessor.py
@@ -325,6 +325,7 @@ class MyPostProcessor(object):
             print(exstr)
             logger.info(self.tr("Export to STDOUT was successful"))
             # self.close
+            return 0
         else:
             # Export Data to file
             try:
@@ -333,10 +334,12 @@ class MyPostProcessor(object):
                 f.write(str_encode(exstr))
                 f.close()
                 logger.info(self.tr("Export to FILE was successful"))
+                return 0
             except IOError:
                 QMessageBox.warning(g.window,
                                     self.tr("Warning during Export"),
                                     self.tr("Cannot Save the File"))
+                return 1
 
     def initialize_export_vars(self):
         """