[英]Is there a way to add a ppa using the python apt module?
我需要使用 python 脚本将 ppa 添加到远程服务器。 bash 相当于我想要做的是:
$ add-apt-repository ppa:user/ppa-name
我假设它看起来像这样:
import apt
cache = apt.Cache()
# ?? add the ppa here ??
cache.update()
cache.open(None)
cache['package_from_ppa'].mark_install()
cache.upgrade()
cache.commit()
但我无法在与添加存储库相关的 apt 模块源中找到太多内容。
取自当前(在 11.04 natty 中)add-apt-repository 代码:
from softwareproperties.SoftwareProperties import SoftwareProperties
sp = SoftwareProperties()
sp.add_source_from_line(ppa_name)
sp.sourceslist.save()
您应该添加检查错误等...查看当前安装的版本,如下所示:
less `which add-apt-repository`
我注意到 op 从来没有得到他想要的答案,所以这里是解决方案。
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.