Revision 8c028e36
b/devflow/autopkg.py | ||
---|---|---|
150 | 150 |
# Get packages from configuration file |
151 | 151 |
config_file = options.config_file or os.path.join(toplevel, "autopkg.conf") |
152 | 152 |
packages = get_packages_to_build(config_file) |
153 |
if packages: |
|
154 |
print_green("Will build the following packages:\n" |
|
155 |
"\n".join(packages)) |
|
156 |
else: |
|
157 |
raise RuntimeError("Configuration file is empty." |
|
158 |
" No packages to build.") |
|
153 |
print_green("Will build the following packages:\n" + "\n".join(packages)) |
|
159 | 154 |
|
160 | 155 |
# Clone the repo |
161 |
repo_dir = options.repo_dir |
|
162 |
if not repo_dir: |
|
163 |
repo_dir = create_temp_directory("df-repo") |
|
164 |
print_green("Created temporary directory '%s' for the cloned repo." |
|
165 |
% repo_dir) |
|
166 |
|
|
156 |
repo_dir = options.repo_dir or create_temp_directory("df-repo") |
|
167 | 157 |
repo = original_repo.clone(repo_dir) |
168 |
print_green("Cloned current repository to '%s'." % repo_dir) |
|
169 |
|
|
170 |
reflog_hexsha = repo.head.log()[-1].newhexsha |
|
171 |
print "Latest Reflog entry is %s" % reflog_hexsha |
|
158 |
print_green("Cloned repository to '%s'." % repo_dir) |
|
172 | 159 |
|
160 |
# Get current branch name and type and check if it is a valid one |
|
173 | 161 |
branch = repo.head.reference.name |
174 |
allowed_branches = ", ".join(x for x in BRANCH_TYPES.keys()) |
|
175 |
if branch.split('-')[0] not in allowed_branches: |
|
162 |
branch_type = versioning.get_branch_type(branch) |
|
163 |
|
|
164 |
if branch_type not in BRANCH_TYPES.keys(): |
|
165 |
allowed_branches = ", ".join(BRANCH_TYPES.keys()) |
|
176 | 166 |
raise ValueError("Malformed branch name '%s', cannot classify as" |
177 | 167 |
" one of %s" % (branch, allowed_branches)) |
178 | 168 |
|
179 |
brnorm = versioning.normalize_branch_name(branch) |
|
180 |
btypestr = versioning.get_branch_type(brnorm) |
|
181 |
|
|
182 |
# Find the debian branch, and create it if does not exist |
|
183 |
debian_branch = "debian-" + brnorm |
|
169 |
# Find the debian branch |
|
170 |
debian_branch = "debian-" + branch |
|
184 | 171 |
origin_debian = "origin/" + debian_branch |
185 | 172 |
if not origin_debian in repo.references: |
186 | 173 |
# Get default debian branch |
187 |
try: |
|
188 |
default_debian = BRANCH_TYPES[btypestr].default_debian_branch |
|
189 |
origin_debian = "origin/" + default_debian |
|
190 |
except KeyError: |
|
191 |
allowed_branches = ", ".join(x for x in BRANCH_TYPES.keys()) |
|
192 |
raise ValueError("Malformed branch name '%s', cannot classify as" |
|
193 |
" one of %s" % (btypestr, allowed_branches)) |
|
194 |
|
|
195 |
repo.git.branch("--track", debian_branch, origin_debian) |
|
174 |
default_debian = BRANCH_TYPES[branch_type].default_debian_branch |
|
175 |
origin_debian = "origin/" + default_debian |
|
176 |
|
|
177 |
repo.git.branch(debian_branch, origin_debian) |
|
196 | 178 |
print_green("Created branch '%s' to track '%s'" % (debian_branch, |
197 | 179 |
origin_debian)) |
198 | 180 |
|
... | ... | |
202 | 184 |
|
203 | 185 |
# Merge with starting branch |
204 | 186 |
repo.git.merge(branch) |
205 |
print_green("Merged branch '%s' into '%s'" % (brnorm, debian_branch))
|
|
187 |
print_green("Merged branch '%s' into '%s'" % (branch, debian_branch))
|
|
206 | 188 |
|
207 | 189 |
# Compute python and debian version |
208 | 190 |
cd(repo_dir) |
... | ... | |
211 | 193 |
debian_version_from_python_version(python_version) |
212 | 194 |
print_green("The new debian version will be: '%s'" % debian_version) |
213 | 195 |
|
196 |
# Tag branch with python version |
|
197 |
branch_tag = python_version |
|
198 |
repo.git.tag(branch_tag, branch) |
|
199 |
|
|
214 | 200 |
# Update changelog |
215 | 201 |
dch = git_dch("--debian-branch=%s" % debian_branch, |
216 | 202 |
"--git-author", |
... | ... | |
221 | 207 |
print_green("Successfully ran '%s'" % " ".join(dch.cmd)) |
222 | 208 |
|
223 | 209 |
if mode == "release": |
224 |
# Commit changelog and update tag branches |
|
225 | 210 |
call("vim debian/changelog") |
226 |
repo.git.add("debian/changelog") |
|
227 |
repo.git.commit("-s", "-a", m="Bump new upstream version") |
|
228 |
python_tag = python_version |
|
229 |
debian_tag = "debian/" + python_tag |
|
230 |
repo.git.tag(debian_tag) |
|
231 |
repo.git.tag(python_tag, brnorm) |
|
232 | 211 |
else: |
233 | 212 |
f = open("debian/changelog", 'r+') |
234 | 213 |
lines = f.readlines() |
235 | 214 |
lines[0] = lines[0].replace("UNRELEASED", "unstable") |
236 |
lines[2] = lines[2].replace("UNRELEASED", "Snapshot version")
|
|
215 |
lines[2] = lines[2].replace("UNRELEASED", "Snapshot build")
|
|
237 | 216 |
f.seek(0) |
238 | 217 |
f.writelines(lines) |
239 | 218 |
f.close() |
240 |
repo.git.add("debian/changelog") |
|
219 |
|
|
220 |
# Add changelog to INDEX |
|
221 |
repo.git.add("debian/changelog") |
|
222 |
# Commit Changes |
|
223 |
repo.git.commit("-s", "-a", m="Bump version to %s" % debian_version) |
|
224 |
# Tag debian branch |
|
225 |
debian_branch_tag = "debian/" + branch_tag |
|
226 |
repo.git.tag(debian_branch_tag) |
|
241 | 227 |
|
242 | 228 |
# Update the python version files |
243 | 229 |
# TODO: remove this |
... | ... | |
253 | 239 |
# Add version.py files to repo |
254 | 240 |
call("grep \"__version_vcs\" -r . -l -I | xargs git add -f") |
255 | 241 |
|
256 |
# Create debian branches |
|
257 |
build_dir = options.build_dir |
|
258 |
if not options.build_dir: |
|
259 |
build_dir = create_temp_directory("df-build") |
|
260 |
print_green("Created directory '%s' to store the .deb files." % |
|
261 |
build_dir) |
|
242 |
# Create debian packages |
|
243 |
build_dir = options.build_dir or create_temp_directory("df-build") |
|
244 |
print_green("Build directory: '%s'" % build_dir) |
|
262 | 245 |
|
263 | 246 |
cd(repo_dir) |
264 | 247 |
call("git-buildpackage --git-export-dir=%s --git-upstream-branch=%s" |
265 | 248 |
" --git-debian-branch=%s --git-export=INDEX --git-ignore-new -sa" |
266 |
% (build_dir, brnorm, debian_branch)) |
|
249 |
" -i\/version\.py" |
|
250 |
% (build_dir, branch, debian_branch)) |
|
267 | 251 |
|
268 | 252 |
# Remove cloned repo |
269 | 253 |
if mode != 'release' and not options.keep_repo: |
270 | 254 |
print_green("Removing cloned repo '%s'." % repo_dir) |
271 | 255 |
rm("-r", repo_dir) |
272 |
else: |
|
273 |
print_green("Repository dir '%s'" % repo_dir) |
|
274 | 256 |
|
275 |
print_green("Completed. Version '%s', build area: '%s'" |
|
276 |
% (debian_version, build_dir)) |
|
257 |
# Print final info |
|
258 |
info = (("Version", debian_version), |
|
259 |
("Upstream branch", branch), |
|
260 |
("Upstream tag", branch_tag), |
|
261 |
("Debian branch", debian_branch), |
|
262 |
("Debian tag", debian_branch_tag), |
|
263 |
("Repository directory", repo_dir), |
|
264 |
("Packages directory", build_dir)) |
|
265 |
print_green("\n".join(["%s: %s" % (name, val) for name, val in info])) |
|
277 | 266 |
|
278 | 267 |
# Print help message |
279 | 268 |
if mode == "release": |
280 |
TAG_MSG = "Tagged branch %s with tag %s\n" |
|
281 |
print_green(TAG_MSG % (brnorm, python_tag)) |
|
282 |
print_green(TAG_MSG % (debian_branch, debian_tag)) |
|
283 |
|
|
284 |
UPDATE_MSG = "To update repository %s, go to %s, and run the"\ |
|
285 |
" following commands:\n" + "git push origin %s\n" * 3 |
|
286 |
|
|
287 |
origin_url = repo.remotes['origin'].url |
|
288 |
remote_url = original_repo.remotes['origin'].url |
|
269 |
origin = original_repo.remote().url |
|
270 |
repo.create_remote("original_origin", origin) |
|
271 |
print_green("Created remote 'original_origin' for the repository '%s'" |
|
272 |
% origin) |
|
289 | 273 |
|
290 |
print_green(UPDATE_MSG % (origin_url, repo_dir, debian_branch, |
|
291 |
debian_tag, python_tag)) |
|
292 |
print_green(UPDATE_MSG % (remote_url, original_repo.working_dir, |
|
293 |
debian_branch, debian_tag, python_tag)) |
|
274 |
print_green("To update repositories '%s' and '%s' go to '%s' and run:" |
|
275 |
% (toplevel, origin, repo_dir)) |
|
276 |
for remote in ['origin', 'original_origin']: |
|
277 |
|
|
278 |
for obj in [debian_branch, branch_tag, debian_branch_tag]: |
|
279 |
print_green("git push %s %s" % (remote, obj)) |
|
294 | 280 |
|
295 | 281 |
|
296 | 282 |
def get_packages_to_build(config_file): |
... | ... | |
298 | 284 |
try: |
299 | 285 |
f = open(config_file) |
300 | 286 |
except IOError as e: |
301 |
raise IOError("Can not access configuration file %s: %s"
|
|
287 |
raise IOError("Can not access configuration file '%s': %s"
|
|
302 | 288 |
% (config_file, e.strerror)) |
303 | 289 |
|
304 | 290 |
lines = [l.strip() for l in f.readlines()] |
305 | 291 |
l = [l for l in lines if not l.startswith("#")] |
306 | 292 |
f.close() |
293 |
if not l: |
|
294 |
raise RuntimeError("Configuration file '%s' is empty." |
|
295 |
" No packages to build." % config_fule) |
|
307 | 296 |
return l |
308 | 297 |
|
309 | 298 |
|
Also available in: Unified diff