Merge lp:~evarlast/software-properties/support-update into lp:software-properties

Proposed by Jay R. Wren on 2015-05-30
Status: Merged
Merged at revision: 932
Proposed branch: lp:~evarlast/software-properties/support-update
Merge into: lp:software-properties
Diff against target: 35 lines (+8/-1)
2 files modified
add-apt-repository (+4/-1)
softwareproperties/SoftwareProperties.py (+4/-0)
To merge this branch: bzr merge lp:~evarlast/software-properties/support-update
Reviewer Review Type Date Requested Status
Michael Vogt 2015-05-30 Approve on 2015-06-02
Review via email: mp+260642@code.launchpad.net

Description of the Change

Add the -u, --update option to add-apt-repository to automatically update the apt cache.

By using apt.cache.Cache().update(sources_list=) only the newly added source is downloaded. The update method automatically sets and resets options so that other sources are not removed. This is similar to running this command:

apt-get update -o Dir::Etc::sourcelist="sources.list.d/${source}" \
        -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"

The benefit is that using -u is faster (potentially MUCH faster) than downloading and building package cache for all sources.

To post a comment you must log in.
Michael Vogt (mvo) wrote :

I like that, thanks a lot!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'add-apt-repository'
2--- add-apt-repository 2014-09-24 09:50:37 +0000
3+++ add-apt-repository 2015-05-30 03:03:01 +0000
4@@ -69,6 +69,9 @@
5 parser.add_option("-y", "--yes", action="store_true",
6 dest="assume_yes", default=False,
7 help=_("Assume yes to all queries"))
8+ parser.add_option("-u", "--update", action="store_true",
9+ dest="update", default=False,
10+ help=_("Update package cache after adding"))
11 (options, args) = parser.parse_args()
12
13 if os.geteuid() != 0:
14@@ -168,5 +171,5 @@
15 except ShortcutException as e:
16 print(e)
17 sys.exit(1)
18-
19+
20 sp.sourceslist.save()
21
22=== modified file 'softwareproperties/SoftwareProperties.py'
23--- softwareproperties/SoftwareProperties.py 2014-12-01 07:05:24 +0000
24+++ softwareproperties/SoftwareProperties.py 2015-05-30 03:03:01 +0000
25@@ -753,6 +753,10 @@
26 if worker:
27 # wait for GPG key to be downloaded
28 worker.join(30)
29+ if self.options.update:
30+ import apt
31+ cache = apt.Cache()
32+ cache.update(sources_list=new_debsrc_entry.file)
33 return True
34
35 def remove_source(self, source, remove_source_code=True):

Subscribers

People subscribed via source and target branches

to status/vote changes: