printrun-src/setup.py

Thu, 30 May 2019 19:02:52 +0200

author
mdd
date
Thu, 30 May 2019 19:02:52 +0200
changeset 42
ea4c43494a19
parent 15
0bbb006204fc
child 45
c82943fb205f
permissions
-rw-r--r--

bugfixes on rastered image column endings, force laser off with G0 + little offset

15
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
1 #!/usr/bin/env python
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
2
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
3 # This file is part of the Printrun suite.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
4 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
5 # Printrun is free software: you can redistribute it and/or modify
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
6 # it under the terms of the GNU General Public License as published by
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
7 # the Free Software Foundation, either version 3 of the License, or
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
8 # (at your option) any later version.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
9 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
10 # Printrun is distributed in the hope that it will be useful,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
13 # GNU General Public License for more details.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
14 #
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
15 # You should have received a copy of the GNU General Public License
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
16 # along with Printrun. If not, see <http://www.gnu.org/licenses/>.
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
17
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
18 import sys
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
19 import os
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
20 from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
21 from distutils.core import setup
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
22 from distutils.command.install import install as _install
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
23 from distutils.command.install_data import install_data as _install_data
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
24 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
25 from Cython.Build import cythonize
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
26 extensions = cythonize("printrun/gcoder_line.pyx")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
27 from Cython.Distutils import build_ext
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
28 except ImportError, e:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
29 print "WARNING: Failed to cythonize: %s" % e
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
30 # Debug helper: uncomment these:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
31 # import traceback
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
32 # traceback.print_exc()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
33 extensions = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
34 build_ext = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
35
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
36 from printrun.printcore import __version__ as printcore_version
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
37
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
38 INSTALLED_FILES = "installed_files"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
39
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
40 class install (_install):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
41
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
42 def run(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
43 _install.run(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
44 outputs = self.get_outputs()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
45 length = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
46 if self.root:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
47 length += len(self.root)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
48 if self.prefix:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
49 length += len(self.prefix)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
50 if length:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
51 for counter in xrange(len(outputs)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
52 outputs[counter] = outputs[counter][length:]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
53 data = "\n".join(outputs)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
54 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
55 file = open(INSTALLED_FILES, "w")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
56 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
57 self.warn("Could not write installed files list %s" %
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
58 INSTALLED_FILES)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
59 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
60 file.write(data)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
61 file.close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
62
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
63 class install_data(_install_data):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
64
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
65 def run(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
66 def chmod_data_file(file):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
67 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
68 os.chmod(file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
69 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
70 self.warn("Could not chmod data file %s" % file)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
71 _install_data.run(self)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
72 map(chmod_data_file, self.get_outputs())
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
73
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
74 class uninstall(_install):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
75
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
76 def run(self):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
77 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
78 file = open(INSTALLED_FILES, "r")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
79 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
80 self.warn("Could not read installed files list %s" %
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
81 INSTALLED_FILES)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
82 return
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
83 files = file.readlines()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
84 file.close()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
85 prepend = ""
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
86 if self.root:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
87 prepend += self.root
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
88 if self.prefix:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
89 prepend += self.prefix
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
90 if len(prepend):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
91 for counter in xrange(len(files)):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
92 files[counter] = prepend + files[counter].rstrip()
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
93 for file in files:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
94 print "Uninstalling", file
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
95 try:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
96 os.unlink(file)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
97 except:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
98 self.warn("Could not remove file %s" % file)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
99
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
100 ops = ("install", "build", "sdist", "uninstall", "clean", "build_ext")
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
101
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
102 if len(sys.argv) < 2 or sys.argv[1] not in ops:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
103 print "Please specify operation : %s" % " | ".join(ops)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
104 raise SystemExit
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
105
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
106 prefix = None
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
107 if len(sys.argv) > 2:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
108 i = 0
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
109 for o in sys.argv:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
110 if o.startswith("--prefix"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
111 if o == "--prefix":
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
112 if len(sys.argv) >= i:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
113 prefix = sys.argv[i + 1]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
114 sys.argv.remove(prefix)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
115 elif o.startswith("--prefix=") and len(o[9:]):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
116 prefix = o[9:]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
117 sys.argv.remove(o)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
118 i += 1
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
119 if not prefix and "PREFIX" in os.environ:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
120 prefix = os.environ["PREFIX"]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
121 if not prefix or not len(prefix):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
122 prefix = sys.prefix
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
123
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
124 if sys.argv[1] in("install", "uninstall") and len(prefix):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
125 sys.argv += ["--prefix", prefix]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
126
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
127 target_images_path = "share/pronterface/images/"
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
128 data_files = [('share/pixmaps', ['pronterface.png', 'plater.png', 'pronsole.png']),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
129 ('share/applications', ['pronterface.desktop', 'pronsole.desktop', 'plater.desktop']),
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
130 ('share/appdata', ['pronterface.appdata.xml', 'pronsole.appdata.xml', 'plater.appdata.xml'])]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
131
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
132 for basedir, subdirs, files in os.walk("images"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
133 images = []
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
134 for filename in files:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
135 if filename.find(".svg") or filename.find(".png"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
136 file_path = os.path.join(basedir, filename)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
137 images.append(file_path)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
138 data_files.append((target_images_path + basedir[len("images/"):], images))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
139
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
140 for basedir, subdirs, files in os.walk("locale"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
141 if not basedir.endswith("LC_MESSAGES"):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
142 continue
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
143 destpath = os.path.join("share", "pronterface", basedir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
144 files = filter(lambda x: x.endswith(".mo"), files)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
145 files = map(lambda x: os.path.join(basedir, x), files)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
146 data_files.append((destpath, files))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
147
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
148 extra_data_dirs = ["css"]
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
149 for extra_data_dir in extra_data_dirs:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
150 for basedir, subdirs, files in os.walk(extra_data_dir):
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
151 files = map(lambda x: os.path.join(basedir, x), files)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
152 destpath = os.path.join("share", "pronterface", basedir)
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
153 data_files.append((destpath, files))
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
154
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
155 cmdclass = {"uninstall": uninstall,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
156 "install": install,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
157 "install_data": install_data}
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
158 if build_ext:
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
159 cmdclass['build_ext'] = build_ext
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
160
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
161 setup(name = "Printrun",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
162 version = printcore_version,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
163 description = "Host software for 3D printers",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
164 author = "Kliment Yanev",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
165 url = "http://github.com/kliment/Printrun/",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
166 license = "GPLv3",
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
167 data_files = data_files,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
168 packages = ["printrun", "printrun.gl", "printrun.gl.libtatlin", "printrun.gui", "printrun.power"],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
169 scripts = ["pronsole.py", "pronterface.py", "plater.py", "printcore.py"],
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
170 cmdclass = cmdclass,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
171 ext_modules = extensions,
0bbb006204fc Added printrun sourcecode from
mbayer
parents:
diff changeset
172 )

mercurial