201 lines
18 KiB
HTML
201 lines
18 KiB
HTML
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<title>pylorax.api.yumbase — Lorax 19.7.10 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../../_static/default.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../../../',
|
|
VERSION: '19.7.10',
|
|
COLLAPSE_INDEX: false,
|
|
FILE_SUFFIX: '.html',
|
|
HAS_SOURCE: true
|
|
};
|
|
</script>
|
|
<script type="text/javascript" src="../../../_static/jquery.js"></script>
|
|
<script type="text/javascript" src="../../../_static/underscore.js"></script>
|
|
<script type="text/javascript" src="../../../_static/doctools.js"></script>
|
|
<link rel="top" title="Lorax 19.7.10 documentation" href="../../../index.html" />
|
|
<link rel="up" title="pylorax.api" href="../api.html" />
|
|
</head>
|
|
<body>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../../genindex.html" title="General Index"
|
|
accesskey="I">index</a></li>
|
|
<li class="right" >
|
|
<a href="../../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../../index.html">Lorax 19.7.10 documentation</a> »</li>
|
|
<li><a href="../../index.html" >Module code</a> »</li>
|
|
<li><a href="../api.html" accesskey="U">pylorax.api</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body">
|
|
|
|
<h1>Source code for pylorax.api.yumbase</h1><div class="highlight"><pre>
|
|
<span class="c">#</span>
|
|
<span class="c"># Copyright (C) 2017 Red Hat, Inc.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># This program is free software; you can redistribute it and/or modify</span>
|
|
<span class="c"># it under the terms of the GNU General Public License as published by</span>
|
|
<span class="c"># the Free Software Foundation; either version 2 of the License, or</span>
|
|
<span class="c"># (at your option) any later version.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># This program is distributed in the hope that it will be useful,</span>
|
|
<span class="c"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
<span class="c"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
|
<span class="c"># GNU General Public License for more details.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># You should have received a copy of the GNU General Public License</span>
|
|
<span class="c"># along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
|
|
<span class="c">#</span>
|
|
<span class="c"># pylint: disable=bad-preconf-access</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">logging</span>
|
|
<span class="n">log</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">"lorax-composer"</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">ConfigParser</span>
|
|
<span class="kn">from</span> <span class="nn">fnmatch</span> <span class="kn">import</span> <span class="n">fnmatchcase</span>
|
|
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
|
|
<span class="kn">from</span> <span class="nn">distutils.util</span> <span class="kn">import</span> <span class="n">strtobool</span>
|
|
<span class="kn">import</span> <span class="nn">os</span>
|
|
<span class="kn">import</span> <span class="nn">yum</span>
|
|
<span class="c"># This is a hack to short circuit yum's internal logging</span>
|
|
<span class="n">yum</span><span class="o">.</span><span class="n">logginglevels</span><span class="o">.</span><span class="n">_added_handlers</span> <span class="o">=</span> <span class="bp">True</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span>
|
|
|
|
<div class="viewcode-block" id="get_base_object"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.yumbase.get_base_object">[docs]</a><span class="k">def</span> <span class="nf">get_base_object</span><span class="p">(</span><span class="n">conf</span><span class="p">):</span>
|
|
<span class="sd">"""Get the Yum object with settings from the config file</span>
|
|
|
|
<span class="sd"> :param conf: configuration object</span>
|
|
<span class="sd"> :type conf: ComposerParser</span>
|
|
<span class="sd"> :returns: A Yum base object</span>
|
|
<span class="sd"> :rtype: YumBase</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">cachedir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">conf</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"composer"</span><span class="p">,</span> <span class="s">"cache_dir"</span><span class="p">))</span>
|
|
<span class="n">yumconf</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">conf</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"composer"</span><span class="p">,</span> <span class="s">"yum_conf"</span><span class="p">))</span>
|
|
<span class="n">repodir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">conf</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"composer"</span><span class="p">,</span> <span class="s">"repo_dir"</span><span class="p">))</span>
|
|
|
|
<span class="n">c</span> <span class="o">=</span> <span class="n">ConfigParser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">()</span>
|
|
|
|
<span class="c"># add the main section</span>
|
|
<span class="n">section</span> <span class="o">=</span> <span class="s">"main"</span>
|
|
<span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s">"cachedir"</span><span class="p">:</span> <span class="n">cachedir</span><span class="p">,</span>
|
|
<span class="s">"keepcache"</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
|
|
<span class="s">"gpgcheck"</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
|
|
<span class="s">"plugins"</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
|
|
<span class="s">"assumeyes"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
|
|
<span class="s">"reposdir"</span><span class="p">:</span> <span class="s">""</span><span class="p">,</span>
|
|
<span class="s">"tsflags"</span><span class="p">:</span> <span class="s">"nodocs"</span><span class="p">}</span>
|
|
|
|
<span class="k">if</span> <span class="n">conf</span><span class="o">.</span><span class="n">get_default</span><span class="p">(</span><span class="s">"yum"</span><span class="p">,</span> <span class="s">"proxy"</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
|
|
<span class="n">data</span><span class="p">[</span><span class="s">"proxy"</span><span class="p">]</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"yum"</span><span class="p">,</span> <span class="s">"proxy"</span><span class="p">)</span>
|
|
|
|
<span class="k">if</span> <span class="n">conf</span><span class="o">.</span><span class="n">has_option</span><span class="p">(</span><span class="s">"yum"</span><span class="p">,</span> <span class="s">"sslverify"</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">conf</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="s">"yum"</span><span class="p">,</span> <span class="s">"sslverify"</span><span class="p">):</span>
|
|
<span class="n">data</span><span class="p">[</span><span class="s">"sslverify"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"0"</span>
|
|
|
|
<span class="n">c</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="n">section</span><span class="p">)</span>
|
|
<span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="n">c</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">),</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
|
|
|
|
<span class="c"># write the yum configuration file</span>
|
|
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">yumconf</span><span class="p">,</span> <span class="s">"w"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
|
|
<span class="n">c</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
|
|
|
|
<span class="c"># create the yum base object</span>
|
|
<span class="n">yb</span> <span class="o">=</span> <span class="n">yum</span><span class="o">.</span><span class="n">YumBase</span><span class="p">()</span>
|
|
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">fn</span> <span class="o">=</span> <span class="n">yumconf</span>
|
|
|
|
<span class="c"># TODO How to handle this?</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">root</span> <span class="o">=</span> <span class="s">"/var/tmp/composer/yum/root"</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isdir</span><span class="p">(</span><span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">root</span><span class="p">):</span>
|
|
<span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">root</span><span class="p">)</span>
|
|
|
|
<span class="n">_releasever</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">get_default</span><span class="p">(</span><span class="s">"composer"</span><span class="p">,</span> <span class="s">"releasever"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">_releasever</span><span class="p">:</span>
|
|
<span class="n">distroverpkg</span> <span class="o">=</span> <span class="p">[</span><span class="s">'system-release(releasever)'</span><span class="p">,</span> <span class="s">'redhat-release'</span><span class="p">]</span>
|
|
<span class="c"># Use yum private function to guess the releasever</span>
|
|
<span class="n">_releasever</span> <span class="o">=</span> <span class="n">yum</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">_getsysver</span><span class="p">(</span><span class="s">"/"</span><span class="p">,</span> <span class="n">distroverpkg</span><span class="p">)</span>
|
|
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s">"releasever = </span><span class="si">%s</span><span class="s">"</span><span class="p">,</span> <span class="n">_releasever</span><span class="p">)</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">releasever</span> <span class="o">=</span> <span class="n">_releasever</span>
|
|
|
|
<span class="c"># Turn on as much yum logging as we can</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">debuglevel</span> <span class="o">=</span> <span class="mi">6</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">preconf</span><span class="o">.</span><span class="n">errorlevel</span> <span class="o">=</span> <span class="mi">6</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">verbose_logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
|
|
|
|
<span class="c"># Gather up all the available repo files, add the ones matching "repos":"enabled" patterns</span>
|
|
<span class="n">enabled_repos</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">"repos"</span><span class="p">,</span> <span class="s">"enabled"</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">","</span><span class="p">)</span>
|
|
<span class="n">repo_files</span> <span class="o">=</span> <span class="n">glob</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">repodir</span><span class="p">,</span> <span class="s">"*.repo"</span><span class="p">))</span>
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">conf</span><span class="o">.</span><span class="n">has_option</span><span class="p">(</span><span class="s">"repos"</span><span class="p">,</span> <span class="s">"use_system_repos"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">conf</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="s">"repos"</span><span class="p">,</span> <span class="s">"use_system_repos"</span><span class="p">):</span>
|
|
<span class="n">repo_files</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">glob</span><span class="p">(</span><span class="s">"/etc/yum.repos.d/*.repo"</span><span class="p">))</span>
|
|
|
|
<span class="k">for</span> <span class="n">repo_file</span> <span class="ow">in</span> <span class="n">repo_files</span><span class="p">:</span>
|
|
<span class="n">name</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">basename</span><span class="p">(</span><span class="n">repo_file</span><span class="p">)[:</span><span class="o">-</span><span class="mi">5</span><span class="p">]</span>
|
|
<span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">pattern</span><span class="p">:</span> <span class="n">fnmatchcase</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">pattern</span><span class="p">),</span> <span class="n">enabled_repos</span><span class="p">)):</span> <span class="c"># pylint: disable=cell-var-from-loop</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">getReposFromConfigFile</span><span class="p">(</span><span class="n">repo_file</span><span class="p">)</span>
|
|
|
|
<span class="k">return</span> <span class="n">yb</span></div>
|
|
</pre></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar">
|
|
<div class="sphinxsidebarwrapper">
|
|
<div id="searchbox" style="display: none">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../../../search.html" method="get">
|
|
<input type="text" name="q" />
|
|
<input type="submit" value="Go" />
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
<input type="hidden" name="area" value="default" />
|
|
</form>
|
|
<p class="searchtip" style="font-size: 90%">
|
|
Enter search terms or a module, class or function name.
|
|
</p>
|
|
</div>
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
</div>
|
|
</div>
|
|
<div class="clearer"></div>
|
|
</div>
|
|
<div class="related">
|
|
<h3>Navigation</h3>
|
|
<ul>
|
|
<li class="right" style="margin-right: 10px">
|
|
<a href="../../../genindex.html" title="General Index"
|
|
>index</a></li>
|
|
<li class="right" >
|
|
<a href="../../../py-modindex.html" title="Python Module Index"
|
|
>modules</a> |</li>
|
|
<li><a href="../../../index.html">Lorax 19.7.10 documentation</a> »</li>
|
|
<li><a href="../../index.html" >Module code</a> »</li>
|
|
<li><a href="../api.html" >pylorax.api</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer">
|
|
© Copyright 2017, Red Hat, Inc..
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
|
</div>
|
|
</body>
|
|
</html> |