Merge lp:~andrea.corbellini/software-properties/fix-621977-1 into lp:software-properties

Proposed by Andrea Corbellini
Status: Merged
Merged at revision: 825
Proposed branch: lp:~andrea.corbellini/software-properties/fix-621977-1
Merge into: lp:software-properties
Diff against target: 130 lines (+41/-9)
3 files modified
add-apt-repository (+4/-1)
softwareproperties/SoftwareProperties.py (+33/-5)
tests/test_dbus.py (+4/-3)
To merge this branch: bzr merge lp:~andrea.corbellini/software-properties/fix-621977-1
Reviewer Review Type Date Requested Status
Michael Terry Approve
Review via email: mp+139919@code.launchpad.net

Description of the change

This is an updated version of my previous merge proposal:

  https://code.launchpad.net/~andrea.corbellini/software-properties/fix-621977/+merge/134815

This branch fixes bug #621977 in the following way:

1. deb-src lines are added, but commented out, so that Software Properties still lets you enable them later;

2. a new -s, --enable-source command line option is added so that you can add uncommented deb-src line with a single command;

Also:

3. when removing a source entry, all related deb-src lines are automatically removed.

I fixed the tests to work with the new code. test_dbus.test_updates_automation fails, but it also fails in trunk.

The point #3 (automatically remove deb-src entries) is required to do a "clean" job by default. Having deb-src lines without correspective deb lines makes sense, however it doesn't make much sense in most situations.

It'd be useful to expose via the DBus API the new parameters enable_source_code (of add_source_from_line) and remove_source_code (from remove_source). However, modifying the signature of the existing DBus methods will break backward compatibility. I suggest adding new methods for that. If you like the idea, I can create a bug task and work on it.

To post a comment you must log in.
Revision history for this message
Michael Terry (mterry) wrote :

This was already approved before. Still looks good and works fine for me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'add-apt-repository'
--- add-apt-repository 2012-11-09 12:21:58 +0000
+++ add-apt-repository 2012-12-14 15:05:45 +0000
@@ -98,6 +98,9 @@
98 parser.add_option("-k", "--keyserver",98 parser.add_option("-k", "--keyserver",
99 dest="keyserver", default=DEFAULT_KEYSERVER,99 dest="keyserver", default=DEFAULT_KEYSERVER,
100 help=_("URL of keyserver. Default: %default"))100 help=_("URL of keyserver. Default: %default"))
101 parser.add_option("-s", "--enable-source", action="store_true",
102 dest="enable_source", default=False,
103 help=_("Allow downloading of the source packages from the repository"))
101 parser.add_option("-y", "--yes", action="store_true",104 parser.add_option("-y", "--yes", action="store_true",
102 dest="assume_yes", default=False,105 dest="assume_yes", default=False,
103 help=_("Assume yes to all queries"))106 help=_("Assume yes to all queries"))
@@ -198,7 +201,7 @@
198 print(_("Error: '%s' doesn't exist in a sourcelist file") % debsrc_line)201 print(_("Error: '%s' doesn't exist in a sourcelist file") % debsrc_line)
199202
200 else:203 else:
201 if not sp.add_source_from_line(line):204 if not sp.add_source_from_line(line, options.enable_source):
202 print(_("Error: '%s' invalid") % line)205 print(_("Error: '%s' invalid") % line)
203 sys.exit(1)206 sys.exit(1)
204 sp.sourceslist.save()207 sp.sourceslist.save()
205208
=== modified file 'softwareproperties/SoftwareProperties.py'
--- softwareproperties/SoftwareProperties.py 2012-10-01 09:24:55 +0000
+++ softwareproperties/SoftwareProperties.py 2012-12-14 15:05:45 +0000
@@ -26,6 +26,7 @@
2626
27import apt27import apt
28import apt_pkg28import apt_pkg
29import copy
29from hashlib import md530from hashlib import md5
30import re31import re
31import os32import os
@@ -696,14 +697,15 @@
696 line = "deb %s %s %s" % ( repo, self.distro.codename, areas )697 line = "deb %s %s %s" % ( repo, self.distro.codename, areas )
697 return line698 return line
698699
699 def add_source_from_line(self, line):700 def add_source_from_line(self, line, enable_source_code=False):
700 """701 """
701 Add a source with the given apt line and auto-add702 Add a source with the given apt line and auto-add
702 signing key if we have it in the whitelist703 signing key if we have it in the whitelist
703 """704 """
704 (deb_line, file) = expand_ppa_line(line.strip(), self.distro.codename)705 (deb_line, file) = expand_ppa_line(line.strip(), self.distro.codename)
705 deb_line = self.expand_http_line(deb_line)706 deb_line = self.expand_http_line(deb_line)
706 debsrc_line = 'deb-src' + deb_line[3:]707 debsrc_entry_type = 'deb-src' if enable_source_code else '# deb-src'
708 debsrc_line = debsrc_entry_type + deb_line[3:]
707 new_deb_entry = SourceEntry(deb_line, file)709 new_deb_entry = SourceEntry(deb_line, file)
708 new_debsrc_entry = SourceEntry(debsrc_line, file)710 new_debsrc_entry = SourceEntry(debsrc_line, file)
709 if new_deb_entry.invalid or new_debsrc_entry.invalid:711 if new_deb_entry.invalid or new_debsrc_entry.invalid:
@@ -716,7 +718,7 @@
716 comment=new_deb_entry.comment,718 comment=new_deb_entry.comment,
717 file=new_deb_entry.file,719 file=new_deb_entry.file,
718 architectures=new_deb_entry.architectures)720 architectures=new_deb_entry.architectures)
719 self.sourceslist.add(new_debsrc_entry.type,721 self.sourceslist.add(debsrc_entry_type,
720 new_debsrc_entry.uri,722 new_debsrc_entry.uri,
721 new_debsrc_entry.dist,723 new_debsrc_entry.dist,
722 new_debsrc_entry.comps,724 new_debsrc_entry.comps,
@@ -729,18 +731,44 @@
729 worker.join(30)731 worker.join(30)
730 return True732 return True
731733
732 def remove_source(self, source):734 def remove_source(self, source, remove_source_code=True):
733 """Remove the given source"""735 """Remove the given source"""
736 if remove_source_code:
737 if isinstance(source, str):
738 # recall this method giving a SourceEntry as an argument
739 source = self._find_source_from_string(source)
740 self.remove_source(source, True)
741 elif source is not None:
742 self.remove_source(source, False)
743 # remove the deb-src lines (enabled or not) associated to
744 # this source entry
745 source = copy.copy(source)
746 source.type = 'deb-src'
747 source.disabled = True
748 self.remove_source(source, False)
749 source.disabled = False
750 self.remove_source(source, False)
751 return
752
734 # first find the source object if we got a string753 # first find the source object if we got a string
735 if isinstance(source, str):754 if isinstance(source, str):
736 source = self._find_source_from_string(source)755 source = self._find_source_from_string(source)
756 if source is None:
757 return
737 # if its a sources.list.d file and it contains only a single line758 # if its a sources.list.d file and it contains only a single line
738 # (the line that we just remove), then all references to that759 # (the line that we just remove), then all references to that
739 # file are gone and the file is not saved. we work around that760 # file are gone and the file is not saved. we work around that
740 # here761 # here
741 if source.file != apt_pkg.config.find_file("Dir::Etc::sourcelist"):762 if source.file != apt_pkg.config.find_file("Dir::Etc::sourcelist"):
742 self.sourceslist.list.append(SourceEntry("", file=source.file))763 self.sourceslist.list.append(SourceEntry("", file=source.file))
743 self.sourceslist.remove(source)764 try:
765 self.sourceslist.remove(source)
766 except ValueError:
767 # this exception is raised if trying to remove an entry that does
768 # not exist. in this case we suppress the error because there's no
769 # need to propagate it (the aim of this method is to ensure that
770 # the given entries are not listed in the sourceslist)
771 pass
744 self.set_modified_sourceslist()772 self.set_modified_sourceslist()
745773
746 def add_key(self, path):774 def add_key(self, path):
747775
=== modified file 'tests/test_dbus.py'
--- tests/test_dbus.py 2012-07-05 13:32:44 +0000
+++ tests/test_dbus.py 2012-12-14 15:05:45 +0000
@@ -243,13 +243,14 @@
243 with open("./aptroot/etc/apt/sources.list") as f:243 with open("./aptroot/etc/apt/sources.list") as f:
244 sourceslist = f.read()244 sourceslist = f.read()
245 self.assertTrue(s in sourceslist)245 self.assertTrue(s in sourceslist)
246 # remove again, needs to remove both deb and deb-src lines246 self.assertTrue(s.replace("deb", "# deb-src") in sourceslist)
247 # remove again
247 self.iface.RemoveSource(s)248 self.iface.RemoveSource(s)
248 self.iface.RemoveSource(s.replace("deb", "deb-src"))
249 with open("./aptroot/etc/apt/sources.list") as f:249 with open("./aptroot/etc/apt/sources.list") as f:
250 sourceslist = f.read()250 sourceslist = f.read()
251 self.assertFalse(s in sourceslist)251 self.assertFalse(s in sourceslist)
252 # wait for the _on_modified_sources_list signal to arrive"252 self.assertFalse(s.replace("deb", "# deb-src") in sourceslist)
253 # wait for the _on_modified_sources_list signal to arrive
253 self.loop.run()254 self.loop.run()
254255
255 def test_add_gpg_key(self):256 def test_add_gpg_key(self):

Subscribers

People subscribed via source and target branches

to status/vote changes: