Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 674
vsekhar Avatar asked Aug 14 '11 00:08

vsekhar


1 Answers

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`
like image 113
xubuntix Avatar answered Sep 19 '22 02:09

xubuntix