Merge lp:~jml/launchpad/watts-on-second into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~jml/launchpad/watts-on-second
Merge into: lp:launchpad
Diff against target: 125 lines (+121/-0)
1 file modified
utilities/on-edge (+121/-0)
To merge this branch: bzr merge lp:~jml/launchpad/watts-on-second
Reviewer Review Type Date Requested Status
Canonical Launchpad Engineering Pending
Review via email: mp+18420@code.launchpad.net

Commit message

Add an 'on-edge' utility script that shows which revisions are being run on staging and edge.

To post a comment you must log in.
Revision history for this message
Jonathan Lange (jml) wrote :

Hello,

This amusingly-named branch adds a new amusingly-named utility script called 'on-edge'. This script will tell you which revision is being run on edge (get it?) and also which revision is being run on staging.

Furthermore, if you run it in verbose mode, it will tell you which revisions edge & staging are missing.

It's a bit slow and clunky, and relies on a conventional branch layout (I'm afraid abentley won't be able to use it), but it's probably useful enough to land as-is.

jml

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

It looks good and useful. The regex to find the edge revno seems extremely fragile, but I can't really see how to do much better.

Please land.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'utilities/on-edge'
2--- utilities/on-edge 1970-01-01 00:00:00 +0000
3+++ utilities/on-edge 2010-02-01 23:45:26 +0000
4@@ -0,0 +1,121 @@
5+#!/usr/bin/python2.5
6+#
7+# Copyright 2010 Canonical Ltd. This software is licensed under the
8+# GNU Affero General Public License version 3 (see the file LICENSE).
9+
10+"""Usage: on-edge [-v] [--edge-only] [--staging-only]
11+
12+This script consults the edge and staging servers to determine which revisions
13+they are running. Once it knows that, it prints a log of all the revisions of
14+stable and db-stable respectively that cannot be found on edge or staging.
15+
16+Note that the stable branch is assumed to be in a directory called 'stable', a
17+sibling to the current branch directory. Likewise, db-stable is assumed to be
18+in '../db-stable', relative to this branch.
19+"""
20+
21+import optparse
22+import os
23+import re
24+import sys
25+
26+from bzrlib.branch import Branch
27+from bzrlib import errors
28+from bzrlib.transport import get_transport
29+
30+
31+class UsageError(Exception):
32+ """Raised when the user makes a dumb error."""
33+
34+
35+def get_staging_revision():
36+ """Get the revision of db-stable deployed on staging.
37+
38+ :return: The staging revno as an int. Corresponds to a revision of
39+ lp:launchpad/db-stable.
40+ """
41+ t = get_transport('https://staging.launchpad.net/')
42+ last_line = t.get_bytes('successful-updates.txt').splitlines()[-1]
43+ return int(last_line.split()[-1])
44+
45+
46+def get_edge_revision():
47+ """Get the revision of stable deployed on edge.
48+
49+ :return: The edge revno as an int. Corresponds to a revision of
50+ lp:launchpad/stable.
51+ """
52+ t = get_transport('https://edge.launchpad.net/')
53+ html = t.get_bytes('index.html')
54+ revision_re = re.compile(r'\(r(\d+)\)')
55+ for line in html.splitlines():
56+ matches = revision_re.search(line)
57+ if matches:
58+ return int(matches.group(1))
59+ raise ValueError("Could not find revision number on edge home page")
60+
61+
62+def get_parent_directory():
63+ """Return the parent directory of the current branch."""
64+ this_file = os.path.abspath(__file__)
65+ return os.path.dirname(os.path.dirname(os.path.dirname(this_file)))
66+
67+
68+def report_difference_to_server(server, branch_path, revno, verbose):
69+ branch = Branch.open(branch_path)
70+ print '%s is running %s r%s' % (server, branch.nick, revno)
71+ try:
72+ branch.dotted_revno_to_revision_id(str(revno + 1))
73+ except errors.NoSuchRevision:
74+ print '%s is up-to-date' % (server,)
75+ else:
76+ if verbose:
77+ command = 'bzr log -r%s.. %s' % (revno, branch_path)
78+ os.system(command)
79+ print
80+
81+
82+def get_opt_parse():
83+ parser = optparse.OptionParser(
84+ description="Show local revisions that aren't on beta servers.")
85+ parser.add_option(
86+ '-v', '--verbose', action='store_true', help="Show revision log")
87+ parser.add_option(
88+ '--edge-only', action='store_true',
89+ help="Only show revisions not on edge. Do not consult staging.")
90+ parser.add_option(
91+ '--staging-only', action='store_true',
92+ help="Only show revisions not on staging. Do not consult edge.")
93+ return parser
94+
95+
96+def run(verbose, edge_only, staging_only):
97+ if edge_only and staging_only:
98+ raise UsageError("Cannot show only edge and only staging.")
99+ parent_dir = get_parent_directory()
100+ if not staging_only:
101+ edge_revision = get_edge_revision()
102+ stable_branch = os.path.join(parent_dir, 'stable')
103+ report_difference_to_server(
104+ 'edge', stable_branch, edge_revision, verbose)
105+ if not edge_only:
106+ staging_revision = get_staging_revision()
107+ db_stable_branch = os.path.join(parent_dir, 'db-stable')
108+ report_difference_to_server(
109+ 'staging', db_stable_branch, staging_revision, verbose)
110+
111+
112+def main(argv):
113+ parser = get_opt_parse()
114+ options, args = parser.parse_args(argv)
115+ if args:
116+ raise UsageError("Don't know what to do with arguments: %s" % args)
117+ run(options.verbose, options.edge_only, options.staging_only)
118+
119+
120+if __name__ == '__main__':
121+ try:
122+ sys.exit(main(sys.argv[1:]))
123+ except UsageError, e:
124+ print 'ERROR: %s' % e
125+ sys.exit(1)