Issue
I am able to add a ppa using it but cannot remove. I cannot find the correct syntax to remove the ppa from sources.list. Here's my code:
import aptsources.sourceslist as s
repo = ('deb', 'http://ppa.launchpad.net/danielrichter2007/grub-customizer/ubuntu', 'xenial', ['main'])
sources = s.SourcesList()
sources.add(repo)
sources.save()
#doesn't work
sources.remove(repo)
I tried reading the docs found here but I still cannot find the format to call sources.remove(repo)
Solution
The SourcesList.remove()
help text reads remove(source_entry)
, which indicates that what it wants is a SourceEntry
object. As it hapens, sources.add()
returns a SourceEntry
object:
import aptsources.sourceslist as sl
sources = sl.SourcesList()
entry = sources.add('deb', 'mirror://mirrors.ubuntu.com/mirrors.txt', 'xenial', ['main'])
print(type(entry))
Outputs:
<class 'aptsources.sourceslist.SourceEntry'>
To remove the entry:
sources.remove(entry)
sources.save()
You can also disable it (which will leave a commented-out entry in sources.list
:
entry.set_enabled(False)
sources.save()
Answered By - muru Answer Checked By - Candace Johnson (WPSolving Volunteer)