359 lines
35 KiB
HTML
359 lines
35 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.projects — 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.projects</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="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">time</span>
|
|
|
|
<span class="kn">from</span> <span class="nn">yum.Errors</span> <span class="kn">import</span> <span class="n">YumBaseError</span>
|
|
|
|
<span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s">"%Y-%m-</span><span class="si">%d</span><span class="s">T%H:%M:%S"</span>
|
|
|
|
|
|
<div class="viewcode-block" id="ProjectsError"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.ProjectsError">[docs]</a><span class="k">class</span> <span class="nc">ProjectsError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
|
|
<span class="k">pass</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="api_time"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.api_time">[docs]</a><span class="k">def</span> <span class="nf">api_time</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
|
|
<span class="sd">"""Convert time since epoch to a string</span>
|
|
|
|
<span class="sd"> :param t: Seconds since epoch</span>
|
|
<span class="sd"> :type t: int</span>
|
|
<span class="sd"> :returns: Time string</span>
|
|
<span class="sd"> :rtype: str</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">return</span> <span class="n">time</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="n">TIME_FORMAT</span><span class="p">,</span> <span class="n">time</span><span class="o">.</span><span class="n">localtime</span><span class="p">(</span><span class="n">t</span><span class="p">))</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="api_changelog"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.api_changelog">[docs]</a><span class="k">def</span> <span class="nf">api_changelog</span><span class="p">(</span><span class="n">changelog</span><span class="p">):</span>
|
|
<span class="sd">"""Convert the changelog to a string</span>
|
|
|
|
<span class="sd"> :param changelog: A list of time, author, string tuples.</span>
|
|
<span class="sd"> :type changelog: tuple</span>
|
|
<span class="sd"> :returns: The most recent changelog text or ""</span>
|
|
<span class="sd"> :rtype: str</span>
|
|
|
|
<span class="sd"> This returns only the most recent changelog entry.</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">entry</span> <span class="o">=</span> <span class="n">changelog</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">2</span><span class="p">]</span>
|
|
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
|
|
<span class="n">entry</span> <span class="o">=</span> <span class="s">""</span>
|
|
<span class="k">return</span> <span class="n">entry</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="yaps_to_project"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.yaps_to_project">[docs]</a><span class="k">def</span> <span class="nf">yaps_to_project</span><span class="p">(</span><span class="n">yaps</span><span class="p">):</span>
|
|
<span class="sd">"""Extract the details from a YumAvailablePackageSqlite object</span>
|
|
|
|
<span class="sd"> :param yaps: Yum object with package details</span>
|
|
<span class="sd"> :type yaps: YumAvailablePackageSqlite</span>
|
|
<span class="sd"> :returns: A dict with the name, summary, description, and url.</span>
|
|
<span class="sd"> :rtype: dict</span>
|
|
|
|
<span class="sd"> upstream_vcs is hard-coded to UPSTREAM_VCS</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">return</span> <span class="p">{</span><span class="s">"name"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
|
|
<span class="s">"summary"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">summary</span><span class="p">,</span>
|
|
<span class="s">"description"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">description</span><span class="p">,</span>
|
|
<span class="s">"homepage"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">url</span><span class="p">,</span>
|
|
<span class="s">"upstream_vcs"</span><span class="p">:</span> <span class="s">"UPSTREAM_VCS"</span><span class="p">}</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="yaps_to_project_info"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.yaps_to_project_info">[docs]</a><span class="k">def</span> <span class="nf">yaps_to_project_info</span><span class="p">(</span><span class="n">yaps</span><span class="p">):</span>
|
|
<span class="sd">"""Extract the details from a YumAvailablePackageSqlite object</span>
|
|
|
|
<span class="sd"> :param yaps: Yum object with package details</span>
|
|
<span class="sd"> :type yaps: YumAvailablePackageSqlite</span>
|
|
<span class="sd"> :returns: A dict with the project details, as well as epoch, release, arch, build_time, changelog, ...</span>
|
|
<span class="sd"> :rtype: dict</span>
|
|
|
|
<span class="sd"> metadata entries are hard-coded to {}</span>
|
|
<span class="sd"> """</span>
|
|
<span class="n">build</span> <span class="o">=</span> <span class="p">{</span><span class="s">"epoch"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">epoch</span><span class="p">,</span>
|
|
<span class="s">"release"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">release</span><span class="p">,</span>
|
|
<span class="s">"arch"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span>
|
|
<span class="s">"build_time"</span><span class="p">:</span> <span class="n">api_time</span><span class="p">(</span><span class="n">yaps</span><span class="o">.</span><span class="n">buildtime</span><span class="p">),</span>
|
|
<span class="s">"changelog"</span><span class="p">:</span> <span class="n">api_changelog</span><span class="p">(</span><span class="n">yaps</span><span class="o">.</span><span class="n">returnChangelog</span><span class="p">()),</span>
|
|
<span class="s">"build_config_ref"</span><span class="p">:</span> <span class="s">"BUILD_CONFIG_REF"</span><span class="p">,</span>
|
|
<span class="s">"build_env_ref"</span><span class="p">:</span> <span class="s">"BUILD_ENV_REF"</span><span class="p">,</span>
|
|
<span class="s">"metadata"</span><span class="p">:</span> <span class="p">{},</span>
|
|
<span class="s">"source"</span><span class="p">:</span> <span class="p">{</span><span class="s">"license"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">license</span><span class="p">,</span>
|
|
<span class="s">"version"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
|
|
<span class="s">"source_ref"</span><span class="p">:</span> <span class="s">"SOURCE_REF"</span><span class="p">,</span>
|
|
<span class="s">"metadata"</span><span class="p">:</span> <span class="p">{}}}</span>
|
|
|
|
<span class="k">return</span> <span class="p">{</span><span class="s">"name"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
|
|
<span class="s">"summary"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">summary</span><span class="p">,</span>
|
|
<span class="s">"description"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">description</span><span class="p">,</span>
|
|
<span class="s">"homepage"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">url</span><span class="p">,</span>
|
|
<span class="s">"upstream_vcs"</span><span class="p">:</span> <span class="s">"UPSTREAM_VCS"</span><span class="p">,</span>
|
|
<span class="s">"builds"</span><span class="p">:</span> <span class="p">[</span><span class="n">build</span><span class="p">]}</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="tm_to_dep"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.tm_to_dep">[docs]</a><span class="k">def</span> <span class="nf">tm_to_dep</span><span class="p">(</span><span class="n">tm</span><span class="p">):</span>
|
|
<span class="sd">"""Extract the info from a TransactionMember object</span>
|
|
|
|
<span class="sd"> :param tm: A Yum transaction object</span>
|
|
<span class="sd"> :type tm: TransactionMember</span>
|
|
<span class="sd"> :returns: A dict with name, epoch, version, release, arch</span>
|
|
<span class="sd"> :rtype: dict</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">return</span> <span class="p">{</span><span class="s">"name"</span><span class="p">:</span> <span class="n">tm</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
|
|
<span class="s">"epoch"</span><span class="p">:</span> <span class="n">tm</span><span class="o">.</span><span class="n">epoch</span><span class="p">,</span>
|
|
<span class="s">"version"</span><span class="p">:</span> <span class="n">tm</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
|
|
<span class="s">"release"</span><span class="p">:</span> <span class="n">tm</span><span class="o">.</span><span class="n">release</span><span class="p">,</span>
|
|
<span class="s">"arch"</span><span class="p">:</span> <span class="n">tm</span><span class="o">.</span><span class="n">arch</span><span class="p">}</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="yaps_to_module"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.yaps_to_module">[docs]</a><span class="k">def</span> <span class="nf">yaps_to_module</span><span class="p">(</span><span class="n">yaps</span><span class="p">):</span>
|
|
<span class="sd">"""Extract the name from a YumAvailablePackageSqlite object</span>
|
|
|
|
<span class="sd"> :param yaps: Yum object with package details</span>
|
|
<span class="sd"> :type yaps: YumAvailablePackageSqlite</span>
|
|
<span class="sd"> :returns: A dict with name, and group_type</span>
|
|
<span class="sd"> :rtype: dict</span>
|
|
|
|
<span class="sd"> group_type is hard-coded to "rpm"</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">return</span> <span class="p">{</span><span class="s">"name"</span><span class="p">:</span> <span class="n">yaps</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
|
|
<span class="s">"group_type"</span><span class="p">:</span> <span class="s">"rpm"</span><span class="p">}</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="dep_evra"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.dep_evra">[docs]</a><span class="k">def</span> <span class="nf">dep_evra</span><span class="p">(</span><span class="n">dep</span><span class="p">):</span>
|
|
<span class="sd">"""Return the epoch:version-release.arch for the dep</span>
|
|
|
|
<span class="sd"> :param dep: dependency dict</span>
|
|
<span class="sd"> :type dep: dict</span>
|
|
<span class="sd"> :returns: epoch:version-release.arch</span>
|
|
<span class="sd"> :rtype: str</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">if</span> <span class="n">dep</span><span class="p">[</span><span class="s">"epoch"</span><span class="p">]</span> <span class="o">==</span> <span class="s">"0"</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">dep</span><span class="p">[</span><span class="s">"version"</span><span class="p">]</span><span class="o">+</span><span class="s">"-"</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s">"release"</span><span class="p">]</span><span class="o">+</span><span class="s">"."</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s">"arch"</span><span class="p">]</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="n">dep</span><span class="p">[</span><span class="s">"epoch"</span><span class="p">]</span><span class="o">+</span><span class="s">":"</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s">"version"</span><span class="p">]</span><span class="o">+</span><span class="s">"-"</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s">"release"</span><span class="p">]</span><span class="o">+</span><span class="s">"."</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s">"arch"</span><span class="p">]</span>
|
|
</div>
|
|
<div class="viewcode-block" id="dep_nevra"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.dep_nevra">[docs]</a><span class="k">def</span> <span class="nf">dep_nevra</span><span class="p">(</span><span class="n">dep</span><span class="p">):</span>
|
|
<span class="sd">"""Return the name-epoch:version-release.arch"""</span>
|
|
<span class="k">return</span> <span class="n">dep</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">+</span><span class="s">"-"</span><span class="o">+</span><span class="n">dep_evra</span><span class="p">(</span><span class="n">dep</span><span class="p">)</span>
|
|
</div>
|
|
<div class="viewcode-block" id="projects_list"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.projects_list">[docs]</a><span class="k">def</span> <span class="nf">projects_list</span><span class="p">(</span><span class="n">yb</span><span class="p">):</span>
|
|
<span class="sd">"""Return a list of projects</span>
|
|
|
|
<span class="sd"> :param yb: yum base object</span>
|
|
<span class="sd"> :type yb: YumBase</span>
|
|
<span class="sd"> :returns: List of project info dicts with name, summary, description, homepage, upstream_vcs</span>
|
|
<span class="sd"> :rtype: list of dicts</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">ybl</span> <span class="o">=</span> <span class="n">yb</span><span class="o">.</span><span class="n">doPackageLists</span><span class="p">(</span><span class="n">pkgnarrow</span><span class="o">=</span><span class="s">"available"</span><span class="p">,</span> <span class="n">showdups</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">YumBaseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem listing projects: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">finally</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
<span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">yaps_to_project</span><span class="p">,</span> <span class="n">ybl</span><span class="o">.</span><span class="n">available</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="projects_info"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.projects_info">[docs]</a><span class="k">def</span> <span class="nf">projects_info</span><span class="p">(</span><span class="n">yb</span><span class="p">,</span> <span class="n">project_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return details about specific projects</span>
|
|
|
|
<span class="sd"> :param yb: yum base object</span>
|
|
<span class="sd"> :type yb: YumBase</span>
|
|
<span class="sd"> :param project_names: List of names of projects to get info about</span>
|
|
<span class="sd"> :type project_names: str</span>
|
|
<span class="sd"> :returns: List of project info dicts with yaps_to_project as well as epoch, version, release, etc.</span>
|
|
<span class="sd"> :rtype: list of dicts</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">ybl</span> <span class="o">=</span> <span class="n">yb</span><span class="o">.</span><span class="n">doPackageLists</span><span class="p">(</span><span class="n">pkgnarrow</span><span class="o">=</span><span class="s">"available"</span><span class="p">,</span> <span class="n">patterns</span><span class="o">=</span><span class="n">project_names</span><span class="p">,</span> <span class="n">showdups</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">YumBaseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem with info for </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">project_names</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
<span class="k">finally</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
<span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">yaps_to_project_info</span><span class="p">,</span> <span class="n">ybl</span><span class="o">.</span><span class="n">available</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="projects_depsolve"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.projects_depsolve">[docs]</a><span class="k">def</span> <span class="nf">projects_depsolve</span><span class="p">(</span><span class="n">yb</span><span class="p">,</span> <span class="n">project_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return the dependencies for a list of projects</span>
|
|
|
|
<span class="sd"> :param yb: yum base object</span>
|
|
<span class="sd"> :type yb: YumBase</span>
|
|
<span class="sd"> :param project_names: The projects to find the dependencies for</span>
|
|
<span class="sd"> :type project_names: List of Strings</span>
|
|
<span class="sd"> :returns: NEVRA's of the project and its dependencies</span>
|
|
<span class="sd"> :rtype: list of dicts</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="c"># This resets the transaction</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">project_names</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">install</span><span class="p">(</span><span class="n">pattern</span><span class="o">=</span><span class="n">p</span><span class="p">)</span>
|
|
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span> <span class="o">=</span> <span class="n">yb</span><span class="o">.</span><span class="n">buildTransaction</span><span class="p">()</span>
|
|
<span class="k">if</span> <span class="n">rc</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">]:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem depsolving </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">project_names</span><span class="p">,</span> <span class="n">msg</span><span class="p">))</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">tsInfo</span><span class="o">.</span><span class="n">makelists</span><span class="p">()</span>
|
|
<span class="n">deps</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">tm_to_dep</span><span class="p">,</span> <span class="n">yb</span><span class="o">.</span><span class="n">tsInfo</span><span class="o">.</span><span class="n">installed</span> <span class="o">+</span> <span class="n">yb</span><span class="o">.</span><span class="n">tsInfo</span><span class="o">.</span><span class="n">depinstalled</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="k">except</span> <span class="n">YumBaseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem depsolving </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">project_names</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
<span class="k">finally</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
<span class="k">return</span> <span class="n">deps</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="modules_list"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.modules_list">[docs]</a><span class="k">def</span> <span class="nf">modules_list</span><span class="p">(</span><span class="n">yb</span><span class="p">,</span> <span class="n">module_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return a list of modules</span>
|
|
|
|
<span class="sd"> :param yb: yum base object</span>
|
|
<span class="sd"> :type yb: YumBase</span>
|
|
<span class="sd"> :param offset: Number of modules to skip</span>
|
|
<span class="sd"> :type limit: int</span>
|
|
<span class="sd"> :param limit: Maximum number of modules to return</span>
|
|
<span class="sd"> :type limit: int</span>
|
|
<span class="sd"> :returns: List of module information and total count</span>
|
|
<span class="sd"> :rtype: tuple of a list of dicts and an Int</span>
|
|
|
|
<span class="sd"> Modules don't exist in RHEL7 so this only returns projects</span>
|
|
<span class="sd"> and sets the type to "rpm"</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="n">ybl</span> <span class="o">=</span> <span class="n">yb</span><span class="o">.</span><span class="n">doPackageLists</span><span class="p">(</span><span class="n">pkgnarrow</span><span class="o">=</span><span class="s">"available"</span><span class="p">,</span> <span class="n">patterns</span><span class="o">=</span><span class="n">module_names</span><span class="p">,</span> <span class="n">showdups</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">YumBaseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem listing modules: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">))</span>
|
|
<span class="k">finally</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
<span class="k">return</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">yaps_to_module</span><span class="p">,</span> <span class="n">ybl</span><span class="o">.</span><span class="n">available</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
|
|
</div>
|
|
<div class="viewcode-block" id="modules_info"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.modules_info">[docs]</a><span class="k">def</span> <span class="nf">modules_info</span><span class="p">(</span><span class="n">yb</span><span class="p">,</span> <span class="n">module_names</span><span class="p">):</span>
|
|
<span class="sd">"""Return details about a module, including dependencies</span>
|
|
|
|
<span class="sd"> :param yb: yum base object</span>
|
|
<span class="sd"> :type yb: YumBase</span>
|
|
<span class="sd"> :param module_names: Names of the modules to get info about</span>
|
|
<span class="sd"> :type module_names: str</span>
|
|
<span class="sd"> :returns: List of dicts with module details and dependencies.</span>
|
|
<span class="sd"> :rtype: list of dicts</span>
|
|
<span class="sd"> """</span>
|
|
<span class="k">try</span><span class="p">:</span>
|
|
<span class="c"># Get the info about each module</span>
|
|
<span class="n">ybl</span> <span class="o">=</span> <span class="n">yb</span><span class="o">.</span><span class="n">doPackageLists</span><span class="p">(</span><span class="n">pkgnarrow</span><span class="o">=</span><span class="s">"available"</span><span class="p">,</span> <span class="n">patterns</span><span class="o">=</span><span class="n">module_names</span><span class="p">,</span> <span class="n">showdups</span><span class="o">=</span><span class="bp">False</span><span class="p">)</span>
|
|
<span class="k">except</span> <span class="n">YumBaseError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
|
|
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s">"There was a problem with info for </span><span class="si">%s</span><span class="s">: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">module_names</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)))</span>
|
|
<span class="k">finally</span><span class="p">:</span>
|
|
<span class="n">yb</span><span class="o">.</span><span class="n">closeRpmDB</span><span class="p">()</span>
|
|
|
|
<span class="n">modules</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">yaps_to_project</span><span class="p">,</span> <span class="n">ybl</span><span class="o">.</span><span class="n">available</span><span class="p">),</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="n">p</span><span class="p">[</span><span class="s">"name"</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
|
|
<span class="c"># Add the dependency info to each one</span>
|
|
<span class="k">for</span> <span class="n">module</span> <span class="ow">in</span> <span class="n">modules</span><span class="p">:</span>
|
|
<span class="n">module</span><span class="p">[</span><span class="s">"dependencies"</span><span class="p">]</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">yb</span><span class="p">,</span> <span class="p">[</span><span class="n">module</span><span class="p">[</span><span class="s">"name"</span><span class="p">]])</span>
|
|
|
|
<span class="k">return</span> <span class="n">modules</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> |