|
| 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 | +# Create a setup package. |
| 6 | + |
| 7 | +import sys |
| 8 | +import os |
| 9 | +import platform |
| 10 | +import argparse |
| 11 | +import re |
| 12 | +import platform |
| 13 | +import shutil |
| 14 | +import glob |
| 15 | +import shutil |
| 16 | + |
| 17 | +BITS = platform.architecture()[0] |
| 18 | +assert (BITS == "32bit" or BITS == "64bit") |
| 19 | +BITS_NUMBER = BITS[0] + BITS[1] |
| 20 | +PACKAGE_NAME = "cefpython3" |
| 21 | + |
| 22 | +README_TEMPLATE = os.getcwd()+r"/README.txt.template" |
| 23 | +INIT_TEMPLATE = os.getcwd()+r"/__init__.py.template" |
| 24 | +SETUP_TEMPLATE = os.getcwd()+r"/setup.py.template" |
| 25 | + |
| 26 | +def glob_remove(pathname): |
| 27 | + filelist = glob.glob(pathname) |
| 28 | + for f in filelist: |
| 29 | + os.remove(f) |
| 30 | + |
| 31 | +def glob_copy(src_glob, dst_folder): |
| 32 | + for fname in glob.iglob(src_glob): |
| 33 | + print("Copying %s to %s" % (fname, dst_folder)) |
| 34 | + if os.path.isdir(fname): |
| 35 | + shutil.copytree(fname, |
| 36 | + os.path.join(dst_folder, os.path.basename(fname))) |
| 37 | + else: |
| 38 | + shutil.copy(fname, |
| 39 | + os.path.join(dst_folder, os.path.basename(fname))) |
| 40 | + |
| 41 | +def glob_move(src_glob, dst_folder): |
| 42 | + if not os.path.exists(dst_folder): |
| 43 | + os.mkdir(dst_folder) |
| 44 | + for fname in glob.iglob(src_glob): |
| 45 | + shutil.move(fname, |
| 46 | + os.path.join(dst_folder, os.path.basename(fname))) |
| 47 | + |
| 48 | +def main(): |
| 49 | + parser = argparse.ArgumentParser(usage="%(prog)s [options]") |
| 50 | + parser.add_argument("-v", "--version", help="cefpython version", |
| 51 | + required=True) |
| 52 | + args = parser.parse_args() |
| 53 | + assert re.search(r"^\d+\.\d+$", args.version), ( |
| 54 | + "Invalid version string") |
| 55 | + |
| 56 | + vars = {} |
| 57 | + vars["APP_VERSION"] = args.version |
| 58 | + |
| 59 | + print("Reading template: %s" % README_TEMPLATE) |
| 60 | + f = open(README_TEMPLATE) |
| 61 | + README_CONTENT = f.read() % vars |
| 62 | + f.close() |
| 63 | + |
| 64 | + print("Reading template: %s" % INIT_TEMPLATE) |
| 65 | + f = open(INIT_TEMPLATE) |
| 66 | + INIT_CONTENT = f.read() % vars |
| 67 | + f.close() |
| 68 | + |
| 69 | + print("Reading template: %s" % SETUP_TEMPLATE) |
| 70 | + f = open(SETUP_TEMPLATE) |
| 71 | + SETUP_CONTENT = f.read() % vars |
| 72 | + f.close() |
| 73 | + |
| 74 | + installer_dir = os.path.dirname(os.path.abspath(__file__)) |
| 75 | + |
| 76 | + pyVersion = str(sys.version_info.major) + str(sys.version_info.minor) |
| 77 | + setup_dir = installer_dir+"/"+PACKAGE_NAME+"-"+vars["APP_VERSION"]\ |
| 78 | + +"-win"+BITS_NUMBER+"-py"+pyVersion+"-setup" |
| 79 | + print("Creating setup dir: "+setup_dir) |
| 80 | + os.mkdir(setup_dir) |
| 81 | + |
| 82 | + package_dir = setup_dir+"/"+PACKAGE_NAME |
| 83 | + #print("Creating package dir") |
| 84 | + #os.mkdir(package_dir) |
| 85 | + |
| 86 | + print("Creating README.txt from template") |
| 87 | + with open(setup_dir+"/README.txt", "w") as f: |
| 88 | + f.write(README_CONTENT) |
| 89 | + |
| 90 | + print("Creating setup.py from template") |
| 91 | + with open(setup_dir+"/setup.py", "w") as f: |
| 92 | + f.write(SETUP_CONTENT) |
| 93 | + |
| 94 | + if BITS == "32bit": |
| 95 | + binaries_dir = os.path.abspath(installer_dir+"/../binaries/") |
| 96 | + else: |
| 97 | + binaries_dir = os.path.abspath(installer_dir+"/../binaries_"+BITS+"/") |
| 98 | + print("Copying binaries to package dir") |
| 99 | + shutil.copytree(binaries_dir, package_dir) |
| 100 | + |
| 101 | + os.chdir(package_dir) |
| 102 | + print("Removing .log .pyc .pdb files from the package dir") |
| 103 | + glob_remove("*.log") |
| 104 | + glob_remove("*.pyc") |
| 105 | + glob_remove("*.pdb") |
| 106 | + os.chdir(installer_dir) |
| 107 | + |
| 108 | + print("Creating __init__.py from template") |
| 109 | + with open(package_dir+"/__init__.py", "w") as f: |
| 110 | + f.write(INIT_CONTENT) |
| 111 | + |
| 112 | + print("Creating examples dir in package dir") |
| 113 | + os.mkdir(package_dir+"/examples/") |
| 114 | + |
| 115 | + print("Creating wx dir in package dir") |
| 116 | + os.mkdir(package_dir+"/wx/") |
| 117 | + |
| 118 | + print("Moving example scripts from package dir to examples dir") |
| 119 | + examples = glob.glob(package_dir+"/*.py") |
| 120 | + for example in examples: |
| 121 | + # Ignore: cefpython_py27.py - dummy API script |
| 122 | + if os.path.basename(example).startswith("cefpython_"): |
| 123 | + continue |
| 124 | + # Ignore: __init__.py |
| 125 | + if os.path.basename(example).startswith("__"): |
| 126 | + continue |
| 127 | + os.rename(example, package_dir+"/examples/"+os.path.basename(example)) |
| 128 | + glob_move(package_dir+"/*.html", package_dir+"/examples/") |
| 129 | + |
| 130 | + print("Copying wx-subpackage to wx dir in package dir") |
| 131 | + wx_subpackage_dir = os.path.abspath(installer_dir+"/../../wx-subpackage/") |
| 132 | + glob_copy(wx_subpackage_dir+"/*", package_dir+"/wx/") |
| 133 | + |
| 134 | + print("Moving wx examples from wx/examples to examples/wx") |
| 135 | + glob_move(package_dir+"/wx/examples/*", package_dir+"/examples/wx/") |
| 136 | + os.rmdir(package_dir+"/wx/examples/") |
| 137 | + |
| 138 | + print("Copying package dir examples to setup dir") |
| 139 | + glob_copy(package_dir+"/examples/", setup_dir+"/examples/") |
| 140 | + |
| 141 | + print("Setup Package created.") |
| 142 | + |
| 143 | +if __name__ == "__main__": |
| 144 | + main() |
0 commit comments