10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python
|
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
2 |
#
|
3 |
# Copyright 2010 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5 |
||
10224.4.5
by Jonathan Lange
Show the Bazaar log if -v passed. Lots of docs. |
6 |
"""Usage: on-edge [-v] [--edge-only] [--staging-only]
|
7 |
||
8 |
This script consults the edge and staging servers to determine which revisions
|
|
9 |
they are running. Once it knows that, it prints a log of all the revisions of
|
|
10 |
stable and db-stable respectively that cannot be found on edge or staging.
|
|
11 |
||
12 |
Note that the stable branch is assumed to be in a directory called 'stable', a
|
|
13 |
sibling to the current branch directory. Likewise, db-stable is assumed to be
|
|
14 |
in '../db-stable', relative to this branch.
|
|
15 |
"""
|
|
16 |
||
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
17 |
import optparse |
10224.4.5
by Jonathan Lange
Show the Bazaar log if -v passed. Lots of docs. |
18 |
import os |
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
19 |
import re |
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
20 |
import sys |
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
21 |
|
14612.2.6
by William Grant
utilities |
22 |
from bzrlib import errors |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
23 |
from bzrlib.branch import Branch |
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
24 |
from bzrlib.transport import get_transport |
25 |
||
26 |
||
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
27 |
class UsageError(Exception): |
28 |
"""Raised when the user makes a dumb error."""
|
|
29 |
||
30 |
||
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
31 |
def get_staging_revision(): |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
32 |
"""Get the revision of db-stable deployed on staging.
|
33 |
||
34 |
:return: The staging revno as an int. Corresponds to a revision of
|
|
35 |
lp:launchpad/db-stable.
|
|
36 |
"""
|
|
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
37 |
t = get_transport('https://staging.launchpad.net/') |
38 |
last_line = t.get_bytes('successful-updates.txt').splitlines()[-1] |
|
39 |
return int(last_line.split()[-1]) |
|
40 |
||
41 |
||
42 |
def get_edge_revision(): |
|
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
43 |
"""Get the revision of stable deployed on edge.
|
44 |
||
45 |
:return: The edge revno as an int. Corresponds to a revision of
|
|
46 |
lp:launchpad/stable.
|
|
47 |
"""
|
|
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
48 |
t = get_transport('https://edge.launchpad.net/') |
49 |
html = t.get_bytes('index.html') |
|
50 |
revision_re = re.compile(r'\(r(\d+)\)') |
|
51 |
for line in html.splitlines(): |
|
52 |
matches = revision_re.search(line) |
|
53 |
if matches: |
|
54 |
return int(matches.group(1)) |
|
55 |
raise ValueError("Could not find revision number on edge home page") |
|
56 |
||
57 |
||
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
58 |
def get_parent_directory(): |
59 |
"""Return the parent directory of the current branch."""
|
|
60 |
this_file = os.path.abspath(__file__) |
|
61 |
return os.path.dirname(os.path.dirname(os.path.dirname(this_file))) |
|
62 |
||
63 |
||
10253.1.1
by Henning Eggers
Added that little bit of vital extra information to the output. |
64 |
def revno_str(revno): |
65 |
"""Make a dotted string from a revno tuple."""
|
|
66 |
return ".".join(map(str, revno)) |
|
67 |
||
68 |
||
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
69 |
def print_revisions(branch, end_id): |
10245.1.3
by Henning Eggers
Doc strings. |
70 |
"""Output revision messages up to end_id."""
|
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
71 |
rev_iter = branch.iter_merge_sorted_revisions( |
72 |
None, end_id, 'include') |
|
73 |
for rev_info in rev_iter: |
|
74 |
(rev_id, depth, revno, end_of_merge) = rev_info |
|
75 |
if depth > 0: |
|
76 |
continue
|
|
10245.1.5
by Henning Eggers
Better named variables. |
77 |
revision = branch.repository.get_revision(rev_id) |
10253.1.1
by Henning Eggers
Added that little bit of vital extra information to the output. |
78 |
print "r%s:\n%s" % (revno_str(revno), revision.message) |
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
79 |
|
80 |
||
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
81 |
def report_difference_to_server(server, branch_path, revno, verbose): |
10245.1.3
by Henning Eggers
Doc strings. |
82 |
"""Output if and how the local branch differs from the server."""
|
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
83 |
branch = Branch.open(branch_path) |
10245.1.2
by Henning Eggers
Added last automatic merge info. |
84 |
print '%s is running %s r%d.' % (server, branch.nick, revno) |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
85 |
try: |
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
86 |
current_id = branch.dotted_revno_to_revision_id((revno,)) |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
87 |
except errors.NoSuchRevision: |
10245.1.2
by Henning Eggers
Added last automatic merge info. |
88 |
print '%s has newer revisions than %s.' % (server, branch.nick) |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
89 |
else: |
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
90 |
if current_id == branch.last_revision(): |
10245.1.2
by Henning Eggers
Added last automatic merge info. |
91 |
print '%s is up-to-date.' % (server,) |
10245.1.1
by Henning Eggers
Fixed divergence detection. Replaced os.system call with bzrlib code. |
92 |
else: |
93 |
if verbose: |
|
94 |
print_revisions(branch, current_id) |
|
10224.4.5
by Jonathan Lange
Show the Bazaar log if -v passed. Lots of docs. |
95 |
|
96 |
||
10245.1.2
by Henning Eggers
Added last automatic merge info. |
97 |
automatic_merge_regex = re.compile( |
98 |
"automatic merge from stable[.] "
|
|
99 |
"Revisions:[0-9,\s]*\s+([0-9]+)\s+included") |
|
100 |
||
10245.1.5
by Henning Eggers
Better named variables. |
101 |
|
10245.1.2
by Henning Eggers
Added last automatic merge info. |
102 |
def get_last_automatic_stable_merge_revno(branch_path): |
10245.1.3
by Henning Eggers
Doc strings. |
103 |
"""Find out which stable revision was last commited to db-stable."""
|
10245.1.2
by Henning Eggers
Added last automatic merge info. |
104 |
branch = Branch.open(branch_path) |
105 |
for rev_info in branch.iter_merge_sorted_revisions(): |
|
106 |
(rev_id, depth, revno, end_of_merge) = rev_info |
|
107 |
if depth > 0: |
|
108 |
continue
|
|
10245.1.5
by Henning Eggers
Better named variables. |
109 |
revision = branch.repository.get_revision(rev_id) |
110 |
match = automatic_merge_regex.search(revision.message) |
|
111 |
if match is not None: |
|
10253.1.1
by Henning Eggers
Added that little bit of vital extra information to the output. |
112 |
return (revno_str(revno), match.group(1)) |
10245.1.2
by Henning Eggers
Added last automatic merge info. |
113 |
|
114 |
||
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
115 |
def get_opt_parse(): |
116 |
parser = optparse.OptionParser( |
|
117 |
description="Show local revisions that aren't on beta servers.") |
|
118 |
parser.add_option( |
|
10245.1.2
by Henning Eggers
Added last automatic merge info. |
119 |
'-v', '--verbose', action='store_true', help="Show revision log.") |
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
120 |
parser.add_option( |
11677.3.3
by Robert Collins
More edge removal. |
121 |
'--edge', action='store_true', |
122 |
help="Show revisions on edge.") |
|
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
123 |
return parser |
124 |
||
125 |
||
11677.3.3
by Robert Collins
More edge removal. |
126 |
def run(verbose, edge): |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
127 |
parent_dir = get_parent_directory() |
11677.3.3
by Robert Collins
More edge removal. |
128 |
if edge: |
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
129 |
edge_revision = get_edge_revision() |
10224.4.6
by Jonathan Lange
Show a nice message if the servers are up-to-date. |
130 |
stable_branch = os.path.join(parent_dir, 'stable') |
131 |
report_difference_to_server( |
|
132 |
'edge', stable_branch, edge_revision, verbose) |
|
11677.3.3
by Robert Collins
More edge removal. |
133 |
staging_revision = get_staging_revision() |
134 |
db_stable_branch = os.path.join(parent_dir, 'db-stable') |
|
135 |
report_difference_to_server( |
|
136 |
'staging', db_stable_branch, staging_revision, verbose) |
|
137 |
print "Last automatic merge on db-stable r%s was stable r%s." % ( |
|
138 |
get_last_automatic_stable_merge_revno(db_stable_branch)) |
|
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
139 |
|
140 |
||
141 |
def main(argv): |
|
142 |
parser = get_opt_parse() |
|
143 |
options, args = parser.parse_args(argv) |
|
144 |
if args: |
|
145 |
raise UsageError("Don't know what to do with arguments: %s" % args) |
|
11677.3.3
by Robert Collins
More edge removal. |
146 |
run(options.verbose, options.edge) |
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
147 |
|
148 |
||
10224.4.2
by Jonathan Lange
First cut -- a couple of functions that get the revision numbers. |
149 |
if __name__ == '__main__': |
10224.4.4
by Jonathan Lange
Give the script some options & help so that one of edge or staging can be |
150 |
try: |
151 |
sys.exit(main(sys.argv[1:])) |
|
152 |
except UsageError, e: |
|
153 |
print 'ERROR: %s' % e |
|
154 |
sys.exit(1) |