我需要使用python脚本将ppa添加到远程服务器。 相当于我想要做的是:
$ 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()
但是我一直无法find与添加存储库相关的apt模块源代码。
add-apt-repository是用Python编写的; 检查它正在做什么并在自己的程序中复制必要的代码行应该是相当微不足道的。
这是我最终做的。
安装软件属性包:
$ sudo apt-get install python-software-properties
然后在你的python脚本中:
import apt from softwareproperties.SoftwareProperties import SoftwareProperties sp = SoftwareProperties() to_add = 'ppa:user/repository' sp.add_source_from_line(to_add) sp.sourceslist.save() cache = apt.Cache() cache.update() cache.open(None) cache['package_from_ppa'].mark_install() cache.upgrade() cache.commit()