Blob Blame History Raw
From 877409f09a91bf9714e2dee3bbb4d4337aaec966 Mon Sep 17 00:00:00 2001
From: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
Date: Wed, 6 Sep 2017 20:08:18 +0200
Subject: [dxf2gcode PATCH 1/3] Add support for system wide installation

Detailed list of changes:
  - added python setuptools compatible installation script (st-setup.py),
  - added Desktop file (dxf2gcode.desktop),
  - added AppStream AppData metadata file (dxf2gcode.appdata.xml),
  - store configuration files in ~/.config/dxf2gcode directory (all platforms),
  - added support for disabling logginng to file by specifying empty ("") string,
  - disable, by default, logging to file (to avoid problems when running from read-only directories),
  - support for loading translation files from /usr/share/dxf2gcode/i18n directory.

Signed-off-by: Damian Wrobel <dwrobel@ertelnet.rybnik.pl>
---
 source/MANIFEST.in           |  6 ++++
 source/dxf2gcode.appdata.xml | 41 ++++++++++++++++++++++
 source/dxf2gcode.desktop     | 10 ++++++
 source/dxf2gcode.py          | 13 ++++---
 source/globals/config.py     |  6 ++--
 source/st-setup.py           | 83 ++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 151 insertions(+), 8 deletions(-)
 create mode 100644 source/MANIFEST.in
 create mode 100644 source/dxf2gcode.appdata.xml
 create mode 100644 source/dxf2gcode.desktop
 create mode 100644 source/st-setup.py

diff --git a/source/MANIFEST.in b/source/MANIFEST.in
new file mode 100644
index 0000000..7152697
--- /dev/null
+++ b/source/MANIFEST.in
@@ -0,0 +1,6 @@
+include dxf2gcode.desktop
+include dxf2gcode.appdata.xml
+include images/dxf2gcode.svg
+include i18n/*.qm
+include COPYING
+
diff --git a/source/dxf2gcode.appdata.xml b/source/dxf2gcode.appdata.xml
new file mode 100644
index 0000000..b3dbb1e
--- /dev/null
+++ b/source/dxf2gcode.appdata.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Copyright 2017 Damian Wrobel <dwrobel@ertelnet.rybnik.pl> -->
+<component type="desktop">
+  <id>dxf2gcode.desktop</id>
+  <metadata_license>CC0-1.0</metadata_license>
+  <project_license>GPL-3.0+</project_license>
+  <name>dxf2gcode</name>
+  <summary>2D dxf drawings to CNC machine compatible G-Code converter</summary>
+  <description>
+    <p>
+      dxf2gcode is a tool for converting 2D (dxf, pdf, ps) drawings to CNC machine compatible GCode.
+    </p>
+
+    <p>Some features:</p>
+      <ul>
+        <li>Integration in EMC2,</li>
+        <li>Fully adjustable Postprocessor,</li>
+        <li>G0 moves reduction by route optimisation,</li>
+        <li>Import of DXF and PDF,</li>
+        <li>Improved accuracy for splines import by Line and Arc's,</li>
+        <li>Mill parameter specifcation by layers,</li>
+        <li>Drag knife and lathe support,</li>
+        <li>Breaks a.k.a Tabs support,</li>
+        <li>AutoCAD Blocks and Inserts,</li>
+        <li>Multiple tools,</li>
+        <li>Multiple language support: english, german, french, russian,</li>
+        <li>3D viewer.</li>
+      </ul>
+  </description>
+  <screenshots>
+    <screenshot type="default">
+      <image>https://a.fsdn.com/con/app/proj/dxf2gcode/screenshots/piede_20.png/1</image>
+    </screenshot>
+    <screenshot>
+      <image>https://a.fsdn.com/con/app/proj/dxf2gcode/screenshots/Frontplatte.png/1</image>
+    </screenshot>
+  </screenshots>
+  <url type="homepage">https://sourceforge.net/projects/dxf2gcode/</url>
+  <update_contact>dwrobel_at_ertelnet.rybnik.pl</update_contact>
+</component>
+
diff --git a/source/dxf2gcode.desktop b/source/dxf2gcode.desktop
new file mode 100644
index 0000000..9a08683
--- /dev/null
+++ b/source/dxf2gcode.desktop
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Name=dxf2gcode converter
+Comment=2D dxf drawings to CNC machine compatible G-Code converter
+Exec=dxf2gcode %f
+Icon=dxf2gcode
+Keywords=cam;cnc;dxf;g-code
+Terminal=false
+StartupNotify=false
+Type=Application
+
diff --git a/source/dxf2gcode.py b/source/dxf2gcode.py
index 52b2ac5..5698a91 100644
--- a/source/dxf2gcode.py
+++ b/source/dxf2gcode.py
@@ -76,10 +76,7 @@ else:
 
 logger = logging.getLogger()
 
-# Get folder of the main instance and write into globals
-g.folder = os.path.dirname(os.path.abspath(sys.argv[0])).replace("\\", "/")
-if os.path.islink(sys.argv[0]):
-    g.folder = os.path.dirname(os.readlink(sys.argv[0]))
+g.folder = os.path.join(os.path.expanduser("~"), ".config/dxf2gcode").replace("\\", "/")
 
 
 class MainWindow(QMainWindow):
@@ -1086,7 +1083,11 @@ if __name__ == "__main__":
 
     g.config = MyConfig()
     Log.set_console_handler_loglevel()
-    Log.add_file_logger()
+
+    if not g.config.vars.Logging['logfile']:
+        Log.add_window_logger()
+    else:
+        Log.add_file_logger()
 
     app = QApplication(sys.argv)
 
@@ -1096,6 +1097,8 @@ if __name__ == "__main__":
     translator = QtCore.QTranslator()
     if translator.load("dxf2gcode_" + locale, "./i18n"):
         app.installTranslator(translator)
+    elif translator.load("dxf2gcode_" + locale, "/usr/share/dxf2gcode/i18n"):
+        app.installTranslator(translator)
 
     # If string version_mismatch isn't empty, we popup an error and exit
     if g.config.version_mismatch:
diff --git a/source/globals/config.py b/source/globals/config.py
index 1c04932..e395e22 100644
--- a/source/globals/config.py
+++ b/source/globals/config.py
@@ -275,8 +275,8 @@ CONFIG_SPEC = str('''
     gcode = string(default = "(change subsection name and insert your custom GCode here. Use triple quote to place the code on several lines)")
 
     [Logging]
-    # Logging to textfile is enabled automatically for now
-    logfile = string(default = "logfile.txt")
+    # Logging to textfile is disabled by default
+    logfile = string(default = "")
 
     # This really goes to stderr
     console_loglevel = option('DEBUG', 'INFO', 'WARNING', 'ERROR','CRITICAL', default = 'CRITICAL')
@@ -351,7 +351,7 @@ class MyConfig(object):
     def make_settings_folder(self):
         """Create settings folder if necessary"""
         try:
-            os.mkdir(self.folder)
+            os.makedirs(self.folder)
         except OSError:
             pass
 
diff --git a/source/st-setup.py b/source/st-setup.py
new file mode 100644
index 0000000..1269931
--- /dev/null
+++ b/source/st-setup.py
@@ -0,0 +1,83 @@
+############################################################################
+#
+#   Copyright (C) 2017
+#    Damian Wrobel <dwrobel@ertelnet.rybnil.pl>
+#
+#   This file is part of DXF2GCODE.
+#
+#   DXF2GCODE is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   DXF2GCODE is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with DXF2GCODE.  If not, see <http://www.gnu.org/licenses/>.
+#
+############################################################################
+
+from setuptools import setup
+import glob
+
+import distutils.command.install_scripts
+import shutil
+
+class install_scripts(distutils.command.install_scripts.install_scripts):
+    def run(self):
+        distutils.command.install_scripts.install_scripts.run(self)
+        for script in self.get_outputs():
+            if script.endswith(".py"):
+                shutil.move(script, script[:-3])
+
+setup(
+    name='dxf2gcode',
+
+    version='20170503',
+
+    description='2D drawings to CNC machine compatible G-Code converter.',
+
+    long_description=('DXF2GCODE is a tool for converting 2D (dxf, pdf, ps)'
+                      ' drawings to CNC machine compatible GCode.'),
+
+    url='https://sourceforge.net/p/dxf2gcode/wiki/Home/',
+
+    author='Christian Kohloffel',
+
+    license='GPLv3',
+
+    packages=[
+        'core',
+        'dxfimport',
+        'globals',
+        'globals.configobj',
+        'gui',
+        'postpro'
+    ],
+
+    py_modules=[
+        "dxf2gcode_images5_rc",
+        "dxf2gcode_ui5"
+    ],
+
+    install_requires=[
+        'PyQt5',
+        'PyOpenGL'
+    ],
+
+    include_package_data=True,
+
+    data_files=[
+        ('share/appdata', ['dxf2gcode.appdata.xml']),
+        ('share/applications', ['dxf2gcode.desktop']),
+        ('share/dxf2gcode/i18n', glob.glob('i18n/*.qm')),
+        ('share/icons/hicolor/scalable/apps/', ['images/dxf2gcode.svg'])
+    ],
+
+    cmdclass = {"install_scripts": install_scripts},
+
+    scripts=['dxf2gcode.py']
+)
-- 
2.9.5