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/dxf2gcode.py
===================================================================
--- dxf2gcode.orig/dxf2gcode.py	2022-11-26 08:03:55.161342304 +0100
+++ dxf2gcode/dxf2gcode.py	2022-11-26 08:05:05.385326257 +0100
@@ -320,7 +320,7 @@
             # If Cancel was pressed
             if not save_filename:
                 self.unsetCursor()
-                return
+                return 0
 
             (beg, ende) = os.path.split(save_filename)
             (fileBaseName, fileExtension) = os.path.splitext(ende)
@@ -347,17 +347,20 @@
         """
 
         # Prepare if any exception happens during export
+        retval = 0
         try:
             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):
         """
@@ -1142,6 +1145,7 @@
     """
     The main function which is executed after program start.
     """
+    retval = 0
     Log = LoggerClass(logger)
 
     g.config = MyConfig()
@@ -1211,8 +1215,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)
