3

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)

2
  • 1
    I dislike undocumented syntaxes ALOT..... have you tried exrepo = 'ppa.launchpad.net/danielrichter2007/grub-customizer/ubuntu' Basically try different components for the exrepo variable. Commented Apr 20, 2017 at 4:05
  • Thanks, but no luck Commented Apr 20, 2017 at 4:15

2 Answers 2

1

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()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for explaining.
0

I'm using this to do the removing for now.

import fileinput 

filename = '/etc/apt/sources.list'
word = 'grub-customizer'
n = ""
remove = fileinput.input(filename, inplace=1)
for line in remove:
    if word in line:
       line = n
    line.strip()
    print line,
remove.close()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.