vsekhar
vsekhar

Reputation: 5520

Is there a way to add a ppa using the python apt module?

I need to add a ppa to remote servers using a python script. The bash equivalent of what I want to do is:

$ add-apt-repository ppa:user/ppa-name

I'm assuming it would look something like this:

import apt
cache = apt.Cache()
# ?? add the ppa here ??
cache.update()
cache.open(None)
cache['package_from_ppa'].mark_install()
cache.upgrade()
cache.commit()

but I haven't been able to find much in the apt module source related to adding repositories.

Upvotes: 5

Views: 1165

Answers (2)

answerSeeker
answerSeeker

Reputation: 2772

I noticed op never got the answer he wanted so here is the solution.

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()

Upvotes: 0

xubuntix
xubuntix

Reputation: 2333

taken from the current (in 11.04 natty) add-apt-repository code:

from softwareproperties.SoftwareProperties import SoftwareProperties
sp = SoftwareProperties()
sp.add_source_from_line(ppa_name)
sp.sourceslist.save()

You should of cause add checks for errors, etc... look at the currently installed version like this:

less `which add-apt-repository`

Upvotes: 5

Related Questions