forked from cztomczak/cefpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-deb.py
More file actions
332 lines (279 loc) · 11.2 KB
/
make-deb.py
File metadata and controls
332 lines (279 loc) · 11.2 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# Copyright (c) 2012-2014 The CEF Python authors. All rights reserved.
# License: New BSD License.
# Website: http://code.google.com/p/cefpython/
"""
Create a Debian Package.
Required dependencies:
sudo apt-get install python-support
sudo apt-get install python-pip
sudo pip install stdeb==0.6.0
"""
import subprocess
import os, sys
import platform
import argparse
import re
import shutil
# -----------------------------------------------------------------------------
# Globals
BITS = platform.architecture()[0]
assert (BITS == "32bit" or BITS == "64bit")
ARCHITECTURE = "i386" if (BITS == "32bit") else "amd64"
if BITS == "32bit":
LINUX_BITS = "linux32"
else:
LINUX_BITS = "linux64"
PACKAGE_NAME = "cefpython3"
PYTHON_NAME ="python2.7" # Directory name in deb archive
HOMEPAGE = "https://code.google.com/p/cefpython/"
MAINTAINER = "Czarek Tomczak <czarek.tomczak@gmail.com>"
DESCRIPTION_EXTENDED = \
""" CEF Python 3 is a python library for embedding the Chromium
browser. It uses the Chromium Embedded Framework (CEF) internally.
Examples of embedding are available for many GUI toolkits,
including wxPython, PyGTK, PyQt, PySide, Kivy and PyWin32.
"""
COPYRIGHT = \
"""Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Name: cefpython3
Maintainer: %s
Source: %s
Copyright: 2012-2014 The CEF Python authors
License: BSD 3-Clause
Files: *
Copyright: 2012-2014 The CEF Python authors
License: BSD 3-Clause
""" % (MAINTAINER, HOMEPAGE)
PYTHON_VERSION_WITH_DOT = (str(sys.version_info.major) + "."
+ str(sys.version_info.minor))
VERSION = None
# cefpython/linux/installer
INSTALLER = os.path.dirname(os.path.abspath(__file__))
# installer/cefpython3-31.0-linux-64bit-setup/
DISTUTILS_SETUP = None
# deb_dist/
DEB_DIST = None
# deb_dist/cefpython3-31.0/
DEB_DIST_PACKAGE = None
# deb_dist/cefpython3-31.0/debian/
DEBIAN = None
# deb_dist/cefpython3-31.0/debian/python-cefpython3/
DEBIAN_PACKAGE = None
# -----------------------------------------------------------------------------
def log(msg):
print("[make-deb.py] %s" % msg)
def replace_in_file(f_path, s_what, s_with):
contents = ""
with open(f_path, "r") as f:
contents = f.read()
assert contents, ("Failed reading file: %s" % f_path)
contents = contents.replace(s_what, s_with)
with open(f_path, "w") as f:
f.write(contents)
def remove_directories_from_previous_run():
if os.path.exists(DISTUTILS_SETUP):
log("The Distutils setup directory already exists, removing..")
shutil.rmtree(DISTUTILS_SETUP)
if os.path.exists(INSTALLER+"/deb_dist/"):
log("The deb_dist/ directory already exists, removing..")
shutil.rmtree(INSTALLER+"/deb_dist/")
if os.path.exists(INSTALLER+"/deb_archive/"):
log("The deb_archive/ directory already exists, removing..")
shutil.rmtree(INSTALLER+"/deb_archive/")
def create_distutils_setup_package():
log("Creating Distutils setup package")
subprocess.call("%s %s/make-setup.py -v %s" % \
(sys.executable, INSTALLER, VERSION), shell=True)
assert os.path.exists(DISTUTILS_SETUP),\
"Distutils Setup directory not found"
def modify_control_file():
log("Modyfing debian control file")
control_file = DEBIAN+"/control"
# Read contents
with open(control_file, "r") as f:
contents = f.read()
# Set architecture to i386 or amd64
contents = contents.replace("Architecture: all",
"Architecture: %s" % ARCHITECTURE)
# Extend the Package section, remove the two ending new lines
contents = re.sub("[\r\n]+$", "", contents)
contents += "\n"
# Extend description
description = DESCRIPTION_EXTENDED
description = re.sub("[\r\n]+", "\n", description)
description = re.sub("\n$", "", description)
contents += "%s\n" % description
# Other fields
contents += "Version: %s-1\n" % VERSION
contents += "Maintainer: %s\n" % MAINTAINER
contents += "Homepage: %s\n" % HOMEPAGE
# Control file should end with two new lines
contents += "\n"
with open(control_file, "w") as f:
f.write(contents)
def create_copyright_file():
# The license is "Unknown" when opening deb package in
# Ubuntu Software Center. It's a known bug:
# https://bugs.launchpad.net/ubuntu/+source/software-center/+bug/435183
log("Creating debian copyright file")
copyright = COPYRIGHT
copyright = re.sub("[\r\n]", "\n", copyright)
copyright += "\n"
copyright += "License: BSD 3-clause\n"
with open(INSTALLER+"/../../../License", "r") as f:
license = f.readlines()
for line in license:
if not len(re.sub("\s+", "", line)):
copyright += " .\n"
else:
copyright += " "+line.rstrip()+"\n"
copyright += "\n"
with open(DEBIAN+"/copyright", "w") as f:
f.write(copyright)
def copy_postinst_script():
# When creating .postinst file in the debian directory,
# it will overwrite the default postinst script created
# by dh_pysupport, its contents are:
# -----------------------------------------------------
# if which update-python-modules >/dev/null 2>&1; then
# update-python-modules python-cefpython3.public
# fi
# -----------------------------------------------------
# The command above creates symlinks for libraries and
# executables, so that they appear to be in one directory.
# CEF executable requires that libcef.so and the subprocess
# executable are in the same directory.
# This solution does not to work correctly in CEF3 branch
# 1650, so we will have to put .so libraries along with
# other files in a real single directory.
log("Copying .postinst script")
shutil.copy(INSTALLER+"/debian.postinst",
DEBIAN+"/python-%s.postinst" % (PACKAGE_NAME))
def create_debian_source_package():
log("Creating Debian source package using stdeb")
os.chdir(DISTUTILS_SETUP)
shutil.copy("../stdeb.cfg.template", "stdeb.cfg")
stdeb_cfg_add_deps("stdeb.cfg")
subprocess.call("%s setup.py --command-packages=stdeb.command sdist_dsc"\
% (sys.executable,), shell=True)
def stdeb_cfg_add_deps(stdeb_cfg):
log("Adding deps to stdeb.cfg")
with open(INSTALLER+"/deps.txt", "r") as f:
deps = f.read()
deps = deps.strip()
deps = deps.splitlines()
for i, dep in enumerate(deps):
deps[i] = dep.strip()
deps = ", ".join(deps)
with open(stdeb_cfg, "a") as f:
f.write("\nDepends: %s" % deps)
def deb_dist_cleanup():
# Move the deb_dist/ directory and remove unnecessary files
log("Preparing the deb_dist directory")
os.system("mv %s %s"\
% (DISTUTILS_SETUP+"/deb_dist", INSTALLER+"/deb_dist"))
os.system("rm -rf %s" % DISTUTILS_SETUP)
# Paths
global DEB_DIST, DEB_DIST_PACKAGE, DEBIAN, DEBIAN_PACKAGE
DEB_DIST = INSTALLER+"/deb_dist"
DEB_DIST_PACKAGE = DEB_DIST+"/"+PACKAGE_NAME+"-"+VERSION
DEBIAN = DEB_DIST_PACKAGE+"/debian"
DEBIAN_PACKAGE = DEBIAN+"/python-"+PACKAGE_NAME
# Remove unnecessary files
os.chdir(DEB_DIST)
os.system("rm *.gz")
os.system("rm *.dsc")
def create_debian_binary_package():
os.chdir(DEB_DIST_PACKAGE)
# Will create .deb .dsc .gz in the upper directory DEB_DIST
subprocess.call("dpkg-buildpackage -rfakeroot -uc -us", shell=True)
def modify_deb_archive():
# CEF branch 1650 doesn't work when the .so files do not reside
# in the same directory as the subprocess executable. The symlinks
# created in /usr/lib/pymodules/ do not help. After launching
# CEF and webpage being displayed, the CEF renderer process
# crashes after a moment. The solution is to modify the deb
# archive, move the /usr/lib/pyshared/.../*.so libraries to
# the /usr/share/pyshared/.../ directory. Also some files with
# hardcoded paths to /usr/lub/pyshared/ need to be modified
# (eg. DEBIAN/md5sums, python-support/python-cefpython3.public).
log("Modifying the deb archive")
# Paths
deb_archive_name = "python-%s_%s-1_%s.deb" \
% (PACKAGE_NAME, VERSION, ARCHITECTURE)
deb_archive_dir = INSTALLER+"/deb_archive"
# Move the deb archive to the deb_archive/ directory
log("Moving the deb archive")
os.system("mkdir %s" % deb_archive_dir)
os.system("mv %s %s" % (DEB_DIST+"/"+deb_archive_name,\
deb_archive_dir+"/"+deb_archive_name))
# Remove the deb_dist/ directory
os.system("rm -rf %s" % DEB_DIST)
# Extract the deb archive
log("Extracting the deb archive")
os.chdir(deb_archive_dir)
# Extract the usr/ directory
os.system("dpkg-deb -x %s ." % deb_archive_name)
# Extract the DEBIAN/ directory
os.system("dpkg-deb -e %s" % deb_archive_name)
# Remove the deb archive that was extracted
os.system("rm %s" % deb_archive_name)
# Move the .so files from the ./usr/lib/pyshared/.../ directory
# to the ./usr/share/pyshared/.../ directory. Also remove the
# ./usr/lib/ directory.
log("Moving the .so libraries")
lib_pyshared = "./usr/lib/pyshared/%s/%s" \
% (PYTHON_NAME, PACKAGE_NAME)
share_pyshared = "./usr/share/pyshared/%s" % PACKAGE_NAME
os.system("mv %s/*.so %s/" % (lib_pyshared, share_pyshared))
os.system("rm -rf ./usr/lib/")
# Modify also the paths in some text files.
# The paths do not start with "/" on purpose. In the md5sums
# file the paths are relative. In the python-cefpython3.public
# file paths are absolute.
log("Modifying paths in the text files")
old_path = "usr/lib/pyshared/%s/%s/" % (PYTHON_NAME, PACKAGE_NAME)
new_path = "usr/share/pyshared/%s/" % PACKAGE_NAME
md5sums_file = "./DEBIAN/md5sums"
cefpython3_public_file = "./usr/share/python-support/python-%s.public" \
% PACKAGE_NAME
old_md5sum = subprocess.check_output("md5sum %s | cut -c 1-32" \
% cefpython3_public_file, shell=True).strip()
# Modify paths in the text files
replace_in_file(md5sums_file, old_path, new_path)
replace_in_file(cefpython3_public_file, old_path, new_path)
# Correct md5 sum for the python-cefpython3.public file
new_md5sum = subprocess.check_output("md5sum %s | cut -c 1-32" \
% cefpython3_public_file, shell=True).strip()
replace_in_file(md5sums_file, old_md5sum, new_md5sum)
# Create deb archive from the modified ./DEBIAN/ and
# ./usr/ directories.
log("Creating deb archive from the modified files")
os.system("fakeroot dpkg-deb -b . ./%s" % deb_archive_name)
def main():
# Command line options
parser = argparse.ArgumentParser(usage="%(prog)s [options]")
parser.add_argument("-v", "--version", help="cefpython version",
required=True)
args = parser.parse_args()
assert re.search(r"^\d+\.\d+$", args.version), (
"Invalid version string")
# Version
global VERSION
VERSION = args.version
# Paths
global DISTUTILS_SETUP
DISTUTILS_SETUP = INSTALLER+"/"+PACKAGE_NAME+"-"+args.version+"-"+\
LINUX_BITS+"-setup"
remove_directories_from_previous_run()
create_distutils_setup_package()
create_debian_source_package()
deb_dist_cleanup()
modify_control_file()
create_copyright_file()
copy_postinst_script()
create_debian_binary_package()
modify_deb_archive()
log("DONE")
if __name__ == "__main__":
main()