Merge lp:~nacc/ubuntu-dev-tools/update-vcs into lp:~ubuntu-dev/ubuntu-dev-tools/trunk

Proposed by Nish Aravamudan on 2016-10-19
Status: Needs review
Proposed branch: lp:~nacc/ubuntu-dev-tools/update-vcs
Merge into: lp:~ubuntu-dev/ubuntu-dev-tools/trunk
Diff against target: 241 lines (+129/-44)
2 files modified
ubuntutools/update_maintainer.py (+122/-43)
update-maintainer (+7/-1)
To merge this branch: bzr merge lp:~nacc/ubuntu-dev-tools/update-vcs
Reviewer Review Type Date Requested Status
Mattia Rizzolo Needs Information on 2017-04-30
Benjamin Drung 2016-10-19 Needs Fixing on 2017-03-29
Review via email: mp+308871@code.launchpad.net

Description of the Change

I am not necessarily requesting this for merging yet, but it's a PoC implementation that resolves a process issue we hit somewhat often on the Server Team.

I am open to:

  - Making this a separate command
  - Adding a new command (update-metadata?) that update-maintainer aliases to for BC which supports the new flag (perhaps without the flag and by default therefore?)
  - Adding a parameter to --vcs to specify a new value should be used instead (similar for vcs-browser I guess?). Could use the protocol of the repository to determine the protocol to use for the tag, if needed?
  - ... any other changes, I just think code speaks louder than words :)

To post a comment you must log in.
Benjamin Drung (bdrung) wrote :

A quick review.

1) Instead of duplicating code (including classes), please re-use ubuntutools.update_maintainer and add your new methods to the Control class.

2) The functions update_maintainer and restore_maintainer could gain an vcs parameter to update the vcs option or you can refactor the code to retrieve the control class and then run update_maintainer, update_vcs on it.

3) Having an option to set the vcs values would be nice

I don't thinks that splitting this feature into a separate command makes sense.

review: Needs Fixing
Nish Aravamudan (nacc) wrote :

I think I have addressed 1) and 2). I need to do some more testing and want to actually write some tests before it gets merged.

Mattia Rizzolo (mapreri) wrote :

I think the current code is fine now.
@nacc do you plan to also write some tests? It would be really nice to have some.

I do not think things like the point 3 @bdrung should stop the merge (but you are welcome to implement it of course!).

Another thing: you are closing bug #1595744 in usd-importer with this, is that really fine?

review: Needs Information
Nish Aravamudan (nacc) wrote :

Hi Mattia,

Yes, I plan on writing tests still. Feel free to hold off on merging
until I get to that!

The importer bug is correct to close (it was a user request to have
this feature in `update-maintainer`, which we use in the server team's
documented git-based merge workflow). But I did update it to have a
task for ubuntu-dev-tools specifically, so I can update the snap of
the importer to fix that task, once this fix is avaiable.

On Sun, Apr 30, 2017 at 10:05 AM, Mattia Rizzolo <email address hidden> wrote:
> Review: Needs Information
>
> I think the current code is fine now.
> @nacc do you plan to also write some tests? It would be really nice to have some.
>
> I do not think things like the point 3 @bdrung should stop the merge (but you are welcome to implement it of course!).
>
> Another thing: you are closing bug #1595744 in usd-importer with this, is that really fine?
> --
> https://code.launchpad.net/~nacc/ubuntu-dev-tools/update-vcs/+merge/308871
> You are the owner of lp:~nacc/ubuntu-dev-tools/update-vcs.

Unmerged revisions

1456. By Nish Aravamudan on 2017-03-31

Fix obvious syntax errors. Sorry!

1455. By Nish Aravamudan on 2017-03-31

Pass verbose down to the internal functions.

1454. By Nish Aravamudan on 2017-03-31

Drop unnecessary whitespace change.

1453. By Nish Aravamudan on 2017-03-31

Merge with lp:ubuntu-dev-tools

1452. By Nish Aravamudan on 2017-03-31

Refactor code based upon MR feedback. Remove duplication of code between
update_maintainer.py and update_vcs.py. Delete update_vcs.py. Add a vcs
parameter to {update,restore}_maintainer to indicate if VCS fields
should be modified. Refactor both functions to not continue in the loop
until both maintainer and VCS fields have been examined if necessary.

1451. By Nish Aravamudan on 2016-10-19

update-maintainer: add --vcs mode

As we perform merges on the server team, we tend to try and replay the
maintainer changes to debian/control via update-maintainer. However, for
those packages that also update the Vcs fields, we have no automated
tooling to do the same. Add a fairly simple version of the same code
as in update_maintainer, but handling Vcs-Git-* fields (including
Browser).

LP: #567629, LP: #1595744

Signed-off-by: Nishanth Aravamudan <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntutools/update_maintainer.py'
2--- ubuntutools/update_maintainer.py 2014-12-18 20:57:17 +0000
3+++ ubuntutools/update_maintainer.py 2017-03-31 22:08:28 +0000
4@@ -53,6 +53,17 @@
5 maintainer = maintainer.group(1)
6 return maintainer
7
8+ def get_vcs(self):
9+ """Returns the value(s) of the Vcs-{Git,Bzr,Browser,...} field(s)."""
10+ return re.findall("^(Vcs-(?:Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn|Browser)): ?(.*)$",
11+ self._content, re.MULTILINE)
12+
13+ def get_original_vcs(self):
14+ """Returns the value(s) of the XS-Debian-Vcs-{Git,Bzr,Browser...} field(s)."""
15+ orig_vcs = re.findall("^(?:[XS]*-)?Debian-(Vcs-(?:Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn|Browser)): ?(.*)$",
16+ self._content, re.MULTILINE)
17+ return orig_vcs
18+
19 def get_original_maintainer(self):
20 """Returns the value of the XSBC-Original-Maintainer field."""
21 orig_maintainer = re.search("^(?:[XSBC]*-)?Original-Maintainer: ?(.*)$",
22@@ -86,6 +97,29 @@
23 self._content = pattern.sub(r"\1\n" + original_maintainer,
24 self._content)
25
26+ def reset_vcs(self, vcs):
27+ """Sets the value of the Vcs- field(s)."""
28+ for v in vcs:
29+ pattern = re.compile("^XS-Debian-%s: ?.*$" % v[0], re.MULTILINE)
30+ self._content = pattern.sub("%s: %s" % (v[0], v[1]), self._content)
31+
32+
33+ def set_original_vcs(self, original_vcs):
34+ replace = False
35+ if self.get_original_vcs():
36+ replace = True
37+ for vcs in original_vcs:
38+ ovcs = "XS-Debian-" + vcs[0] + ": " + vcs[1]
39+ if replace:
40+ pattern = re.compile("^(?:[XS]*-)?Debian-" + vcs[0] + ":.*$",
41+ re.MULTILINE)
42+ self._content = pattern.sub(ovcs, self._content)
43+ else:
44+ pattern = re.compile("^(" + vcs[0] + ":.*)$",
45+ re.MULTILINE)
46+ self._content = pattern.sub(ovcs,
47+ self._content)
48+
49 def remove_original_maintainer(self):
50 """Strip out out the XSBC-Original-Maintainer line"""
51 pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^",
52@@ -133,16 +167,71 @@
53 return (changelog_file, control_files)
54
55
56-def update_maintainer(debian_directory, verbose=False):
57- """updates the Maintainer field of an Ubuntu package
58+def _update_maintainer(control, verbose):
59+ original_maintainer = control.get_maintainer()
60+
61+ if original_maintainer is None:
62+ Logger.error("No Maintainer field found in %s.", control_file)
63+ raise MaintainerUpdateException("No Maintainer field found")
64+
65+ if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER:
66+ if verbose:
67+ print("The old maintainer was: %s" % original_maintainer)
68+ print("Resetting as: %s" % _UBUNTU_MAINTAINER)
69+ control.set_maintainer(_UBUNTU_MAINTAINER)
70+ control.save()
71+ return
72+
73+ if original_maintainer.strip().endswith("ubuntu.com>"):
74+ if verbose:
75+ print ("The Maintainer email is set to an ubuntu.com address. "
76+ "Doing nothing.")
77+ return
78+
79+ if control.get_original_maintainer() is not None:
80+ Logger.warn("Overwriting original maintainer: %s",
81+ control.get_original_maintainer())
82+
83+ if verbose:
84+ print("The original maintainer is: %s" % original_maintainer)
85+ print("Resetting as: %s" % _UBUNTU_MAINTAINER)
86+ control.set_original_maintainer(original_maintainer)
87+ control.set_maintainer(_UBUNTU_MAINTAINER)
88+ control.save()
89+
90+
91+def _update_vcs(control, verbose):
92+ original_vcs = control.get_vcs()
93+ if len(original_vcs) == 0:
94+ Logger.error("No Vcs-* fields found in %s.", control_file)
95+ raise VcsUpdateException("No Vcs-* fields found")
96+
97+ if len(control.get_original_vcs()) != 0:
98+ Logger.warn("Overwriting original Vcs: %s",
99+ control.get_original_vcs())
100+
101+ if verbose:
102+ print("The original Vcs values are:")
103+ for vcs in original_vcs:
104+ print(" %s: %s" % (vcs[0], vcs[1]))
105+ control.set_original_vcs(original_vcs)
106+ control.save()
107+
108+
109+def update_maintainer(debian_directory, verbose=False, vcs=False):
110+ """updates the Maintainer and VCS field(s) of an Ubuntu package
111
112 * No modifications are made if the Maintainer field contains an ubuntu.com
113 email address. Otherwise, the Maintainer field will be set to
114 Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
115 * The old value will be saved in a field named XSBC-Original-Maintainer
116 if the Maintainer field is modified.
117+ * If @vcs is True, no modifications are made if no Vcs-<SCM> or
118+ Vcs-Browser fields are found. Otherwise, they are replaced with
119+ Xs-Debian-Vcs-<SCM> and Xs-Debian-Vcs-Browser, respectively.
120
121 Policy: https://wiki.ubuntu.com/DebianMaintainerField
122+ VCS discussion: https://lists.ubuntu.com/archives/ubuntu-devel/2007-March/023332.html
123 """
124 try:
125 changelog_file, control_files = _find_files(debian_directory, verbose)
126@@ -152,47 +241,42 @@
127
128 distribution = _get_distribution(changelog_file)
129 for control_file in control_files:
130- control = Control(control_file)
131- original_maintainer = control.get_maintainer()
132-
133- if original_maintainer is None:
134- Logger.error("No Maintainer field found in %s.", control_file)
135- raise MaintainerUpdateException("No Maintainer field found")
136-
137- if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER:
138- if verbose:
139- print("The old maintainer was: %s" % original_maintainer)
140- print("Resetting as: %s" % _UBUNTU_MAINTAINER)
141- control.set_maintainer(_UBUNTU_MAINTAINER)
142- control.save()
143- continue
144-
145- if original_maintainer.strip().endswith("ubuntu.com>"):
146- if verbose:
147- print ("The Maintainer email is set to an ubuntu.com address. "
148- "Doing nothing.")
149- continue
150-
151 if distribution in ("stable", "testing", "unstable", "experimental"):
152 if verbose:
153 print("The package targets Debian. Doing nothing.")
154 return
155
156- if control.get_original_maintainer() is not None:
157- Logger.warn("Overwriting original maintainer: %s",
158- control.get_original_maintainer())
159-
160- if verbose:
161- print("The original maintainer is: %s" % original_maintainer)
162- print("Resetting as: %s" % _UBUNTU_MAINTAINER)
163- control.set_original_maintainer(original_maintainer)
164- control.set_maintainer(_UBUNTU_MAINTAINER)
165- control.save()
166-
167+ control = Control(control_file)
168+ _update_maintainer(control, verbose)
169+ if vcs:
170+ _update_vcs(control, verbose)
171 return
172
173
174-def restore_maintainer(debian_directory, verbose=False):
175+def _restore_maintainer(control, verbose):
176+ orig_maintainer = control.get_original_maintainer()
177+ if not orig_maintainer:
178+ return
179+ if verbose:
180+ print("Restoring original maintainer: %s" % orig_maintainer)
181+ control.set_maintainer(orig_maintainer)
182+ control.remove_original_maintainer()
183+ control.save()
184+
185+
186+def _restore_vcs(control, verbose):
187+ orig_vcs = control.get_original_vcs()
188+ if not orig_vcs:
189+ return
190+ if verbose:
191+ print("Restoring original Vcs values:")
192+ for vcs in orig_vcs:
193+ print(" %s: %s" % (vcs[0], vcs[1]))
194+ control.reset_vcs(orig_vcs)
195+ control.save()
196+
197+
198+def restore_maintainer(debian_directory, verbose=False, vcs=False):
199 """Restore the original maintainer"""
200 try:
201 changelog_file, control_files = _find_files(debian_directory, verbose)
202@@ -202,11 +286,6 @@
203
204 for control_file in control_files:
205 control = Control(control_file)
206- orig_maintainer = control.get_original_maintainer()
207- if not orig_maintainer:
208- continue
209- if verbose:
210- print("Restoring original maintainer: %s" % orig_maintainer)
211- control.set_maintainer(orig_maintainer)
212- control.remove_original_maintainer()
213- control.save()
214+ _restore_maintainer(control, verbose)
215+ if vcs:
216+ _restore_vcs(control, verbose)
217
218=== modified file 'update-maintainer'
219--- update-maintainer 2012-05-06 17:42:39 +0000
220+++ update-maintainer 2017-03-31 22:08:28 +0000
221@@ -36,6 +36,10 @@
222 action='store_true', default=False)
223 parser.add_option("-q", "--quiet", help="print no informational messages",
224 dest="quiet", action="store_true", default=False)
225+ parser.add_option("-v", "--vcs",
226+ help="Apply the same operation (change/restore) "
227+ "to VCS fields",
228+ action='store_true', default=False)
229 (options, args) = parser.parse_args()
230
231 if len(args) != 0:
232@@ -49,7 +53,9 @@
233 operation = restore_maintainer
234
235 try:
236- operation(options.debian_directory, not options.quiet)
237+ operation(options.debian_directory,
238+ not options.quiet,
239+ options.vcs)
240 except MaintainerUpdateException:
241 sys.exit(1)
242

Subscribers

People subscribed via source and target branches

to status/vote changes: