~launchpad-pqm/launchpad/devel

9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
#
4
# Copyright 2009 Canonical Ltd.  This software is licensed under the
5
# GNU Affero General Public License version 3 (see the file LICENSE).
6
9373.1.3 by Karl Fogel
* utilities/community-contributions.py: Update doc string to start
7
"""Show what Launchpad community contributors have done.
8
9
Trawl a Launchpad branch's history to detect contributions by non-Canonical
10
developers, then update https://dev.launchpad.net/Contributions accordingly.
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
11
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
12
Usage: community-contributions.py [options] --devel=PATH --db-devel=DB_PATH
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
13
14
Requirements:
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
15
       You need both the 'devel' and 'db-devel' branches of Launchpad
16
       available locally (see https://dev.launchpad.net/Getting),
17
       your ~/.moin_ids file must be set up correctly, and you need
18
       editmoin.py (if you don't have it, the error message will tell
19
       you where to get it).
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
20
21
Options:
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
22
  -q               Print no non-essential messages.
23
  -h, --help       Print this help.
24
  --dry-run        Don't update the wiki, just print the new page to stdout.
25
  --draft-run      Update the wiki "/Draft" page instead of the real page.
26
  --devel=PATH     Specify the filesystem path to the 'devel' branch.
27
  --db-devel=PATH  Specify the filesystem path to the 'db-devel' branch.
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
28
"""
29
30
# General notes:
31
#
32
# The Right Way to do this would probably be to output some kind of
33
# XML format, and then have a separate converter script transform that
34
# to wiki syntax and update the wiki page.  But as the wiki is our
35
# only consumer right now, we just output wiki syntax and update the
36
# wiki page directly, premature generalization being the root of all
37
# evil.
38
#
39
# For understanding the code, you may find it helpful to see
40
# bzrlib/log.py and http://bazaar-vcs.org/Integrating_with_Bazaar.
41
9373.1.16 by Karl Fogel
* utilities/community-contributions.py: Sort imports, as per jml's review.
42
import getopt
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
43
import re
44
import sys
9373.1.16 by Karl Fogel
* utilities/community-contributions.py: Sort imports, as per jml's review.
45
46
from bzrlib import log
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
47
from bzrlib.branch import Branch
48
from bzrlib.osutils import format_date
49
14612.2.6 by William Grant
utilities
50
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
51
try:
52
    from editmoin import editshortcut
53
except:
10281.1.2 by Jamal Fanaian
Fixed lint messages regardling line length
54
    sys.stderr.write("""ERROR: Unable to import from 'editmoin'. How to solve:
9521.1.1 by Karl Fogel
In utilities/community-contributions.py, update error message to give
55
Get editmoin.py from launchpadlib's "contrib/" directory:
56
57
  http://bazaar.launchpad.net/~lazr-developers/launchpadlib/trunk/annotate/head%3A/contrib/editmoin.py
58
59
(Put it in the same directory as this script and everything should work.)
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
60
""")
61
    sys.exit(1)
62
63
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
64
def wiki_encode(x):
65
    """Encode a Unicode string for display on the wiki."""
66
    return x.encode('utf-8', 'xmlcharrefreplace')
67
68
69
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
70
# The output contains two classes of contributors: people who don't
71
# work for Canonical at all, and people who do work for Canonical but
72
# not on the Launchpad team.
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
73
#
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
74
# People who used to work for Canonical on the Launchpad team are not
75
# shown in the output, since they don't help us from a "contributions
76
# from outside the team" perspective, so they are listed as known
77
# Canonical Launchpad developers even though they aren't actually on
78
# the team anymore.  There may be a few former Canonicalites who
79
# didn't work on the Launchpad team but who still contributed to
80
# Launchpad; most of them would have done so before Launchpad was open
81
# sourced in July 2009, though, and since this script is really about
82
# showing things that have happened since Launchpad was open sourced,
83
# they may be listed as Launchpad team members anyway just to ensure
84
# they don't appear in the output.
85
#
86
# (As time goes on, that assumption will be less and less correct, of
87
# course, and eventually we may wish to do something about it.  Also,
88
# there are some people, e.g. Jelmer Vernooij, who made contributions
89
# to Launchpad before working at Canonical, but who now work on the
90
# Launchpad team at Canonical.  Ideally, each potentially listable
91
# contributor could have a set of roles, and a date range associated
92
# with each role... but that would be overkill for this script.  That
93
# last 2% of correctness would cost way too much to achieve.)
94
#
10224.15.1 by Karl Fogel
* utilities/community-contributions.py
95
# XXX: Karl Fogel 2009-09-10 bug=513608: We should use launchpadlib
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
96
# to consult Launchpad itself to find out who's a Canonical developer,
97
# and within that who's a Launchpad developer.
98
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
99
100
# If a contributor's address contains this, then they are or were a
101
# Canonical developer -- maybe on the Launchpad team, maybe not.
102
CANONICAL_ADDR = wiki_encode(u" {_AT_} canonical.com")
103
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
104
# People on the Canonical Launchpad team.
105
known_canonical_lp_devs = \
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
106
    [wiki_encode(x) for x in (u'Aaron Bentley',
107
                              u'Abel Deuring',
108
                              u'Andrew Bennetts',
109
                              u'Barry Warsaw',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
110
                              u'Benji York',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
111
                              u'Bjorn Tillenius',
112
                              u'Björn Tillenius',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
113
                              u'Brad Bollenbach',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
114
                              u'Brad Crittenden',
115
                              u'Brian Fromme',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
116
                              u'Canonical.com Patch Queue Manager',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
117
                              u'Carlos Perello Marin',
118
                              u'Carlos Perelló Marín',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
119
                              u'carlos.perello {_AT_} canonical.com',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
120
                              u'Celso Providelo',
121
                              u'Christian Reis',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
122
                              u'Christian Robottom Reis',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
123
                              u'kiko {_AT_} beetle',
124
                              u'Curtis Hovey',
125
                              u'Dafydd Harries',
126
                              u'Danilo Šegan',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
127
                              u'Danilo Segan',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
128
                              u'david <david {_AT_} marvin>',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
129
                              u'Данило Шеган',
130
                              u'данило шеган',
131
                              u'Daniel Silverstone',
132
                              u'David Allouche',
133
                              u'Deryck Hodge',
134
                              u'Diogo Matsubara',
135
                              u'Edwin Grubbs',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
136
                              u'Elliot Murphy',
137
                              u'Firstname Lastname',
14503.1.1 by William Grant
Add frankban to the Canonical LP devs list.
138
                              u'Francesco Banconi',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
139
                              u'Francis Lacoste',
140
                              u'Francis J. Lacoste',
141
                              u'Gary Poster',
142
                              u'Gavin Panella',
143
                              u'Graham Binns',
144
                              u'Guilherme Salgado',
145
                              u'Henning Eggers',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
146
                              u'Herb McNew',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
147
                              u'Huw Wilkins',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
148
                              u'Ian Booth',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
149
                              u'James Henstridge',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
150
                              u'j.c.sackett',
151
                              u'jc',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
152
                              u'Jelmer Vernooij',
153
                              u'Jeroen Vermeulen',
154
                              u'Jeroen T. Vermeulen',
155
                              u'Joey Stanford',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
156
                              u'Jon Sackett',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
157
                              u'Jonathan Lange',
11702.2.2 by Brian Murray
j.c.sackett works on Launchpad
158
                              u'j.c.sackett',
159
                              u'jonathan.sackett {_AT_} canonical.com',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
160
                              u'jml {_AT_} canonical.com',
161
                              u'jml {_AT_} mumak.net',
162
                              u'Jonathan Knowles',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
163
                              u'jonathan.knowles {_AT_} canonical.com',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
164
                              u'Julian Edwards',
165
                              u'Karl Fogel',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
166
                              u'Launch Pad',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
167
                              u'Launchpad APA',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
168
                              u'Launchpad Developers',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
169
                              u'Launchpad Patch Queue Manager',
170
                              u'Launchpad PQM Bot',
171
                              u'Leonard Richardson',
172
                              u'Malcolm Cleaton',
173
                              u'Maris Fogels',
174
                              u'Mark Shuttleworth',
175
                              u'Martin Albisetti',
176
                              u'Matt Zimmerman',
177
                              u'Matthew Paul Thomas',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
178
                              u'Matthew Thomas',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
179
                              u'Matthew Revell',
180
                              u'matthew.revell {_AT_} canonical.com',
181
                              u'Michael Hudson',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
182
                              u'michael.hudson {_AT_} canonical.com',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
183
                              u'Michael Nelson',
184
                              u'Muharem Hrnjadovic',
185
                              u'muharem {_AT_} canonical.com',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
186
                              u'Patch Queue Manager',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
187
                              u'Paul Hummer',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
188
                              u'Raphael Badin',
189
                              u'Raphaël Badin',
14358.1.1 by William Grant
Add rickh to the lp devs list.
190
                              u'Richard Harding',
191
                              u'Rick Harding',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
192
                              u'Robert Collins',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
193
                              u'root <root {_AT_} ubuntu>',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
194
                              u'rvb',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
195
                              u'Stuart Bishop',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
196
                              u'Steve Alexander',
11057.1.1 by Jonathan Lange
Correct some bugs with the Launchpad data
197
                              u'Steve Kowalik',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
198
                              u'Steve McInerney',
199
                              u'<steve {_AT_} stedee.id.au>',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
200
                              u'test {_AT_} canonical.com',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
201
                              u'Tom Haddon',
202
                              u'Tim Penhey',
203
                              u'Tom Berger',
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
204
                              u'ubuntu <ubuntu {_AT_} lp-dev>',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
205
                              u'Ursula Junque',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
206
                              u'William Grant <william.grant {_AT_} canonical.com>',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
207
                              )]
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
208
209
# People known to work for Canonical but not on the Launchpad team.
210
# Anyone with "@canonical.com" in their email address is considered to
211
# work for Canonical, but some people occasionally submit changes from
212
# their personal email addresses; this list contains people known to
213
# do that, so we can treat them appropriately in the output.
214
known_canonical_non_lp_devs = \
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
215
    [wiki_encode(x) for x in (u'Adam Conrad',
216
                              u'Andrew Bennetts',
217
                              u'Anthony Lenton',
218
                              u'Cody Somerville',
219
                              u'Cody A.W. Somerville',
220
                              u'David Murphy',
11057.1.1 by Jonathan Lange
Correct some bugs with the Launchpad data
221
                              u'Didier Roche',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
222
                              u'Elliot Murphy',
223
                              u'Gabriel Neuman gneuman {_AT_} async.com',
224
                              u'Gustavo Niemeyer',
225
                              u'James Henstridge',
11057.1.1 by Jonathan Lange
Correct some bugs with the Launchpad data
226
                              u'James Westby',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
227
                              u'John Lenton',
228
                              u'Kees Cook',
229
                              u'LaMont Jones',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
230
                              u'Loïc Minier',
11057.1.1 by Jonathan Lange
Correct some bugs with the Launchpad data
231
                              u'Martin Pitt',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
232
                              u'Martin Pool',
233
                              u'Matt Zimmerman',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
234
                              u'mbp {_AT_} sourcefrog.net',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
235
                              u'Michael Casadevall',
236
                              u'Michael Vogt',
237
                              u'Sidnei da Silva',
10667.1.1 by Karl Fogel
* utilities/community-contributions.py
238
                              u'Dustin Kirkland',
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
239
                              u'John Arbash Meinel',
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
240
                              )]
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
241
11057.1.2 by Jonathan Lange
Flakes, space
242
# Some people have made commits using various names and/or email
10281.1.1 by Jamal Fanaian
Created name map for community-contributions to merge people using different names/email addresses.
243
# addresses, so this map will be used to merge them accordingly.
10301.1.8 by Karl Fogel
Clean up the way we do string encoding. No functional change.
244
# The map is initialized from this list of pairs, where each pair is
245
# of the form (CONTRIBUTOR_AS_SEEN, UNIFYING_IDENTITY_FOR_CONTRIBUTOR).
246
merge_names_pairs = (
247
    (u'Jamal Fanaian <jfanaian {_AT_} gmail.com>',
248
     u'Jamal Fanaian <jamal.fanaian {_AT_} gmail.com>'),
249
    (u'Jamal Fanaian <jamal {_AT_} jfvm1>',
250
     u'Jamal Fanaian <jamal.fanaian {_AT_} gmail.com>'),
251
    (u'LaMont Jones <lamont {_AT_} rover3>',
252
     u'LaMont Jones <lamont {_AT_} debian.org>'),
10456.1.12 by William Grant
Start at revision 1 of both branches, and update the name maps for the older revisions.
253
    (u'Sidnei <sidnei {_AT_} ubuntu>',
254
     u'Sidnei da Silva <sidnei.da.silva {_AT_} canonical.com>'),
255
    (u'Sidnei da Silva <sidnei.da.silva {_AT_} gmail.com>',
256
     u'Sidnei da Silva <sidnei.da.silva {_AT_} canonical.com>'),
257
    (u'Sidnei da Silva <sidnei {_AT_} canonical.com>',
258
     u'Sidnei da Silva <sidnei.da.silva {_AT_} canonical.com>'),
259
    (u'Adam Conrad <adconrad {_AT_} ziggup>',
260
     u'Adam Conrad <adconrad {_AT_} 0c3.net>'),
261
    (u'Elliot Murphy <elliot {_AT_} elliotmurphy.com>',
262
     u'Elliot Murphy <elliot {_AT_} canonical.com>'),
263
    (u'Elliot Murphy <elliot.murphy {_AT_} canonical.com>',
264
     u'Elliot Murphy <elliot {_AT_} canonical.com>'),
265
    (u'Cody Somerville <cody-somerville {_AT_} mercurial>',
266
     u'Cody A.W. Somerville <cody.somerville {_AT_} canonical.com>'),
267
    (u'Adam Conrad <adconrad {_AT_} chinstrap>',
268
     u'Adam Conrad <adconrad {_AT_} 0c3.net>'),
269
    (u'Adam Conrad <adconrad {_AT_} cthulhu>',
270
     u'Adam Conrad <adconrad {_AT_} 0c3.net>'),
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
271
    (u'James Westby <james.westby {_AT_} linaro.org>',
13531.1.2 by William Grant
Update community-contributions.py's name maps.
272
     u'James Westby <james.westby {_AT_} canonical.com>'),
11728.1.1 by William Grant
Update community-contributions.py's list Launchpad and Canonical developers, and add some more email merges.
273
    (u'Bryce Harrington <bryce {_AT_} canonical.com>',
274
     u'Bryce Harrington <bryce.harrington {_AT_} canonical.com>'),
275
    (u'Dustin Kirkland <kirkland {_AT_} x200>',
276
     u'Dustin Kirkland <kirkland {_AT_} canonical.com>'),
277
    (u'Anthony Lenton <antoniolenton {_AT_} gmail.com>',
278
     u'Anthony Lenton <anthony.lenton {_AT_} canonical.com>'),
279
    (u'Steve Kowalik <steven {_AT_} quelled>',
280
     u'Steve Kowalik <steve.kowalik {_AT_} canonical.com>'),
281
    (u'Steve Kowalik <stevenk {_AT_} ubuntu.com>',
282
     u'Steve Kowalik <steve.kowalik {_AT_} canonical.com>'),
283
    (u'jc <jc {_AT_} launchpad>',
284
     u'j.c.sackett <jonathan.sackett {_AT_} canonical.com>'),
285
    (u'Jon Sackett <jc {_AT_} jabberwocky>',
286
     u'j.c.sackett <jonathan.sackett {_AT_} canonical.com>'),
287
    (u'John Arbash Meinel <jameinel {_AT_} falco-lucid>',
288
     u'John Arbash Meinel <john {_AT_} arbash-meinel.com>'),
289
    (u'Martin Pool <mbp {_AT_} sourcefrog.net>',
290
     u'Martin Pool <mbp {_AT_} canonical.com>'),
13531.1.2 by William Grant
Update community-contributions.py's name maps.
291
    (u'mbp {_AT_} sourcefrog.net',
292
     u'Martin Pool <mbp {_AT_} canonical.com>'),
293
    (u'mbp {_AT_} canonical.com',
294
     u'Martin Pool <mbp {_AT_} canonical.com>'),
11728.1.2 by William Grant
Add another email mapping.
295
    (u'Andrea Corbellini <corbellini.andrea {_AT_} gmail.com>',
296
     u'Andrea Corbellini <andrea.corbellini {_AT_} beeseek.org>'),
13531.1.2 by William Grant
Update community-contributions.py's name maps.
297
    (u'Luke Faraone <luke {_AT_} faraone.cc',
298
     u'Luke Faraone <luke {_AT_} faraone.cc>'),
10301.1.8 by Karl Fogel
Clean up the way we do string encoding. No functional change.
299
    )
300
# Then put it in dictionary form with the correct encodings.
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
301
merge_names_map = dict((wiki_encode(a), wiki_encode(b))
302
                       for a, b in merge_names_pairs)
10301.1.8 by Karl Fogel
Clean up the way we do string encoding. No functional change.
303
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
304
305
class ContainerRevision():
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
306
    """A wrapper for a top-level LogRevision containing child LogRevisions."""
307
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
308
    def __init__(self, top_lr, branch_info):
10456.1.7 by William Grant
Address review comments.
309
        """Create a new ContainerRevision.
310
311
        :param top_lr: The top-level LogRevision.
312
        :param branch_info: The BranchInfo for the containing branch.
313
        """
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
314
        self.top_rev = top_lr       # e.g. LogRevision for r9371.
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
315
        self.contained_revs = []    # e.g. [ {9369.1.1}, {9206.4.4}, ... ],
316
                                    # where "{X}" means "LogRevision for X"
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
317
        self.branch_info = branch_info
318
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
319
    def add_subrev(self, lr):
320
        """Add a descendant child of this container revision."""
321
        self.contained_revs.append(lr)
322
323
    def __str__(self):
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
324
        timestamp = self.top_rev.rev.timestamp
325
        timezone = self.top_rev.rev.timezone
326
        message = self.top_rev.rev.message or "(NO LOG MESSAGE)"
327
        rev_id = self.top_rev.rev.revision_id or "(NO REVISION ID)"
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
328
        if timestamp:
329
            date_str = format_date(timestamp, timezone or 0, 'original')
330
        else:
331
            date_str = "(NO DATE)"
332
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
333
        rev_url_base = "http://bazaar.launchpad.net/%s/revision/" % (
10456.1.7 by William Grant
Address review comments.
334
            self.branch_info.loggerhead_path)
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
335
336
        # In loggerhead, you can use either a revision number or a
337
        # revision ID.  In other words, these would reach the same page:
338
        #
339
        # http://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel/\
340
        # revision/9202
341
        #
342
        #   -and-
343
        #
10281.1.2 by Jamal Fanaian
Fixed lint messages regardling line length
344
        # http://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel/\
345
        # revision/launchpad@pqm.canonical.com-20090821221206-\
346
        # ritpv21q8w61gbpt
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
347
        #
348
        # In our links, even when the link text is a revnum, we still
349
        # use a rev-id for the target.  This is both so that the URL will
350
        # still work if you manually tweak it (say to "db-devel" from
351
        # "devel") and so that hovering over a revnum on the wiki page
352
        # will give you some information about it before you click
353
        # (because a rev id often identifies the committer).
354
        rev_id_url = rev_url_base + rev_id
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
355
356
        if len(self.contained_revs) <= 10:
357
            commits_block = "\n ".join(
358
                ["[[%s|%s]]" % (rev_url_base + lr.rev.revision_id, lr.revno)
359
                 for lr in self.contained_revs])
360
        else:
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
361
            commits_block = ("''see the [[%s|full revision]] for details "
362
                             "(it contains %d commits)''"
363
                             % (rev_id_url, len(self.contained_revs)))
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
364
10456.1.7 by William Grant
Address review comments.
365
        name = self.branch_info.name
366
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
367
        text = [
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
368
            " * [[%s|r%s%s]] -- %s\n" % (
369
                rev_id_url, self.top_rev.revno,
13531.1.1 by William Grant
community-contributions.py no longer blows up on Unicode names or messages.
370
                ' (%s)' % name.encode('utf-8') if name else '',
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
371
                date_str),
13531.1.1 by William Grant
community-contributions.py no longer blows up on Unicode names or messages.
372
            " {{{\n%s\n}}}\n" % message.encode('utf-8'),
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
373
            " '''Commits:'''\n ",
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
374
            commits_block,
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
375
            "\n",
376
            ]
377
        return ''.join(text)
11057.1.2 by Jonathan Lange
Flakes, space
378
379
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
380
# "ExternalContributor" is too much to type, so I guess we'll just use this.
381
class ExCon():
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
382
    """A contributor to Launchpad from outside Canonical's Launchpad team."""
9373.1.9 by Karl Fogel
* utilities/community-contributions.py: Blank line after class docstrings.
383
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
384
    def __init__(self, name, is_canonical=False):
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
385
        """Create a new external contributor named 'name'.
386
387
        If 'is_canonical' is True, then this is a contributor from
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
388
        within Canonical, but not on the Launchpad team at Canonical.
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
389
        'name' is something like "Veronica Random <vr {_AT_} example.com>".
390
        """
10301.1.3 by Karl Fogel
Disguise email addresses in the source code.
391
        self.name = name
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
392
        self.is_canonical = is_canonical
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
393
        # If name is "Veronica Random <veronica {_AT_} example.com>",
394
        # then name_as_anchor will be "veronica_random".
395
        self.name_as_anchor = \
396
            re.compile("\\s+").sub("_", name.split("<")[0].strip()).lower()
397
        # All the top-level revisions this contributor is associated with
398
        # (key == value == ContainerRevision).  We use a dictionary
399
        # instead of list to get set semantics; set() would be overkill.
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
400
        self._landings = {}
10456.1.6 by William Grant
Comment on the purpose and usage of seen_revs.
401
        # A map of revision IDs authored by this contributor (probably
402
        # not top-level) to a (LogRevision, ContainerRevision) pair. The
403
        # pair contains details of the shallowest found instance of this
404
        # revision.
10456.1.3 by William Grant
Collect the shallowest authored revisions across all branches for each ExCon, only adding their top-level revs once we've seen everything. This gives sane results by ignoring merges from devel->db-devel and db-devel->devel. The main problem now is that db-devel links will point to devel instead.
405
        self.seen_revs = {}
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
406
407
    def num_landings(self):
408
        """Return the number of top-level landings that include revisions
409
        by this contributor."""
410
        return len(self._landings)
411
412
    def add_top_level_revision(self, cr):
9373.1.11 by Karl Fogel
* utilities/community-contributions.py: Stay within 80 columns.
413
        "Record ContainableRevision CR as associated with this contributor."
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
414
        self._landings[cr] = cr
415
416
    def show_contributions(self):
9373.1.11 by Karl Fogel
* utilities/community-contributions.py: Stay within 80 columns.
417
        "Return a wikified string showing this contributor's contributions."
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
418
        plural = "s"
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
419
        name = self.name
420
        if self.is_canonical:
421
            name = name + " (Canonical developer)"
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
422
        if self.num_landings() == 1:
423
            plural = ""
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
424
        text = [
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
425
            "=== %s ===\n\n" % name,
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
426
            "''%d top-level landing%s:''\n\n" % (self.num_landings(), plural),
427
            ''.join(map(str, sorted(self._landings,
10456.1.1 by William Grant
Order top-level revs by timestamp, not revno string (this broke when we reached r10000).
428
                                    key=lambda x: x.top_rev.rev.timestamp,
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
429
                                    reverse=True))),
430
            "\n",
431
            ]
432
        return ''.join(text)
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
433
434
435
def get_ex_cons(authors, all_ex_cons):
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
436
    """Return a list of ExCon objects corresponding to AUTHORS (a list
437
    of strings).  If there are no external contributors in authors,
438
    return an empty list.
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
439
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
440
    ALL_EX_CONS is a dictionary mapping author names (as received from
441
    the bzr logs, i.e., with email address undisguised) to ExCon objects.
442
    """
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
443
    ex_cons_this_rev = []
10301.1.2 by Karl Fogel
* community-contributions.py
444
    for author in authors:
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
445
        known_canonical_lp_dev = False
446
        known_canonical_non_lp_dev = False
10301.1.3 by Karl Fogel
Disguise email addresses in the source code.
447
        # The authors we list in the source code have their addresses
448
        # disguised (since this source code is public).  We must
449
        # disguise the ones coming from the Bazaar logs in the same way,
450
        # so string matches will work.
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
451
        author = wiki_encode(author)
10301.1.3 by Karl Fogel
Disguise email addresses in the source code.
452
        author = author.replace("@", " {_AT_} ")
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
453
454
        # If someone works/worked for Canonical on the Launchpad team,
455
        # then skip them -- we don't want to show them in the output.
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
456
        for name_fragment in known_canonical_lp_devs:
457
            if name_fragment in author:
458
                known_canonical_lp_dev = True
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
459
                break
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
460
        if known_canonical_lp_dev:
461
            continue
462
463
        # Use the merge names map to merge contributions from the same
464
        # person using alternate names and/or emails.
10301.1.5 by Karl Fogel
* community-contributions.py
465
        author = merge_names_map.get(author, author)
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
466
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
467
        if CANONICAL_ADDR in author:
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
468
            known_canonical_non_lp_dev = True
469
        else:
470
            for name_fragment in known_canonical_non_lp_devs:
471
                if name_fragment in author:
472
                    known_canonical_non_lp_dev = True
473
                    break
474
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
475
        # There's a variant of the Singleton pattern that could be
476
        # used for this, whereby instantiating an ExCon object would
477
        # just get back an existing object if such has already been
478
        # instantiated for this name.  But that would make this code
479
        # non-reentrant, and that's just not cool.
480
        ec = all_ex_cons.get(author, None)
481
        if ec is None:
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
482
            ec = ExCon(author, is_canonical=known_canonical_non_lp_dev)
483
            all_ex_cons[author] = ec
484
        ex_cons_this_rev.append(ec)
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
485
    return ex_cons_this_rev
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
486
487
488
# The LogFormatter abstract class should really be called LogReceiver
489
# or something -- subclasses don't have to be about display.
490
class LogExCons(log.LogFormatter):
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
491
    """Log all the external contributions, by Contributor."""
9373.1.9 by Karl Fogel
* utilities/community-contributions.py: Blank line after class docstrings.
492
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
493
    # See log.LogFormatter documentation.
494
    supports_merge_revisions = True
495
496
    def __init__(self):
497
        super(LogExCons, self).__init__(to_file=None)
498
        # Dictionary mapping author names (with undisguised email
499
        # addresses) to ExCon objects.
9373.1.12 by Karl Fogel
* utilities/community-contributions.py: More formatting and
500
        self.all_ex_cons = {}
9373.1.11 by Karl Fogel
* utilities/community-contributions.py: Stay within 80 columns.
501
        # ContainerRevision object representing most-recently-seen
502
        # top-level rev.
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
503
        self.current_top_level_rev = None
504
        self.branch_info = None
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
505
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
506
    def _toc(self, contributors):
507
        toc_text = []
508
        for val in contributors:
509
            plural = "s"
510
            if val.num_landings() == 1:
511
                plural = ""
512
            toc_text.extend(" 1. [[#%s|%s]] ''(%d top-level landing%s)''\n"
513
                            % (val.name_as_anchor, val.name,
514
                               val.num_landings(), plural))
515
        return toc_text
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
516
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
517
    def result(self):
9373.1.11 by Karl Fogel
* utilities/community-contributions.py: Stay within 80 columns.
518
        "Return a moin-wiki-syntax string with TOC followed by contributions."
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
519
10456.1.6 by William Grant
Comment on the purpose and usage of seen_revs.
520
        # Go through the shallowest authored revisions and add their
521
        # top level revisions.
10456.1.3 by William Grant
Collect the shallowest authored revisions across all branches for each ExCon, only adding their top-level revs once we've seen everything. This gives sane results by ignoring merges from devel->db-devel and db-devel->devel. The main problem now is that db-devel links will point to devel instead.
522
        for excon in self.all_ex_cons.values():
523
            for rev, top_level_rev in excon.seen_revs.values():
524
                excon.add_top_level_revision(top_level_rev)
525
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
526
        # Divide contributors into non-Canonical and Canonical.
527
        non_canonical_contributors = [x for x in self.all_ex_cons.values()
528
                                      if not x.is_canonical]
529
        canonical_contributors = [x for x in self.all_ex_cons.values()
530
                                      if x.is_canonical]
531
        # Sort them.
532
        non_canonical_contributors = sorted(non_canonical_contributors,
533
                                            key=lambda x: x.num_landings(),
534
                                            reverse=True)
535
        canonical_contributors = sorted(canonical_contributors,
536
                                        key=lambda x: x.num_landings(),
537
                                        reverse=True)
538
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
539
        text = [
540
            "-----\n\n",
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
541
            "= Who =\n\n"
542
            "== Contributors (from outside Canonical) ==\n\n",
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
543
            ]
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
544
        text.extend(self._toc(non_canonical_contributors))
545
        text.extend([
546
            "== Contributors (from Canonical, but outside "
547
            "the Launchpad team) ==\n\n",
548
            ])
549
        text.extend(self._toc(canonical_contributors))
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
550
        text.extend(["\n-----\n\n",
551
                     "= What =\n\n",
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
552
                     "== Contributions (from outside Canonical) ==\n\n",
553
                     ])
554
        for val in non_canonical_contributors:
555
            text.extend("<<Anchor(%s)>>\n" % val.name_as_anchor)
556
            text.extend(val.show_contributions())
557
        text.extend(["== Contributions (from Canonical, but outside "
558
                     "the Launchpad team) ==\n\n",
559
                     ])
560
        for val in canonical_contributors:
9373.1.13 by Karl Fogel
* utilities/community-contributions.py:
561
            text.extend("<<Anchor(%s)>>\n" % val.name_as_anchor)
562
            text.extend(val.show_contributions())
563
        return ''.join(text)
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
564
565
    def log_revision(self, lr):
566
        """Log a revision.
567
        :param  lr:   The LogRevision to be logged.
568
        """
569
        # We count on always seeing the containing rev before its subrevs.
570
        if lr.merge_depth == 0:
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
571
            self.current_top_level_rev = ContainerRevision(
572
                lr, self.branch_info)
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
573
        else:
574
            self.current_top_level_rev.add_subrev(lr)
575
        ex_cons = get_ex_cons(lr.rev.get_apparent_authors(), self.all_ex_cons)
576
        for ec in ex_cons:
10456.1.6 by William Grant
Comment on the purpose and usage of seen_revs.
577
            # If this is the shallowest sighting of a revision, note it
10456.1.9 by William Grant
Comment on shallowness a little more.
578
            # in the ExCon. We may see the revision at different depths
579
            # in different branches, mostly when one of the trunks is
580
            # merged into the other. We only care about the initial
581
            # merge, which should be shallowest.
10456.1.3 by William Grant
Collect the shallowest authored revisions across all branches for each ExCon, only adding their top-level revs once we've seen everything. This gives sane results by ignoring merges from devel->db-devel and db-devel->devel. The main problem now is that db-devel links will point to devel instead.
582
            if (lr.rev.revision_id not in ec.seen_revs or
10456.1.11 by William Grant
Wrap two long lines.
583
                lr.merge_depth <
584
                    ec.seen_revs[lr.rev.revision_id][0].merge_depth):
585
                ec.seen_revs[lr.rev.revision_id] = (
586
                    lr, self.current_top_level_rev)
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
587
588
10456.1.7 by William Grant
Address review comments.
589
class BranchInfo:
590
    """A collection of information about a branch."""
591
10456.1.13 by William Grant
Remove start_revno support.
592
    def __init__(self, path, loggerhead_path, name=None):
10456.1.7 by William Grant
Address review comments.
593
        """Create a new BranchInfo.
594
595
        :param path: Filesystem path to the branch.
596
        :param loggerhead_path: The path to the branch on Launchpad's
597
            Loggerhead instance.
598
        :param name: Optional name to identify the branch's revisions in the
599
            produced document.
600
        """
601
        self.path = path
602
        self.name = name
603
        self.loggerhead_path = loggerhead_path
604
605
9373.1.15 by Karl Fogel
* utilities/community-contributions.py: Add name to "XXX" comments, as
606
# XXX: Karl Fogel 2009-09-10: is this really necessary?  See bzrlib/log.py.
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
607
log.log_formatter_registry.register('external_contributors', LogExCons,
608
                                    'Find non-Canonical contributors.')
609
610
611
def usage():
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
612
    print __doc__
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
613
614
10301.1.13 by Karl Fogel
Various tweaks, based on Jonathan Lange's review.
615
# Use backslashes to suppress newlines because this is wiki syntax,
616
# not HTML, so newlines would be rendered as line breaks.
9373.1.14 by Karl Fogel
* utilities/community-contributions.py (page_intro): Format source
617
page_intro = """This page shows contributions to Launchpad from \
10301.1.4 by Karl Fogel
Show Canonical contributors from outside the Launchpad team.
618
developers not on the Launchpad team at Canonical.
619
10456.1.5 by William Grant
Fix obsolete comments, and add a couple more.
620
It lists all changes that have landed in the Launchpad ''devel'' \
621
or ''db-devel'' trees (see the [[Trunk|trunk explanation]] for more).
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
622
13541.2.1 by William Grant
kfogel no longer runs community-contributions.py. I do.
623
~-''Note for maintainers: this page is updated every hour by a \
624
cron job running as wgrant on devpad (though if there are no new \
9373.1.14 by Karl Fogel
* utilities/community-contributions.py (page_intro): Format source
625
contributions, the page's timestamp won't change).  The code that \
626
generates this page is \
627
[[http://bazaar.launchpad.net/%7Elaunchpad-pqm/launchpad/devel/annotate/head%3A/utilities/community-contributions.py|utilities/community-contributions.py]] \
628
in the Launchpad tree.''-~
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
629
630
"""
631
632
def main():
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
633
    quiet = False
634
    dry_run = False
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
635
    devel_path = None
636
    db_devel_path = None
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
637
10301.1.1 by Karl Fogel
* community-contributions.py
638
    wiki_dest = "https://dev.launchpad.net/Contributions"
639
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
640
    if len(sys.argv) < 3:
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
641
        usage()
642
        sys.exit(1)
643
644
    try:
645
        opts, args = getopt.getopt(sys.argv[1:], '?hq',
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
646
                                   ['help', 'usage', 'dry-run', 'draft-run',
647
                                    'devel=', 'db-devel='])
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
648
    except getopt.GetoptError, e:
649
        sys.stderr.write("ERROR: " + str(e) + '\n\n')
650
        usage()
651
        sys.exit(1)
652
653
    for opt, value in opts:
654
        if opt == '--help' or opt == '-h' or opt == '-?' or opt == 'usage':
655
            usage()
656
            sys.exit(0)
657
        elif opt == '-q' or opt == '--quiet':
658
            quiet = True
659
        elif opt == '--dry-run':
660
            dry_run = True
10301.1.1 by Karl Fogel
* community-contributions.py
661
        elif opt == '--draft-run':
662
            wiki_dest += "/Draft"
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
663
        elif opt == '--devel':
664
            devel_path = value
665
        elif opt == '--db-devel':
666
            db_devel_path = value
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
667
668
    # Ensure we have the arguments we need.
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
669
    if not devel_path or not db_devel_path:
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
670
        sys.stderr.write("ERROR: paths to Launchpad devel and db-devel "
10456.1.10 by William Grant
Take devel and db-devel paths as options instead of arguments, to make ordering more obvious.
671
                         "branches required as options\n")
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
672
        usage()
673
        sys.exit(1)
674
10456.1.7 by William Grant
Address review comments.
675
    branches = (
676
        BranchInfo(
10456.1.13 by William Grant
Remove start_revno support.
677
            devel_path, '~launchpad-pqm/launchpad/devel'),
10456.1.7 by William Grant
Address review comments.
678
        BranchInfo(
10456.1.13 by William Grant
Remove start_revno support.
679
            db_devel_path, '~launchpad-pqm/launchpad/db-devel', 'db-devel'),
10456.1.7 by William Grant
Address review comments.
680
        )
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
681
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
682
    lec = LogExCons()
10456.1.2 by William Grant
Take multiple branches, and only count each authored revision once.
683
10456.1.7 by William Grant
Address review comments.
684
    for branch_info in branches:
10456.1.2 by William Grant
Take multiple branches, and only count each authored revision once.
685
        # Do everything.
10456.1.7 by William Grant
Address review comments.
686
        b = Branch.open(branch_info.path)
10456.1.2 by William Grant
Take multiple branches, and only count each authored revision once.
687
10456.1.13 by William Grant
Remove start_revno support.
688
        logger = log.Logger(b, {'direction' : 'reverse',
10456.1.2 by William Grant
Take multiple branches, and only count each authored revision once.
689
                                'levels' : 0, })
690
        if not quiet:
691
            print "Calculating (this may take a while)..."
10456.1.5 by William Grant
Fix obsolete comments, and add a couple more.
692
693
        # Set information about the current branch for later formatting.
10456.1.4 by William Grant
Fully support multiple branches -- they will now be linked properly, and their revisions will be labeled.
694
        lec.branch_info = branch_info
10456.1.2 by William Grant
Take multiple branches, and only count each authored revision once.
695
        logger.show(lec)  # Won't "show" anything -- just gathers data.
696
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
697
    page_contents = page_intro + lec.result()
698
    def update_if_modified(moinfile):
699
        if moinfile._unescape(moinfile.body) == page_contents:
700
            return 0  # Nothing changed, so cancel the edit.
701
        else:
702
            moinfile.body = page_contents
703
            return 1
704
    if not dry_run:
705
        if not quiet:
706
            print "Updating wiki..."
707
        # Not sure how to get editmoin to obey our quiet flag.
10301.1.1 by Karl Fogel
* community-contributions.py
708
        editshortcut(wiki_dest, editfile_func=update_if_modified)
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
709
        if not quiet:
710
            print "Done updating wiki."
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
711
    else:
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
712
        print page_contents
9373.1.1 by Karl Fogel
Add utilities/community-contributions.py (descended from lpcc.py in
713
714
715
if __name__ == '__main__':
9373.1.4 by Karl Fogel
* utilities/community-contributions.py: Reindent with py-offset-level 4,
716
    main()