forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstallpanda.py
More file actions
300 lines (261 loc) · 13.9 KB
/
installpanda.py
File metadata and controls
300 lines (261 loc) · 13.9 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env python
########################################################################
#
# Caution: there are two separate, independent build systems:
# 'makepanda', and 'ppremake'. Use one or the other, do not attempt
# to use both. This file is part of the 'makepanda' system.
#
# To install panda using this script, type 'installpanda.py'.
# To specify an alternate location than the filesystem root /,
# either pass it as only argument or set the DESTDIR environment
# variable. This script only functions on Linux, for now.
#
########################################################################
import os, sys, platform
from distutils.sysconfig import get_python_lib
from optparse import OptionParser
from makepandacore import *
def python_sitepackages_path():
from distutils.sysconfig import get_python_lib
return get_python_lib(1)
PYTHON_SITEPACKAGES=python_sitepackages_path()
MIME_INFO = (
("egg", "model/x-egg", "EGG model file", "pview"),
("bam", "model/x-bam", "Panda3D binary model file", "pview"),
("egg.pz", "model/x-compressed-egg", "Compressed EGG model file", "pview"),
("bam.pz", "model/x-compressed-bam", "Compressed Panda3D binary model file", "pview"),
)
MIME_INFO_PLUGIN = (
("p3d", "application/x-panda3d", "Panda3D game/applet", "panda3d"),
)
APP_INFO = (
("pview", "Panda3D Model Viewer", ("egg", "bam", "egg.pz", "bam.pz")),
)
APP_INFO_PLUGIN = (
("panda3d", "Panda3D", ("p3d")),
)
def WriteApplicationsFile(fname, appinfo, mimeinfo):
fhandle = open(fname, "w")
for app, desc, exts in appinfo:
fhandle.write("%s\n" % (app))
fhandle.write("\tcommand=%s\n" % (app))
fhandle.write("\tname=%s\n" % (desc))
fhandle.write("\tcan_open_multiple_files=true\n")
fhandle.write("\texpects_uris=false\n")
fhandle.write("\trequires_terminal=false\n")
fhandle.write("\tmime_types=")
first = True
for ext, mime, desc2, app2 in mimeinfo:
if ext in exts:
if first:
fhandle.write(mime)
first = False
else:
fhandle.write("," + mime)
fhandle.write("\n\n")
fhandle.close()
def WriteMimeXMLFile(fname, info):
fhandle = open(fname, "w")
fhandle.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
fhandle.write("<mime-info xmlns=\"http://www.freedesktop.org/standards/shared-mime-info\">\n")
for ext, mime, desc, app in info:
fhandle.write("\t<mime-type type=\"%s\">\n" % (mime))
fhandle.write("\t\t<comment xml:lang=\"en\">%s</comment>\n" % (desc))
fhandle.write("\t\t<glob pattern=\"*.%s\"/>\n" % (ext))
fhandle.write("\t</mime-type>\s")
fhandle.write("</mime-info>\n")
fhandle.close()
def WriteMimeFile(fname, info):
fhandle = open(fname, "w")
for ext, mime, desc, app in info:
fhandle.write("%s:\n" % (mime))
if "." in ext:
fhandle.write("\tregex,2: %s$\n" % (ext.replace(".", "\\.")))
fhandle.write("\text: %s\n" % (ext))
fhandle.write("\n")
fhandle.close()
def WriteKeysFile(fname, info):
fhandle = open(fname, "w")
for ext, mime, desc, app in info:
fhandle.write("%s:\n" % (mime))
fhandle.write("\tdescription=%s\n" % (desc))
fhandle.write("\tdefault_action_type=application\n")
fhandle.write("\tshort_list_application_ids_for_novice_user_level=%s\n" % (app))
fhandle.write("\topen=%s %%f\n" % (app))
fhandle.write("\tview=%s %%f\n" % (app))
fhandle.write("\n")
fhandle.close()
def GetDebLibDir():
""" Returns the lib dir according to the debian system. """
# We're on Debian or Ubuntu, which use multiarch directories.
# Call dpkg-architecture to get the multiarch libdir.
handle = os.popen("dpkg-architecture -qDEB_HOST_MULTIARCH")
multiarch = handle.read().strip()
if handle.close():
# It failed. Old Debian/Ubuntu version?
pass
elif len(multiarch) > 0:
return "lib/" + multiarch
return "lib"
def GetRPMLibDir():
""" Returns the lib dir according to the rpm system. """
handle = os.popen("rpm -E '%_lib'")
result = handle.read().strip()
handle.close()
if len(result) > 0:
assert result == "lib64" or result == "lib"
return result
else:
return "lib"
def GetLibDir():
""" Returns the directory to install architecture-dependent
libraries in, relative to the prefix directory. This may be
something like "lib" or "lib64" or in some cases, something
similar to "lib/x86_64-linux-gnu". """
if sys.platform in ("darwin", "win32"):
return "lib"
# This one's a bit tricky. Some systems require us to install
# 64-bits libraries into /usr/lib64, some into /usr/lib.
# Debian forbids installing to lib64 nowadays, and the only distros
# I know of that use lib64 are all RPM-based. So, the 'solution'
# seems to be to use the rpm command to give us the libdir for now,
# unless we know we're on debian, since rpm may be installed on
# Debian and will give the wrong result. Ugh.
if os.environ.get("DEB_HOST_MULTIARCH"):
# We're building inside the Debian build environment.
return "lib/" + os.environ["DEB_HOST_MULTIARCH"]
if os.path.isfile('/etc/debian_version'):
return GetDebLibDir()
else:
# Okay, maybe we're on an RPM-based system?
return GetRPMLibDir()
# If Python is installed into /usr/lib64, it's probably safe
# to assume that we should install there as well.
python_lib = get_python_lib(1)
if python_lib.startswith('/usr/lib64/') or \
python_lib.startswith('/usr/local/lib64/'):
return "lib64"
return "lib"
def InstallPanda(destdir="", prefix="/usr", outputdir="built", libdir=GetLibDir()):
if (not prefix.startswith("/")):
prefix = "/" + prefix
libdir = prefix + "/" + libdir
# Determine the location of the Python executable and site-packages dir.
PPATH = get_python_lib(1)
if os.path.islink(sys.executable):
PEXEC = os.path.join(os.path.dirname(sys.executable), os.readlink(sys.executable))
else:
PEXEC = sys.executable
# Create the directory structure that we will be putting our files in.
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/bin")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/include")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/panda3d")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/mime-info")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/mime/packages")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/application-registry")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/applications")
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/panda3d")
oscmd("mkdir -m 0755 -p "+destdir+PPATH)
if (sys.platform.startswith("freebsd")):
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/etc")
oscmd("mkdir -m 0755 -p "+destdir+"/usr/local/libdata/ldconfig")
else:
oscmd("mkdir -m 0755 -p "+destdir+"/etc/ld.so.conf.d")
# Write the Config.prc file.
Configrc = ReadFile(outputdir+"/etc/Config.prc")
Configrc = Configrc.replace("model-path $THIS_PRC_DIR/..", "model-path "+prefix+"/share/panda3d")
if (sys.platform.startswith("freebsd")):
WriteFile(destdir+prefix+"/etc/Config.prc", Configrc)
oscmd("cp "+outputdir+"/etc/Confauto.prc "+destdir+prefix+"/etc/Confauto.prc")
else:
WriteFile(destdir+"/etc/Config.prc", Configrc)
oscmd("cp "+outputdir+"/etc/Confauto.prc "+destdir+"/etc/Confauto.prc")
oscmd("cp -R "+outputdir+"/include "+destdir+prefix+"/include/panda3d")
oscmd("cp -R "+outputdir+"/pandac "+destdir+prefix+"/share/panda3d/")
oscmd("cp -R "+outputdir+"/panda3d "+destdir+PPATH+"/")
oscmd("cp -R "+outputdir+"/models "+destdir+prefix+"/share/panda3d/")
if os.path.isdir("samples"): oscmd("cp -R samples "+destdir+prefix+"/share/panda3d/")
if os.path.isdir(outputdir+"/direct"): oscmd("cp -R "+outputdir+"/direct "+destdir+prefix+"/share/panda3d/")
if os.path.isdir(outputdir+"/Pmw"): oscmd("cp -R "+outputdir+"/Pmw "+destdir+prefix+"/share/panda3d/")
if os.path.isdir(outputdir+"/plugins"): oscmd("cp -R "+outputdir+"/plugins "+destdir+prefix+"/share/panda3d/")
WriteMimeFile(destdir+prefix+"/share/mime-info/panda3d.mime", MIME_INFO)
WriteKeysFile(destdir+prefix+"/share/mime-info/panda3d.keys", MIME_INFO)
WriteMimeXMLFile(destdir+prefix+"/share/mime/packages/panda3d.xml", MIME_INFO)
WriteApplicationsFile(destdir+prefix+"/share/application-registry/panda3d.applications", APP_INFO, MIME_INFO)
if os.path.isfile(outputdir+"/bin/pview"):
oscmd("cp makepanda/pview.desktop "+destdir+prefix+"/share/applications/pview.desktop")
oscmd("cp doc/ReleaseNotes "+destdir+prefix+"/share/panda3d/ReleaseNotes")
oscmd("echo '"+prefix+"/share/panda3d' > "+destdir+PPATH+"/panda3d.pth")
oscmd("echo '"+libdir+"/panda3d'>> "+destdir+PPATH+"/panda3d.pth")
if (sys.platform.startswith("freebsd")):
oscmd("echo '"+libdir+"/panda3d'> "+destdir+"/usr/local/libdata/ldconfig/panda3d")
else:
oscmd("echo '"+libdir+"/panda3d'> "+destdir+"/etc/ld.so.conf.d/panda3d.conf")
oscmd("cp "+outputdir+"/bin/* "+destdir+prefix+"/bin/")
for base in os.listdir(outputdir+"/lib"):
if (not base.endswith(".a")) or base == "libp3pystub.a":
# We really need to specify -R in order not to follow symlinks on non-GNU
oscmd("cp -R -P "+outputdir+"/lib/"+base+" "+destdir+libdir+"/panda3d/"+base)
DeleteVCS(destdir+prefix+"/share/panda3d")
DeleteBuildFiles(destdir+prefix+"/share/panda3d")
DeleteEmptyDirs(destdir+prefix+"/share/panda3d")
DeleteVCS(destdir+prefix+"/include/panda3d")
DeleteBuildFiles(destdir+prefix+"/include/panda3d")
DeleteEmptyDirs(destdir+prefix+"/include/panda3d")
# rpmlint doesn't like this file, for some reason.
if (os.path.isfile(destdir+prefix+"/share/panda3d/direct/leveleditor/copyfiles.pl")):
os.remove(destdir+prefix+"/share/panda3d/direct/leveleditor/copyfiles.pl")
def InstallRuntime(destdir="", prefix="/usr", outputdir="built", libdir=GetLibDir()):
if (not prefix.startswith("/")):
prefix = "/" + prefix
libdir = prefix + "/" + libdir
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/bin")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/mime-info")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/mime/packages")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/application-registry")
oscmd("mkdir -m 0755 -p "+destdir+prefix+"/share/applications")
if (os.path.exists(outputdir+"/plugins/nppanda3d.so")):
oscmd("mkdir -m 0755 -p "+destdir+libdir)
oscmd("cp "+outputdir+"/plugins/nppanda3d.so "+destdir+libdir+"/nppanda3d.so")
if sys.platform.startswith("freebsd"):
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/browser_plugins/symlinks/gecko19")
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/libxul/plugins")
oscmd("ln -f -s "+libdir+"/nppanda3d.so "+destdir+libdir+"/browser_plugins/symlinks/gecko19/nppanda3d.so")
oscmd("ln -f -s "+libdir+"/nppanda3d.so "+destdir+libdir+"/libxul/plugins/nppanda3d.so")
else:
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/mozilla/plugins")
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/mozilla-firefox/plugins")
oscmd("mkdir -m 0755 -p "+destdir+libdir+"/xulrunner-addons/plugins")
oscmd("ln -f -s "+libdir+"/nppanda3d.so "+destdir+libdir+"/mozilla/plugins/nppanda3d.so")
oscmd("ln -f -s "+libdir+"/nppanda3d.so "+destdir+libdir+"/mozilla-firefox/plugins/nppanda3d.so")
oscmd("ln -f -s "+libdir+"/nppanda3d.so "+destdir+libdir+"/xulrunner-addons/plugins/nppanda3d.so")
WriteMimeFile(destdir+prefix+"/share/mime-info/panda3d-runtime.mime", MIME_INFO_PLUGIN)
WriteKeysFile(destdir+prefix+"/share/mime-info/panda3d-runtime.keys", MIME_INFO_PLUGIN)
WriteMimeXMLFile(destdir+prefix+"/share/mime/packages/panda3d-runtime.xml", MIME_INFO_PLUGIN)
WriteApplicationsFile(destdir+prefix+"/share/application-registry/panda3d-runtime.applications", APP_INFO_PLUGIN, MIME_INFO_PLUGIN)
oscmd("cp makepanda/panda3d.desktop "+destdir+prefix+"/share/applications/panda3d.desktop")
oscmd("cp "+outputdir+"/bin/panda3d "+destdir+prefix+"/bin/")
if (__name__ == "__main__"):
if (sys.platform.startswith("win") or sys.platform == "darwin"):
exit("This script is not supported on Windows or Mac OS X at the moment!")
destdir = os.environ.get("DESTDIR", "/")
parser = OptionParser()
parser.add_option('', '--outputdir', dest = 'outputdir', help = 'Makepanda\'s output directory (default: built)', default = 'built')
parser.add_option('', '--destdir', dest = 'destdir', help = 'Destination directory [default=%s]' % destdir, default = destdir)
parser.add_option('', '--prefix', dest = 'prefix', help = 'Prefix [default=/usr/local]', default = '/usr/local')
parser.add_option('', '--runtime', dest = 'runtime', help = 'Specify if runtime build [default=no]', action = 'store_true', default = False)
(options, args) = parser.parse_args()
destdir = options.destdir
if (destdir.endswith("/")):
destdir = destdir[:-1]
if (destdir == "/"):
destdir = ""
if (destdir != "" and not os.path.isdir(destdir)):
exit("Directory '%s' does not exist!" % destdir)
if (options.runtime):
print("Installing Panda3D Runtime into " + destdir + options.prefix)
InstallRuntime(destdir = destdir, prefix = options.prefix, outputdir = options.outputdir)
else:
print("Installing Panda3D SDK into " + destdir + options.prefix)
InstallPanda(destdir = destdir, prefix = options.prefix, outputdir = options.outputdir)
print("Installation finished!")