|
| 1 | +# Copyright (c) 2012-2013 The CEF Python authors. All rights reserved. |
| 2 | +# License: New BSD License. |
| 3 | +# Website: http://code.google.com/p/cefpython/ |
| 4 | + |
| 5 | +""" |
| 6 | +Create a Debian Package. |
| 7 | +
|
| 8 | +Required dependencies: |
| 9 | + sudo apt-get install python-support |
| 10 | + sudo apt-get install python-pip |
| 11 | + sudo pip install -U stdeb |
| 12 | +""" |
| 13 | + |
| 14 | +import subprocess |
| 15 | +import os, sys |
| 16 | +import platform |
| 17 | +import argparse |
| 18 | +import re |
| 19 | +import shutil |
| 20 | + |
| 21 | +BITS = platform.architecture()[0] |
| 22 | +assert (BITS == "32bit" or BITS == "64bit") |
| 23 | +PACKAGE_NAME = "cefpython3" |
| 24 | +PYTHON_VERSION_WITH_DOT = (str(sys.version_info.major) + "." |
| 25 | + + str(sys.version_info.minor)) |
| 26 | + |
| 27 | +def replace_in_file(f_path, s_what, s_with): |
| 28 | + contents = "" |
| 29 | + with open(f_path, "r") as f: |
| 30 | + contents = f.read() |
| 31 | + assert contents, ("Failed reading file: %s" % f_path) |
| 32 | + contents = contents.replace(s_what, s_with) |
| 33 | + with open(f_path, "w") as f: |
| 34 | + f.write(contents) |
| 35 | + |
| 36 | +def main(): |
| 37 | + |
| 38 | + # Options |
| 39 | + parser = argparse.ArgumentParser(usage="%(prog)s [options]") |
| 40 | + parser.add_argument("-v", "--version", help="cefpython version", |
| 41 | + required=True) |
| 42 | + args = parser.parse_args() |
| 43 | + assert re.search(r"^\d+\.\d+$", args.version), ( |
| 44 | + "Invalid version string") |
| 45 | + |
| 46 | + # Directories |
| 47 | + installer_dir = os.path.dirname(os.path.abspath(__file__)) |
| 48 | + setup_dir = installer_dir+"/"+PACKAGE_NAME+"-"+args.version+"-linux-"+BITS+"-setup" |
| 49 | + |
| 50 | + # Call make-setup.py |
| 51 | + if os.path.exists(setup_dir): |
| 52 | + print("Setup directory already exists, removing..") |
| 53 | + shutil.rmtree(setup_dir) |
| 54 | + subprocess.call("%s %s/make-setup.py -v %s" % \ |
| 55 | + (sys.executable, installer_dir, args.version), shell=True) |
| 56 | + assert os.path.exists(setup_dir), "Setup directory not found" |
| 57 | + |
| 58 | + # Create debian package |
| 59 | + os.chdir(setup_dir) |
| 60 | + shutil.copy("../stdeb.cfg.template", "stdeb.cfg") |
| 61 | + |
| 62 | + # Create debian source package |
| 63 | + subprocess.call("%s setup.py --command-packages=stdeb.command sdist_dsc"\ |
| 64 | + % (sys.executable,), shell=True) |
| 65 | + |
| 66 | + # Set architecture |
| 67 | + if BITS == "32bit": |
| 68 | + architecture = "i386" |
| 69 | + elif BITS == "64bit": |
| 70 | + architecture = "amd64" |
| 71 | + control_file = setup_dir+"/deb_dist/"+PACKAGE_NAME+"-"+args.version+"/debian/control" |
| 72 | + replace_in_file(control_file, "Architecture: all", "Architecture: %s" % architecture) |
| 73 | + |
| 74 | + # Create debian binary package |
| 75 | + os.chdir("deb_dist/%s-%s/" % (PACKAGE_NAME, args.version)) |
| 76 | + # When creating .postinst file in the debian directory, |
| 77 | + # it will overwrite the default postinst script created |
| 78 | + # by dh_pysupport, its contents are: |
| 79 | + # ----------------------------------------------------- |
| 80 | + # if which update-python-modules >/dev/null 2>&1; then |
| 81 | + # update-python-modules python-cefpython3.public |
| 82 | + # fi |
| 83 | + # ----------------------------------------------------- |
| 84 | + # This command creates symbolic links for both shared/ and lib/ |
| 85 | + # files. This is critical as this makes all files appear in single |
| 86 | + # directory, so that subprocess executable which is in shared/ |
| 87 | + # can see libcef.so which is in lib/. |
| 88 | + with open("debian/python-%s.postinst" % (PACKAGE_NAME), "w") as f: |
| 89 | + f.write("#! /bin/sh\n") |
| 90 | + f.write("set -e\n") |
| 91 | + f.write("chmod 755 /usr/share/pyshared/%s/cefclient\n"\ |
| 92 | + % (PACKAGE_NAME,)) |
| 93 | + f.write("chmod 755 /usr/share/pyshared/%s/subprocess\n"\ |
| 94 | + % (PACKAGE_NAME,)) |
| 95 | + f.write("update-python-modules python-cefpython3.public\n") |
| 96 | + subprocess.call("dpkg-buildpackage -rfakeroot -uc -us", shell=True) |
| 97 | + |
| 98 | + print("DONE") |
| 99 | + |
| 100 | +if __name__ == "__main__": |
| 101 | + main() |
0 commit comments