|
| 1 | +# Create a setup package. |
| 2 | + |
| 3 | +import sys |
| 4 | +import os |
| 5 | +import platform |
| 6 | +import argparse |
| 7 | +import re |
| 8 | +import platform |
| 9 | +import shutil |
| 10 | +import glob |
| 11 | + |
| 12 | +BITS = platform.architecture()[0] |
| 13 | +assert (BITS == "32bit" or BITS == "64bit") |
| 14 | + |
| 15 | +PACKAGE_NAME = "cefpython3" |
| 16 | + |
| 17 | +README_TEMPLATE = os.getcwd()+r"/README.txt.template" |
| 18 | +INIT_TEMPLATE = os.getcwd()+r"/__init__.py.template" |
| 19 | +SETUP_TEMPLATE = os.getcwd()+r"/setup.py.template" |
| 20 | + |
| 21 | +def main(): |
| 22 | + parser = argparse.ArgumentParser(usage="%(prog)s [options]") |
| 23 | + parser.add_argument("-v", "--version", help="cefpython version", |
| 24 | + required=True) |
| 25 | + args = parser.parse_args() |
| 26 | + assert re.search(r"^(v\d+)|(\d+\.\d+)$", args.version), ( |
| 27 | + "Invalid version string") |
| 28 | + |
| 29 | + vars = {} |
| 30 | + vars["APP_VERSION"] = args.version |
| 31 | + |
| 32 | + print("Reading template: %s" % README_TEMPLATE) |
| 33 | + f = open(README_TEMPLATE) |
| 34 | + README_CONTENT = f.read() % vars |
| 35 | + f.close() |
| 36 | + |
| 37 | + print("Reading template: %s" % INIT_TEMPLATE) |
| 38 | + f = open(INIT_TEMPLATE) |
| 39 | + INIT_CONTENT = f.read() % vars |
| 40 | + f.close() |
| 41 | + |
| 42 | + print("Reading template: %s" % SETUP_TEMPLATE) |
| 43 | + f = open(SETUP_TEMPLATE) |
| 44 | + SETUP_CONTENT = f.read() % vars |
| 45 | + f.close() |
| 46 | + |
| 47 | + installer_dir = os.path.dirname(os.path.abspath(__file__)) |
| 48 | + |
| 49 | + setup_dir = installer_dir+"/"+PACKAGE_NAME+"-"+vars["APP_VERSION"]+"-linux-"+BITS+"-setup" |
| 50 | + print("Creating setup dir: "+setup_dir) |
| 51 | + os.mkdir(setup_dir) |
| 52 | + |
| 53 | + package_dir = setup_dir+"/"+PACKAGE_NAME |
| 54 | + print("Creating package dir") |
| 55 | + os.mkdir(package_dir) |
| 56 | + |
| 57 | + print("Creating README.txt from template") |
| 58 | + with open(setup_dir+"/README.txt", "w") as f: |
| 59 | + f.write(README_CONTENT) |
| 60 | + |
| 61 | + print("Creating setup.py from template") |
| 62 | + with open(setup_dir+"/setup.py", "w") as f: |
| 63 | + f.write(SETUP_CONTENT) |
| 64 | + |
| 65 | + binaries_dir = os.path.abspath(installer_dir+"/../binaries_"+BITS+"/") |
| 66 | + print("Copying binaries to package dir") |
| 67 | + ret = os.system("cp -rf "+binaries_dir+"/* "+package_dir) |
| 68 | + assert ret == 0 |
| 69 | + |
| 70 | + os.chdir(package_dir) |
| 71 | + print("Removing .log files from the package dir") |
| 72 | + ret = os.system("rm *.log") |
| 73 | + # assert ret == 0 - if there are no .log files this assert would fail. |
| 74 | + os.chdir(installer_dir) |
| 75 | + |
| 76 | + print("Creating __init__.py from template") |
| 77 | + with open(package_dir+"/__init__.py", "w") as f: |
| 78 | + f.write(INIT_CONTENT) |
| 79 | + |
| 80 | + print("Creating examples dir in package dir") |
| 81 | + os.mkdir(package_dir+"/examples/") |
| 82 | + |
| 83 | + # print("Creating wx dir in package dir") |
| 84 | + # os.mkdir(package_dir+"/wx/") |
| 85 | + |
| 86 | + print("Moving example scripts from package dir to examples dir") |
| 87 | + examples = glob.glob(package_dir+"/*.py") |
| 88 | + for example in examples: |
| 89 | + # Ignore: cefpython_py27.py - dummy API script |
| 90 | + if os.path.basename(example).startswith("cefpython_"): |
| 91 | + continue |
| 92 | + # Ignore: __init__.py |
| 93 | + if os.path.basename(example).startswith("__"): |
| 94 | + continue |
| 95 | + os.rename(example, package_dir+"/examples/"+os.path.basename(example)) |
| 96 | + ret = os.system("mv "+package_dir+"/*.html "+package_dir+"/examples/") |
| 97 | + assert ret == 0 |
| 98 | + |
| 99 | + # print("Copying wx-subpackage to wx dir in package dir") |
| 100 | + # wx_subpackage_dir = os.path.abspath(installer_dir+"/../../wx-subpackage/") |
| 101 | + # ret = os.system("cp -rf "+wx_subpackage_dir+"/* "+package_dir+"/wx/") |
| 102 | + # assert ret == 0 |
| 103 | + |
| 104 | + # print("Moving wx examples from wx/examples to examples/wx") |
| 105 | + # shutil.move(package_dir+"/wx/examples", package_dir+"/wx/wx/") |
| 106 | + # shutil.move(package_dir+"/wx/wx/", package_dir+"/examples/") |
| 107 | + |
| 108 | + print("Copying package dir examples to setup dir") |
| 109 | + ret = os.system("cp -rf "+package_dir+"/examples/ "+setup_dir+"/examples/") |
| 110 | + assert ret == 0 |
| 111 | + |
| 112 | + print("Setup Package created.") |
| 113 | + |
| 114 | +if __name__ == "__main__": |
| 115 | + main() |
0 commit comments