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