forked from dictation-toolbox/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_dist.py
145 lines (120 loc) · 4.92 KB
/
build_dist.py
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
#
# This file is part of Dragonfly.
# (c) Copyright 2007, 2008 by Christo Butcher
# Licensed under the LGPL.
#
# Dragonfly is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Dragonfly is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with Dragonfly. If not, see
# <http://www.gnu.org/licenses/>.
#
import sys
import os
import os.path
import subprocess
from pkg_resources import resource_filename
import googlecode_upload
#---------------------------------------------------------------------------
# Functions for running setup.py and building packages.
def build_commands(commands, directory, setup_path):
# Make sure HOME is defined; required for .pypirc use
if "HOME" not in os.environ:
os.putenv("HOME", os.path.expanduser("~"))
arguments = [sys.executable, setup_path] + commands
os.chdir(directory)
subprocess.call(arguments)
def build_distribution_and_upload(directory, setup_path):
# Register and upload to pypi.
commands = [
"egg_info", # "--tag-build=.dev", "-r",
"register",
"sdist",
"bdist_wininst",
"bdist_egg",
"upload", "--show-response",
]
build_commands(commands, directory, setup_path)
# Find new packages to upload to Google code.
dist_directory = os.path.join(directory, "dist")
filelist = []
for filename in os.listdir(dist_directory):
path = os.path.join(dist_directory, filename)
modified = os.path.getmtime(path)
filelist.append((modified, path))
filelist = sorted(filelist)
most_recent_path = filelist[-1][1]
print("most recent", most_recent_path)
filename = os.path.basename(most_recent_path)
basename, extension = os.path.splitext(filename)
print("most recent basename", basename)
if extension != ".egg":
raise RuntimeError("Most recent package not an egg file: %r"
% most_recent_path)
if not basename.startswith("dragonfly-"):
raise RuntimeError("Most recent package not for dragonfly: %r"
% most_recent_path)
if basename[-6:-3] != "-py":
raise RuntimeError("Most recent package funny name: %r"
% most_recent_path)
basename = basename[:-6]
# Upload to Google code.
upload_gcode(directory, basename)
def build_distribution(directory, setup_path):
commands = [
"egg_info", # "--tag-build=.dev", "-r",
"sdist",
"bdist_wininst",
"bdist_egg",
]
build_commands(commands, directory, setup_path)
#---------------------------------------------------------------------------
# Functions for uploading to Google code.
def load_gcode_credentials(path):
namespace = {}
exec(open(path, "r").read(), namespace)
return namespace["gcode_username"], namespace["gcode_password"]
def upload_gcode_single(path, summary, labels, username, password):
googlecode_upload.upload(
file=path,
project_name="dragonfly",
user_name=username,
password=password,
summary=summary,
labels=labels,
)
def upload_gcode(directory, basename):
credentials_path = os.path.join(directory, "local.txt")
basepath = os.path.join(directory, "dist", basename)
basepath = basepath.replace("_", "-")
username, password = load_gcode_credentials(credentials_path)
upload_gcode_single(
basepath + ".win32.exe",
"Windows installer",
["Featured", "OpSys-Windows", "Type-Installer"],
username, password,
)
upload_gcode_single(
basepath + ".zip",
"Source archive",
["Featured", "OpSys-Windows", "Type-Source"],
username, password,
)
#---------------------------------------------------------------------------
# Main control.
def main():
# Retrieve directory and file location information.
setup_path = os.path.abspath(resource_filename(__name__, "setup.py"))
directory = os.path.dirname(setup_path)
# Build the distribution packages.
build_distribution(directory, setup_path)
if __name__ == "__main__":
main()