Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/300.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何执行一个“任务”;百胜更新;使用Yumbase Python模块?_Python_Yum - Fatal编程技术网

我如何执行一个“任务”;百胜更新;使用Yumbase Python模块?

我如何执行一个“任务”;百胜更新;使用Yumbase Python模块?,python,yum,Python,Yum,编辑:很明显我的安装不起作用。这让我找到了一个邮件列表,在那里我找到了我缺少的命令。我有下面更新的答案。现在我想起来了,这是有道理的。我只是希望他们能把这个放在开发页面上简单的地方 yb = yum.YumBase() yb.conf.assumeyes = True yb.update(name='aws-cli') yb.buildTransaction() yb.processTransaction() 当服务器第一次使用我的kickstart脚本启动时,我正在尝试使用yumbase执

编辑:很明显我的安装不起作用。这让我找到了一个邮件列表,在那里我找到了我缺少的命令。我有下面更新的答案。现在我想起来了,这是有道理的。我只是希望他们能把这个放在开发页面上简单的地方

yb = yum.YumBase()
yb.conf.assumeyes = True

yb.update(name='aws-cli')
yb.buildTransaction()
yb.processTransaction()
当服务器第一次使用我的kickstart脚本启动时,我正在尝试使用yumbase执行更新。目前,我有一个相当粗糙的python子流程来执行“yum update”,并希望使其更好

我正试图连接到Yumbase,但是文档非常稀少。我在本页上查看了源代码和文档:

我已经知道如何使用2008年的SO答案列出所有软件包,但不列出需要更新的软件包:

我还发现,安装新软件包是一个非常简单的三行流程:

yb = yum.YumBase()
yb.conf.assumeyes = True
yb.install(name='aws-cli')
但是,以下内容无法“更新”包:

yb = yum.YumBase()
yb.conf.assumeyes = True
yb.update(name='aws-cli')
所以我需要的是:

1:列出需要更新的包的方法,类似于“yum-check-update”


2:使用“yum update”安装上面的软件包从我在
yum
代码中看到的内容来看,它似乎不是作为库来编写的。你给出的代码不是正确的方法,在幕后还有很多其他的事情发生

基本上,从
yum-3.4.3
开始,流程如下所示:

->yummain.__main__
<trap KeyboardInterrupt>
->yummain.user_main(sys.argv[1:], exit_code=True)
 <check YUM_PROF,YUM_PDB envvars, wrap the following into debugger/profiler if set>
 ->yummain.main(args)
  <set up locale, set up logging>
  -><create a YumBaseCli (child of YumBase & YumOutput)>
   <incl. fill a list field with YumCommand instances of known commands>
  ->cli.YumBaseCli.getOptionsConfig()
   <parse args into the YumBaseCli instance, includes initializing plugins>
  <obtain global yum lock>
  <check write permissions for current dir>
  ->cli.YumBaseCli.doCommands()
   <select a YumCommand from the list>
   ->YumCommand.needTs/needTsRemove if needed
   ->YumCommand.doCommand(self, self.basecmd, self.extcmds)
  <handle errors & set error code if any>
  'Resolving Dependencies'
  ->cli.YumBaseCli.buildTransaction()
   <check for an unfinished transaction>
   <resolve deps using the info written by the YumCommand into the object>
   <honor clean_requirements_on_remove, protected_packages,
    protected_multilib, perform some checks>
  <handle errors & set error code if any>
  'Dependencies Resolved'
  ->cli.YumBaseCli.doTransaction()
   <download, transaction check, transaction test, transaction
   using the info in the object>
  <handle errors & set error code if any>
  'Complete!'
  <release global yum lock>
 sys.exit(error_code)

这与运行单独的进程减去进程隔离是一样的。

粗糙的python子进程有什么问题?从我在代码中看到的情况来看,它似乎并不是为了用作库而编写的。您提供的代码不是正确的方法:您错过了例如获取全局锁。如果您只想用可用更新更新所有包,这是默认的更新行为。您根本不需要指定任何包,我认为应该是
yb.update()
yum
该工具不是
yum
python模块。python模块是cli在下面使用的。@EtanReisner这些发现表明,尽管您可以使用该模块,但为了正确执行操作(与工具一样),你需要复制所有这些逻辑,这是如此的繁重以至于违背了原则。我认为你不需要任何接近所有代码的地方,很可能在调用
update()
后窃取并使用
doTransaction
,但我必须对其进行测试才能确定。(至少要检查选项/命令/等等。出于这个目的,应该完全不需要位。)这当然比最好的情况更复杂。好吧,你可以尝试报告你的发现。我对序列进行了详细的阐述,这样您就可以更好地了解到有多少内容是硬编码到主要例程中的。这甚至不是
YumBase
,后者的docstring说它“几乎是一个抽象类,您需要在它上面添加您自己的类以供实际使用”。
 yummain.main(<sequence of cmdline arguments>)