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

Proposed by Nish Aravamudan
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
Benjamin Drung Needs Fixing
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.
Revision history for this message
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
Revision history for this message
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.

Revision history for this message
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
Revision history for this message
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.

Revision history for this message
Mattia Rizzolo (mapreri) wrote :

@nacc any update here?

Revision history for this message
Mattia Rizzolo (mapreri) wrote :

@nacc Could you please finish this up? :)

Unmerged revisions

1456. By Nish Aravamudan

Fix obvious syntax errors. Sorry!

1455. By Nish Aravamudan

Pass verbose down to the internal functions.

1454. By Nish Aravamudan

Drop unnecessary whitespace change.

1453. By Nish Aravamudan

Merge with lp:ubuntu-dev-tools

1452. By Nish Aravamudan

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

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
=== modified file 'ubuntutools/update_maintainer.py'
--- ubuntutools/update_maintainer.py 2014-12-18 20:57:17 +0000
+++ ubuntutools/update_maintainer.py 2017-03-31 22:08:28 +0000
@@ -53,6 +53,17 @@
53 maintainer = maintainer.group(1)53 maintainer = maintainer.group(1)
54 return maintainer54 return maintainer
5555
56 def get_vcs(self):
57 """Returns the value(s) of the Vcs-{Git,Bzr,Browser,...} field(s)."""
58 return re.findall("^(Vcs-(?:Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn|Browser)): ?(.*)$",
59 self._content, re.MULTILINE)
60
61 def get_original_vcs(self):
62 """Returns the value(s) of the XS-Debian-Vcs-{Git,Bzr,Browser...} field(s)."""
63 orig_vcs = re.findall("^(?:[XS]*-)?Debian-(Vcs-(?:Arch|Bzr|Cvs|Darcs|Git|Hg|Mtn|Svn|Browser)): ?(.*)$",
64 self._content, re.MULTILINE)
65 return orig_vcs
66
56 def get_original_maintainer(self):67 def get_original_maintainer(self):
57 """Returns the value of the XSBC-Original-Maintainer field."""68 """Returns the value of the XSBC-Original-Maintainer field."""
58 orig_maintainer = re.search("^(?:[XSBC]*-)?Original-Maintainer: ?(.*)$",69 orig_maintainer = re.search("^(?:[XSBC]*-)?Original-Maintainer: ?(.*)$",
@@ -86,6 +97,29 @@
86 self._content = pattern.sub(r"\1\n" + original_maintainer,97 self._content = pattern.sub(r"\1\n" + original_maintainer,
87 self._content)98 self._content)
8899
100 def reset_vcs(self, vcs):
101 """Sets the value of the Vcs- field(s)."""
102 for v in vcs:
103 pattern = re.compile("^XS-Debian-%s: ?.*$" % v[0], re.MULTILINE)
104 self._content = pattern.sub("%s: %s" % (v[0], v[1]), self._content)
105
106
107 def set_original_vcs(self, original_vcs):
108 replace = False
109 if self.get_original_vcs():
110 replace = True
111 for vcs in original_vcs:
112 ovcs = "XS-Debian-" + vcs[0] + ": " + vcs[1]
113 if replace:
114 pattern = re.compile("^(?:[XS]*-)?Debian-" + vcs[0] + ":.*$",
115 re.MULTILINE)
116 self._content = pattern.sub(ovcs, self._content)
117 else:
118 pattern = re.compile("^(" + vcs[0] + ":.*)$",
119 re.MULTILINE)
120 self._content = pattern.sub(ovcs,
121 self._content)
122
89 def remove_original_maintainer(self):123 def remove_original_maintainer(self):
90 """Strip out out the XSBC-Original-Maintainer line"""124 """Strip out out the XSBC-Original-Maintainer line"""
91 pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^",125 pattern = re.compile("^(?:[XSBC]*-)?Original-Maintainer:.*?$.*?^",
@@ -133,16 +167,71 @@
133 return (changelog_file, control_files)167 return (changelog_file, control_files)
134168
135169
136def update_maintainer(debian_directory, verbose=False):170def _update_maintainer(control, verbose):
137 """updates the Maintainer field of an Ubuntu package171 original_maintainer = control.get_maintainer()
172
173 if original_maintainer is None:
174 Logger.error("No Maintainer field found in %s.", control_file)
175 raise MaintainerUpdateException("No Maintainer field found")
176
177 if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER:
178 if verbose:
179 print("The old maintainer was: %s" % original_maintainer)
180 print("Resetting as: %s" % _UBUNTU_MAINTAINER)
181 control.set_maintainer(_UBUNTU_MAINTAINER)
182 control.save()
183 return
184
185 if original_maintainer.strip().endswith("ubuntu.com>"):
186 if verbose:
187 print ("The Maintainer email is set to an ubuntu.com address. "
188 "Doing nothing.")
189 return
190
191 if control.get_original_maintainer() is not None:
192 Logger.warn("Overwriting original maintainer: %s",
193 control.get_original_maintainer())
194
195 if verbose:
196 print("The original maintainer is: %s" % original_maintainer)
197 print("Resetting as: %s" % _UBUNTU_MAINTAINER)
198 control.set_original_maintainer(original_maintainer)
199 control.set_maintainer(_UBUNTU_MAINTAINER)
200 control.save()
201
202
203def _update_vcs(control, verbose):
204 original_vcs = control.get_vcs()
205 if len(original_vcs) == 0:
206 Logger.error("No Vcs-* fields found in %s.", control_file)
207 raise VcsUpdateException("No Vcs-* fields found")
208
209 if len(control.get_original_vcs()) != 0:
210 Logger.warn("Overwriting original Vcs: %s",
211 control.get_original_vcs())
212
213 if verbose:
214 print("The original Vcs values are:")
215 for vcs in original_vcs:
216 print(" %s: %s" % (vcs[0], vcs[1]))
217 control.set_original_vcs(original_vcs)
218 control.save()
219
220
221def update_maintainer(debian_directory, verbose=False, vcs=False):
222 """updates the Maintainer and VCS field(s) of an Ubuntu package
138223
139 * No modifications are made if the Maintainer field contains an ubuntu.com224 * No modifications are made if the Maintainer field contains an ubuntu.com
140 email address. Otherwise, the Maintainer field will be set to225 email address. Otherwise, the Maintainer field will be set to
141 Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>226 Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
142 * The old value will be saved in a field named XSBC-Original-Maintainer227 * The old value will be saved in a field named XSBC-Original-Maintainer
143 if the Maintainer field is modified.228 if the Maintainer field is modified.
229 * If @vcs is True, no modifications are made if no Vcs-<SCM> or
230 Vcs-Browser fields are found. Otherwise, they are replaced with
231 Xs-Debian-Vcs-<SCM> and Xs-Debian-Vcs-Browser, respectively.
144232
145 Policy: https://wiki.ubuntu.com/DebianMaintainerField233 Policy: https://wiki.ubuntu.com/DebianMaintainerField
234 VCS discussion: https://lists.ubuntu.com/archives/ubuntu-devel/2007-March/023332.html
146 """235 """
147 try:236 try:
148 changelog_file, control_files = _find_files(debian_directory, verbose)237 changelog_file, control_files = _find_files(debian_directory, verbose)
@@ -152,47 +241,42 @@
152241
153 distribution = _get_distribution(changelog_file)242 distribution = _get_distribution(changelog_file)
154 for control_file in control_files:243 for control_file in control_files:
155 control = Control(control_file)
156 original_maintainer = control.get_maintainer()
157
158 if original_maintainer is None:
159 Logger.error("No Maintainer field found in %s.", control_file)
160 raise MaintainerUpdateException("No Maintainer field found")
161
162 if original_maintainer.strip().lower() in _PREVIOUS_UBUNTU_MAINTAINER:
163 if verbose:
164 print("The old maintainer was: %s" % original_maintainer)
165 print("Resetting as: %s" % _UBUNTU_MAINTAINER)
166 control.set_maintainer(_UBUNTU_MAINTAINER)
167 control.save()
168 continue
169
170 if original_maintainer.strip().endswith("ubuntu.com>"):
171 if verbose:
172 print ("The Maintainer email is set to an ubuntu.com address. "
173 "Doing nothing.")
174 continue
175
176 if distribution in ("stable", "testing", "unstable", "experimental"):244 if distribution in ("stable", "testing", "unstable", "experimental"):
177 if verbose:245 if verbose:
178 print("The package targets Debian. Doing nothing.")246 print("The package targets Debian. Doing nothing.")
179 return247 return
180248
181 if control.get_original_maintainer() is not None:249 control = Control(control_file)
182 Logger.warn("Overwriting original maintainer: %s",250 _update_maintainer(control, verbose)
183 control.get_original_maintainer())251 if vcs:
184252 _update_vcs(control, verbose)
185 if verbose:
186 print("The original maintainer is: %s" % original_maintainer)
187 print("Resetting as: %s" % _UBUNTU_MAINTAINER)
188 control.set_original_maintainer(original_maintainer)
189 control.set_maintainer(_UBUNTU_MAINTAINER)
190 control.save()
191
192 return253 return
193254
194255
195def restore_maintainer(debian_directory, verbose=False):256def _restore_maintainer(control, verbose):
257 orig_maintainer = control.get_original_maintainer()
258 if not orig_maintainer:
259 return
260 if verbose:
261 print("Restoring original maintainer: %s" % orig_maintainer)
262 control.set_maintainer(orig_maintainer)
263 control.remove_original_maintainer()
264 control.save()
265
266
267def _restore_vcs(control, verbose):
268 orig_vcs = control.get_original_vcs()
269 if not orig_vcs:
270 return
271 if verbose:
272 print("Restoring original Vcs values:")
273 for vcs in orig_vcs:
274 print(" %s: %s" % (vcs[0], vcs[1]))
275 control.reset_vcs(orig_vcs)
276 control.save()
277
278
279def restore_maintainer(debian_directory, verbose=False, vcs=False):
196 """Restore the original maintainer"""280 """Restore the original maintainer"""
197 try:281 try:
198 changelog_file, control_files = _find_files(debian_directory, verbose)282 changelog_file, control_files = _find_files(debian_directory, verbose)
@@ -202,11 +286,6 @@
202286
203 for control_file in control_files:287 for control_file in control_files:
204 control = Control(control_file)288 control = Control(control_file)
205 orig_maintainer = control.get_original_maintainer()289 _restore_maintainer(control, verbose)
206 if not orig_maintainer:290 if vcs:
207 continue291 _restore_vcs(control, verbose)
208 if verbose:
209 print("Restoring original maintainer: %s" % orig_maintainer)
210 control.set_maintainer(orig_maintainer)
211 control.remove_original_maintainer()
212 control.save()
213292
=== modified file 'update-maintainer'
--- update-maintainer 2012-05-06 17:42:39 +0000
+++ update-maintainer 2017-03-31 22:08:28 +0000
@@ -36,6 +36,10 @@
36 action='store_true', default=False)36 action='store_true', default=False)
37 parser.add_option("-q", "--quiet", help="print no informational messages",37 parser.add_option("-q", "--quiet", help="print no informational messages",
38 dest="quiet", action="store_true", default=False)38 dest="quiet", action="store_true", default=False)
39 parser.add_option("-v", "--vcs",
40 help="Apply the same operation (change/restore) "
41 "to VCS fields",
42 action='store_true', default=False)
39 (options, args) = parser.parse_args()43 (options, args) = parser.parse_args()
4044
41 if len(args) != 0:45 if len(args) != 0:
@@ -49,7 +53,9 @@
49 operation = restore_maintainer53 operation = restore_maintainer
5054
51 try:55 try:
52 operation(options.debian_directory, not options.quiet)56 operation(options.debian_directory,
57 not options.quiet,
58 options.vcs)
53 except MaintainerUpdateException:59 except MaintainerUpdateException:
54 sys.exit(1)60 sys.exit(1)
5561