-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
172 lines (152 loc) · 5.81 KB
/
setup.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env python
# This file is part of the Printrun suite.
#
# Printrun 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.
#
# Printrun 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 Printrun. If not, see <http://www.gnu.org/licenses/>.
import sys
import os
from stat import S_IRUSR, S_IWUSR, S_IRGRP, S_IROTH
from distutils.core import setup
from distutils.command.install import install as _install
from distutils.command.install_data import install_data as _install_data
try:
from Cython.Build import cythonize
extensions = cythonize("printrun/gcoder_line.pyx")
from Cython.Distutils import build_ext
except ImportError, e:
print "WARNING: Failed to cythonize: %s" % e
# Debug helper: uncomment these:
# import traceback
# traceback.print_exc()
extensions = None
build_ext = None
from printrun.printcore import __version__ as printcore_version
INSTALLED_FILES = "installed_files"
class install (_install):
def run(self):
_install.run(self)
outputs = self.get_outputs()
length = 0
if self.root:
length += len(self.root)
if self.prefix:
length += len(self.prefix)
if length:
for counter in xrange(len(outputs)):
outputs[counter] = outputs[counter][length:]
data = "\n".join(outputs)
try:
file = open(INSTALLED_FILES, "w")
except:
self.warn("Could not write installed files list %s" %
INSTALLED_FILES)
return
file.write(data)
file.close()
class install_data(_install_data):
def run(self):
def chmod_data_file(file):
try:
os.chmod(file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
except:
self.warn("Could not chmod data file %s" % file)
_install_data.run(self)
map(chmod_data_file, self.get_outputs())
class uninstall(_install):
def run(self):
try:
file = open(INSTALLED_FILES, "r")
except:
self.warn("Could not read installed files list %s" %
INSTALLED_FILES)
return
files = file.readlines()
file.close()
prepend = ""
if self.root:
prepend += self.root
if self.prefix:
prepend += self.prefix
if len(prepend):
for counter in xrange(len(files)):
files[counter] = prepend + files[counter].rstrip()
for file in files:
print "Uninstalling", file
try:
os.unlink(file)
except:
self.warn("Could not remove file %s" % file)
ops = ("install", "build", "sdist", "uninstall", "clean", "build_ext")
if len(sys.argv) < 2 or sys.argv[1] not in ops:
print "Please specify operation : %s" % " | ".join(ops)
raise SystemExit
prefix = None
if len(sys.argv) > 2:
i = 0
for o in sys.argv:
if o.startswith("--prefix"):
if o == "--prefix":
if len(sys.argv) >= i:
prefix = sys.argv[i + 1]
sys.argv.remove(prefix)
elif o.startswith("--prefix=") and len(o[9:]):
prefix = o[9:]
sys.argv.remove(o)
i += 1
if not prefix and "PREFIX" in os.environ:
prefix = os.environ["PREFIX"]
if not prefix or not len(prefix):
prefix = sys.prefix
if sys.argv[1] in("install", "uninstall") and len(prefix):
sys.argv += ["--prefix", prefix]
target_images_path = "share/pronterface/images/"
data_files = [('share/pixmaps/', ['pronterface.png', 'plater.png', 'pronsole.png']),
('share/applications', ['pronterface.desktop', 'pronsole.desktop', 'plater.desktop']),
('share/appdata', ['pronterface.appdata.xml', 'pronsole.appdata.xml', 'plater.appdata.xml'])]
for basedir, subdirs, files in os.walk("images"):
images = []
for filename in files:
if filename.find(".svg") or filename.find(".png"):
file_path = os.path.join(basedir, filename)
images.append(file_path)
data_files.append((target_images_path + basedir[len("images/"):], images))
for basedir, subdirs, files in os.walk("locale"):
if not basedir.endswith("LC_MESSAGES"):
continue
destpath = os.path.join("share", "pronterface", basedir)
files = filter(lambda x: x.endswith(".mo"), files)
files = map(lambda x: os.path.join(basedir, x), files)
data_files.append((destpath, files))
extra_data_dirs = ["css"]
for extra_data_dir in extra_data_dirs:
for basedir, subdirs, files in os.walk(extra_data_dir):
files = map(lambda x: os.path.join(basedir, x), files)
destpath = os.path.join("share", "pronterface", basedir)
data_files.append((destpath, files))
cmdclass = {"uninstall": uninstall,
"install": install,
"install_data": install_data}
if build_ext:
cmdclass['build_ext'] = build_ext
setup(name = "Printrun",
version = printcore_version,
description = "Host software for 3D printers",
author = "Kliment Yanev",
url = "http://github.com/kliment/Printrun/",
license = "GPLv3",
data_files = data_files,
packages = ["printrun", "printrun.gl", "printrun.gl.libtatlin", "printrun.gui", "printrun.power"],
scripts = ["pronsole.py", "pronterface.py", "plater.py", "printcore.py"],
cmdclass = cmdclass,
ext_modules = extensions,
)