|
23 | 23 | import os |
24 | 24 | import os.path |
25 | 25 | import subprocess |
26 | | - |
27 | | -upload = False |
28 | | - |
29 | 26 | from pkg_resources import resource_filename |
30 | | -setup_path = os.path.abspath(resource_filename(__name__, "setup.py")) |
| 27 | +import googlecode_upload |
| 28 | + |
31 | 29 |
|
32 | | -commands = [] |
33 | | -commands += ["egg_info", "--tag-build=.dev", "-r"] |
34 | | -commands += ["sdist"] |
35 | | -commands += ["bdist_wininst"] |
36 | | -#commands += ["bdist_msi"] |
37 | | -commands += ["bdist_egg"] |
| 30 | +#--------------------------------------------------------------------------- |
| 31 | +# Functions for running setup.py and building packages. |
38 | 32 |
|
39 | | -if upload: |
40 | | - # Make sure HOME is defined; required for .pypirc use. |
| 33 | +def build_commands(commands, directory, setup_path): |
| 34 | + # Make sure HOME is defined; required for .pypirc use |
41 | 35 | if "HOME" not in os.environ: |
42 | 36 | os.putenv("HOME", os.path.expanduser("~")) |
43 | | - commands.insert(3, "register") |
44 | | - commands += ["upload", "--show-response"] |
45 | | -# commands += ["upload_gcode", "--src"] |
46 | | -# commands += ["upload_gcode", "--windows"] |
47 | | - |
48 | | -arguments = [sys.executable, setup_path] + commands |
49 | | -os.chdir(os.path.dirname(setup_path)) |
50 | | -subprocess.call(arguments) |
| 37 | + |
| 38 | + arguments = [sys.executable, setup_path] + commands |
| 39 | + os.chdir(directory) |
| 40 | + subprocess.call(arguments) |
| 41 | + |
| 42 | + |
| 43 | +def build_distribution_and_upload(directory, setup_path): |
| 44 | + # Register and upload to pypi. |
| 45 | + commands = [ |
| 46 | + "egg_info", "--tag-build=.dev", "-r", |
| 47 | + "register", |
| 48 | + "sdist", |
| 49 | + "bdist_wininst", |
| 50 | + "bdist_egg", |
| 51 | + "upload", "--show-response", |
| 52 | + ] |
| 53 | + build_commands(commands, directory, setup_path) |
| 54 | + |
| 55 | + # Find new packages to upload to Google code. |
| 56 | + dist_directory = os.path.join(directory, "dist") |
| 57 | + filelist = [] |
| 58 | + for filename in os.listdir(dist_directory): |
| 59 | + path = os.path.join(dist_directory, filename) |
| 60 | + modified = os.path.getmtime(path) |
| 61 | + filelist.append((modified, path)) |
| 62 | + filelist = sorted(filelist) |
| 63 | + most_recent_path = filelist[-1][1] |
| 64 | + print "most recent", most_recent_path |
| 65 | + filename = os.path.basename(most_recent_path) |
| 66 | + basename, extension = os.path.splitext(filename) |
| 67 | + print "most recent basename", basename |
| 68 | + if extension != ".egg": |
| 69 | + raise RuntimeError("Most recent package not an egg file: %r" |
| 70 | + % most_recent_path) |
| 71 | + if not basename.startswith("dragonfly-"): |
| 72 | + raise RuntimeError("Most recent package not for dragonfly: %r" |
| 73 | + % most_recent_path) |
| 74 | + if basename[-6:-3] != "-py": |
| 75 | + raise RuntimeError("Most recent package funny name: %r" |
| 76 | + % most_recent_path) |
| 77 | + basename = basename[:-6] |
| 78 | + |
| 79 | + # Upload to Google code. |
| 80 | + upload_gcode(directory, basename) |
| 81 | + |
| 82 | + |
| 83 | +def build_distribution(directory, setup_path): |
| 84 | + commands = [ |
| 85 | + "egg_info", "--tag-build=.dev", "-r", |
| 86 | + "sdist", |
| 87 | + "bdist_wininst", |
| 88 | + "bdist_egg", |
| 89 | + ] |
| 90 | + build_commands(commands, directory, setup_path) |
| 91 | + |
| 92 | + |
| 93 | +#--------------------------------------------------------------------------- |
| 94 | +# Functions for uploading to Google code. |
| 95 | + |
| 96 | +def load_gcode_credentials(path): |
| 97 | + namespace = {} |
| 98 | + exec open(path, "r").read() in namespace |
| 99 | + return namespace["gcode_username"], namespace["gcode_password"] |
| 100 | + |
| 101 | + |
| 102 | +def upload_gcode_single(path, summary, labels, username, password): |
| 103 | + googlecode_upload.upload( |
| 104 | + file=path, |
| 105 | + project_name="dragonfly", |
| 106 | + user_name=username, |
| 107 | + password=password, |
| 108 | + summary=summary, |
| 109 | + labels=labels, |
| 110 | + ) |
| 111 | + |
| 112 | + |
| 113 | +def upload_gcode(directory, basename): |
| 114 | + credentials_path = os.path.join(directory, "local.txt") |
| 115 | + basepath = os.path.join(directory, "dist", basename) |
| 116 | + basepath = basepath.replace("_", "-") |
| 117 | + username, password = load_gcode_credentials(credentials_path) |
| 118 | + upload_gcode_single( |
| 119 | + basepath + ".win32.exe", |
| 120 | + "Windows installer", |
| 121 | + ["Featured", "OpSys-Windows", "Type-Installer"], |
| 122 | + username, password, |
| 123 | + ) |
| 124 | + upload_gcode_single( |
| 125 | + basepath + ".zip", |
| 126 | + "Source archive", |
| 127 | + ["Featured", "OpSys-Windows", "Type-Source"], |
| 128 | + username, password, |
| 129 | + ) |
| 130 | + |
| 131 | + |
| 132 | +#--------------------------------------------------------------------------- |
| 133 | +# Main control. |
| 134 | + |
| 135 | +def main(): |
| 136 | + # Retrieve directory and file location information. |
| 137 | + setup_path = os.path.abspath(resource_filename(__name__, "setup.py")) |
| 138 | + directory = os.path.dirname(setup_path) |
| 139 | + |
| 140 | + # Build the distribution packages. |
| 141 | + build_distribution(directory, setup_path) |
| 142 | + |
| 143 | + |
| 144 | +if __name__ == "__main__": |
| 145 | + main() |
0 commit comments