10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python
|
10383.1.1
by Aaron Bentley
Add qa-ready script. |
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 |
||
6 |
import re |
|
7 |
import sys |
|
8 |
||
9 |
from bzrlib.branch import Branch |
|
10 |
from bzrlib.config import LocationConfig |
|
10383.1.4
by Aaron Bentley
Handle out-of-date local mirrors better. |
11 |
from bzrlib.errors import NoSuchRevision |
10383.1.1
by Aaron Bentley
Add qa-ready script. |
12 |
from bzrlib.transport import get_transport |
13 |
||
14 |
||
15 |
class UsageError(Exception): |
|
16 |
"""Raised when the user makes a dumb error."""
|
|
17 |
||
18 |
||
19 |
def get_staging_revision(): |
|
20 |
"""Get the revision of db-stable deployed on staging.
|
|
21 |
||
22 |
:return: The staging revno as an int. Corresponds to a revision of
|
|
23 |
lp:launchpad/db-stable.
|
|
24 |
"""
|
|
25 |
t = get_transport('https://staging.launchpad.net/') |
|
26 |
last_line = t.get_bytes('successful-updates.txt').splitlines()[-1] |
|
27 |
return int(last_line.split()[-1]) |
|
28 |
||
29 |
||
30 |
def get_edge_revision(): |
|
31 |
"""Get the revision of stable deployed on edge.
|
|
32 |
||
33 |
:return: The edge revno as an int. Corresponds to a revision of
|
|
34 |
lp:launchpad/stable.
|
|
35 |
"""
|
|
36 |
t = get_transport('https://edge.launchpad.net/') |
|
37 |
html = t.get_bytes('index.html') |
|
11047.1.3
by Brad Crittenden
Make the revision regex more specific so it doesn't match any string like 'rdddd'. |
38 |
revision_re = re.compile(r' r(\d+)$') |
10383.1.1
by Aaron Bentley
Add qa-ready script. |
39 |
for line in html.splitlines(): |
40 |
matches = revision_re.search(line) |
|
41 |
if matches: |
|
42 |
return int(matches.group(1)) |
|
43 |
raise ValueError("Could not find revision number on edge home page") |
|
44 |
||
45 |
||
10383.1.2
by Aaron Bentley
Update from review. |
46 |
def is_present(local_branch, deployed_location, deployed_revno): |
47 |
local_mirror = LocationConfig(deployed_location).get_user_option( |
|
48 |
'local_location') |
|
49 |
if local_mirror is None: |
|
50 |
print ( |
|
51 |
'Please configure a local_location for %s in locations.conf ' |
|
52 |
'to improve performance.' % deployed_location) |
|
53 |
deployed_branch = Branch.open(deployed_location) |
|
54 |
else: |
|
55 |
deployed_branch = Branch.open(local_mirror) |
|
10383.1.4
by Aaron Bentley
Handle out-of-date local mirrors better. |
56 |
deployed_branch.lock_write() |
10383.1.2
by Aaron Bentley
Update from review. |
57 |
try: |
10383.1.4
by Aaron Bentley
Handle out-of-date local mirrors better. |
58 |
try: |
59 |
deployed_rev_id = deployed_branch.get_rev_id(deployed_revno) |
|
60 |
except NoSuchRevision: |
|
61 |
if local_mirror is None: |
|
62 |
raise
|
|
63 |
else: |
|
64 |
remote = Branch.open(deployed_location) |
|
65 |
remote.lock_read() |
|
66 |
try: |
|
67 |
deployed_rev_id = remote.get_rev_id(deployed_revno) |
|
68 |
print "Mirror %s is out of date." % deployed_branch.base |
|
69 |
if not deployed_branch.repository.has_revision( |
|
70 |
deployed_rev_id): |
|
71 |
deployed_branch.repository.fetch( |
|
72 |
remote.repository, deployed_rev_id) |
|
73 |
assert deployed_branch.repository.has_revision( |
|
74 |
deployed_rev_id) |
|
75 |
finally: |
|
76 |
remote.unlock() |
|
10492.1.1
by Aaron Bentley
Swap order for get_graph. |
77 |
graph = deployed_branch.repository.get_graph(local_branch.repository) |
10383.1.2
by Aaron Bentley
Update from review. |
78 |
return graph.is_ancestor(local_branch.last_revision(), deployed_rev_id) |
79 |
finally: |
|
80 |
deployed_branch.unlock() |
|
81 |
||
82 |
||
83 |
||
10383.1.1
by Aaron Bentley
Add qa-ready script. |
84 |
stable = 'bzr+ssh://bazaar.launchpad.net/~launchpad-pqm/launchpad/stable' |
85 |
dbstable = 'bzr+ssh://bazaar.launchpad.net/~launchpad-pqm/launchpad/db-stable' |
|
86 |
def main(argv): |
|
87 |
if len(sys.argv) > 1: |
|
88 |
location = sys.argv[1] |
|
89 |
else: |
|
90 |
location = '.' |
|
91 |
b = Branch.open_containing(location)[0] |
|
92 |
b.lock_read() |
|
93 |
try: |
|
94 |
print 'Branch: %s' % b.base |
|
95 |
print 'Deployed on edge: %s' % is_present( |
|
96 |
b, stable, get_edge_revision()) |
|
97 |
print 'Deployed on staging: %s' % is_present( |
|
98 |
b, dbstable, get_staging_revision()) |
|
99 |
finally: |
|
100 |
b.unlock() |
|
101 |
||
102 |
||
103 |
if __name__ == '__main__': |
|
104 |
try: |
|
105 |
sys.exit(main(sys.argv[1:])) |
|
106 |
except UsageError, e: |
|
107 |
print 'ERROR: %s' % e |
|
108 |
sys.exit(1) |