开发者

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.


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`


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜