Merge lp:~manishsinha/software-properties/add-update-after-repo-add into lp:software-properties

Status: Needs review
Proposed branch: lp:~manishsinha/software-properties/add-update-after-repo-add
Merge into: lp:software-properties
Diff against target: 53 lines (+25/-0)
1 file modified
add-apt-repository (+25/-0)
To merge this branch: bzr merge lp:~manishsinha/software-properties/add-update-after-repo-add
Reviewer Review Type Date Requested Status
Michael Terry Needs Fixing
Review via email: mp+150185@code.launchpad.net

Commit message

Adds a new option -u/--update for updating the source list after a PPA has been added via apt-add-repository

Description of the change

Adds a new option -u/--update for updating the source list after a PPA has been added via apt-add-repository

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

44 + print("YAY")

Should be dropped.

52 - sp.sourceslist.save()
53 + if options.assume_update:
54 + sp.sourceslist.save()

Why does the save move inside the if? It seems like without the -u, you should still save.

review: Needs Fixing
835. By Manish Sinha (मनीष सिन्हा)

Move sp.sourceslist.save() above options.assume_update

836. By Manish Sinha (मनीष सिन्हा)

The save should be intended 4 chars left else it will never be executed

837. By Manish Sinha (मनीष सिन्हा)

Remove YAY print line

Unmerged revisions

837. By Manish Sinha (मनीष सिन्हा)

Remove YAY print line

836. By Manish Sinha (मनीष सिन्हा)

The save should be intended 4 chars left else it will never be executed

835. By Manish Sinha (मनीष सिन्हा)

Move sp.sourceslist.save() above options.assume_update

834. By Manish Sinha (मनीष सिन्हा)

Adds a new option -u/--update for updating the source list after a PPA has been added via apt-add-repository

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 2012-12-14 13:46:35 +0000
3+++ add-apt-repository 2013-03-10 03:40:27 +0000
4@@ -16,6 +16,8 @@
5 from aptsources.distro import *
6 from optparse import OptionParser
7 from gettext import gettext as _
8+from apt.progress.text import AcquireProgress
9+from apt.cache import Cache, FetchFailedException
10
11 try:
12 from urllib.error import HTTPError, URLError
13@@ -23,6 +25,16 @@
14 import pycurl
15 HTTPError = pycurl.error
16
17+class UpdateProgress(AcquireProgress):
18+ def __init__(self):
19+ AcquireProgress.__init__(self)
20+
21+ def current_items(self, items):
22+ for item in items:
23+ print(item)
24+
25+ return True
26+
27 def _maybe_suggest_ppa_name_based_on_user(user):
28 try:
29 from launchpadlib.launchpad import Launchpad
30@@ -104,6 +116,9 @@
31 parser.add_option("-y", "--yes", action="store_true",
32 dest="assume_yes", default=False,
33 help=_("Assume yes to all queries"))
34+ parser.add_option("-u","--update", action="store_true",
35+ dest="assume_update", default=False,
36+ help=_("Update after adding the PPA"))
37 (options, args) = parser.parse_args()
38
39 if os.geteuid() != 0:
40@@ -205,3 +220,13 @@
41 print(_("Error: '%s' invalid") % line)
42 sys.exit(1)
43 sp.sourceslist.save()
44+ if options.assume_update:
45+ cache = Cache()
46+ update_progress = UpdateProgress()
47+ try:
48+ cache.update(update_progress)
49+ except SystemError as e:
50+ print(e.args[0])
51+ except FetchFailedException as e:
52+ print(e.args[0])
53+