【问题标题】:Is there a way to add a ppa using the python apt module?有没有办法使用 python apt 模块添加 ppa?
【发布时间】:2011-08-14 00:30:26
【问题描述】:

我需要使用 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 模块源中找不到太多与添加存储库相关的内容。

【问题讨论】:

  • 尝试在serverfault.com 上提问,他们应该能够提供帮助!祝你好运! :)
  • add-apt-repository 是一个 python 脚本 :)
  • 这是source

标签: python ubuntu debian apt


【解决方案1】:

取自当前(在 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`

【讨论】:

    【解决方案2】:

    我注意到 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      • 2017-06-04
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 2020-12-04
      • 2023-03-15
      相关资源
      最近更新 更多