Add lorax 33.10 documentation in f33-branch

This commit is contained in:
Brian C. Lane 2020-10-01 15:50:46 -07:00
parent be2893e54d
commit b52e78c1ba
170 changed files with 86523 additions and 0 deletions

4
f33-branch/.buildinfo Normal file
View File

@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 9b3b905a33a257ccd41a2e1f4238d37b
tags: 645f666f9bcd5a90fca523b33c5a78b7

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

5
f33-branch/README Normal file
View File

@ -0,0 +1,5 @@
To build the docs for this branch run:
make test-in-docker
make docs-in-docker
If you already have a welder/lorax-composer:latest docker image you can skip running 'test-in-docker'.

View File

@ -0,0 +1,259 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>composer.cli</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># composer-cli</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">composer.cli.blueprints</span> <span class="kn">import</span> <span class="n">blueprints_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.modules</span> <span class="kn">import</span> <span class="n">modules_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.projects</span> <span class="kn">import</span> <span class="n">projects_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.compose</span> <span class="kn">import</span> <span class="n">compose_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.sources</span> <span class="kn">import</span> <span class="n">sources_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.status</span> <span class="kn">import</span> <span class="n">status_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.upload</span> <span class="kn">import</span> <span class="n">upload_cmd</span>
<span class="kn">from</span> <span class="nn">composer.cli.providers</span> <span class="kn">import</span> <span class="n">providers_cmd</span>
<span class="n">command_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;blueprints&quot;</span><span class="p">:</span> <span class="n">blueprints_cmd</span><span class="p">,</span>
<span class="s2">&quot;modules&quot;</span><span class="p">:</span> <span class="n">modules_cmd</span><span class="p">,</span>
<span class="s2">&quot;projects&quot;</span><span class="p">:</span> <span class="n">projects_cmd</span><span class="p">,</span>
<span class="s2">&quot;compose&quot;</span><span class="p">:</span> <span class="n">compose_cmd</span><span class="p">,</span>
<span class="s2">&quot;sources&quot;</span><span class="p">:</span> <span class="n">sources_cmd</span><span class="p">,</span>
<span class="s2">&quot;status&quot;</span><span class="p">:</span> <span class="n">status_cmd</span><span class="p">,</span>
<span class="s2">&quot;upload&quot;</span><span class="p">:</span> <span class="n">upload_cmd</span><span class="p">,</span>
<span class="s2">&quot;providers&quot;</span><span class="p">:</span> <span class="n">providers_cmd</span>
<span class="p">}</span>
<div class="viewcode-block" id="main"><a class="viewcode-back" href="../../composer.cli.html#composer.cli.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Main program execution</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Making sure opts.args is not empty (thus, has a command and subcommand)</span>
<span class="c1"># is already handled in src/bin/composer-cli.</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">command_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown command </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="n">command_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]](</span><span class="n">opts</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,779 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.blueprints &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.blueprints</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.blueprints</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">blueprints_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">argify</span><span class="p">,</span> <span class="n">frozen_toml_filename</span><span class="p">,</span> <span class="n">toml_filename</span><span class="p">,</span> <span class="n">handle_api_result</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">packageNEVRA</span>
<div class="viewcode-block" id="blueprints_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_cmd">[docs]</a><span class="k">def</span> <span class="nf">blueprints_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process blueprints commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> This dispatches the blueprints commands to a function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">blueprints_list</span><span class="p">,</span>
<span class="s2">&quot;show&quot;</span><span class="p">:</span> <span class="n">blueprints_show</span><span class="p">,</span>
<span class="s2">&quot;changes&quot;</span><span class="p">:</span> <span class="n">blueprints_changes</span><span class="p">,</span>
<span class="s2">&quot;diff&quot;</span><span class="p">:</span> <span class="n">blueprints_diff</span><span class="p">,</span>
<span class="s2">&quot;save&quot;</span><span class="p">:</span> <span class="n">blueprints_save</span><span class="p">,</span>
<span class="s2">&quot;delete&quot;</span><span class="p">:</span> <span class="n">blueprints_delete</span><span class="p">,</span>
<span class="s2">&quot;depsolve&quot;</span><span class="p">:</span> <span class="n">blueprints_depsolve</span><span class="p">,</span>
<span class="s2">&quot;push&quot;</span><span class="p">:</span> <span class="n">blueprints_push</span><span class="p">,</span>
<span class="s2">&quot;freeze&quot;</span><span class="p">:</span> <span class="n">blueprints_freeze</span><span class="p">,</span>
<span class="s2">&quot;tag&quot;</span><span class="p">:</span> <span class="n">blueprints_tag</span><span class="p">,</span>
<span class="s2">&quot;undo&quot;</span><span class="p">:</span> <span class="n">blueprints_undo</span><span class="p">,</span>
<span class="s2">&quot;workspace&quot;</span><span class="p">:</span> <span class="n">blueprints_workspace</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">blueprints_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown blueprints command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">)</span></div>
<div class="viewcode-block" id="blueprints_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_list">[docs]</a><span class="k">def</span> <span class="nf">blueprints_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Output the list of available blueprints</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/list&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json_unlimited</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="c1"># &quot;list&quot; should output a plain list of identifiers, one per line.</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprints&quot;</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="blueprints_show"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_show">[docs]</a><span class="k">def</span> <span class="nf">blueprints_show</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Show the blueprints, in TOML format</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints show &lt;blueprint,...&gt; Display the blueprint in TOML format.</span>
<span class="sd"> Multiple blueprints will be separated by \n\n</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/info/</span><span class="si">%s</span><span class="s2">?format=toml&quot;</span> <span class="o">%</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="blueprints_changes"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_changes">[docs]</a><span class="k">def</span> <span class="nf">blueprints_changes</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Display the changes for each of the blueprints</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints changes &lt;blueprint,...&gt; Display the changes for each blueprint.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">changes_total_fn</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the maximum number of possible changes&quot;&quot;&quot;</span>
<span class="c1"># Each blueprint can have a different total, return the largest one</span>
<span class="k">return</span> <span class="nb">max</span><span class="p">([</span><span class="n">c</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;blueprints&quot;</span><span class="p">]])</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/changes/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">))))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json_unlimited</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">total_fn</span><span class="o">=</span><span class="n">changes_total_fn</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprints&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
<span class="k">for</span> <span class="n">change</span> <span class="ow">in</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;changes&quot;</span><span class="p">]:</span>
<span class="n">prettyCommitDetails</span><span class="p">(</span><span class="n">change</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="prettyCommitDetails"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.prettyCommitDetails">[docs]</a><span class="k">def</span> <span class="nf">prettyCommitDetails</span><span class="p">(</span><span class="n">change</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Print the blueprint&#39;s change in a nice way</span>
<span class="sd"> :param change: The individual blueprint change dict</span>
<span class="sd"> :type change: dict</span>
<span class="sd"> :param indent: Number of spaces to indent</span>
<span class="sd"> :type indent: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">revision</span><span class="p">():</span>
<span class="k">if</span> <span class="n">change</span><span class="p">[</span><span class="s2">&quot;revision&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot; revision </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">change</span><span class="p">[</span><span class="s2">&quot;revision&quot;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">*</span> <span class="n">indent</span> <span class="o">+</span> <span class="n">change</span><span class="p">[</span><span class="s2">&quot;timestamp&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">change</span><span class="p">[</span><span class="s2">&quot;commit&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">revision</span><span class="p">())</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">*</span> <span class="n">indent</span> <span class="o">+</span> <span class="n">change</span><span class="p">[</span><span class="s2">&quot;message&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="blueprints_diff"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_diff">[docs]</a><span class="k">def</span> <span class="nf">blueprints_diff</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Display the differences between 2 versions of a blueprint</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints diff &lt;blueprint-name&gt; Display the differences between 2 versions of a blueprint.</span>
<span class="sd"> &lt;from-commit&gt; Commit hash or NEWEST</span>
<span class="sd"> &lt;to-commit&gt; Commit hash, NEWEST, or WORKSPACE</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;blueprints diff is missing the blueprint name, from commit, and to commit&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;blueprints diff is missing the from commit, and the to commit&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;blueprints diff is missing the to commit&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/diff/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">diff</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;diff&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">pretty_diff_entry</span><span class="p">(</span><span class="n">diff</span><span class="p">))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="pretty_dict"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.pretty_dict">[docs]</a><span class="k">def</span> <span class="nf">pretty_dict</span><span class="p">(</span><span class="n">d</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the dict as a human readable single line</span>
<span class="sd"> :param d: key/values</span>
<span class="sd"> :type d: dict</span>
<span class="sd"> :returns: String of the dict&#39;s keys and values</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> key=&quot;str&quot;, key=&quot;str1,str2&quot;, ...</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">result</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">d</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">=&quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]))</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">([])</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">=&quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])))</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">([])</span> <span class="ow">and</span> <span class="nb">type</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="n">result</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">=&quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">pretty_dict</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">])))</span>
<span class="k">return</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">result</span><span class="p">)</span></div>
<div class="viewcode-block" id="dict_names"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.dict_names">[docs]</a><span class="k">def</span> <span class="nf">dict_names</span><span class="p">(</span><span class="n">lst</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return comma-separated list of the dict&#39;s name/user fields</span>
<span class="sd"> :param d: key/values</span>
<span class="sd"> :type d: dict</span>
<span class="sd"> :returns: String of the dict&#39;s keys and values</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> root, norm</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="s2">&quot;user&quot;</span> <span class="ow">in</span> <span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
<span class="n">field_name</span> <span class="o">=</span> <span class="s2">&quot;user&quot;</span>
<span class="k">elif</span> <span class="s2">&quot;name&quot;</span> <span class="ow">in</span> <span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]:</span>
<span class="n">field_name</span> <span class="o">=</span> <span class="s2">&quot;name&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Use first fields in sorted keys</span>
<span class="n">field_name</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">lst</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">return</span> <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="n">field_name</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">lst</span><span class="p">)</span></div>
<div class="viewcode-block" id="pretty_diff_entry"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.pretty_diff_entry">[docs]</a><span class="k">def</span> <span class="nf">pretty_diff_entry</span><span class="p">(</span><span class="n">diff</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Generate nice diff entry string.</span>
<span class="sd"> :param diff: Difference entry dict</span>
<span class="sd"> :type diff: dict</span>
<span class="sd"> :returns: Nice string</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]:</span>
<span class="n">change</span> <span class="o">=</span> <span class="s2">&quot;Changed&quot;</span>
<span class="k">elif</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">]:</span>
<span class="n">change</span> <span class="o">=</span> <span class="s2">&quot;Added&quot;</span>
<span class="k">elif</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">]</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]:</span>
<span class="n">change</span> <span class="o">=</span> <span class="s2">&quot;Removed&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">change</span> <span class="o">=</span> <span class="s2">&quot;Unknown&quot;</span>
<span class="k">if</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">]:</span>
<span class="n">name</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]:</span>
<span class="n">name</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">name</span> <span class="o">=</span> <span class="s2">&quot;Unknown&quot;</span>
<span class="k">def</span> <span class="nf">details</span><span class="p">(</span><span class="n">diff</span><span class="p">):</span>
<span class="k">if</span> <span class="n">change</span> <span class="o">==</span> <span class="s2">&quot;Changed&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">if</span> <span class="n">name</span> <span class="o">==</span> <span class="s2">&quot;Description&quot;</span> <span class="ow">or</span> <span class="s2">&quot; &quot;</span> <span class="ow">in</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]:</span>
<span class="k">return</span> <span class="s1">&#39;&quot;</span><span class="si">%s</span><span class="s1">&quot; -&gt; &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">],</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> -&gt; </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">],</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Module&quot;</span><span class="p">,</span> <span class="s2">&quot;Package&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> -&gt; </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">],</span>
<span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">([]):</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> -&gt; </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]),</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]))</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="c1"># Lists of dicts are too long to display in detail, just show their names</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> -&gt; </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">dict_names</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]),</span> <span class="n">dict_names</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]))</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> -&gt; </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pretty_dict</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]),</span> <span class="n">pretty_dict</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;Unknown&quot;</span>
<span class="k">elif</span> <span class="n">change</span> <span class="o">==</span> <span class="s2">&quot;Added&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Module&quot;</span><span class="p">,</span> <span class="s2">&quot;Package&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Group&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">([]):</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="c1"># Lists of dicts are too long to display in detail, just show their names</span>
<span class="k">return</span> <span class="n">dict_names</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="k">return</span> <span class="n">pretty_dict</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;unknown/todo: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">change</span> <span class="o">==</span> <span class="s2">&quot;Removed&quot;</span><span class="p">:</span>
<span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Module&quot;</span><span class="p">,</span> <span class="s2">&quot;Package&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">name</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;Group&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">]</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">([]):</span>
<span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">][</span><span class="mi">0</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="c1"># Lists of dicts are too long to display in detail, just show their names</span>
<span class="k">return</span> <span class="n">dict_names</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">elif</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span> <span class="o">==</span> <span class="nb">type</span><span class="p">({}):</span>
<span class="k">return</span> <span class="n">pretty_dict</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;old&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;unknown/todo: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">type</span><span class="p">(</span><span class="n">diff</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">][</span><span class="n">name</span><span class="p">])</span>
<span class="k">return</span> <span class="n">change</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">name</span> <span class="o">+</span> <span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">details</span><span class="p">(</span><span class="n">diff</span><span class="p">)</span></div>
<div class="viewcode-block" id="blueprints_save"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_save">[docs]</a><span class="k">def</span> <span class="nf">blueprints_save</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Save the blueprint to a TOML file</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints save &lt;blueprint,...&gt; Save the blueprint to a file, &lt;blueprint-name&gt;.toml</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/info/</span><span class="si">%s</span><span class="s2">?format=toml&quot;</span> <span class="o">%</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="n">blueprint_toml</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="nb">open</span><span class="p">(</span><span class="n">toml_filename</span><span class="p">(</span><span class="n">blueprint</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blueprint_toml</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="blueprints_delete"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_delete">[docs]</a><span class="k">def</span> <span class="nf">blueprints_delete</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a blueprint from the server</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> delete &lt;blueprint&gt; Delete a blueprint from the server</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/delete/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="blueprints_depsolve"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_depsolve">[docs]</a><span class="k">def</span> <span class="nf">blueprints_depsolve</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Display the packages needed to install the blueprint</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints depsolve &lt;blueprint,...&gt; Display the packages needed to install the blueprint.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/depsolve/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">))))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprints&quot;</span><span class="p">]:</span>
<span class="k">if</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;version&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;blueprint: </span><span class="si">%s</span><span class="s2"> v</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;blueprint: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">]))</span>
<span class="k">for</span> <span class="n">dep</span> <span class="ow">in</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;dependencies&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">packageNEVRA</span><span class="p">(</span><span class="n">dep</span><span class="p">))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="blueprints_push"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_push">[docs]</a><span class="k">def</span> <span class="nf">blueprints_push</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Push a blueprint TOML file to the server, updating the blueprint</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> push &lt;blueprint&gt; Push a blueprint TOML file to the server.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/new&quot;</span><span class="p">)</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</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">exists</span><span class="p">(</span><span class="n">blueprint</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing blueprint file: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">blueprint_toml</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">blueprint</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_toml</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">blueprint_toml</span><span class="p">)</span>
<span class="k">if</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]:</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rval</span></div>
<div class="viewcode-block" id="blueprints_freeze"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_freeze">[docs]</a><span class="k">def</span> <span class="nf">blueprints_freeze</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Handle the blueprints freeze commands</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints freeze &lt;blueprint,...&gt; Display the frozen blueprint&#39;s modules and packages.</span>
<span class="sd"> blueprints freeze show &lt;blueprint,...&gt; Display the frozen blueprint in TOML format.</span>
<span class="sd"> blueprints freeze save &lt;blueprint,...&gt; Save the frozen blueprint to a file, &lt;blueprint-name&gt;.frozen.toml.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;show&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="n">blueprints_freeze_show</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;save&quot;</span><span class="p">:</span>
<span class="k">return</span> <span class="n">blueprints_freeze_save</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;freeze is missing the blueprint name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/freeze/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">))))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprints&quot;</span><span class="p">]:</span>
<span class="n">blueprint</span> <span class="o">=</span> <span class="n">entry</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">blueprint</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;version&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;blueprint: </span><span class="si">%s</span><span class="s2"> v</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;blueprint: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]))</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;modules&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">blueprint</span><span class="p">[</span><span class="s2">&quot;packages&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">p</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="blueprints_freeze_show"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_freeze_show">[docs]</a><span class="k">def</span> <span class="nf">blueprints_freeze_show</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Show the frozen blueprint in TOML format</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints freeze show &lt;blueprint,...&gt; Display the frozen blueprint in TOML format.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;freeze show is missing the blueprint name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/freeze/</span><span class="si">%s</span><span class="s2">?format=toml&quot;</span> <span class="o">%</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="blueprints_freeze_save"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_freeze_save">[docs]</a><span class="k">def</span> <span class="nf">blueprints_freeze_save</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Save the frozen blueprint to a TOML file</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints freeze save &lt;blueprint,...&gt; Save the frozen blueprint to a file, &lt;blueprint-name&gt;.frozen.toml.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;freeze save is missing the blueprint name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/freeze/</span><span class="si">%s</span><span class="s2">?format=toml&quot;</span> <span class="o">%</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="n">blueprint_toml</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="nb">open</span><span class="p">(</span><span class="n">frozen_toml_filename</span><span class="p">(</span><span class="n">blueprint</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">blueprint_toml</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="blueprints_tag"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_tag">[docs]</a><span class="k">def</span> <span class="nf">blueprints_tag</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Tag the most recent blueprint commit as a release</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints tag &lt;blueprint&gt; Tag the most recent blueprint commit as a release.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/tag/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="blueprints_undo"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_undo">[docs]</a><span class="k">def</span> <span class="nf">blueprints_undo</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Undo changes to a blueprint</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints undo &lt;blueprint&gt; &lt;commit&gt; Undo changes to a blueprint by reverting to the selected commit.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;undo is missing the blueprint name and commit hash&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;undo is missing commit hash&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/undo/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="blueprints_workspace"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.blueprints.blueprints_workspace">[docs]</a><span class="k">def</span> <span class="nf">blueprints_workspace</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Push the blueprint TOML to the temporary workspace storage</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> blueprints workspace &lt;blueprint&gt; Push the blueprint TOML to the temporary workspace storage.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/blueprints/workspace&quot;</span><span class="p">)</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">blueprint</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</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">exists</span><span class="p">(</span><span class="n">blueprint</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing blueprint file: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">blueprint_toml</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">blueprint</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_toml</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">blueprint_toml</span><span class="p">)</span>
<span class="k">if</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]:</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rval</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,251 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.cmdline &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.cmdline</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.cmdline</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">vernum</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">epilog</span>
<span class="n">VERSION</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">-</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</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">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">vernum</span><span class="p">)</span>
<div class="viewcode-block" id="composer_cli_parser"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.cmdline.composer_cli_parser">[docs]</a><span class="k">def</span> <span class="nf">composer_cli_parser</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot; Return the ArgumentParser for composer-cli&quot;&quot;&quot;</span>
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">&quot;Lorax Composer commandline tool&quot;</span><span class="p">,</span>
<span class="n">epilog</span><span class="o">=</span><span class="n">epilog</span><span class="p">,</span>
<span class="n">formatter_class</span><span class="o">=</span><span class="n">argparse</span><span class="o">.</span><span class="n">RawDescriptionHelpFormatter</span><span class="p">,</span>
<span class="n">fromfile_prefix_chars</span><span class="o">=</span><span class="s2">&quot;@&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-j&quot;</span><span class="p">,</span> <span class="s2">&quot;--json&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Output the raw JSON response instead of the normal output.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="s2">&quot;--socket&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/run/weldr/api.socket&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;SOCKET&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to the socket file to listen on&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--log&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;logfile&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;LOG&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to logfile (./composer-cli.log)&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-a&quot;</span><span class="p">,</span> <span class="s2">&quot;--api&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;api_version&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;1&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;APIVER&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;API Version to use&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--test&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;testmode&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;TESTMODE&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Pass test mode to compose. 1=Mock compose with fail. 2=Mock compose with finished.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-V&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;showver&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;show program&#39;s version number and exit&quot;</span><span class="p">)</span>
<span class="c1"># Commands are implemented by parsing the remaining arguments outside of argparse</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;args&#39;</span><span class="p">,</span> <span class="n">nargs</span><span class="o">=</span><span class="n">argparse</span><span class="o">.</span><span class="n">REMAINDER</span><span class="p">)</span>
<span class="k">return</span> <span class="n">parser</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,892 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.compose &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.compose</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.compose</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018-2020 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">toml</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">compose_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">argify</span><span class="p">,</span> <span class="n">handle_api_result</span><span class="p">,</span> <span class="n">packageNEVRA</span><span class="p">,</span> <span class="n">get_arg</span>
<div class="viewcode-block" id="compose_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_cmd">[docs]</a><span class="k">def</span> <span class="nf">compose_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process compose commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> This dispatches the compose commands to a function</span>
<span class="sd"> compose_cmd expects api to be passed. eg.</span>
<span class="sd"> {&quot;version&quot;: 1, &quot;backend&quot;: &quot;lorax-composer&quot;}</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="s2">&quot;/api/status&quot;</span><span class="p">)</span>
<span class="c1"># Get the api version and fall back to 0 if it fails.</span>
<span class="n">api_version</span> <span class="o">=</span> <span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;api&quot;</span><span class="p">,</span> <span class="s2">&quot;0&quot;</span><span class="p">)</span>
<span class="n">backend</span> <span class="o">=</span> <span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;backend&quot;</span><span class="p">,</span> <span class="s2">&quot;unknown&quot;</span><span class="p">)</span>
<span class="n">api</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;backend&quot;</span><span class="p">:</span> <span class="n">backend</span><span class="p">}</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">compose_list</span><span class="p">,</span>
<span class="s2">&quot;status&quot;</span><span class="p">:</span> <span class="n">compose_status</span><span class="p">,</span>
<span class="s2">&quot;types&quot;</span><span class="p">:</span> <span class="n">compose_types</span><span class="p">,</span>
<span class="s2">&quot;start&quot;</span><span class="p">:</span> <span class="n">compose_start</span><span class="p">,</span>
<span class="s2">&quot;log&quot;</span><span class="p">:</span> <span class="n">compose_log</span><span class="p">,</span>
<span class="s2">&quot;cancel&quot;</span><span class="p">:</span> <span class="n">compose_cancel</span><span class="p">,</span>
<span class="s2">&quot;delete&quot;</span><span class="p">:</span> <span class="n">compose_delete</span><span class="p">,</span>
<span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">compose_info</span><span class="p">,</span>
<span class="s2">&quot;metadata&quot;</span><span class="p">:</span> <span class="n">compose_metadata</span><span class="p">,</span>
<span class="s2">&quot;results&quot;</span><span class="p">:</span> <span class="n">compose_results</span><span class="p">,</span>
<span class="s2">&quot;logs&quot;</span><span class="p">:</span> <span class="n">compose_logs</span><span class="p">,</span>
<span class="s2">&quot;image&quot;</span><span class="p">:</span> <span class="n">compose_image</span><span class="p">,</span>
<span class="s2">&quot;start-ostree&quot;</span><span class="p">:</span> <span class="n">compose_ostree</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">compose_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown compose command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">testmode</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="n">api</span><span class="p">)</span></div>
<div class="viewcode-block" id="get_size"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.get_size">[docs]</a><span class="k">def</span> <span class="nf">get_size</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return optional --size argument, and remaining args</span>
<span class="sd"> :param args: list of arguments</span>
<span class="sd"> :type args: list of strings</span>
<span class="sd"> :returns: (args, size)</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> - check size argument for int</span>
<span class="sd"> - check other args for --size in wrong place</span>
<span class="sd"> - raise error? Or just return 0?</span>
<span class="sd"> - no size returns 0 in size</span>
<span class="sd"> - multiply by 1024**2 to make it easier on users to specify large sizes</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">args</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">get_arg</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="s2">&quot;--size&quot;</span><span class="p">,</span> <span class="nb">int</span><span class="p">)</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">value</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span> <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="mi">0</span>
<span class="k">return</span> <span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div>
<div class="viewcode-block" id="get_parent"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.get_parent">[docs]</a><span class="k">def</span> <span class="nf">get_parent</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return optional --parent argument, and remaining args</span>
<span class="sd"> :param args: list of arguments</span>
<span class="sd"> :type args: list of strings</span>
<span class="sd"> :returns: (args, parent)</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">args</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">get_arg</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="s2">&quot;--parent&quot;</span><span class="p">)</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">value</span> <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="k">return</span> <span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div>
<div class="viewcode-block" id="get_ref"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.get_ref">[docs]</a><span class="k">def</span> <span class="nf">get_ref</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return optional --ref argument, and remaining args</span>
<span class="sd"> :param args: list of arguments</span>
<span class="sd"> :type args: list of strings</span>
<span class="sd"> :returns: (args, parent)</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">args</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">get_arg</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="s2">&quot;--ref&quot;</span><span class="p">)</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">value</span> <span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="k">else</span> <span class="s2">&quot;&quot;</span>
<span class="k">return</span> <span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span></div>
<div class="viewcode-block" id="compose_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_list">[docs]</a><span class="k">def</span> <span class="nf">compose_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a simple list of compose identifiers&quot;&quot;&quot;</span>
<span class="n">states</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;running&quot;</span><span class="p">,</span> <span class="s2">&quot;waiting&quot;</span><span class="p">,</span> <span class="s2">&quot;finished&quot;</span><span class="p">,</span> <span class="s2">&quot;failed&quot;</span><span class="p">)</span>
<span class="n">which</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">any</span><span class="p">(</span><span class="n">a</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">states</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">):</span>
<span class="c1"># TODO: error about unknown state</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span>
<span class="n">which</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">states</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">which</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="s2">&quot;running&quot;</span> <span class="ow">in</span> <span class="n">which</span> <span class="ow">or</span> <span class="s2">&quot;waiting&quot;</span> <span class="ow">in</span> <span class="n">which</span><span class="p">:</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/queue&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;running&quot;</span> <span class="ow">in</span> <span class="n">which</span><span class="p">:</span>
<span class="n">results</span> <span class="o">+=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;run&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;waiting&quot;</span> <span class="ow">in</span> <span class="n">which</span><span class="p">:</span>
<span class="n">results</span> <span class="o">+=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;finished&quot;</span> <span class="ow">in</span> <span class="n">which</span><span class="p">:</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/finished&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">+=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;finished&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;failed&quot;</span> <span class="ow">in</span> <span class="n">which</span><span class="p">:</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/failed&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">+=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;failed&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">results</span><span class="p">:</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">list_fmt</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{id}</span><span class="s2"> </span><span class="si">{queue_status}</span><span class="s2"> </span><span class="si">{blueprint}</span><span class="s2"> </span><span class="si">{version}</span><span class="s2"> </span><span class="si">{compose_type}</span><span class="s2">&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">list_fmt</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">c</span><span class="p">)</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">results</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="compose_status"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_status">[docs]</a><span class="k">def</span> <span class="nf">compose_status</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the status of all known composes</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> This doesn&#39;t map directly to an API command, it combines the results from queue, finished,</span>
<span class="sd"> and failed so raw JSON output is not available.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">get_status</span><span class="p">(</span><span class="n">compose</span><span class="p">):</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">],</span>
<span class="s2">&quot;blueprint&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">],</span>
<span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">],</span>
<span class="s2">&quot;compose_type&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;compose_type&quot;</span><span class="p">],</span>
<span class="s2">&quot;image_size&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;image_size&quot;</span><span class="p">],</span>
<span class="s2">&quot;status&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="p">[</span><span class="s2">&quot;queue_status&quot;</span><span class="p">],</span>
<span class="s2">&quot;created&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;job_created&quot;</span><span class="p">),</span>
<span class="s2">&quot;started&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;job_started&quot;</span><span class="p">),</span>
<span class="s2">&quot;finished&quot;</span><span class="p">:</span> <span class="n">compose</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;job_finished&quot;</span><span class="p">)}</span>
<span class="c1"># Sort the status in a specific order</span>
<span class="k">def</span> <span class="nf">sort_status</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>
<span class="n">order</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;RUNNING&quot;</span><span class="p">,</span> <span class="s2">&quot;WAITING&quot;</span><span class="p">,</span> <span class="s2">&quot;FINISHED&quot;</span><span class="p">,</span> <span class="s2">&quot;FAILED&quot;</span><span class="p">]</span>
<span class="k">return</span> <span class="p">(</span><span class="n">order</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="s2">&quot;status&quot;</span><span class="p">]),</span> <span class="n">a</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">],</span> <span class="n">a</span><span class="p">[</span><span class="s2">&quot;compose_type&quot;</span><span class="p">])</span>
<span class="n">status</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># Get the composes currently in the queue</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/queue&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">status</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">get_status</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;run&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;new&quot;</span><span class="p">])))</span>
<span class="c1"># Get the list of finished composes</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/finished&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">status</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">get_status</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;finished&quot;</span><span class="p">])))</span>
<span class="c1"># Get the list of failed composes</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/failed&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">status</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">get_status</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;failed&quot;</span><span class="p">])))</span>
<span class="c1"># Sort them by status (running, waiting, finished, failed) and then by name and version.</span>
<span class="n">status</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="n">sort_status</span><span class="p">)</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="c1"># Print them as UUID blueprint STATUS</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">status</span><span class="p">:</span>
<span class="k">if</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;image_size&quot;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">image_size</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="s2">&quot;image_size&quot;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">image_size</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">dt</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">fromtimestamp</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;finished&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;started&quot;</span><span class="p">)</span> <span class="ow">or</span> <span class="n">c</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;created&quot;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%-8s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> </span><span class="si">%-15s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> </span><span class="si">%-16s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">c</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;status&quot;</span><span class="p">],</span> <span class="n">dt</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%c</span><span class="s2">&quot;</span><span class="p">),</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">],</span>
<span class="n">c</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">],</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;compose_type&quot;</span><span class="p">],</span> <span class="n">image_size</span><span class="p">))</span></div>
<div class="viewcode-block" id="compose_types"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_types">[docs]</a><span class="k">def</span> <span class="nf">compose_types</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return information about the supported compose types</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> Add additional details to types that are known to composer-cli. Raw JSON output does not</span>
<span class="sd"> include this extra information.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/types&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="c1"># output a plain list of identifiers, one per line</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;types&quot;</span><span class="p">]</span> <span class="k">if</span> <span class="n">t</span><span class="p">[</span><span class="s2">&quot;enabled&quot;</span><span class="p">]))</span></div>
<div class="viewcode-block" id="compose_start"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_start">[docs]</a><span class="k">def</span> <span class="nf">compose_start</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Start a new compose using the selected blueprint and type</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: Set to 1 to simulate a failed compose, set to 2 to simulate a finished one.</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> :param api: Details about the API server, &quot;version&quot; and &quot;backend&quot;</span>
<span class="sd"> :type api: dict</span>
<span class="sd"> compose start [--size XXX] &lt;blueprint-name&gt; &lt;compose-type&gt; [&lt;image-name&gt; &lt;provider&gt; &lt;profile&gt; | &lt;image-name&gt; &lt;profile.toml&gt;]</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">api</span> <span class="o">==</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing api version/backend&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="c1"># Get the optional size before checking other parameters</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">args</span><span class="p">,</span> <span class="n">size</span> <span class="o">=</span> <span class="n">get_size</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">RuntimeError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the blueprint name and output type&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the output type&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the provider and profile details&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">config</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;blueprint_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
<span class="s2">&quot;compose_type&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="s2">&quot;branch&quot;</span><span class="p">:</span> <span class="s2">&quot;master&quot;</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">size</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="n">api</span><span class="p">[</span><span class="s2">&quot;backend&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;lorax-composer&quot;</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;lorax-composer does not support --size, it will be ignored.&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">size</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]}</span>
<span class="c1"># profile TOML file (maybe)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">5</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
<span class="s2">&quot;provider&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span>
<span class="s2">&quot;profile&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">testmode</span><span class="p">:</span>
<span class="n">test_url</span> <span class="o">=</span> <span class="s2">&quot;?test=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">testmode</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">test_url</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose&quot;</span> <span class="o">+</span> <span class="n">test_url</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">config</span><span class="p">))</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Compose </span><span class="si">%s</span><span class="s2"> added to the queue&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;build_id&quot;</span><span class="p">])</span>
<span class="k">if</span> <span class="s2">&quot;upload_id&quot;</span> <span class="ow">in</span> <span class="n">result</span> <span class="ow">and</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">]:</span>
<span class="nb">print</span> <span class="p">(</span><span class="s2">&quot;Upload </span><span class="si">%s</span><span class="s2"> added to the upload queue&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">])</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_ostree"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_ostree">[docs]</a><span class="k">def</span> <span class="nf">compose_ostree</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Start a new ostree compose using the selected blueprint and type</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: Set to 1 to simulate a failed compose, set to 2 to simulate a finished one.</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> :param api: Details about the API server, &quot;version&quot; and &quot;backend&quot;</span>
<span class="sd"> :type api: dict</span>
<span class="sd"> compose start-ostree [--size XXXX] [--parent PARENT] [--ref REF] &lt;BLUEPRINT&gt; &lt;TYPE&gt; [&lt;IMAGE-NAME&gt; &lt;PROFILE.TOML&gt;]</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">api</span> <span class="o">==</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing api version/backend&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">api</span><span class="p">[</span><span class="s2">&quot;backend&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;lorax-composer&quot;</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;lorax-composer doesn not support start-ostree.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="c1"># Get the optional size before checking other parameters</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">args</span><span class="p">,</span> <span class="n">size</span> <span class="o">=</span> <span class="n">get_size</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="n">args</span><span class="p">,</span> <span class="n">parent</span> <span class="o">=</span> <span class="n">get_parent</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="n">args</span><span class="p">,</span> <span class="n">ref</span> <span class="o">=</span> <span class="n">get_ref</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">RuntimeError</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start-ostree is missing the blueprint name, output type, and ostree details&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start-ostree is missing the output type&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start-ostree is missing the provider TOML file&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">config</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;blueprint_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
<span class="s2">&quot;compose_type&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="s2">&quot;branch&quot;</span><span class="p">:</span> <span class="s2">&quot;master&quot;</span><span class="p">,</span>
<span class="s2">&quot;ostree&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;ref&quot;</span><span class="p">:</span> <span class="n">ref</span><span class="p">,</span> <span class="s2">&quot;parent&quot;</span><span class="p">:</span> <span class="n">parent</span><span class="p">},</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">size</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">size</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]}</span>
<span class="c1"># profile TOML file (maybe)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">config</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">testmode</span><span class="p">:</span>
<span class="n">test_url</span> <span class="o">=</span> <span class="s2">&quot;?test=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">testmode</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">test_url</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose&quot;</span> <span class="o">+</span> <span class="n">test_url</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">config</span><span class="p">))</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Compose </span><span class="si">%s</span><span class="s2"> added to the queue&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;build_id&quot;</span><span class="p">])</span>
<span class="k">if</span> <span class="s2">&quot;upload_id&quot;</span> <span class="ow">in</span> <span class="n">result</span> <span class="ow">and</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">]:</span>
<span class="nb">print</span> <span class="p">(</span><span class="s2">&quot;Upload </span><span class="si">%s</span><span class="s2"> added to the upload queue&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">])</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_log"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_log">[docs]</a><span class="k">def</span> <span class="nf">compose_log</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Show the last part of the compose log</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose log &lt;uuid&gt; [&lt;size&gt;kB]</span>
<span class="sd"> This will display the last 1kB of the compose&#39;s log file. Can be used to follow progress</span>
<span class="sd"> during the build.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;log is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">log_size</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Log size must be an integer.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">log_size</span> <span class="o">=</span> <span class="mi">1024</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/log/</span><span class="si">%s</span><span class="s2">?size=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">log_size</span><span class="p">))</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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">return</span> <span class="mi">1</span>
<span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="compose_cancel"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_cancel">[docs]</a><span class="k">def</span> <span class="nf">compose_cancel</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Cancel a running compose</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose cancel &lt;uuid&gt;</span>
<span class="sd"> This will cancel a running compose. It does nothing if the compose has finished.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;cancel is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/cancel/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="compose_delete"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_delete">[docs]</a><span class="k">def</span> <span class="nf">compose_delete</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a finished compose&#39;s results</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose delete &lt;uuid,...&gt;</span>
<span class="sd"> Delete the listed compose results. It will only delete results for composes that have finished</span>
<span class="sd"> or failed, not a running compose.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;delete is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/delete/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">))))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="compose_info"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_info">[docs]</a><span class="k">def</span> <span class="nf">compose_info</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return detailed information about the compose</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose info &lt;uuid&gt;</span>
<span class="sd"> This returns information about the compose, including the blueprint and the dependencies.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;info is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/info/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">if</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;image_size&quot;</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">image_size</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;image_size&quot;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">image_size</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%-8s</span><span class="s2"> </span><span class="si">%-15s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> </span><span class="si">%-16s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;queue_status&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;compose_type&quot;</span><span class="p">],</span>
<span class="n">image_size</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Packages:&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;packages&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">p</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Modules:&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;blueprint&quot;</span><span class="p">][</span><span class="s2">&quot;modules&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">m</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Dependencies:&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;deps&quot;</span><span class="p">][</span><span class="s2">&quot;packages&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">packageNEVRA</span><span class="p">(</span><span class="n">d</span><span class="p">))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_metadata"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_metadata">[docs]</a><span class="k">def</span> <span class="nf">compose_metadata</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Download a tar file of the compose&#39;s metadata</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose metadata &lt;uuid&gt;</span>
<span class="sd"> Saves the metadata as uuid-metadata.tar</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;metadata is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/metadata/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">download_file</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_results"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_results">[docs]</a><span class="k">def</span> <span class="nf">compose_results</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Download a tar file of the compose&#39;s results</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose results &lt;uuid&gt;</span>
<span class="sd"> The results includes the metadata, output image, and logs.</span>
<span class="sd"> It is saved as uuid.tar</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;results is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/results/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">download_file</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">isatty</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_logs"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_logs">[docs]</a><span class="k">def</span> <span class="nf">compose_logs</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Download a tar of the compose&#39;s logs</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose logs &lt;uuid&gt;</span>
<span class="sd"> Saves the logs as uuid-logs.tar</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;logs is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/logs/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">download_file</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">isatty</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="compose_image"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.compose.compose_image">[docs]</a><span class="k">def</span> <span class="nf">compose_image</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Download the compose&#39;s output image</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> compose image &lt;uuid&gt;</span>
<span class="sd"> This downloads only the result image, saving it as the image name, which depends on the type</span>
<span class="sd"> of compose that was selected.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;logs is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/image/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">download_file</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">isatty</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rc</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,249 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.modules &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.modules</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.modules</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">modules_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">handle_api_result</span>
<div class="viewcode-block" id="modules_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.modules.modules_cmd">[docs]</a><span class="k">def</span> <span class="nf">modules_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process modules commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">modules_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">&quot;list&quot;</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown modules command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/modules/list&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json_unlimited</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="c1"># &quot;list&quot; should output a plain list of identifiers, one per line.</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">r</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;modules&quot;</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">rc</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,311 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.projects &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.projects</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.projects</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">textwrap</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">projects_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">handle_api_result</span>
<div class="viewcode-block" id="projects_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.projects.projects_cmd">[docs]</a><span class="k">def</span> <span class="nf">projects_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process projects commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">projects_list</span><span class="p">,</span>
<span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">projects_info</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">projects_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown projects command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">)</span></div>
<div class="viewcode-block" id="projects_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.projects.projects_list">[docs]</a><span class="k">def</span> <span class="nf">projects_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Output the list of available projects</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> projects list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/list&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json_unlimited</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">proj</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;projects&quot;</span><span class="p">]:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="n">field</span> <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;summary&quot;</span><span class="p">,</span> <span class="s2">&quot;homepage&quot;</span><span class="p">,</span> <span class="s2">&quot;description&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">proj</span><span class="p">[</span><span class="n">field</span><span class="p">]]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">title</span><span class="p">(),</span> <span class="n">textwrap</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">proj</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">subsequent_indent</span><span class="o">=</span><span class="s2">&quot; &quot;</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">+</span><span class="mi">2</span><span class="p">))))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="projects_info"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.projects.projects_info">[docs]</a><span class="k">def</span> <span class="nf">projects_info</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Output info on a list of projects</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> projects info &lt;project,...&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;projects info is missing the packages&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/info/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="k">for</span> <span class="n">proj</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;projects&quot;</span><span class="p">]:</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="p">[</span><span class="n">field</span> <span class="k">for</span> <span class="n">field</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;name&quot;</span><span class="p">,</span> <span class="s2">&quot;summary&quot;</span><span class="p">,</span> <span class="s2">&quot;homepage&quot;</span><span class="p">,</span> <span class="s2">&quot;description&quot;</span><span class="p">)</span> <span class="k">if</span> <span class="n">proj</span><span class="p">[</span><span class="n">field</span><span class="p">]]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="o">.</span><span class="n">title</span><span class="p">(),</span> <span class="n">textwrap</span><span class="o">.</span><span class="n">fill</span><span class="p">(</span><span class="n">proj</span><span class="p">[</span><span class="n">k</span><span class="p">],</span> <span class="n">subsequent_indent</span><span class="o">=</span><span class="s2">&quot; &quot;</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">k</span><span class="p">)</span><span class="o">+</span><span class="mi">2</span><span class="p">))))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Builds: &quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">build</span> <span class="ow">in</span> <span class="n">proj</span><span class="p">[</span><span class="s2">&quot;builds&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%s%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2"> at </span><span class="si">%s</span><span class="s2"> for </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="s2">&quot;&quot;</span> <span class="k">if</span> <span class="ow">not</span> <span class="n">build</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">]</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">build</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">])</span> <span class="o">+</span> <span class="s2">&quot;:&quot;</span><span class="p">,</span>
<span class="n">build</span><span class="p">[</span><span class="s2">&quot;source&quot;</span><span class="p">][</span><span class="s2">&quot;version&quot;</span><span class="p">],</span>
<span class="n">build</span><span class="p">[</span><span class="s2">&quot;release&quot;</span><span class="p">],</span>
<span class="n">build</span><span class="p">[</span><span class="s2">&quot;arch&quot;</span><span class="p">],</span>
<span class="n">build</span><span class="p">[</span><span class="s2">&quot;build_time&quot;</span><span class="p">],</span>
<span class="n">build</span><span class="p">[</span><span class="s2">&quot;changelog&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rc</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,523 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.providers &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.providers</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.providers</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">toml</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">providers_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">handle_api_result</span><span class="p">,</span> <span class="n">toml_filename</span>
<div class="viewcode-block" id="providers_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_cmd">[docs]</a><span class="k">def</span> <span class="nf">providers_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process providers commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> This dispatches the providers commands to a function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">providers_list</span><span class="p">,</span>
<span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">providers_info</span><span class="p">,</span>
<span class="s2">&quot;show&quot;</span><span class="p">:</span> <span class="n">providers_show</span><span class="p">,</span>
<span class="s2">&quot;push&quot;</span><span class="p">:</span> <span class="n">providers_push</span><span class="p">,</span>
<span class="s2">&quot;save&quot;</span><span class="p">:</span> <span class="n">providers_save</span><span class="p">,</span>
<span class="s2">&quot;delete&quot;</span><span class="p">:</span> <span class="n">providers_delete</span><span class="p">,</span>
<span class="s2">&quot;template&quot;</span><span class="p">:</span> <span class="n">providers_template</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">providers_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown providers command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">testmode</span><span class="p">)</span></div>
<div class="viewcode-block" id="providers_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_list">[docs]</a><span class="k">def</span> <span class="nf">providers_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the list of providers</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;providers&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid provider&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())))</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">results</span><span class="o">.</span><span class="n">keys</span><span class="p">())))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="providers_info"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_info">[docs]</a><span class="k">def</span> <span class="nf">providers_info</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Show information about each provider</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers info &lt;PROVIDER&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;info is missing the provider name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;providers&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid provider&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">p</span> <span class="o">=</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> supports these image types: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s2">&quot;display&quot;</span><span class="p">],</span> <span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="s2">&quot;supported_types&quot;</span><span class="p">])))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Settings:&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">p</span><span class="p">[</span><span class="s2">&quot;settings-info&quot;</span><span class="p">]:</span>
<span class="n">f</span> <span class="o">=</span> <span class="n">p</span><span class="p">[</span><span class="s2">&quot;settings-info&quot;</span><span class="p">][</span><span class="n">k</span><span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; </span><span class="si">%-20s</span><span class="s2">: </span><span class="si">%s</span><span class="s2"> is a </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">f</span><span class="p">[</span><span class="s2">&quot;display&quot;</span><span class="p">],</span> <span class="n">f</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="providers_show"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_show">[docs]</a><span class="k">def</span> <span class="nf">providers_show</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return details about a provider</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers show &lt;provider&gt; &lt;profile&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;show is missing the provider name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;show is missing the profile name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;providers&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid provider&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">]:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid </span><span class="si">%s</span><span class="s2"> profile&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="c1"># Print the details for this profile</span>
<span class="c1"># fields are different for each provider, so we just print out the key:values</span>
<span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">][</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">][</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]][</span><span class="n">k</span><span class="p">]))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="providers_push"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_push">[docs]</a><span class="k">def</span> <span class="nf">providers_push</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add a new provider profile or overwrite an existing one</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers push &lt;profile.toml&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;push is missing the profile TOML file&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</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">exists</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing profile TOML file: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers/save&quot;</span><span class="p">)</span>
<span class="n">profile</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">profile</span><span class="p">))</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="providers_save"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_save">[docs]</a><span class="k">def</span> <span class="nf">providers_save</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Save a provider&#39;s profile to a TOML file</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers save &lt;provider&gt; &lt;profile&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;save is missing the provider name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;save is missing the profile name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;providers&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid provider&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">]:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid </span><span class="si">%s</span><span class="s2"> profile&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">profile</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;provider&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
<span class="s2">&quot;profile&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
<span class="s2">&quot;settings&quot;</span><span class="p">:</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;profiles&quot;</span><span class="p">][</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]]</span>
<span class="p">}</span>
<span class="nb">open</span><span class="p">(</span><span class="n">toml_filename</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">profile</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="providers_delete"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_delete">[docs]</a><span class="k">def</span> <span class="nf">providers_delete</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a profile from a provider</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers delete &lt;provider&gt; &lt;profile&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;delete is missing the provider name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;delete is missing the profile name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers/delete/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="providers_template"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.providers.providers_template">[docs]</a><span class="k">def</span> <span class="nf">providers_template</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a TOML template for setting the provider&#39;s fields</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> providers template &lt;provider&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;template is missing the provider name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/providers&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;providers&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is not a valid provider&quot;</span><span class="p">,</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">template</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;provider&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]}</span>
<span class="n">settings</span> <span class="o">=</span> <span class="n">results</span><span class="p">[</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]][</span><span class="s2">&quot;settings-info&quot;</span><span class="p">]</span>
<span class="n">template</span><span class="p">[</span><span class="s2">&quot;settings&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">([(</span><span class="n">k</span><span class="p">,</span> <span class="n">settings</span><span class="p">[</span><span class="n">k</span><span class="p">][</span><span class="s2">&quot;display&quot;</span><span class="p">])</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">settings</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">template</span><span class="p">))</span>
<span class="k">return</span> <span class="mi">0</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,353 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.sources &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.sources</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.sources</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">sources_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">argify</span><span class="p">,</span> <span class="n">handle_api_result</span>
<div class="viewcode-block" id="sources_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.sources.sources_cmd">[docs]</a><span class="k">def</span> <span class="nf">sources_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process sources commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">sources_list</span><span class="p">,</span>
<span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">sources_info</span><span class="p">,</span>
<span class="s2">&quot;add&quot;</span><span class="p">:</span> <span class="n">sources_add</span><span class="p">,</span>
<span class="s2">&quot;change&quot;</span><span class="p">:</span> <span class="n">sources_add</span><span class="p">,</span>
<span class="s2">&quot;delete&quot;</span><span class="p">:</span> <span class="n">sources_delete</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">sources_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown sources command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">)</span></div>
<div class="viewcode-block" id="sources_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.sources.sources_list">[docs]</a><span class="k">def</span> <span class="nf">sources_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Output the list of available sources</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> sources list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/source/list&quot;</span><span class="p">)</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="c1"># &quot;list&quot; should output a plain list of identifiers, one per line.</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;sources&quot;</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="sources_info"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.sources.sources_info">[docs]</a><span class="k">def</span> <span class="nf">sources_info</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Output info on a list of projects</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> sources info &lt;source-name&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;sources info is missing the name of the source&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/source/info/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/source/info/</span><span class="si">%s</span><span class="s2">?format=toml&quot;</span> <span class="o">%</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">))</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">except</span> <span class="ne">RuntimeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="nb">print</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="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="sources_add"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.sources.sources_add">[docs]</a><span class="k">def</span> <span class="nf">sources_add</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add or change a source</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> sources add &lt;source.toml&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/source/new&quot;</span><span class="p">)</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">source</span> <span class="ow">in</span> <span class="n">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</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">exists</span><span class="p">(</span><span class="n">source</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing source file: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">source</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">source_toml</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_toml</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">source_toml</span><span class="p">)</span>
<span class="k">if</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]:</span>
<span class="n">rval</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">rval</span></div>
<div class="viewcode-block" id="sources_delete"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.sources.sources_delete">[docs]</a><span class="k">def</span> <span class="nf">sources_delete</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a source</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> sources delete &lt;source-name&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/projects/source/delete/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,257 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.status &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.status</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.status</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">status_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">handle_api_result</span>
<div class="viewcode-block" id="status_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.status.status_cmd">[docs]</a><span class="k">def</span> <span class="nf">status_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process status commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">status_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">&quot;show&quot;</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown status command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="s2">&quot;/api/status&quot;</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;API server status:&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Database version: &quot;</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;db_version&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Database supported: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;db_supported&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Schema version: &quot;</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;schema_version&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; API version: &quot;</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;api&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Backend: &quot;</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;backend&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot; Build: &quot;</span> <span class="o">+</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;build&quot;</span><span class="p">])</span>
<span class="k">if</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;msgs&quot;</span><span class="p">]:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Error messages:&quot;</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot; &quot;</span> <span class="o">+</span> <span class="n">r</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;msgs&quot;</span><span class="p">]]))</span>
<span class="k">return</span> <span class="n">rc</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,478 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.upload &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.upload</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.upload</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">toml</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">composer</span> <span class="kn">import</span> <span class="n">http_client</span> <span class="k">as</span> <span class="n">client</span>
<span class="kn">from</span> <span class="nn">composer.cli.help</span> <span class="kn">import</span> <span class="n">upload_help</span>
<span class="kn">from</span> <span class="nn">composer.cli.utilities</span> <span class="kn">import</span> <span class="n">handle_api_result</span>
<div class="viewcode-block" id="upload_cmd"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_cmd">[docs]</a><span class="k">def</span> <span class="nf">upload_cmd</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Process upload commands</span>
<span class="sd"> :param opts: Cmdline arguments</span>
<span class="sd"> :type opts: argparse.Namespace</span>
<span class="sd"> :returns: Value to return from sys.exit()</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> This dispatches the upload commands to a function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">cmd_map</span> <span class="o">=</span> <span class="p">{</span>
<span class="s2">&quot;list&quot;</span><span class="p">:</span> <span class="n">upload_list</span><span class="p">,</span>
<span class="s2">&quot;info&quot;</span><span class="p">:</span> <span class="n">upload_info</span><span class="p">,</span>
<span class="s2">&quot;start&quot;</span><span class="p">:</span> <span class="n">upload_start</span><span class="p">,</span>
<span class="s2">&quot;log&quot;</span><span class="p">:</span> <span class="n">upload_log</span><span class="p">,</span>
<span class="s2">&quot;cancel&quot;</span><span class="p">:</span> <span class="n">upload_cancel</span><span class="p">,</span>
<span class="s2">&quot;delete&quot;</span><span class="p">:</span> <span class="n">upload_delete</span><span class="p">,</span>
<span class="s2">&quot;reset&quot;</span><span class="p">:</span> <span class="n">upload_reset</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;help&quot;</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;--help&quot;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">upload_help</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">cmd_map</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Unknown upload command: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">cmd_map</span><span class="p">[</span><span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]](</span><span class="n">opts</span><span class="o">.</span><span class="n">socket</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">api_version</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">:],</span> <span class="n">opts</span><span class="o">.</span><span class="n">json</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">testmode</span><span class="p">)</span></div>
<div class="viewcode-block" id="upload_list"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_list">[docs]</a><span class="k">def</span> <span class="nf">upload_list</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the composes and their associated upload uuids and status</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/finished&quot;</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="n">results</span> <span class="o">=</span> <span class="n">r</span><span class="p">[</span><span class="s2">&quot;finished&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">results</span><span class="p">:</span>
<span class="k">return</span> <span class="mi">0</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">compose_fmt</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{id}</span><span class="s2"> </span><span class="si">{queue_status}</span><span class="s2"> </span><span class="si">{blueprint}</span><span class="s2"> </span><span class="si">{version}</span><span class="s2"> </span><span class="si">{compose_type}</span><span class="s2">&quot;</span>
<span class="n">upload_fmt</span> <span class="o">=</span> <span class="s1">&#39; </span><span class="si">{uuid}</span><span class="s1"> &quot;</span><span class="si">{image_name}</span><span class="s1">&quot; </span><span class="si">{provider_name}</span><span class="s1"> </span><span class="si">{status}</span><span class="s1">&#39;</span>
<span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="n">results</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">compose_fmt</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">c</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">upload_fmt</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">u</span><span class="p">)</span> <span class="k">for</span> <span class="n">u</span> <span class="ow">in</span> <span class="n">c</span><span class="p">[</span><span class="s2">&quot;uploads&quot;</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">()</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="upload_info"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_info">[docs]</a><span class="k">def</span> <span class="nf">upload_info</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return detailed information about the upload</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload info &lt;uuid&gt;</span>
<span class="sd"> This returns information about the upload, including uuid, name, status, service, and image.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;info is missing the upload uuid&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/info/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="n">image_path</span> <span class="o">=</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">][</span><span class="s2">&quot;image_path&quot;</span><span class="p">]</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%-8s</span><span class="s2"> </span><span class="si">%-15s</span><span class="s2"> </span><span class="si">%-8s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">][</span><span class="s2">&quot;uuid&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">][</span><span class="s2">&quot;status&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">][</span><span class="s2">&quot;image_name&quot;</span><span class="p">],</span>
<span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload&quot;</span><span class="p">][</span><span class="s2">&quot;provider_name&quot;</span><span class="p">],</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">image_path</span><span class="p">)</span> <span class="k">if</span> <span class="n">image_path</span> <span class="k">else</span> <span class="s2">&quot;UNFINISHED&quot;</span><span class="p">))</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="upload_start"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_start">[docs]</a><span class="k">def</span> <span class="nf">upload_start</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Start upload up a build uuid image</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload start &lt;build-uuid&gt; &lt;image-name&gt; [&lt;provider&gt; &lt;profile&gt; | &lt;profile.toml&gt;]</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the compose build id&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the image name&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start is missing the provider and profile details&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">body</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="n">args</span><span class="p">[</span><span class="mi">1</span><span class="p">]}</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">body</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</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">return</span> <span class="mi">1</span>
<span class="k">elif</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span><span class="p">:</span>
<span class="n">body</span><span class="p">[</span><span class="s2">&quot;provider&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="n">body</span><span class="p">[</span><span class="s2">&quot;profile&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;start has incorrect number of arguments&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/compose/uploads/schedule/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">body</span><span class="p">))</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Upload </span><span class="si">%s</span><span class="s2"> added to the queue&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">])</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="upload_log"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_log">[docs]</a><span class="k">def</span> <span class="nf">upload_log</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the upload log</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload log &lt;build-uuid&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;log is missing the upload uuid&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/log/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span> <span class="o">=</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exit_now</span><span class="p">:</span>
<span class="k">return</span> <span class="n">rc</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Upload log for </span><span class="si">%s</span><span class="s2">:</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;upload_id&quot;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">result</span><span class="p">[</span><span class="s2">&quot;log&quot;</span><span class="p">])</span>
<span class="k">return</span> <span class="mi">0</span></div>
<div class="viewcode-block" id="upload_cancel"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_cancel">[docs]</a><span class="k">def</span> <span class="nf">upload_cancel</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Cancel the queued or running upload</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload cancel &lt;build-uuid&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;cancel is missing the upload uuid&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/cancel/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="upload_delete"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_delete">[docs]</a><span class="k">def</span> <span class="nf">upload_delete</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete an upload and remove it from the build</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload delete &lt;build-uuid&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;delete is missing the upload uuid&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/delete/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">)</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="upload_reset"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.upload.upload_reset">[docs]</a><span class="k">def</span> <span class="nf">upload_reset</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_version</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">testmode</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Reset the upload and execute it again</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param api_version: Version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param args: List of remaining arguments from the cmdline</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :param show_json: Set to True to show the JSON output instead of the human readable output</span>
<span class="sd"> :type show_json: bool</span>
<span class="sd"> :param testmode: unused in this function</span>
<span class="sd"> :type testmode: int</span>
<span class="sd"> upload reset &lt;build-uuid&gt;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;reset is missing the upload uuid&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span>
<span class="n">api_route</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="s2">&quot;/upload/reset/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">api_route</span><span class="p">,</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({}))</span>
<span class="k">return</span> <span class="n">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,324 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.cli.utilities &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../cli.html">composer.cli</a> &raquo;</li>
<li>composer.cli.utilities</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.cli.utilities</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">json</span>
<div class="viewcode-block" id="argify"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.argify">[docs]</a><span class="k">def</span> <span class="nf">argify</span><span class="p">(</span><span class="n">args</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Take a list of human args and return a list with each item</span>
<span class="sd"> :param args: list of strings with possible commas and spaces</span>
<span class="sd"> :type args: list of str</span>
<span class="sd"> :returns: List of all the items</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> Examples:</span>
<span class="sd"> [&quot;one,two&quot;, &quot;three&quot;, &quot;,four&quot;, &quot;,five,&quot;] returns [&quot;one&quot;, &quot;two&quot;, &quot;three&quot;, &quot;four&quot;, &quot;five&quot;]</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">[</span><span class="n">i</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="p">[</span><span class="n">arg</span> <span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">args</span> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">entry</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">)]</span> <span class="k">if</span> <span class="n">i</span><span class="p">]</span></div>
<div class="viewcode-block" id="toml_filename"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.toml_filename">[docs]</a><span class="k">def</span> <span class="nf">toml_filename</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Convert a blueprint name into a filename.toml</span>
<span class="sd"> :param blueprint_name: The blueprint&#39;s name</span>
<span class="sd"> :type blueprint_name: str</span>
<span class="sd"> :returns: The blueprint name with &#39; &#39; converted to - and .toml appended</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">blueprint_name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;-&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;.toml&quot;</span></div>
<div class="viewcode-block" id="frozen_toml_filename"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.frozen_toml_filename">[docs]</a><span class="k">def</span> <span class="nf">frozen_toml_filename</span><span class="p">(</span><span class="n">blueprint_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Convert a blueprint name into a filename.toml</span>
<span class="sd"> :param blueprint_name: The blueprint&#39;s name</span>
<span class="sd"> :type blueprint_name: str</span>
<span class="sd"> :returns: The blueprint name with &#39; &#39; converted to - and .toml appended</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">blueprint_name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;-&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;.frozen.toml&quot;</span></div>
<div class="viewcode-block" id="handle_api_result"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.handle_api_result">[docs]</a><span class="k">def</span> <span class="nf">handle_api_result</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">show_json</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Log any errors, return the correct value</span>
<span class="sd"> :param result: JSON result from the http query</span>
<span class="sd"> :type result: dict</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> :returns: (rc, should_exit_now)</span>
<span class="sd"> Return the correct rc for the program (0 or 1), and whether or</span>
<span class="sd"> not to continue processing the results.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">show_json</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">for</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;errors&quot;</span><span class="p">,</span> <span class="p">[]):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">err</span><span class="p">[</span><span class="s2">&quot;msg&quot;</span><span class="p">])</span>
<span class="c1"># What&#39;s the rc? If status is present, use that</span>
<span class="c1"># If not, use length of errors</span>
<span class="k">if</span> <span class="s2">&quot;status&quot;</span> <span class="ow">in</span> <span class="n">result</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="ow">not</span> <span class="n">result</span><span class="p">[</span><span class="s2">&quot;status&quot;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">result</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;errors&quot;</span><span class="p">,</span> <span class="p">[]))</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">)</span>
<span class="c1"># Caller should return if showing json, or status was present and False</span>
<span class="n">exit_now</span> <span class="o">=</span> <span class="n">show_json</span> <span class="ow">or</span> <span class="p">(</span><span class="s2">&quot;status&quot;</span> <span class="ow">in</span> <span class="n">result</span> <span class="ow">and</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">rc</span><span class="p">,</span> <span class="n">exit_now</span><span class="p">)</span></div>
<div class="viewcode-block" id="packageNEVRA"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.packageNEVRA">[docs]</a><span class="k">def</span> <span class="nf">packageNEVRA</span><span class="p">(</span><span class="n">pkg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the package info as a NEVRA</span>
<span class="sd"> :param pkg: The package details</span>
<span class="sd"> :type pkg: dict</span>
<span class="sd"> :returns: name-[epoch:]version-release-arch</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">:</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;release&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;arch&quot;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;release&quot;</span><span class="p">],</span> <span class="n">pkg</span><span class="p">[</span><span class="s2">&quot;arch&quot;</span><span class="p">])</span></div>
<div class="viewcode-block" id="get_arg"><a class="viewcode-back" href="../../../composer.cli.html#composer.cli.utilities.get_arg">[docs]</a><span class="k">def</span> <span class="nf">get_arg</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">argtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return optional value from args, and remaining args</span>
<span class="sd"> :param args: list of arguments</span>
<span class="sd"> :type args: list of strings</span>
<span class="sd"> :param name: The argument to remove from the args list</span>
<span class="sd"> :type name: string</span>
<span class="sd"> :param argtype: Type to use for checking the argument value</span>
<span class="sd"> :type argtype: type</span>
<span class="sd"> :returns (args, value)</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> This removes the optional argument and value from the argument list, returns the new list,</span>
<span class="sd"> and the value of the argument.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">idx</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">&lt;</span> <span class="n">idx</span><span class="o">+</span><span class="mi">2</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">name</span><span class="si">}</span><span class="s2"> is missing the value&quot;</span><span class="p">)</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="n">idx</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
<span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">argtype</span><span class="p">:</span>
<span class="n">value</span> <span class="o">=</span> <span class="n">argtype</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">args</span><span class="p">[:</span><span class="n">idx</span><span class="p">]</span><span class="o">+</span><span class="n">args</span><span class="p">[</span><span class="n">idx</span><span class="o">+</span><span class="mi">2</span><span class="p">:],</span> <span class="n">value</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,459 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.http_client &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>composer.http_client</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.http_client</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;composer-cli&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">from</span> <span class="nn">urllib.parse</span> <span class="kn">import</span> <span class="n">urlparse</span><span class="p">,</span> <span class="n">urlunparse</span>
<span class="kn">from</span> <span class="nn">composer.unix_socket</span> <span class="kn">import</span> <span class="n">UnixHTTPConnectionPool</span>
<div class="viewcode-block" id="api_url"><a class="viewcode-back" href="../../composer.html#composer.http_client.api_url">[docs]</a><span class="k">def</span> <span class="nf">api_url</span><span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the versioned path to the API route</span>
<span class="sd"> :param api_version: The version of the API to talk to. eg. &quot;0&quot;</span>
<span class="sd"> :type api_version: str</span>
<span class="sd"> :param url: The API route to talk to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :returns: The full url to use for the route and API version</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">normpath</span><span class="p">(</span><span class="s2">&quot;/api/v</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">api_version</span><span class="p">,</span> <span class="n">url</span><span class="p">))</span></div>
<div class="viewcode-block" id="append_query"><a class="viewcode-back" href="../../composer.html#composer.http_client.append_query">[docs]</a><span class="k">def</span> <span class="nf">append_query</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">query</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add a query argument to a URL</span>
<span class="sd"> The query should be of the form &quot;param1=what&amp;param2=ever&quot;, i.e., no</span>
<span class="sd"> leading &#39;?&#39;. The new query data will be appended to any existing</span>
<span class="sd"> query string.</span>
<span class="sd"> :param url: The original URL</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :param query: The query to append</span>
<span class="sd"> :type query: str</span>
<span class="sd"> :returns: The new URL with the query argument included</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">url_parts</span> <span class="o">=</span> <span class="n">urlparse</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
<span class="k">if</span> <span class="n">url_parts</span><span class="o">.</span><span class="n">query</span><span class="p">:</span>
<span class="n">new_query</span> <span class="o">=</span> <span class="n">url_parts</span><span class="o">.</span><span class="n">query</span> <span class="o">+</span> <span class="s2">&quot;&amp;&quot;</span> <span class="o">+</span> <span class="n">query</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">new_query</span> <span class="o">=</span> <span class="n">query</span>
<span class="k">return</span> <span class="n">urlunparse</span><span class="p">([</span><span class="n">url_parts</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">url_parts</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">url_parts</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
<span class="n">url_parts</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">new_query</span><span class="p">,</span> <span class="n">url_parts</span><span class="p">[</span><span class="mi">5</span><span class="p">]])</span></div>
<div class="viewcode-block" id="get_url_raw"><a class="viewcode-back" href="../../composer.html#composer.http_client.get_url_raw">[docs]</a><span class="k">def</span> <span class="nf">get_url_raw</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the raw results of a GET request</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to request</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :returns: The raw response from the server</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="k">if</span> <span class="n">r</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">400</span><span class="p">:</span>
<span class="n">err</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="s2">&quot;status&quot;</span> <span class="ow">in</span> <span class="n">err</span> <span class="ow">and</span> <span class="n">err</span><span class="p">[</span><span class="s2">&quot;status&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
<span class="n">msgs</span> <span class="o">=</span> <span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="s2">&quot;msg&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">err</span><span class="p">[</span><span class="s2">&quot;errors&quot;</span><span class="p">]]</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">msgs</span><span class="p">))</span>
<span class="k">return</span> <span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="get_url_json"><a class="viewcode-back" href="../../composer.html#composer.http_client.get_url_json">[docs]</a><span class="k">def</span> <span class="nf">get_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the JSON results of a GET request</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to request</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span></div>
<div class="viewcode-block" id="get_url_json_unlimited"><a class="viewcode-back" href="../../composer.html#composer.http_client.get_url_json_unlimited">[docs]</a><span class="k">def</span> <span class="nf">get_url_json_unlimited</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">total_fn</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the JSON results of a GET request</span>
<span class="sd"> For URLs that use offset/limit arguments, this command will</span>
<span class="sd"> fetch all results for the given request.</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to request</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">default_total_fn</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the total number of available results&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;total&quot;</span><span class="p">]</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="c1"># Start with limit=0 to just get the number of objects</span>
<span class="n">total_url</span> <span class="o">=</span> <span class="n">append_query</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="s2">&quot;limit=0&quot;</span><span class="p">)</span>
<span class="n">r_total</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="n">total_url</span><span class="p">)</span>
<span class="n">json_total</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r_total</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span>
<span class="c1"># Where to get the total from</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">total_fn</span><span class="p">:</span>
<span class="n">total_fn</span> <span class="o">=</span> <span class="n">default_total_fn</span>
<span class="c1"># Add the &quot;total&quot; returned by limit=0 as the new limit</span>
<span class="n">unlimited_url</span> <span class="o">=</span> <span class="n">append_query</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="s2">&quot;limit=</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">total_fn</span><span class="p">(</span><span class="n">json_total</span><span class="p">))</span>
<span class="n">r_unlimited</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="n">unlimited_url</span><span class="p">)</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r_unlimited</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">))</span></div>
<div class="viewcode-block" id="delete_url_json"><a class="viewcode-back" href="../../composer.html#composer.http_client.delete_url_json">[docs]</a><span class="k">def</span> <span class="nf">delete_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Send a DELETE request to the url and return JSON response</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to send DELETE to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;DELETE&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">)</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span></div>
<div class="viewcode-block" id="post_url"><a class="viewcode-back" href="../../composer.html#composer.http_client.post_url">[docs]</a><span class="k">def</span> <span class="nf">post_url</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;POST raw data to the URL</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to send POST to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :param body: The data for the body of the POST</span>
<span class="sd"> :type body: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span>
<span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span></div>
<div class="viewcode-block" id="post_url_toml"><a class="viewcode-back" href="../../composer.html#composer.http_client.post_url_toml">[docs]</a><span class="k">def</span> <span class="nf">post_url_toml</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;POST a TOML string to the URL</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to send POST to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :param body: The data for the body of the POST</span>
<span class="sd"> :type body: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span>
<span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">),</span>
<span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;Content-Type&quot;</span><span class="p">:</span> <span class="s2">&quot;text/x-toml&quot;</span><span class="p">})</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span></div>
<div class="viewcode-block" id="post_url_json"><a class="viewcode-back" href="../../composer.html#composer.http_client.post_url_json">[docs]</a><span class="k">def</span> <span class="nf">post_url_json</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">body</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;POST some JSON data to the URL</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to send POST to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> :param body: The data for the body of the POST</span>
<span class="sd"> :type body: str</span>
<span class="sd"> :returns: The json response from the server</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span>
<span class="n">body</span><span class="o">=</span><span class="n">body</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">),</span>
<span class="n">headers</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;Content-Type&quot;</span><span class="p">:</span> <span class="s2">&quot;application/json&quot;</span><span class="p">})</span>
<span class="k">return</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span></div>
<div class="viewcode-block" id="get_filename"><a class="viewcode-back" href="../../composer.html#composer.http_client.get_filename">[docs]</a><span class="k">def</span> <span class="nf">get_filename</span><span class="p">(</span><span class="n">headers</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Get the filename from the response header</span>
<span class="sd"> :param response: The urllib3 response object</span>
<span class="sd"> :type response: Response</span>
<span class="sd"> :raises: RuntimeError if it cannot find a filename in the header</span>
<span class="sd"> :returns: Filename from content-disposition header</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Headers = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">headers</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;content-disposition&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;No Content-Disposition header; cannot get filename&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">k</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">v</span> <span class="o">=</span> <span class="n">headers</span><span class="p">[</span><span class="s2">&quot;content-disposition&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;;&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">partition</span><span class="p">(</span><span class="s2">&quot;=&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="s2">&quot;filename&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;No filename= found in content-disposition header&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">RuntimeError</span><span class="p">:</span>
<span class="k">raise</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Error parsing filename from content-disposition header: </span><span class="si">%s</span><span class="s2">&quot;</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">return</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">v</span><span class="p">)</span></div>
<div class="viewcode-block" id="download_file"><a class="viewcode-back" href="../../composer.html#composer.http_client.download_file">[docs]</a><span class="k">def</span> <span class="nf">download_file</span><span class="p">(</span><span class="n">socket_path</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">progress</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Download a file, saving it to the CWD with the included filename</span>
<span class="sd"> :param socket_path: Path to the Unix socket to use for API communication</span>
<span class="sd"> :type socket_path: str</span>
<span class="sd"> :param url: URL to send POST to</span>
<span class="sd"> :type url: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">http</span> <span class="o">=</span> <span class="n">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">socket_path</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">http</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">preload_content</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">r</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="mi">400</span><span class="p">:</span>
<span class="n">err</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">err</span><span class="p">[</span><span class="s2">&quot;status&quot;</span><span class="p">]:</span>
<span class="n">msgs</span> <span class="o">=</span> <span class="p">[</span><span class="n">e</span><span class="p">[</span><span class="s2">&quot;msg&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">err</span><span class="p">[</span><span class="s2">&quot;errors&quot;</span><span class="p">]]</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">msgs</span><span class="p">))</span>
<span class="n">filename</span> <span class="o">=</span> <span class="n">get_filename</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">headers</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> exists, skipping download&quot;</span> <span class="o">%</span> <span class="n">filename</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">r</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">10</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="k">if</span> <span class="n">progress</span><span class="p">:</span>
<span class="n">data_written</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">tell</span><span class="p">()</span>
<span class="k">if</span> <span class="n">data_written</span> <span class="o">&gt;</span> <span class="mi">5</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">:</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%0.2f</span><span class="s2"> MB </span><span class="se">\r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">data_written</span> <span class="o">/</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">: </span><span class="si">%0.2f</span><span class="s2"> kB</span><span class="se">\r</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">data_written</span> <span class="o">/</span> <span class="mi">1024</span><span class="p">))</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="n">r</span><span class="o">.</span><span class="n">release_conn</span><span class="p">()</span>
<span class="k">return</span> <span class="mi">0</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,262 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>composer.unix_socket &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>composer.unix_socket</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for composer.unix_socket</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">http.client</span>
<span class="kn">import</span> <span class="nn">socket</span>
<span class="kn">import</span> <span class="nn">urllib3</span>
<span class="c1"># These 2 classes were adapted and simplified for use with just urllib3.</span>
<span class="c1"># Originally from https://github.com/msabramo/requests-unixsocket/blob/master/requests_unixsocket/adapters.py</span>
<span class="c1"># The following was adapted from some code from docker-py</span>
<span class="c1"># https://github.com/docker/docker-py/blob/master/docker/transport/unixconn.py</span>
<div class="viewcode-block" id="UnixHTTPConnection"><a class="viewcode-back" href="../../composer.html#composer.unix_socket.UnixHTTPConnection">[docs]</a><span class="k">class</span> <span class="nc">UnixHTTPConnection</span><span class="p">(</span><span class="n">http</span><span class="o">.</span><span class="n">client</span><span class="o">.</span><span class="n">HTTPConnection</span><span class="p">,</span> <span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">socket_path</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">60</span><span class="o">*</span><span class="mi">5</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create an HTTP connection to a unix domain socket</span>
<span class="sd"> :param socket_path: The path to the Unix domain socket</span>
<span class="sd"> :param timeout: Number of seconds to timeout the connection</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">(</span><span class="n">UnixHTTPConnection</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">socket_path</span> <span class="o">=</span> <span class="n">socket_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sock</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">def</span> <span class="fm">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="c1"># base class does not have d&#39;tor</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sock</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<div class="viewcode-block" id="UnixHTTPConnection.connect"><a class="viewcode-back" href="../../composer.html#composer.unix_socket.UnixHTTPConnection.connect">[docs]</a> <span class="k">def</span> <span class="nf">connect</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">sock</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_UNIX</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span>
<span class="n">sock</span><span class="o">.</span><span class="n">settimeout</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">)</span>
<span class="n">sock</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">socket_path</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sock</span> <span class="o">=</span> <span class="n">sock</span></div></div>
<div class="viewcode-block" id="UnixHTTPConnectionPool"><a class="viewcode-back" href="../../composer.html#composer.unix_socket.UnixHTTPConnectionPool">[docs]</a><span class="k">class</span> <span class="nc">UnixHTTPConnectionPool</span><span class="p">(</span><span class="n">urllib3</span><span class="o">.</span><span class="n">connectionpool</span><span class="o">.</span><span class="n">HTTPConnectionPool</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">socket_path</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">60</span><span class="o">*</span><span class="mi">5</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create a connection pool using a Unix domain socket</span>
<span class="sd"> :param socket_path: The path to the Unix domain socket</span>
<span class="sd"> :param timeout: Number of seconds to timeout the connection</span>
<span class="sd"> NOTE: retries are disabled for these connections, they are never useful</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">(</span><span class="n">UnixHTTPConnectionPool</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="s1">&#39;localhost&#39;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">,</span> <span class="n">retries</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">socket_path</span> <span class="o">=</span> <span class="n">socket_path</span>
<span class="k">def</span> <span class="nf">_new_conn</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">UnixHTTPConnection</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">socket_path</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">timeout</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,250 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Overview: module code &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> &raquo;</li>
<li>Overview: module code</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>All modules for which code is available</h1>
<ul><li><a href="composer/cli.html">composer.cli</a></li>
<ul><li><a href="composer/cli/blueprints.html">composer.cli.blueprints</a></li>
<li><a href="composer/cli/cmdline.html">composer.cli.cmdline</a></li>
<li><a href="composer/cli/compose.html">composer.cli.compose</a></li>
<li><a href="composer/cli/modules.html">composer.cli.modules</a></li>
<li><a href="composer/cli/projects.html">composer.cli.projects</a></li>
<li><a href="composer/cli/providers.html">composer.cli.providers</a></li>
<li><a href="composer/cli/sources.html">composer.cli.sources</a></li>
<li><a href="composer/cli/status.html">composer.cli.status</a></li>
<li><a href="composer/cli/upload.html">composer.cli.upload</a></li>
<li><a href="composer/cli/utilities.html">composer.cli.utilities</a></li>
</ul><li><a href="composer/http_client.html">composer.http_client</a></li>
<li><a href="composer/unix_socket.html">composer.unix_socket</a></li>
<li><a href="lifted/config.html">lifted.config</a></li>
<li><a href="lifted/providers.html">lifted.providers</a></li>
<li><a href="lifted/queue.html">lifted.queue</a></li>
<li><a href="lifted/upload.html">lifted.upload</a></li>
<li><a href="pylorax.html">pylorax</a></li>
<ul><li><a href="pylorax/api/bisect.html">pylorax.api.bisect</a></li>
<li><a href="pylorax/api/checkparams.html">pylorax.api.checkparams</a></li>
<li><a href="pylorax/api/cmdline.html">pylorax.api.cmdline</a></li>
<li><a href="pylorax/api/compose.html">pylorax.api.compose</a></li>
<li><a href="pylorax/api/config.html">pylorax.api.config</a></li>
<li><a href="pylorax/api/dnfbase.html">pylorax.api.dnfbase</a></li>
<li><a href="pylorax/api/flask_blueprint.html">pylorax.api.flask_blueprint</a></li>
<li><a href="pylorax/api/gitrpm.html">pylorax.api.gitrpm</a></li>
<li><a href="pylorax/api/projects.html">pylorax.api.projects</a></li>
<li><a href="pylorax/api/queue.html">pylorax.api.queue</a></li>
<li><a href="pylorax/api/recipes.html">pylorax.api.recipes</a></li>
<li><a href="pylorax/api/server.html">pylorax.api.server</a></li>
<li><a href="pylorax/api/timestamp.html">pylorax.api.timestamp</a></li>
<li><a href="pylorax/api/toml.html">pylorax.api.toml</a></li>
<li><a href="pylorax/api/utils.html">pylorax.api.utils</a></li>
<li><a href="pylorax/api/v0.html">pylorax.api.v0</a></li>
<li><a href="pylorax/api/v1.html">pylorax.api.v1</a></li>
<li><a href="pylorax/api/workspace.html">pylorax.api.workspace</a></li>
<li><a href="pylorax/base.html">pylorax.base</a></li>
<li><a href="pylorax/buildstamp.html">pylorax.buildstamp</a></li>
<li><a href="pylorax/cmdline.html">pylorax.cmdline</a></li>
<li><a href="pylorax/creator.html">pylorax.creator</a></li>
<li><a href="pylorax/decorators.html">pylorax.decorators</a></li>
<li><a href="pylorax/discinfo.html">pylorax.discinfo</a></li>
<li><a href="pylorax/dnfbase.html">pylorax.dnfbase</a></li>
<li><a href="pylorax/dnfhelper.html">pylorax.dnfhelper</a></li>
<li><a href="pylorax/executils.html">pylorax.executils</a></li>
<li><a href="pylorax/imgutils.html">pylorax.imgutils</a></li>
<li><a href="pylorax/installer.html">pylorax.installer</a></li>
<li><a href="pylorax/ltmpl.html">pylorax.ltmpl</a></li>
<li><a href="pylorax/monitor.html">pylorax.monitor</a></li>
<li><a href="pylorax/mount.html">pylorax.mount</a></li>
<li><a href="pylorax/sysutils.html">pylorax.sysutils</a></li>
<li><a href="pylorax/treebuilder.html">pylorax.treebuilder</a></li>
<li><a href="pylorax/treeinfo.html">pylorax.treeinfo</a></li>
</ul></ul>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,234 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lifted.config &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>lifted.config</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for lifted.config</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="configure"><a class="viewcode-back" href="../../lifted.html#lifted.config.configure">[docs]</a><span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="n">conf</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add lifted settings to the configuration</span>
<span class="sd"> :param conf: configuration object</span>
<span class="sd"> :type conf: ComposerConfig</span>
<span class="sd"> :returns: None</span>
<span class="sd"> This uses the composer.share_dir and composer.lib_dir as the base</span>
<span class="sd"> directories for the settings.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">share_dir</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;share_dir&quot;</span><span class="p">)</span>
<span class="n">lib_dir</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;lib_dir&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;upload&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;upload&quot;</span><span class="p">,</span> <span class="s2">&quot;providers_dir&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">share_dir</span><span class="p">,</span> <span class="s2">&quot;/lifted/providers/&quot;</span><span class="p">))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;upload&quot;</span><span class="p">,</span> <span class="s2">&quot;queue_dir&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">lib_dir</span><span class="p">,</span> <span class="s2">&quot;/upload/queue/&quot;</span><span class="p">))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;upload&quot;</span><span class="p">,</span> <span class="s2">&quot;settings_dir&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">lib_dir</span><span class="p">,</span> <span class="s2">&quot;/upload/settings/&quot;</span><span class="p">))</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,444 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lifted.providers &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>lifted.providers</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for lifted.providers</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">stat</span>
<span class="kn">import</span> <span class="nn">pylorax.api.toml</span> <span class="k">as</span> <span class="nn">toml</span>
<span class="k">def</span> <span class="nf">_get_profile_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">exists</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Helper to return the directory and path for a provider&#39;s profile file</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the cloud provider, e.g. &quot;azure&quot;</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param profile: the name of the profile to save</span>
<span class="sd"> :type profile: str != &quot;&quot;</span>
<span class="sd"> :returns: Full path of the profile .toml file</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> :raises: ValueError when passed invalid settings or an invalid profile name</span>
<span class="sd"> :raises: RuntimeError when the provider or profile couldn&#39;t be found</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Make sure no path elements are present</span>
<span class="n">profile</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">profile</span><span class="p">)</span>
<span class="n">provider_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">provider_name</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">profile</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Profile name cannot be empty!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">provider_name</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Provider name cannot be empty!&quot;</span><span class="p">)</span>
<span class="n">directory</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">join</span><span class="p">(</span><span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;settings_dir&quot;</span><span class="p">],</span> <span class="n">provider_name</span><span class="p">)</span>
<span class="c1"># create the settings directory if it doesn&#39;t exist</span>
<span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">directory</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">path</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">join</span><span class="p">(</span><span class="n">directory</span><span class="p">,</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">profile</span><span class="si">}</span><span class="s2">.toml&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">exists</span> <span class="ow">and</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">isfile</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Couldn</span><span class="se">\&#39;</span><span class="s1">t find profile &quot;</span><span class="si">{</span><span class="n">profile</span><span class="si">}</span><span class="s1">&quot;!&#39;</span><span class="p">)</span>
<span class="k">return</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">path</span><span class="p">)</span>
<div class="viewcode-block" id="resolve_provider"><a class="viewcode-back" href="../../lifted.html#lifted.providers.resolve_provider">[docs]</a><span class="k">def</span> <span class="nf">resolve_provider</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Get information about the specified provider as defined in that</span>
<span class="sd"> provider&#39;s `provider.toml`, including the provider&#39;s display name and expected</span>
<span class="sd"> settings.</span>
<span class="sd"> At a minimum, each setting has a display name (that likely differs from its</span>
<span class="sd"> snake_case name) and a type. Currently, there are two types of settings:</span>
<span class="sd"> string and boolean. String settings can optionally have a &quot;placeholder&quot;</span>
<span class="sd"> value for use on the front end and a &quot;regex&quot; for making sure that a value</span>
<span class="sd"> follows an expected pattern.</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the provider to look for</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :raises: RuntimeError when the provider couldn&#39;t be found</span>
<span class="sd"> :returns: the provider</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Make sure no path elements are present</span>
<span class="n">provider_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">provider_name</span><span class="p">)</span>
<span class="n">path</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">join</span><span class="p">(</span><span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;providers_dir&quot;</span><span class="p">],</span> <span class="n">provider_name</span><span class="p">,</span> <span class="s2">&quot;provider.toml&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="k">as</span> <span class="n">provider_file</span><span class="p">:</span>
<span class="n">provider</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">provider_file</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">error</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Couldn</span><span class="se">\&#39;</span><span class="s1">t find provider &quot;</span><span class="si">{</span><span class="n">provider_name</span><span class="si">}</span><span class="s1">&quot;!&#39;</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">error</span>
<span class="k">return</span> <span class="n">provider</span></div>
<div class="viewcode-block" id="load_profiles"><a class="viewcode-back" href="../../lifted.html#lifted.providers.load_profiles">[docs]</a><span class="k">def</span> <span class="nf">load_profiles</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return all settings profiles associated with a provider</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: name a provider to find profiles for</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :returns: a dict of settings dicts, keyed by profile name</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Make sure no path elements are present</span>
<span class="n">provider_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">provider_name</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">load_path</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">get_name</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</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">path</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">paths</span> <span class="o">=</span> <span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;settings_dir&quot;</span><span class="p">],</span> <span class="n">provider_name</span><span class="p">,</span> <span class="s2">&quot;*&quot;</span><span class="p">))</span>
<span class="k">return</span> <span class="p">{</span><span class="n">get_name</span><span class="p">(</span><span class="n">path</span><span class="p">):</span> <span class="n">load_path</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">}</span></div>
<div class="viewcode-block" id="resolve_playbook_path"><a class="viewcode-back" href="../../lifted.html#lifted.providers.resolve_playbook_path">[docs]</a><span class="k">def</span> <span class="nf">resolve_playbook_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Given a provider&#39;s name, return the path to its playbook</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the provider to find the playbook for</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :raises: RuntimeError when the provider couldn&#39;t be found</span>
<span class="sd"> :returns: the path to the playbook</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Make sure no path elements are present</span>
<span class="n">provider_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">provider_name</span><span class="p">)</span>
<span class="n">path</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">join</span><span class="p">(</span><span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;providers_dir&quot;</span><span class="p">],</span> <span class="n">provider_name</span><span class="p">,</span> <span class="s2">&quot;playbook.yaml&quot;</span><span class="p">)</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">isfile</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Couldn</span><span class="se">\&#39;</span><span class="s1">t find playbook for &quot;</span><span class="si">{</span><span class="n">provider_name</span><span class="si">}</span><span class="s1">&quot;!&#39;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">path</span></div>
<div class="viewcode-block" id="list_providers"><a class="viewcode-back" href="../../lifted.html#lifted.providers.list_providers">[docs]</a><span class="k">def</span> <span class="nf">list_providers</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;List the names of the available upload providers</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :returns: a list of all available provider_names</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">paths</span> <span class="o">=</span> <span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;providers_dir&quot;</span><span class="p">],</span> <span class="s2">&quot;*&quot;</span><span class="p">))</span>
<span class="k">return</span> <span class="nb">sorted</span><span class="p">(</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">path</span><span class="p">)</span> <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">)</span></div>
<div class="viewcode-block" id="validate_settings"><a class="viewcode-back" href="../../lifted.html#lifted.providers.validate_settings">[docs]</a><span class="k">def</span> <span class="nf">validate_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">image_name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Raise a ValueError if any settings are invalid</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the provider to validate the settings against</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param settings: the settings to validate</span>
<span class="sd"> :type settings: dict</span>
<span class="sd"> :param image_name: optionally check whether an image_name is valid</span>
<span class="sd"> :type image_name: str</span>
<span class="sd"> :raises: ValueError when the passed settings are invalid</span>
<span class="sd"> :raises: RuntimeError when provider_name can&#39;t be found</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">image_name</span> <span class="o">==</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Image name cannot be empty!&quot;</span><span class="p">)</span>
<span class="n">type_map</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;string&quot;</span><span class="p">:</span> <span class="nb">str</span><span class="p">,</span> <span class="s2">&quot;boolean&quot;</span><span class="p">:</span> <span class="nb">bool</span><span class="p">}</span>
<span class="n">settings_info</span> <span class="o">=</span> <span class="n">resolve_provider</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">)[</span><span class="s2">&quot;settings-info&quot;</span><span class="p">]</span>
<span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">settings_info</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Received unexpected setting: &quot;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">&quot;!&#39;</span><span class="p">)</span>
<span class="n">setting_type</span> <span class="o">=</span> <span class="n">settings_info</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">&quot;type&quot;</span><span class="p">]</span>
<span class="n">correct_type</span> <span class="o">=</span> <span class="n">type_map</span><span class="p">[</span><span class="n">setting_type</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">correct_type</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
<span class="sa">f</span><span class="s1">&#39;Expected a </span><span class="si">{</span><span class="n">correct_type</span><span class="si">}</span><span class="s1"> for &quot;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">&quot;, received a </span><span class="si">{</span><span class="nb">type</span><span class="p">(</span><span class="n">value</span><span class="p">)</span><span class="si">}</span><span class="s1">!&#39;</span>
<span class="p">)</span>
<span class="k">if</span> <span class="n">setting_type</span> <span class="o">==</span> <span class="s2">&quot;string&quot;</span> <span class="ow">and</span> <span class="s2">&quot;regex&quot;</span> <span class="ow">in</span> <span class="n">settings_info</span><span class="p">[</span><span class="n">key</span><span class="p">]:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">settings_info</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">&quot;regex&quot;</span><span class="p">],</span> <span class="n">value</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Value &quot;</span><span class="si">{</span><span class="n">value</span><span class="si">}</span><span class="s1">&quot; is invalid for setting &quot;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">&quot;!&#39;</span><span class="p">)</span></div>
<div class="viewcode-block" id="save_settings"><a class="viewcode-back" href="../../lifted.html#lifted.providers.save_settings">[docs]</a><span class="k">def</span> <span class="nf">save_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Save (and overwrite) settings for a given provider</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the cloud provider, e.g. &quot;azure&quot;</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param profile: the name of the profile to save</span>
<span class="sd"> :type profile: str != &quot;&quot;</span>
<span class="sd"> :param settings: settings to save for that provider</span>
<span class="sd"> :type settings: dict</span>
<span class="sd"> :raises: ValueError when passed invalid settings or an invalid profile name</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">_get_profile_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">,</span> <span class="n">exists</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">validate_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">image_name</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="c1"># touch the TOML file if it doesn&#39;t exist</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">isfile</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;a&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="c1"># make sure settings files aren&#39;t readable by others, as they will contain</span>
<span class="c1"># sensitive credentials</span>
<span class="n">current</span> <span class="o">=</span> <span class="n">stat</span><span class="o">.</span><span class="n">S_IMODE</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">lstat</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">st_mode</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">current</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IROTH</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">settings_file</span><span class="p">:</span>
<span class="n">toml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">settings</span><span class="p">,</span> <span class="n">settings_file</span><span class="p">)</span></div>
<div class="viewcode-block" id="load_settings"><a class="viewcode-back" href="../../lifted.html#lifted.providers.load_settings">[docs]</a><span class="k">def</span> <span class="nf">load_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Load settings for a provider&#39;s profile</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the cloud provider, e.g. &quot;azure&quot;</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param profile: the name of the profile to save</span>
<span class="sd"> :type profile: str != &quot;&quot;</span>
<span class="sd"> :returns: The profile settings for the selected provider</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> :raises: ValueError when passed invalid settings or an invalid profile name</span>
<span class="sd"> :raises: RuntimeError when the provider or profile couldn&#39;t be found</span>
<span class="sd"> :raises: ValueError when the passed settings are invalid</span>
<span class="sd"> This also calls validate_settings on the loaded settings, potentially</span>
<span class="sd"> raising an error if the saved settings are invalid.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">_get_profile_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">)</span> <span class="k">as</span> <span class="n">file</span><span class="p">:</span>
<span class="n">settings</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="n">validate_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">settings</span><span class="p">)</span>
<span class="k">return</span> <span class="n">settings</span></div>
<div class="viewcode-block" id="delete_profile"><a class="viewcode-back" href="../../lifted.html#lifted.providers.delete_profile">[docs]</a><span class="k">def</span> <span class="nf">delete_profile</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a provider&#39;s profile settings file</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the cloud provider, e.g. &quot;azure&quot;</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param profile: the name of the profile to save</span>
<span class="sd"> :type profile: str != &quot;&quot;</span>
<span class="sd"> :raises: ValueError when passed invalid settings or an invalid profile name</span>
<span class="sd"> :raises: RuntimeError when the provider or profile couldn&#39;t be found</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">_get_profile_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">profile</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,468 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lifted.queue &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>lifted.queue</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for lifted.queue</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">multiprocessing</span>
<span class="c1"># We use a multiprocessing Pool for uploads so that we can cancel them with a</span>
<span class="c1"># simple SIGINT, which should bubble down to subprocesses.</span>
<span class="kn">from</span> <span class="nn">multiprocessing</span> <span class="kn">import</span> <span class="n">Pool</span>
<span class="c1"># multiprocessing.dummy is to threads as multiprocessing is to processes.</span>
<span class="c1"># Since daemonic processes can&#39;t have children, we use a thread to monitor the</span>
<span class="c1"># upload pool.</span>
<span class="kn">from</span> <span class="nn">multiprocessing.dummy</span> <span class="kn">import</span> <span class="n">Process</span>
<span class="kn">from</span> <span class="nn">operator</span> <span class="kn">import</span> <span class="n">attrgetter</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">stat</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">pylorax.api.toml</span> <span class="k">as</span> <span class="nn">toml</span>
<span class="kn">from</span> <span class="nn">lifted.upload</span> <span class="kn">import</span> <span class="n">Upload</span>
<span class="kn">from</span> <span class="nn">lifted.providers</span> <span class="kn">import</span> <span class="n">resolve_playbook_path</span><span class="p">,</span> <span class="n">validate_settings</span>
<span class="c1"># the maximum number of simultaneous uploads</span>
<span class="n">SIMULTANEOUS_UPLOADS</span> <span class="o">=</span> <span class="mi">1</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="s2">&quot;lifted&quot;</span><span class="p">)</span>
<span class="n">multiprocessing</span><span class="o">.</span><span class="n">log_to_stderr</span><span class="p">()</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">INFO</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_get_queue_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">ucfg</span><span class="p">[</span><span class="s2">&quot;queue_dir&quot;</span><span class="p">]</span>
<span class="c1"># create the upload_queue directory if it doesn&#39;t exist</span>
<span class="n">os</span><span class="o">.</span><span class="n">makedirs</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">return</span> <span class="n">path</span>
<span class="k">def</span> <span class="nf">_get_upload_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">write</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="c1"># Make sure no path elements are present</span>
<span class="n">uuid</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">uuid</span><span class="p">)</span>
<span class="n">path</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">join</span><span class="p">(</span><span class="n">_get_queue_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">),</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">uuid</span><span class="si">}</span><span class="s2">.toml&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">write</span> <span class="ow">and</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">exists</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;a&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="c1"># make sure uploads aren&#39;t readable by others, as they will contain</span>
<span class="c1"># sensitive credentials</span>
<span class="n">current</span> <span class="o">=</span> <span class="n">stat</span><span class="o">.</span><span class="n">S_IMODE</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">lstat</span><span class="p">(</span><span class="n">path</span><span class="p">)</span><span class="o">.</span><span class="n">st_mode</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">current</span> <span class="o">&amp;</span> <span class="o">~</span><span class="n">stat</span><span class="o">.</span><span class="n">S_IROTH</span><span class="p">)</span>
<span class="k">return</span> <span class="n">path</span>
<span class="k">def</span> <span class="nf">_list_upload_uuids</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="n">paths</span> <span class="o">=</span> <span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">_get_queue_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">),</span> <span class="s2">&quot;*&quot;</span><span class="p">))</span>
<span class="k">return</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">splitext</span><span class="p">(</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">path</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span> <span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="n">paths</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_write_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">upload</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">_get_upload_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">upload</span><span class="o">.</span><span class="n">uuid</span><span class="p">,</span> <span class="n">write</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">upload_file</span><span class="p">:</span>
<span class="n">toml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">upload</span><span class="o">.</span><span class="n">serializable</span><span class="p">(),</span> <span class="n">upload_file</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="k">return</span> <span class="n">partial</span><span class="p">(</span><span class="n">_write_upload</span><span class="p">,</span> <span class="n">ucfg</span><span class="p">)</span>
<div class="viewcode-block" id="get_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.get_upload">[docs]</a><span class="k">def</span> <span class="nf">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">ignore_missing</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">ignore_corrupt</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Get an Upload object by UUID</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param uuid: UUID of the upload to get</span>
<span class="sd"> :type uuid: str</span>
<span class="sd"> :param ignore_missing: if True, don&#39;t raise a RuntimeError when the specified upload is missing, instead just return None</span>
<span class="sd"> :type ignore_missing: bool</span>
<span class="sd"> :param ignore_corrupt: if True, don&#39;t raise a RuntimeError when the specified upload could not be deserialized, instead just return None</span>
<span class="sd"> :type ignore_corrupt: bool</span>
<span class="sd"> :returns: the upload object or None</span>
<span class="sd"> :rtype: Upload or None</span>
<span class="sd"> :raises: RuntimeError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">_get_upload_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">),</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">upload_file</span><span class="p">:</span>
<span class="k">return</span> <span class="n">Upload</span><span class="p">(</span><span class="o">**</span><span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">upload_file</span><span class="p">))</span>
<span class="k">except</span> <span class="ne">FileNotFoundError</span> <span class="k">as</span> <span class="n">error</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">ignore_missing</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not find upload </span><span class="si">{</span><span class="n">uuid</span><span class="si">}</span><span class="s2">!&quot;</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">error</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlError</span> <span class="k">as</span> <span class="n">error</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">ignore_corrupt</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Could not parse upload </span><span class="si">{</span><span class="n">uuid</span><span class="si">}</span><span class="s2">!&quot;</span><span class="p">)</span> <span class="kn">from</span> <span class="nn">error</span></div>
<div class="viewcode-block" id="get_uploads"><a class="viewcode-back" href="../../lifted.html#lifted.queue.get_uploads">[docs]</a><span class="k">def</span> <span class="nf">get_uploads</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuids</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Gets a list of Upload objects from a list of upload UUIDs, ignoring</span>
<span class="sd"> missing or corrupt uploads</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param uuids: list of upload UUIDs to get</span>
<span class="sd"> :type uuids: list of str</span>
<span class="sd"> :returns: a list of the uploads that were successfully deserialized</span>
<span class="sd"> :rtype: list of Upload</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">uploads</span> <span class="o">=</span> <span class="p">(</span>
<span class="n">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">ignore_missing</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">ignore_corrupt</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">for</span> <span class="n">uuid</span> <span class="ow">in</span> <span class="n">uuids</span>
<span class="p">)</span>
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="nb">filter</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">uploads</span><span class="p">))</span></div>
<div class="viewcode-block" id="get_all_uploads"><a class="viewcode-back" href="../../lifted.html#lifted.queue.get_all_uploads">[docs]</a><span class="k">def</span> <span class="nf">get_all_uploads</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Get a list of all stored Upload objects</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :returns: a list of all stored upload objects</span>
<span class="sd"> :rtype: list of Upload</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">get_uploads</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">_list_upload_uuids</span><span class="p">(</span><span class="n">ucfg</span><span class="p">))</span></div>
<div class="viewcode-block" id="create_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.create_upload">[docs]</a><span class="k">def</span> <span class="nf">create_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">image_name</span><span class="p">,</span> <span class="n">settings</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Creates a new upload</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param provider_name: the name of the cloud provider to upload to, e.g. &quot;azure&quot;</span>
<span class="sd"> :type provider_name: str</span>
<span class="sd"> :param image_name: what to name the image in the cloud</span>
<span class="sd"> :type image_name: str</span>
<span class="sd"> :param settings: settings to pass to the upload, specific to the cloud provider</span>
<span class="sd"> :type settings: dict</span>
<span class="sd"> :returns: the created upload object</span>
<span class="sd"> :rtype: Upload</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">validate_settings</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">,</span> <span class="n">settings</span><span class="p">,</span> <span class="n">image_name</span><span class="p">)</span>
<span class="k">return</span> <span class="n">Upload</span><span class="p">(</span>
<span class="n">provider_name</span><span class="o">=</span><span class="n">provider_name</span><span class="p">,</span>
<span class="n">playbook_path</span><span class="o">=</span><span class="n">resolve_playbook_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">provider_name</span><span class="p">),</span>
<span class="n">image_name</span><span class="o">=</span><span class="n">image_name</span><span class="p">,</span>
<span class="n">settings</span><span class="o">=</span><span class="n">settings</span><span class="p">,</span>
<span class="n">status_callback</span><span class="o">=</span><span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">),</span>
<span class="p">)</span></div>
<div class="viewcode-block" id="ready_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.ready_upload">[docs]</a><span class="k">def</span> <span class="nf">ready_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">image_path</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Pass an image_path to an upload and mark it ready to execute</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param uuid: the UUID of the upload to mark ready</span>
<span class="sd"> :type uuid: str</span>
<span class="sd"> :param image_path: the path of the image to pass to the upload</span>
<span class="sd"> :type image_path: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">)</span><span class="o">.</span><span class="n">ready</span><span class="p">(</span><span class="n">image_path</span><span class="p">,</span> <span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">))</span></div>
<div class="viewcode-block" id="reset_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.reset_upload">[docs]</a><span class="k">def</span> <span class="nf">reset_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">,</span> <span class="n">new_image_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">new_settings</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Reset an upload so it can be attempted again</span>
<span class="sd"> :param ucfg: upload config</span>
<span class="sd"> :type ucfg: object</span>
<span class="sd"> :param uuid: the UUID of the upload to reset</span>
<span class="sd"> :type uuid: str</span>
<span class="sd"> :param new_image_name: optionally update the upload&#39;s image_name</span>
<span class="sd"> :type new_image_name: str</span>
<span class="sd"> :param new_settings: optionally update the upload&#39;s settings</span>
<span class="sd"> :type new_settings: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">upload</span> <span class="o">=</span> <span class="n">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">)</span>
<span class="n">validate_settings</span><span class="p">(</span>
<span class="n">ucfg</span><span class="p">,</span>
<span class="n">upload</span><span class="o">.</span><span class="n">provider_name</span><span class="p">,</span>
<span class="n">new_settings</span> <span class="ow">or</span> <span class="n">upload</span><span class="o">.</span><span class="n">settings</span><span class="p">,</span>
<span class="n">new_image_name</span> <span class="ow">or</span> <span class="n">upload</span><span class="o">.</span><span class="n">image_name</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">if</span> <span class="n">new_image_name</span><span class="p">:</span>
<span class="n">upload</span><span class="o">.</span><span class="n">image_name</span> <span class="o">=</span> <span class="n">new_image_name</span>
<span class="k">if</span> <span class="n">new_settings</span><span class="p">:</span>
<span class="n">upload</span><span class="o">.</span><span class="n">settings</span> <span class="o">=</span> <span class="n">new_settings</span>
<span class="n">upload</span><span class="o">.</span><span class="n">reset</span><span class="p">(</span><span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">))</span></div>
<div class="viewcode-block" id="cancel_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.cancel_upload">[docs]</a><span class="k">def</span> <span class="nf">cancel_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Cancel an upload</span>
<span class="sd"> :param ucfg: the compose config</span>
<span class="sd"> :type ucfg: ComposerConfig</span>
<span class="sd"> :param uuid: the UUID of the upload to cancel</span>
<span class="sd"> :type uuid: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">)</span><span class="o">.</span><span class="n">cancel</span><span class="p">(</span><span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">))</span></div>
<div class="viewcode-block" id="delete_upload"><a class="viewcode-back" href="../../lifted.html#lifted.queue.delete_upload">[docs]</a><span class="k">def</span> <span class="nf">delete_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete an upload</span>
<span class="sd"> :param ucfg: the compose config</span>
<span class="sd"> :type ucfg: ComposerConfig</span>
<span class="sd"> :param uuid: the UUID of the upload to delete</span>
<span class="sd"> :type uuid: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">upload</span> <span class="o">=</span> <span class="n">get_upload</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">upload</span> <span class="ow">and</span> <span class="n">upload</span><span class="o">.</span><span class="n">is_cancellable</span><span class="p">():</span>
<span class="n">upload</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span>
<span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">_get_upload_path</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,</span> <span class="n">uuid</span><span class="p">))</span></div>
<div class="viewcode-block" id="start_upload_monitor"><a class="viewcode-back" href="../../lifted.html#lifted.queue.start_upload_monitor">[docs]</a><span class="k">def</span> <span class="nf">start_upload_monitor</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Start a thread that manages the upload queue</span>
<span class="sd"> :param ucfg: the compose config</span>
<span class="sd"> :type ucfg: ComposerConfig</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">process</span> <span class="o">=</span> <span class="n">Process</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="n">_monitor</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">ucfg</span><span class="p">,))</span>
<span class="n">process</span><span class="o">.</span><span class="n">daemon</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">process</span><span class="o">.</span><span class="n">start</span><span class="p">()</span></div>
<span class="k">def</span> <span class="nf">_monitor</span><span class="p">(</span><span class="n">ucfg</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="s2">&quot;Started upload monitor.&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">upload</span> <span class="ow">in</span> <span class="n">get_all_uploads</span><span class="p">(</span><span class="n">ucfg</span><span class="p">):</span>
<span class="c1"># Set abandoned uploads to FAILED</span>
<span class="k">if</span> <span class="n">upload</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;RUNNING&quot;</span><span class="p">:</span>
<span class="n">upload</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;FAILED&quot;</span><span class="p">,</span> <span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">))</span>
<span class="n">pool</span> <span class="o">=</span> <span class="n">Pool</span><span class="p">(</span><span class="n">processes</span><span class="o">=</span><span class="n">SIMULTANEOUS_UPLOADS</span><span class="p">)</span>
<span class="n">pool_uuids</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">remover</span><span class="p">(</span><span class="n">uuid</span><span class="p">):</span>
<span class="k">return</span> <span class="k">lambda</span> <span class="n">_</span><span class="p">:</span> <span class="n">pool_uuids</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">uuid</span><span class="p">)</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="c1"># Every second, scoop up READY uploads from the filesystem and throw</span>
<span class="c1"># them in the pool</span>
<span class="n">all_uploads</span> <span class="o">=</span> <span class="n">get_all_uploads</span><span class="p">(</span><span class="n">ucfg</span><span class="p">)</span>
<span class="k">for</span> <span class="n">upload</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">all_uploads</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="n">attrgetter</span><span class="p">(</span><span class="s2">&quot;creation_time&quot;</span><span class="p">)):</span>
<span class="n">ready</span> <span class="o">=</span> <span class="n">upload</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;READY&quot;</span>
<span class="k">if</span> <span class="n">ready</span> <span class="ow">and</span> <span class="n">upload</span><span class="o">.</span><span class="n">uuid</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">pool_uuids</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="s2">&quot;Starting upload </span><span class="si">%s</span><span class="s2">...&quot;</span><span class="p">,</span> <span class="n">upload</span><span class="o">.</span><span class="n">uuid</span><span class="p">)</span>
<span class="n">pool_uuids</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">upload</span><span class="o">.</span><span class="n">uuid</span><span class="p">)</span>
<span class="n">callback</span> <span class="o">=</span> <span class="n">remover</span><span class="p">(</span><span class="n">upload</span><span class="o">.</span><span class="n">uuid</span><span class="p">)</span>
<span class="n">pool</span><span class="o">.</span><span class="n">apply_async</span><span class="p">(</span>
<span class="n">upload</span><span class="o">.</span><span class="n">execute</span><span class="p">,</span>
<span class="p">(</span><span class="n">_write_callback</span><span class="p">(</span><span class="n">ucfg</span><span class="p">),),</span>
<span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">,</span>
<span class="n">error_callback</span><span class="o">=</span><span class="n">callback</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,411 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lifted.upload &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>lifted.upload</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for lifted.upload</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">datetime</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">from</span> <span class="nn">multiprocessing</span> <span class="kn">import</span> <span class="n">current_process</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">from</span> <span class="nn">uuid</span> <span class="kn">import</span> <span class="n">uuid4</span>
<span class="kn">from</span> <span class="nn">ansible_runner.interface</span> <span class="kn">import</span> <span class="n">run</span> <span class="k">as</span> <span class="n">ansible_run</span>
<span class="kn">from</span> <span class="nn">ansible_runner.exceptions</span> <span class="kn">import</span> <span class="n">AnsibleRunnerException</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="s2">&quot;lifted&quot;</span><span class="p">)</span>
<div class="viewcode-block" id="Upload"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload">[docs]</a><span class="k">class</span> <span class="nc">Upload</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;Represents an upload of an image to a cloud provider. Instances of this</span>
<span class="sd"> class are serialized as TOML and stored in the upload queue directory,</span>
<span class="sd"> which is /var/lib/lorax/upload/queue/ by default&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">uuid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">provider_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">playbook_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">image_name</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">settings</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">creation_time</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">upload_log</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">upload_pid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">image_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">status</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uuid</span> <span class="o">=</span> <span class="n">uuid</span> <span class="ow">or</span> <span class="nb">str</span><span class="p">(</span><span class="n">uuid4</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">provider_name</span> <span class="o">=</span> <span class="n">provider_name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">playbook_path</span> <span class="o">=</span> <span class="n">playbook_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_name</span> <span class="o">=</span> <span class="n">image_name</span>
<span class="bp">self</span><span class="o">.</span><span class="n">settings</span> <span class="o">=</span> <span class="n">settings</span>
<span class="bp">self</span><span class="o">.</span><span class="n">creation_time</span> <span class="o">=</span> <span class="n">creation_time</span> <span class="ow">or</span> <span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span><span class="o">.</span><span class="n">timestamp</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_log</span> <span class="o">=</span> <span class="n">upload_log</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span> <span class="o">=</span> <span class="n">upload_pid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_path</span> <span class="o">=</span> <span class="n">image_path</span>
<span class="k">if</span> <span class="n">status</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;WAITING&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_log</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Logs something to the upload log with an optional callback</span>
<span class="sd"> :param message: the object to log</span>
<span class="sd"> :type message: object</span>
<span class="sd"> :param callback: a function of the form callback(self)</span>
<span class="sd"> :type callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">message</span><span class="p">:</span>
<span class="n">messages</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">message</span><span class="p">)</span><span class="o">.</span><span class="n">splitlines</span><span class="p">()</span>
<span class="c1"># Log multi-line messages as individual log lines</span>
<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">messages</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="n">m</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_log</span> <span class="o">+=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">message</span><span class="si">}</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">if</span> <span class="n">callback</span><span class="p">:</span>
<span class="n">callback</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<div class="viewcode-block" id="Upload.serializable"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.serializable">[docs]</a> <span class="k">def</span> <span class="nf">serializable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Returns a representation of the object as a dict for serialization</span>
<span class="sd"> :returns: the object&#39;s __dict__</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span></div>
<div class="viewcode-block" id="Upload.summary"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.summary">[docs]</a> <span class="k">def</span> <span class="nf">summary</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a dict with useful information about the upload</span>
<span class="sd"> :returns: upload information</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span>
<span class="s2">&quot;uuid&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">uuid</span><span class="p">,</span>
<span class="s2">&quot;status&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="p">,</span>
<span class="s2">&quot;provider_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">provider_name</span><span class="p">,</span>
<span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_name</span><span class="p">,</span>
<span class="s2">&quot;image_path&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">,</span>
<span class="s2">&quot;creation_time&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">creation_time</span><span class="p">,</span>
<span class="s2">&quot;settings&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">,</span>
<span class="p">}</span></div>
<div class="viewcode-block" id="Upload.set_status"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.set_status">[docs]</a> <span class="k">def</span> <span class="nf">set_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Sets the status of the upload with an optional callback</span>
<span class="sd"> :param status: the new status</span>
<span class="sd"> :type status: str</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Setting status to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">status</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">=</span> <span class="n">status</span>
<span class="k">if</span> <span class="n">status_callback</span><span class="p">:</span>
<span class="n">status_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.ready"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.ready">[docs]</a> <span class="k">def</span> <span class="nf">ready</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">image_path</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Provide an image_path and mark the upload as ready to execute</span>
<span class="sd"> :param image_path: path of the image to upload</span>
<span class="sd"> :type image_path: str</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Setting image_path to </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">image_path</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image_path</span> <span class="o">=</span> <span class="n">image_path</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;WAITING&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.reset"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.reset">[docs]</a> <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Reset the upload so it can be attempted again</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_cancellable</span><span class="p">():</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Can&#39;t reset, status is </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="si">}</span><span class="s2">!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Can&#39;t reset, no image supplied yet!&quot;</span><span class="p">)</span>
<span class="c1"># self.error = None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Resetting state&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.is_cancellable"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.is_cancellable">[docs]</a> <span class="k">def</span> <span class="nf">is_cancellable</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Is the upload in a cancellable state?</span>
<span class="sd"> :returns: whether the upload is cancellable</span>
<span class="sd"> :rtype: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;WAITING&quot;</span><span class="p">,</span> <span class="s2">&quot;READY&quot;</span><span class="p">,</span> <span class="s2">&quot;RUNNING&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.cancel"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.cancel">[docs]</a> <span class="k">def</span> <span class="nf">cancel</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Cancel the upload. Sends a SIGINT to self.upload_pid.</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">is_cancellable</span><span class="p">():</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Can&#39;t cancel, status is already </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">status</span><span class="si">}</span><span class="s2">!&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">kill</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIGINT</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;CANCELLED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="Upload.execute"><a class="viewcode-back" href="../../lifted.html#lifted.upload.Upload.execute">[docs]</a> <span class="k">def</span> <span class="nf">execute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status_callback</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Execute the upload. Meant to be called from a dedicated process so</span>
<span class="sd"> that the upload can be cancelled by sending a SIGINT to</span>
<span class="sd"> self.upload_pid.</span>
<span class="sd"> :param status_callback: a function of the form callback(self)</span>
<span class="sd"> :type status_callback: function</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">status</span> <span class="o">!=</span> <span class="s2">&quot;READY&quot;</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;This upload is not ready!&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">upload_pid</span> <span class="o">=</span> <span class="n">current_process</span><span class="p">()</span><span class="o">.</span><span class="n">pid</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;RUNNING&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;Executing playbook.yml&quot;</span><span class="p">)</span>
<span class="c1"># NOTE: event_handler doesn&#39;t seem to be called for playbook errors</span>
<span class="n">logger</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">e</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="n">e</span><span class="p">[</span><span class="s2">&quot;stdout&quot;</span><span class="p">],</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="n">runner</span> <span class="o">=</span> <span class="n">ansible_run</span><span class="p">(</span>
<span class="n">playbook</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">playbook_path</span><span class="p">,</span>
<span class="n">extravars</span><span class="o">=</span><span class="p">{</span>
<span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">settings</span><span class="p">,</span>
<span class="s2">&quot;image_name&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_name</span><span class="p">,</span>
<span class="s2">&quot;image_path&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">image_path</span><span class="p">,</span>
<span class="p">},</span>
<span class="n">event_handler</span><span class="o">=</span><span class="n">logger</span><span class="p">,</span>
<span class="n">verbosity</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Try logging events and stats -- but they may not exist, so catch the error</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">runner</span><span class="o">.</span><span class="n">events</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="nb">dir</span><span class="p">(</span><span class="n">e</span><span class="p">),</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">runner</span><span class="o">.</span><span class="n">stats</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">except</span> <span class="n">AnsibleRunnerException</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_log</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">runner</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">read</span><span class="p">(),</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">if</span> <span class="n">runner</span><span class="o">.</span><span class="n">status</span> <span class="o">==</span> <span class="s2">&quot;successful&quot;</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;FINISHED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">set_status</span><span class="p">(</span><span class="s2">&quot;FAILED&quot;</span><span class="p">,</span> <span class="n">status_callback</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">traceback</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">(</span><span class="n">limit</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,657 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script type="text/javascript" src="../_static/js/theme.js"></script>
<link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> &raquo;</li>
<li><a href="index.html">Module code</a> &raquo;</li>
<li>pylorax</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># __init__.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2010-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1"># David Cantrell &lt;dcantrell@redhat.com&gt;</span>
<span class="c1"># Will Woods &lt;wwoods@redhat.com&gt;</span>
<span class="c1"># set up logging</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax&quot;</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">NullHandler</span><span class="p">())</span>
<span class="n">program_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="s2">&quot;program&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">configparser</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">locale</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">CalledProcessError</span>
<span class="kn">import</span> <span class="nn">selinux</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">pylorax.base</span> <span class="kn">import</span> <span class="n">BaseLoraxClass</span><span class="p">,</span> <span class="n">DataHolder</span>
<span class="kn">import</span> <span class="nn">pylorax.output</span> <span class="k">as</span> <span class="nn">output</span>
<span class="kn">import</span> <span class="nn">dnf</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span><span class="p">,</span> <span class="n">remove</span><span class="p">,</span> <span class="n">linktree</span>
<span class="kn">from</span> <span class="nn">pylorax.treebuilder</span> <span class="kn">import</span> <span class="n">RuntimeBuilder</span><span class="p">,</span> <span class="n">TreeBuilder</span>
<span class="kn">from</span> <span class="nn">pylorax.buildstamp</span> <span class="kn">import</span> <span class="n">BuildStamp</span>
<span class="kn">from</span> <span class="nn">pylorax.treeinfo</span> <span class="kn">import</span> <span class="n">TreeInfo</span>
<span class="kn">from</span> <span class="nn">pylorax.discinfo</span> <span class="kn">import</span> <span class="n">DiscInfo</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">runcmd</span><span class="p">,</span> <span class="n">runcmd_output</span>
<span class="c1"># get lorax version</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">pylorax.version</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="n">vernum</span> <span class="o">=</span> <span class="s2">&quot;devel&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">vernum</span> <span class="o">=</span> <span class="n">pylorax</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">num</span>
<span class="n">DRACUT_DEFAULT</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;--xz&quot;</span><span class="p">,</span> <span class="s2">&quot;--install&quot;</span><span class="p">,</span> <span class="s2">&quot;/.buildstamp&quot;</span><span class="p">,</span> <span class="s2">&quot;--no-early-microcode&quot;</span><span class="p">,</span> <span class="s2">&quot;--add&quot;</span><span class="p">,</span> <span class="s2">&quot;fips&quot;</span><span class="p">]</span>
<span class="c1"># Used for DNF conf.module_platform_id</span>
<span class="n">DEFAULT_PLATFORM_ID</span> <span class="o">=</span> <span class="s2">&quot;platform:f32&quot;</span>
<div class="viewcode-block" id="ArchData"><a class="viewcode-back" href="../pylorax.html#pylorax.ArchData">[docs]</a><span class="k">class</span> <span class="nc">ArchData</span><span class="p">(</span><span class="n">DataHolder</span><span class="p">):</span>
<span class="n">lib64_arches</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;x86_64&quot;</span><span class="p">,</span> <span class="s2">&quot;ppc64le&quot;</span><span class="p">,</span> <span class="s2">&quot;s390x&quot;</span><span class="p">,</span> <span class="s2">&quot;ia64&quot;</span><span class="p">,</span> <span class="s2">&quot;aarch64&quot;</span><span class="p">)</span>
<span class="n">bcj_arch</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">i386</span><span class="o">=</span><span class="s2">&quot;x86&quot;</span><span class="p">,</span> <span class="n">x86_64</span><span class="o">=</span><span class="s2">&quot;x86&quot;</span><span class="p">,</span>
<span class="n">ppc64le</span><span class="o">=</span><span class="s2">&quot;powerpc&quot;</span><span class="p">,</span>
<span class="n">arm</span><span class="o">=</span><span class="s2">&quot;arm&quot;</span><span class="p">,</span> <span class="n">armhfp</span><span class="o">=</span><span class="s2">&quot;arm&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">buildarch</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">ArchData</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">buildarch</span> <span class="o">=</span> <span class="n">buildarch</span>
<span class="bp">self</span><span class="o">.</span><span class="n">basearch</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">rpm</span><span class="o">.</span><span class="n">basearch</span><span class="p">(</span><span class="n">buildarch</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">libdir</span> <span class="o">=</span> <span class="s2">&quot;lib64&quot;</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">basearch</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">lib64_arches</span> <span class="k">else</span> <span class="s2">&quot;lib&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bcj</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">bcj_arch</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">basearch</span><span class="p">)</span></div>
<div class="viewcode-block" id="Lorax"><a class="viewcode-back" href="../pylorax.html#pylorax.Lorax">[docs]</a><span class="k">class</span> <span class="nc">Lorax</span><span class="p">(</span><span class="n">BaseLoraxClass</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">BaseLoraxClass</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_configured</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">product</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">workdir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">arch</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inroot</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_templatedir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1"># set locale to C</span>
<span class="n">locale</span><span class="o">.</span><span class="n">setlocale</span><span class="p">(</span><span class="n">locale</span><span class="o">.</span><span class="n">LC_ALL</span><span class="p">,</span> <span class="s1">&#39;C&#39;</span><span class="p">)</span>
<div class="viewcode-block" id="Lorax.configure"><a class="viewcode-back" href="../pylorax.html#pylorax.Lorax.configure">[docs]</a> <span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conf_file</span><span class="o">=</span><span class="s2">&quot;/etc/lorax/lorax.conf&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span> <span class="o">=</span> <span class="n">configparser</span><span class="o">.</span><span class="n">SafeConfigParser</span><span class="p">()</span>
<span class="c1"># set defaults</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;lorax&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;debug&quot;</span><span class="p">,</span> <span class="s2">&quot;1&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;sharedir&quot;</span><span class="p">,</span> <span class="s2">&quot;/usr/share/lorax&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;logdir&quot;</span><span class="p">,</span> <span class="s2">&quot;/var/log/lorax&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;output&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;colors&quot;</span><span class="p">,</span> <span class="s2">&quot;1&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;encoding&quot;</span><span class="p">,</span> <span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;ignorelist&quot;</span><span class="p">,</span> <span class="s2">&quot;/usr/share/lorax/ignorelist&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;templates&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;templates&quot;</span><span class="p">,</span> <span class="s2">&quot;ramdisk&quot;</span><span class="p">,</span> <span class="s2">&quot;ramdisk.ltmpl&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;compression&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">,</span> <span class="s2">&quot;xz&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;args&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;bcj&quot;</span><span class="p">,</span> <span class="s2">&quot;on&quot;</span><span class="p">)</span>
<span class="c1"># read the config file</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">conf_file</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">conf_file</span><span class="p">)</span>
<span class="c1"># set up the output</span>
<span class="bp">self</span><span class="o">.</span><span class="n">debug</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;debug&quot;</span><span class="p">)</span>
<span class="n">output_level</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">DEBUG</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span> <span class="k">else</span> <span class="n">output</span><span class="o">.</span><span class="n">INFO</span>
<span class="k">if</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">isatty</span><span class="p">():</span>
<span class="n">colors</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;colors&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">colors</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">encoding</span> <span class="o">=</span> <span class="bp">self</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="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;encoding&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">basic_config</span><span class="p">(</span><span class="n">output_level</span><span class="o">=</span><span class="n">output_level</span><span class="p">,</span>
<span class="n">colors</span><span class="o">=</span><span class="n">colors</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="n">encoding</span><span class="p">)</span>
<span class="n">ignorelist</span> <span class="o">=</span> <span class="bp">self</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="s2">&quot;output&quot;</span><span class="p">,</span> <span class="s2">&quot;ignorelist&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">ignorelist</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">ignorelist</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fobj</span><span class="p">:</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">fobj</span><span class="p">:</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="k">if</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;#&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">ignore</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="c1"># cron does not have sbin in PATH,</span>
<span class="c1"># so we have to add it ourselves</span>
<span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;PATH&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">:/sbin:/usr/sbin&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">&quot;PATH&quot;</span><span class="p">])</span>
<span class="c1"># remove some environmental variables that can cause problems with package scripts</span>
<span class="n">env_remove</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;DISPLAY&#39;</span><span class="p">,</span> <span class="s1">&#39;DBUS_SESSION_BUS_ADDRESS&#39;</span><span class="p">)</span>
<span class="nb">list</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">k</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">env_remove</span> <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_configured</span> <span class="o">=</span> <span class="kc">True</span></div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">templatedir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Find the template directory.</span>
<span class="sd"> Pick the first directory under sharedir/templates.d/ if it exists.</span>
<span class="sd"> Otherwise use the sharedir</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_templatedir</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_templatedir</span> <span class="o">=</span> <span class="n">find_templates</span><span class="p">(</span><span class="bp">self</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="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;sharedir&quot;</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Using templatedir </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_templatedir</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_templatedir</span>
<div class="viewcode-block" id="Lorax.init_stream_logging"><a class="viewcode-back" href="../pylorax.html#pylorax.Lorax.init_stream_logging">[docs]</a> <span class="k">def</span> <span class="nf">init_stream_logging</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">sh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">()</span>
<span class="n">sh</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">INFO</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">sh</span><span class="p">)</span></div>
<div class="viewcode-block" id="Lorax.init_file_logging"><a class="viewcode-back" href="../pylorax.html#pylorax.Lorax.init_file_logging">[docs]</a> <span class="k">def</span> <span class="nf">init_file_logging</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">logdir</span><span class="p">,</span> <span class="n">logname</span><span class="o">=</span><span class="s2">&quot;pylorax.log&quot;</span><span class="p">):</span>
<span class="n">fh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">FileHandler</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">logdir</span><span class="p">,</span> <span class="n">logname</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">fh</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">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span></div>
<div class="viewcode-block" id="Lorax.run"><a class="viewcode-back" href="../pylorax.html#pylorax.Lorax.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dbo</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">version</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">variant</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">bugurl</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">isfinal</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">workdir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">outputdir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">buildarch</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">volid</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">domacboot</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">doupgrade</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">remove_temp</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">installpkgs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">excludepkgs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">size</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="n">add_templates</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_template_vars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_arch_templates</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_arch_template_vars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">verify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">user_dracut_args</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">squashfs_only</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">skip_branding</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="k">assert</span> <span class="bp">self</span><span class="o">.</span><span class="n">_configured</span>
<span class="n">installpkgs</span> <span class="o">=</span> <span class="n">installpkgs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="n">excludepkgs</span> <span class="o">=</span> <span class="n">excludepkgs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">domacboot</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;rpm&quot;</span><span class="p">,</span> <span class="s2">&quot;-q&quot;</span><span class="p">,</span> <span class="s2">&quot;hfsplus-tools&quot;</span><span class="p">])</span>
<span class="k">except</span> <span class="n">CalledProcessError</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;you need to install hfsplus-tools to create mac images&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># set up work directory</span>
<span class="bp">self</span><span class="o">.</span><span class="n">workdir</span> <span class="o">=</span> <span class="n">workdir</span> <span class="ow">or</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;pylorax.work.&quot;</span><span class="p">)</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="bp">self</span><span class="o">.</span><span class="n">workdir</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="bp">self</span><span class="o">.</span><span class="n">workdir</span><span class="p">)</span>
<span class="c1"># set up log directory</span>
<span class="n">logdir</span> <span class="o">=</span> <span class="bp">self</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="s2">&quot;lorax&quot;</span><span class="p">,</span> <span class="s2">&quot;logdir&quot;</span><span class="p">)</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">logdir</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">logdir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">init_stream_logging</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">init_file_logging</span><span class="p">(</span><span class="n">logdir</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;version is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">vernum</span><span class="p">)</span>
<span class="n">log_selinux_state</span><span class="p">()</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;using work directory </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">workdir</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;using log directory </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">logdir</span><span class="p">)</span>
<span class="c1"># set up output directory</span>
<span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span> <span class="o">=</span> <span class="n">outputdir</span> <span class="ow">or</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;pylorax.out.&quot;</span><span class="p">)</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="bp">self</span><span class="o">.</span><span class="n">outputdir</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="bp">self</span><span class="o">.</span><span class="n">outputdir</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;using output directory </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span><span class="p">)</span>
<span class="c1"># do we have root privileges?</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;checking for root privileges&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">geteuid</span><span class="p">()</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;no root privileges&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># do we have a proper dnf base object?</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;checking dnf base object&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">dnf</span><span class="o">.</span><span class="n">Base</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;no dnf base object&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">inroot</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">installroot</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;using install root: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">inroot</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">buildarch</span><span class="p">:</span>
<span class="n">buildarch</span> <span class="o">=</span> <span class="n">get_buildarch</span><span class="p">(</span><span class="n">dbo</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;setting up build architecture&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">arch</span> <span class="o">=</span> <span class="n">ArchData</span><span class="p">(</span><span class="n">buildarch</span><span class="p">)</span>
<span class="k">for</span> <span class="n">attr</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;buildarch&#39;</span><span class="p">,</span> <span class="s1">&#39;basearch&#39;</span><span class="p">,</span> <span class="s1">&#39;libdir&#39;</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;self.arch.</span><span class="si">%s</span><span class="s2"> = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">attr</span><span class="p">,</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span><span class="n">attr</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;setting up build parameters&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">product</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">product</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">version</span><span class="p">,</span> <span class="n">release</span><span class="o">=</span><span class="n">release</span><span class="p">,</span>
<span class="n">variant</span><span class="o">=</span><span class="n">variant</span><span class="p">,</span> <span class="n">bugurl</span><span class="o">=</span><span class="n">bugurl</span><span class="p">,</span> <span class="n">isfinal</span><span class="o">=</span><span class="n">isfinal</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;product data: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="p">)</span>
<span class="c1"># NOTE: if you change isolabel, you need to change pungi to match, or</span>
<span class="c1"># the pungi images won&#39;t boot.</span>
<span class="n">isolabel</span> <span class="o">=</span> <span class="n">volid</span> <span class="ow">or</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">version</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">isolabel</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">32</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">fatal</span><span class="p">(</span><span class="s2">&quot;the volume id cannot be longer than 32 characters&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># NOTE: rb.root = dbo.conf.installroot (== self.inroot)</span>
<span class="n">rb</span> <span class="o">=</span> <span class="n">RuntimeBuilder</span><span class="p">(</span><span class="n">product</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span>
<span class="n">dbo</span><span class="o">=</span><span class="n">dbo</span><span class="p">,</span> <span class="n">templatedir</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">templatedir</span><span class="p">,</span>
<span class="n">installpkgs</span><span class="o">=</span><span class="n">installpkgs</span><span class="p">,</span>
<span class="n">excludepkgs</span><span class="o">=</span><span class="n">excludepkgs</span><span class="p">,</span>
<span class="n">add_templates</span><span class="o">=</span><span class="n">add_templates</span><span class="p">,</span>
<span class="n">add_template_vars</span><span class="o">=</span><span class="n">add_template_vars</span><span class="p">,</span>
<span class="n">skip_branding</span><span class="o">=</span><span class="n">skip_branding</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;installing runtime packages&quot;</span><span class="p">)</span>
<span class="n">rb</span><span class="o">.</span><span class="n">install</span><span class="p">()</span>
<span class="c1"># write .buildstamp</span>
<span class="n">buildstamp</span> <span class="o">=</span> <span class="n">BuildStamp</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">bugurl</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">isfinal</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">buildarch</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">variant</span><span class="p">)</span>
<span class="n">buildstamp</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inroot</span><span class="p">,</span> <span class="s2">&quot;.buildstamp&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">:</span>
<span class="n">rb</span><span class="o">.</span><span class="n">writepkglists</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">logdir</span><span class="p">,</span> <span class="s2">&quot;pkglists&quot;</span><span class="p">))</span>
<span class="n">rb</span><span class="o">.</span><span class="n">writepkgsizes</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">logdir</span><span class="p">,</span> <span class="s2">&quot;original-pkgsizes.txt&quot;</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;doing post-install configuration&quot;</span><span class="p">)</span>
<span class="n">rb</span><span class="o">.</span><span class="n">postinstall</span><span class="p">()</span>
<span class="c1"># write .discinfo</span>
<span class="n">discinfo</span> <span class="o">=</span> <span class="n">DiscInfo</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">release</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">)</span>
<span class="n">discinfo</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span><span class="p">,</span> <span class="s2">&quot;.discinfo&quot;</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;backing up installroot&quot;</span><span class="p">)</span>
<span class="n">installroot</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">workdir</span><span class="p">,</span> <span class="s2">&quot;installroot&quot;</span><span class="p">)</span>
<span class="n">linktree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">inroot</span><span class="p">,</span> <span class="n">installroot</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;generating kernel module metadata&quot;</span><span class="p">)</span>
<span class="n">rb</span><span class="o">.</span><span class="n">generate_module_data</span><span class="p">()</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;cleaning unneeded files&quot;</span><span class="p">)</span>
<span class="n">rb</span><span class="o">.</span><span class="n">cleanup</span><span class="p">()</span>
<span class="k">if</span> <span class="n">verify</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;verifying the installroot&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">rb</span><span class="o">.</span><span class="n">verify</span><span class="p">():</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Skipping verify&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">debug</span><span class="p">:</span>
<span class="n">rb</span><span class="o">.</span><span class="n">writepkgsizes</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">logdir</span><span class="p">,</span> <span class="s2">&quot;final-pkgsizes.txt&quot;</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;creating the runtime image&quot;</span><span class="p">)</span>
<span class="n">runtime</span> <span class="o">=</span> <span class="s2">&quot;images/install.img&quot;</span>
<span class="n">compression</span> <span class="o">=</span> <span class="bp">self</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="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;type&quot;</span><span class="p">)</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="bp">self</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="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;args&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> <span class="c1"># pylint: disable=no-member</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="s2">&quot;compression&quot;</span><span class="p">,</span> <span class="s2">&quot;bcj&quot;</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">bcj</span><span class="p">:</span>
<span class="n">compressargs</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-Xbcj&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">bcj</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;no BCJ filter for arch </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">)</span>
<span class="k">if</span> <span class="n">squashfs_only</span><span class="p">:</span>
<span class="c1"># Create an ext4 rootfs.img and compress it with squashfs</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">rb</span><span class="o">.</span><span class="n">create_squashfs_runtime</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">installroot</span><span class="p">,</span><span class="n">runtime</span><span class="p">),</span>
<span class="n">compression</span><span class="o">=</span><span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="n">compressargs</span><span class="p">,</span>
<span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Create an ext4 rootfs.img and compress it with squashfs</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">rb</span><span class="o">.</span><span class="n">create_ext4_runtime</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">installroot</span><span class="p">,</span><span class="n">runtime</span><span class="p">),</span>
<span class="n">compression</span><span class="o">=</span><span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="n">compressargs</span><span class="p">,</span>
<span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;rootfs.img creation failed. See program.log&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">rb</span><span class="o">.</span><span class="n">finished</span><span class="p">()</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;preparing to build output tree and boot images&quot;</span><span class="p">)</span>
<span class="n">treebuilder</span> <span class="o">=</span> <span class="n">TreeBuilder</span><span class="p">(</span><span class="n">product</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span>
<span class="n">inroot</span><span class="o">=</span><span class="n">installroot</span><span class="p">,</span> <span class="n">outroot</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span><span class="p">,</span>
<span class="n">runtime</span><span class="o">=</span><span class="n">runtime</span><span class="p">,</span> <span class="n">isolabel</span><span class="o">=</span><span class="n">isolabel</span><span class="p">,</span>
<span class="n">domacboot</span><span class="o">=</span><span class="n">domacboot</span><span class="p">,</span> <span class="n">doupgrade</span><span class="o">=</span><span class="n">doupgrade</span><span class="p">,</span>
<span class="n">templatedir</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">templatedir</span><span class="p">,</span>
<span class="n">add_templates</span><span class="o">=</span><span class="n">add_arch_templates</span><span class="p">,</span>
<span class="n">add_template_vars</span><span class="o">=</span><span class="n">add_arch_template_vars</span><span class="p">,</span>
<span class="n">workdir</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">workdir</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;rebuilding initramfs images&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">user_dracut_args</span><span class="p">:</span>
<span class="n">dracut_args</span> <span class="o">=</span> <span class="n">DRACUT_DEFAULT</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">dracut_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">user_dracut_args</span><span class="p">:</span>
<span class="n">dracut_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">anaconda_args</span> <span class="o">=</span> <span class="n">dracut_args</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;--add&quot;</span><span class="p">,</span> <span class="s2">&quot;anaconda pollcdrom qemu qemu-net&quot;</span><span class="p">]</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;dracut args = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">dracut_args</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;anaconda args = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">anaconda_args</span><span class="p">)</span>
<span class="n">treebuilder</span><span class="o">.</span><span class="n">rebuild_initrds</span><span class="p">(</span><span class="n">add_args</span><span class="o">=</span><span class="n">anaconda_args</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;populating output tree and building boot images&quot;</span><span class="p">)</span>
<span class="n">treebuilder</span><span class="o">.</span><span class="n">build</span><span class="p">()</span>
<span class="c1"># write .treeinfo file and we&#39;re done</span>
<span class="n">treeinfo</span> <span class="o">=</span> <span class="n">TreeInfo</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">variant</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">)</span>
<span class="k">for</span> <span class="n">section</span><span class="p">,</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">treebuilder</span><span class="o">.</span><span class="n">treeinfo_data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">treeinfo</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="n">data</span><span class="p">)</span>
<span class="n">treeinfo</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">outputdir</span><span class="p">,</span> <span class="s2">&quot;.treeinfo&quot;</span><span class="p">))</span>
<span class="c1"># cleanup</span>
<span class="k">if</span> <span class="n">remove_temp</span><span class="p">:</span>
<span class="n">remove</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">workdir</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="get_buildarch"><a class="viewcode-back" href="../pylorax.html#pylorax.get_buildarch">[docs]</a><span class="k">def</span> <span class="nf">get_buildarch</span><span class="p">(</span><span class="n">dbo</span><span class="p">):</span>
<span class="c1"># get architecture of the available anaconda package</span>
<span class="n">buildarch</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">q</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">available</span><span class="p">()</span>
<span class="k">for</span> <span class="n">anaconda</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s2">&quot;anaconda-core&quot;</span><span class="p">):</span>
<span class="k">if</span> <span class="n">anaconda</span><span class="o">.</span><span class="n">arch</span> <span class="o">!=</span> <span class="s2">&quot;src&quot;</span><span class="p">:</span>
<span class="n">buildarch</span> <span class="o">=</span> <span class="n">anaconda</span><span class="o">.</span><span class="n">arch</span>
<span class="k">break</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">buildarch</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;no anaconda-core package in the repository&quot;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">return</span> <span class="n">buildarch</span></div>
<div class="viewcode-block" id="setup_logging"><a class="viewcode-back" href="../pylorax.html#pylorax.setup_logging">[docs]</a><span class="k">def</span> <span class="nf">setup_logging</span><span class="p">(</span><span class="n">logfile</span><span class="p">,</span> <span class="n">theLogger</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Setup the various logs</span>
<span class="sd"> :param logfile: filename to write the log to</span>
<span class="sd"> :type logfile: string</span>
<span class="sd"> :param theLogger: top-level logger</span>
<span class="sd"> :type theLogger: logging.Logger</span>
<span class="sd"> &quot;&quot;&quot;</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">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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">logfile</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">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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">logfile</span><span class="p">)))</span>
<span class="c1"># Setup logging to console and to logfile</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">theLogger</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">sh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">()</span>
<span class="n">sh</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">INFO</span><span class="p">)</span>
<span class="n">fmt</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%(asctime)s</span><span class="s2">: </span><span class="si">%(message)s</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">sh</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">fmt</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">sh</span><span class="p">)</span>
<span class="n">theLogger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">sh</span><span class="p">)</span>
<span class="n">fh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">FileHandler</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">logfile</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">fh</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">fmt</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%(asctime)s</span><span class="s2"> </span><span class="si">%(levelname)s</span><span class="s2"> </span><span class="si">%(name)s</span><span class="s2">: </span><span class="si">%(message)s</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">fh</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">fmt</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span>
<span class="n">theLogger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span>
<span class="c1"># External program output log</span>
<span class="n">program_log</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">f</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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">logfile</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;/program.log&quot;</span>
<span class="n">fh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">FileHandler</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">f</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">fh</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">fmt</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%(asctime)s</span><span class="s2"> </span><span class="si">%(levelname)s</span><span class="s2">: </span><span class="si">%(message)s</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">fh</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">fmt</span><span class="p">)</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span></div>
<div class="viewcode-block" id="find_templates"><a class="viewcode-back" href="../pylorax.html#pylorax.find_templates">[docs]</a><span class="k">def</span> <span class="nf">find_templates</span><span class="p">(</span><span class="n">templatedir</span><span class="o">=</span><span class="s2">&quot;/usr/share/lorax&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Find the templates to use.</span>
<span class="sd"> :param str templatedir: Top directory to search for templates</span>
<span class="sd"> :returns: Path to templates</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> If there is a templates.d directory under templatedir the</span>
<span class="sd"> lowest numbered directory entry is returned.</span>
<span class="sd"> eg. /usr/share/lorax/templates.d/99-generic/</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</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">joinpaths</span><span class="p">(</span><span class="n">templatedir</span><span class="p">,</span> <span class="s2">&quot;templates.d&quot;</span><span class="p">)):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">templatedir</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">glob</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">templatedir</span><span class="p">,</span> <span class="s2">&quot;templates.d&quot;</span><span class="p">,</span> <span class="s2">&quot;*&quot;</span><span class="p">)))[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">return</span> <span class="n">templatedir</span></div>
<div class="viewcode-block" id="log_selinux_state"><a class="viewcode-back" href="../pylorax.html#pylorax.log_selinux_state">[docs]</a><span class="k">def</span> <span class="nf">log_selinux_state</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;Log the current state of selinux&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">selinux</span><span class="o">.</span><span class="n">is_selinux_enabled</span><span class="p">():</span>
<span class="k">if</span> <span class="n">selinux</span><span class="o">.</span><span class="n">security_getenforce</span><span class="p">():</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;selinux is enabled and in Enforcing mode&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;selinux is enabled and in Permissive mode&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;selinux is Disabled&quot;</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,250 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.bisect &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.bisect</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.bisect</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<div class="viewcode-block" id="insort_left"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.bisect.insort_left">[docs]</a><span class="k">def</span> <span class="nf">insort_left</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">lo</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">hi</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Insert item x in list a, and keep it sorted assuming a is sorted.</span>
<span class="sd"> :param a: sorted list</span>
<span class="sd"> :type a: list</span>
<span class="sd"> :param x: item to insert into the list</span>
<span class="sd"> :type x: object</span>
<span class="sd"> :param key: Function to use to compare items in the list</span>
<span class="sd"> :type key: function</span>
<span class="sd"> :returns: index where the item was inserted</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> If x is already in a, insert it to the left of the leftmost x.</span>
<span class="sd"> Optional args lo (default 0) and hi (default len(a)) bound the</span>
<span class="sd"> slice of a to be searched.</span>
<span class="sd"> This is a modified version of bisect.insort_left that can use a</span>
<span class="sd"> function for the compare, and returns the index position where it</span>
<span class="sd"> was inserted.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">key</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">key</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span>
<span class="k">if</span> <span class="n">lo</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;lo must be non-negative&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">hi</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">hi</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
<span class="k">while</span> <span class="n">lo</span> <span class="o">&lt;</span> <span class="n">hi</span><span class="p">:</span>
<span class="n">mid</span> <span class="o">=</span> <span class="p">(</span><span class="n">lo</span><span class="o">+</span><span class="n">hi</span><span class="p">)</span><span class="o">//</span><span class="mi">2</span>
<span class="k">if</span> <span class="n">key</span><span class="p">(</span><span class="n">a</span><span class="p">[</span><span class="n">mid</span><span class="p">])</span> <span class="o">&lt;</span> <span class="n">key</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> <span class="n">lo</span> <span class="o">=</span> <span class="n">mid</span><span class="o">+</span><span class="mi">1</span>
<span class="k">else</span><span class="p">:</span> <span class="n">hi</span> <span class="o">=</span> <span class="n">mid</span>
<span class="n">a</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="n">lo</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="k">return</span> <span class="n">lo</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,245 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.checkparams &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.checkparams</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.checkparams</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;lorax-composer&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">jsonify</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">update_wrapper</span>
<span class="c1"># A decorator for checking the parameters provided to the API route implementing</span>
<span class="c1"># functions. The tuples parameter is a list of tuples. Each tuple is the string</span>
<span class="c1"># name of a parameter (&quot;blueprint_name&quot;, not blueprint_name), the value it&#39;s set</span>
<span class="c1"># to by flask if the caller did not provide it, and a message to be returned to</span>
<span class="c1"># the user.</span>
<span class="c1">#</span>
<span class="c1"># If the parameter is set to its default, the error message is returned. Otherwise,</span>
<span class="c1"># the decorated function is called and its return value is returned.</span>
<div class="viewcode-block" id="checkparams"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.checkparams.checkparams">[docs]</a><span class="k">def</span> <span class="nf">checkparams</span><span class="p">(</span><span class="n">tuples</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">wrapped_function</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">for</span> <span class="n">tup</span> <span class="ow">in</span> <span class="n">tuples</span><span class="p">:</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="p">[</span><span class="n">tup</span><span class="p">[</span><span class="mi">0</span><span class="p">]]</span> <span class="o">==</span> <span class="n">tup</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;(</span><span class="si">%s</span><span class="s2">) </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">f</span><span class="o">.</span><span class="vm">__name__</span><span class="p">,</span> <span class="n">tup</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[</span><span class="n">tup</span><span class="p">[</span><span class="mi">2</span><span class="p">]]),</span> <span class="mi">400</span>
<span class="k">return</span> <span class="n">f</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">return</span> <span class="n">update_wrapper</span><span class="p">(</span><span class="n">wrapped_function</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="k">return</span> <span class="n">decorator</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,264 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.cmdline &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.cmdline</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.cmdline</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># cmdline.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">vernum</span>
<span class="n">DEFAULT_USER</span> <span class="o">=</span> <span class="s2">&quot;root&quot;</span>
<span class="n">DEFAULT_GROUP</span> <span class="o">=</span> <span class="s2">&quot;weldr&quot;</span>
<span class="n">version</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">-</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</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">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">vernum</span><span class="p">)</span>
<div class="viewcode-block" id="lorax_composer_parser"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.cmdline.lorax_composer_parser">[docs]</a><span class="k">def</span> <span class="nf">lorax_composer_parser</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot; Return the ArgumentParser for lorax-composer&quot;&quot;&quot;</span>
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">&quot;Lorax Composer API Server&quot;</span><span class="p">,</span>
<span class="n">fromfile_prefix_chars</span><span class="o">=</span><span class="s2">&quot;@&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--socket&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/run/weldr/api.socket&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;SOCKET&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to the socket file to listen on&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--user&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">DEFAULT_USER</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;USER&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;User to use for reduced permissions&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--group&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="n">DEFAULT_GROUP</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;GROUP&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Group to set ownership of the socket to&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--log&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;logfile&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/var/log/lorax-composer/composer.log&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;LOG&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to logfile (/var/log/lorax-composer/composer.log)&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--mockfiles&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/var/tmp/bdcs-mockfiles/&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;MOCKFILES&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to JSON files used for /api/mock/ paths (/var/tmp/bdcs-mockfiles/)&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--sharedir&quot;</span><span class="p">,</span> <span class="nb">type</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">metavar</span><span class="o">=</span><span class="s2">&quot;SHAREDIR&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Directory containing all the templates. Overrides config file sharedir&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-V&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;showver&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;show program&#39;s version number and exit&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-c&quot;</span><span class="p">,</span> <span class="s2">&quot;--config&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/etc/lorax/composer.conf&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;CONFIG&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to lorax-composer configuration file.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--releasever&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;STRING&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Release version to use for $releasever in dnf repository urls&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--tmp&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/var/tmp&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Top level temporary directory&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--proxy&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;PROXY&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Set proxy for DNF, overrides configuration file setting.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--no-system-repos&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Do not copy over system repos from /etc/yum.repos.d/ at startup&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;BLUEPRINTS&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;BLUEPRINTS&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to the blueprints&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">parser</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,341 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.config &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.config</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.config</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">configparser</span>
<span class="kn">import</span> <span class="nn">grp</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">pwd</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="ComposerConfig"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.ComposerConfig">[docs]</a><span class="k">class</span> <span class="nc">ComposerConfig</span><span class="p">(</span><span class="n">configparser</span><span class="o">.</span><span class="n">ConfigParser</span><span class="p">):</span>
<div class="viewcode-block" id="ComposerConfig.get_default"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.ComposerConfig.get_default">[docs]</a> <span class="k">def</span> <span class="nf">get_default</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">default</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">)</span>
<span class="k">except</span> <span class="n">configparser</span><span class="o">.</span><span class="n">Error</span><span class="p">:</span>
<span class="k">return</span> <span class="n">default</span></div></div>
<div class="viewcode-block" id="configure"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.configure">[docs]</a><span class="k">def</span> <span class="nf">configure</span><span class="p">(</span><span class="n">conf_file</span><span class="o">=</span><span class="s2">&quot;/etc/lorax/composer.conf&quot;</span><span class="p">,</span> <span class="n">root_dir</span><span class="o">=</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="n">test_config</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;lorax-composer configuration</span>
<span class="sd"> :param conf_file: Path to the config file overriding the default settings</span>
<span class="sd"> :type conf_file: str</span>
<span class="sd"> :param root_dir: Directory to prepend to paths, defaults to /</span>
<span class="sd"> :type root_dir: str</span>
<span class="sd"> :param test_config: Set to True to skip reading conf_file</span>
<span class="sd"> :type test_config: bool</span>
<span class="sd"> :returns: Configuration</span>
<span class="sd"> :rtype: ComposerConfig</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">conf</span> <span class="o">=</span> <span class="n">ComposerConfig</span><span class="p">()</span>
<span class="c1"># set defaults</span>
<span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;share_dir&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/usr/share/lorax/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;lib_dir&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/lib/lorax/composer/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;repo_dir&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/lib/lorax/composer/repos.d/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;dnf_conf&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/tmp/composer/dnf.conf&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;dnf_root&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/tmp/composer/dnf/root/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;cache_dir&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/tmp/composer/cache/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;tmp&quot;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;/var/tmp/&quot;</span><span class="p">)))</span>
<span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;users&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;users&quot;</span><span class="p">,</span> <span class="s2">&quot;root&quot;</span><span class="p">,</span> <span class="s2">&quot;1&quot;</span><span class="p">)</span>
<span class="c1"># Enable all available repo files by default</span>
<span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;repos&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;use_system_repos&quot;</span><span class="p">,</span> <span class="s2">&quot;1&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;enabled&quot;</span><span class="p">,</span> <span class="s2">&quot;*&quot;</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">add_section</span><span class="p">(</span><span class="s2">&quot;dnf&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">test_config</span><span class="p">:</span>
<span class="c1"># read the config file</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">conf_file</span><span class="p">):</span>
<span class="n">conf</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">conf_file</span><span class="p">)</span>
<span class="k">return</span> <span class="n">conf</span></div>
<div class="viewcode-block" id="make_owned_dir"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.make_owned_dir">[docs]</a><span class="k">def</span> <span class="nf">make_owned_dir</span><span class="p">(</span><span class="n">p_dir</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Make a directory and its parents, setting owner and group</span>
<span class="sd"> :param p_dir: path to directory to create</span>
<span class="sd"> :type p_dir: string</span>
<span class="sd"> :param uid: uid of owner</span>
<span class="sd"> :type uid: int</span>
<span class="sd"> :param gid: gid of owner</span>
<span class="sd"> :type gid: int</span>
<span class="sd"> :returns: list of errors</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> Check to make sure it does not have o+rw permissions and that it is owned by uid:gid</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</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">p_dir</span><span class="p">):</span>
<span class="c1"># Make sure no o+rw permissions are set</span>
<span class="n">orig_umask</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">umask</span><span class="p">(</span><span class="mo">0o006</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">p_dir</span><span class="p">,</span> <span class="mo">0o771</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">chown</span><span class="p">(</span><span class="n">p_dir</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">umask</span><span class="p">(</span><span class="n">orig_umask</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">p_stat</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">p_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="n">p_stat</span><span class="o">.</span><span class="n">st_mode</span> <span class="o">&amp;</span> <span class="mo">0o006</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Incorrect permissions on </span><span class="si">%s</span><span class="s2">, no o+rw permissions are allowed.&quot;</span> <span class="o">%</span> <span class="n">p_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="n">p_stat</span><span class="o">.</span><span class="n">st_gid</span> <span class="o">!=</span> <span class="n">gid</span> <span class="ow">or</span> <span class="n">p_stat</span><span class="o">.</span><span class="n">st_uid</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">gr_name</span> <span class="o">=</span> <span class="n">grp</span><span class="o">.</span><span class="n">getgrgid</span><span class="p">(</span><span class="n">gid</span><span class="p">)</span><span class="o">.</span><span class="n">gr_name</span>
<span class="n">u_name</span> <span class="o">=</span> <span class="n">pwd</span><span class="o">.</span><span class="n">getpwuid</span><span class="p">(</span><span class="n">uid</span><span class="p">)</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> should be owned by </span><span class="si">%s</span><span class="s2">:</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">p_dir</span><span class="p">,</span> <span class="n">u_name</span><span class="p">,</span> <span class="n">gr_name</span><span class="p">))</span>
<span class="k">return</span> <span class="n">errors</span></div>
<div class="viewcode-block" id="make_dnf_dirs"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.make_dnf_dirs">[docs]</a><span class="k">def</span> <span class="nf">make_dnf_dirs</span><span class="p">(</span><span class="n">conf</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Make any missing dnf directories owned by user:group</span>
<span class="sd"> :param conf: The configuration to use</span>
<span class="sd"> :type conf: ComposerConfig</span>
<span class="sd"> :param uid: uid of owner</span>
<span class="sd"> :type uid: int</span>
<span class="sd"> :param gid: gid of owner</span>
<span class="sd"> :type gid: int</span>
<span class="sd"> :returns: list of errors</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;dnf_conf&quot;</span><span class="p">,</span> <span class="s2">&quot;repo_dir&quot;</span><span class="p">,</span> <span class="s2">&quot;cache_dir&quot;</span><span class="p">,</span> <span class="s2">&quot;dnf_root&quot;</span><span class="p">]:</span>
<span class="n">p_dir</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">))</span>
<span class="k">if</span> <span class="n">p</span> <span class="o">==</span> <span class="s2">&quot;dnf_conf&quot;</span><span class="p">:</span>
<span class="n">p_dir</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">dirname</span><span class="p">(</span><span class="n">p_dir</span><span class="p">)</span>
<span class="n">errors</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">make_owned_dir</span><span class="p">(</span><span class="n">p_dir</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">))</span></div>
<div class="viewcode-block" id="make_queue_dirs"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.config.make_queue_dirs">[docs]</a><span class="k">def</span> <span class="nf">make_queue_dirs</span><span class="p">(</span><span class="n">conf</span><span class="p">,</span> <span class="n">gid</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Make any missing queue directories</span>
<span class="sd"> :param conf: The configuration to use</span>
<span class="sd"> :type conf: ComposerConfig</span>
<span class="sd"> :param gid: Group ID that has access to the queue directories</span>
<span class="sd"> :type gid: int</span>
<span class="sd"> :returns: list of errors</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">lib_dir</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;lib_dir&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;queue/run&quot;</span><span class="p">,</span> <span class="s2">&quot;queue/new&quot;</span><span class="p">,</span> <span class="s2">&quot;results&quot;</span><span class="p">]:</span>
<span class="n">p_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">lib_dir</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span>
<span class="n">errors</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">make_owned_dir</span><span class="p">(</span><span class="n">p_dir</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="n">gid</span><span class="p">))</span>
<span class="k">return</span> <span class="n">errors</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,264 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.crossdomain &mdash; Lorax 31.7 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></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>
<script type="text/javascript" src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
31.7
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.crossdomain</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.crossdomain</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># crossdomain decorator from - http://flask.pocoo.org/snippets/56/</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">timedelta</span>
<span class="kn">from</span> <span class="nn">flask</span> <span class="k">import</span> <span class="n">make_response</span><span class="p">,</span> <span class="n">request</span><span class="p">,</span> <span class="n">current_app</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">update_wrapper</span>
<div class="viewcode-block" id="crossdomain"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.crossdomain.crossdomain">[docs]</a><span class="k">def</span> <span class="nf">crossdomain</span><span class="p">(</span><span class="n">origin</span><span class="p">,</span> <span class="n">methods</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">max_age</span><span class="o">=</span><span class="mi">21600</span><span class="p">,</span> <span class="n">attach_to_all</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">automatic_options</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="k">if</span> <span class="n">methods</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">methods</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">methods</span><span class="p">))</span>
<span class="k">if</span> <span class="n">headers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">headers</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
<span class="n">headers</span> <span class="o">=</span> <span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">x</span><span class="o">.</span><span class="n">upper</span><span class="p">()</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">headers</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">origin</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
<span class="n">origin</span> <span class="o">=</span> <span class="p">[</span><span class="n">origin</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">max_age</span><span class="p">,</span> <span class="n">timedelta</span><span class="p">):</span>
<span class="n">max_age</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">max_age</span><span class="o">.</span><span class="n">total_seconds</span><span class="p">())</span>
<span class="k">def</span> <span class="nf">get_methods</span><span class="p">():</span>
<span class="k">if</span> <span class="n">methods</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">return</span> <span class="n">methods</span>
<span class="n">options_resp</span> <span class="o">=</span> <span class="n">current_app</span><span class="o">.</span><span class="n">make_default_options_response</span><span class="p">()</span>
<span class="k">return</span> <span class="n">options_resp</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s1">&#39;allow&#39;</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">decorator</span><span class="p">(</span><span class="n">f</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">wrapped_function</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="k">if</span> <span class="n">automatic_options</span> <span class="ow">and</span> <span class="n">request</span><span class="o">.</span><span class="n">method</span> <span class="o">==</span> <span class="s1">&#39;OPTIONS&#39;</span><span class="p">:</span>
<span class="n">resp</span> <span class="o">=</span> <span class="n">current_app</span><span class="o">.</span><span class="n">make_default_options_response</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">resp</span> <span class="o">=</span> <span class="n">make_response</span><span class="p">(</span><span class="n">f</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">attach_to_all</span> <span class="ow">and</span> <span class="n">request</span><span class="o">.</span><span class="n">method</span> <span class="o">!=</span> <span class="s1">&#39;OPTIONS&#39;</span><span class="p">:</span>
<span class="k">return</span> <span class="n">resp</span>
<span class="n">h</span> <span class="o">=</span> <span class="n">resp</span><span class="o">.</span><span class="n">headers</span>
<span class="n">h</span><span class="o">.</span><span class="n">extend</span><span class="p">([(</span><span class="s2">&quot;Access-Control-Allow-Origin&quot;</span><span class="p">,</span> <span class="n">orig</span><span class="p">)</span> <span class="k">for</span> <span class="n">orig</span> <span class="ow">in</span> <span class="n">origin</span><span class="p">])</span>
<span class="n">h</span><span class="p">[</span><span class="s1">&#39;Access-Control-Allow-Methods&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">get_methods</span><span class="p">()</span>
<span class="n">h</span><span class="p">[</span><span class="s1">&#39;Access-Control-Max-Age&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">max_age</span><span class="p">)</span>
<span class="k">if</span> <span class="n">headers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">h</span><span class="p">[</span><span class="s1">&#39;Access-Control-Allow-Headers&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">headers</span>
<span class="k">return</span> <span class="n">resp</span>
<span class="n">f</span><span class="o">.</span><span class="n">provide_automatic_options</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">f</span><span class="o">.</span><span class="n">required_methods</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;OPTIONS&#39;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">update_wrapper</span><span class="p">(</span><span class="n">wrapped_function</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="k">return</span> <span class="n">decorator</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,387 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.dnfbase &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.dnfbase</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.dnfbase</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017-2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># 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="s2">&quot;lorax-composer&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">dnf</span>
<span class="kn">import</span> <span class="nn">dnf.logging</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Lock</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">DEFAULT_PLATFORM_ID</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">flatconfig</span>
<div class="viewcode-block" id="DNFLock"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.dnfbase.DNFLock">[docs]</a><span class="k">class</span> <span class="nc">DNFLock</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Hold the dnf.Base object and a Lock to control access to it.</span>
<span class="sd"> self.dbo is a property that returns the dnf.Base object, but it *may* change</span>
<span class="sd"> from one call to the next if the upstream repositories have changed.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conf</span><span class="p">,</span> <span class="n">expire_secs</span><span class="o">=</span><span class="mi">6</span><span class="o">*</span><span class="mi">60</span><span class="o">*</span><span class="mi">60</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_conf</span> <span class="o">=</span> <span class="n">conf</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_lock</span> <span class="o">=</span> <span class="n">Lock</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dbo</span> <span class="o">=</span> <span class="n">get_base_object</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_conf</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_expire_secs</span> <span class="o">=</span> <span class="n">expire_secs</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_expire_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expire_secs</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">lock</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Check for repo updates (using expiration time) and return the lock</span>
<span class="sd"> If the repository has been updated, tear down the old dnf.Base and</span>
<span class="sd"> create a new one. This is the only way to force dnf to use the new</span>
<span class="sd"> metadata.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expire_time</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">lock_check</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lock</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">lock_check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Force a check for repo updates and return the lock</span>
<span class="sd"> Use this method sparingly, it removes the repodata and downloads a new copy every time.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_expire_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">_expire_secs</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">update_cache</span><span class="p">()</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_lock</span></div>
<div class="viewcode-block" id="get_base_object"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.dnfbase.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">&quot;&quot;&quot;Get the DNF 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 DNF Base object</span>
<span class="sd"> :rtype: dnf.Base</span>
<span class="sd"> &quot;&quot;&quot;</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;cache_dir&quot;</span><span class="p">))</span>
<span class="n">dnfconf</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;dnf_conf&quot;</span><span class="p">))</span>
<span class="n">dnfroot</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;dnf_root&quot;</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;repo_dir&quot;</span><span class="p">))</span>
<span class="c1"># Setup the config for the DNF Base object</span>
<span class="n">dbo</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">Base</span><span class="p">()</span>
<span class="n">dbc</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">conf</span>
<span class="c1"># TODO - Handle this</span>
<span class="c1"># dbc.logdir = logdir</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">installroot</span> <span class="o">=</span> <span class="n">dnfroot</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">dnfroot</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">dnfroot</span><span class="p">)</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">repodir</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">repodir</span><span class="p">)</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">cachedir</span> <span class="o">=</span> <span class="n">cachedir</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">reposdir</span> <span class="o">=</span> <span class="p">[</span><span class="n">repodir</span><span class="p">]</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">install_weak_deps</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">prepend_installroot</span><span class="p">(</span><span class="s1">&#39;persistdir&#39;</span><span class="p">)</span>
<span class="c1"># this is a weird &#39;AppendOption&#39; thing that, when you set it,</span>
<span class="c1"># actually appends. Doing this adds &#39;nodocs&#39; to the existing list</span>
<span class="c1"># of values, over in libdnf, it does not replace the existing values.</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">tsflags</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;nodocs&#39;</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="s2">&quot;dnf&quot;</span><span class="p">,</span> <span class="s2">&quot;proxy&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">):</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">proxy</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="s2">&quot;dnf&quot;</span><span class="p">,</span> <span class="s2">&quot;proxy&quot;</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="s2">&quot;dnf&quot;</span><span class="p">,</span> <span class="s2">&quot;sslverify&quot;</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="s2">&quot;dnf&quot;</span><span class="p">,</span> <span class="s2">&quot;sslverify&quot;</span><span class="p">):</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">sslverify</span> <span class="o">=</span> <span class="kc">False</span>
<span class="c1"># If the system repos are enabled read the dnf vars from /etc/dnf/vars/</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="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;use_system_repos&quot;</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="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;use_system_repos&quot;</span><span class="p">):</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">substitutions</span><span class="o">.</span><span class="n">update_from_etc</span><span class="p">(</span><span class="s2">&quot;/&quot;</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="s2">&quot;dnf vars: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">dbc</span><span class="o">.</span><span class="n">substitutions</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="s2">&quot;composer&quot;</span><span class="p">,</span> <span class="s2">&quot;releasever&quot;</span><span class="p">,</span> <span class="kc">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="c1"># Use the releasever of the host system</span>
<span class="n">_releasever</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">rpm</span><span class="o">.</span><span class="n">detect_releasever</span><span class="p">(</span><span class="s2">&quot;/&quot;</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="s2">&quot;releasever = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">_releasever</span><span class="p">)</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">releasever</span> <span class="o">=</span> <span class="n">_releasever</span>
<span class="c1"># DNF 3.2 needs to have module_platform_id set, otherwise depsolve won&#39;t work correctly</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">exists</span><span class="p">(</span><span class="s2">&quot;/etc/os-release&quot;</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;/etc/os-release is missing, cannot determine platform id, falling back to </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">DEFAULT_PLATFORM_ID</span><span class="p">)</span>
<span class="n">platform_id</span> <span class="o">=</span> <span class="n">DEFAULT_PLATFORM_ID</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">os_release</span> <span class="o">=</span> <span class="n">flatconfig</span><span class="p">(</span><span class="s2">&quot;/etc/os-release&quot;</span><span class="p">)</span>
<span class="n">platform_id</span> <span class="o">=</span> <span class="n">os_release</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PLATFORM_ID&quot;</span><span class="p">,</span> <span class="n">DEFAULT_PLATFORM_ID</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="s2">&quot;Using </span><span class="si">%s</span><span class="s2"> for module_platform_id&quot;</span><span class="p">,</span> <span class="n">platform_id</span><span class="p">)</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">module_platform_id</span> <span class="o">=</span> <span class="n">platform_id</span>
<span class="c1"># Make sure metadata is always current</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">metadata_expire</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">dbc</span><span class="o">.</span><span class="n">metadata_expire_filter</span> <span class="o">=</span> <span class="s2">&quot;never&quot;</span>
<span class="c1"># write the dnf configuration file</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">dnfconf</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">dbc</span><span class="o">.</span><span class="n">dump</span><span class="p">())</span>
<span class="c1"># dnf needs the repos all in one directory, composer uses repodir for this</span>
<span class="c1"># if system repos are supposed to be used, copy them into repodir, overwriting any previous copies</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="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;use_system_repos&quot;</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="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="s2">&quot;use_system_repos&quot;</span><span class="p">):</span>
<span class="k">for</span> <span class="n">repo_file</span> <span class="ow">in</span> <span class="n">glob</span><span class="p">(</span><span class="s2">&quot;/etc/yum.repos.d/*.repo&quot;</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">repo_file</span><span class="p">,</span> <span class="n">repodir</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">read_all_repos</span><span class="p">()</span>
<span class="c1"># Remove any duplicate repo entries. These can cause problems with Anaconda, which will fail</span>
<span class="c1"># with space problems.</span>
<span class="n">repos</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="nb">list</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">iter_enabled</span><span class="p">()))</span>
<span class="n">seen</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;baseurl&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;mirrorlist&quot;</span><span class="p">:</span> <span class="p">[],</span> <span class="s2">&quot;metalink&quot;</span><span class="p">:</span> <span class="p">[]}</span>
<span class="k">for</span> <span class="n">source_name</span> <span class="ow">in</span> <span class="n">repos</span><span class="p">:</span>
<span class="n">remove</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">source_name</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">repo</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;repo </span><span class="si">%s</span><span class="s2"> vanished while removing duplicates&quot;</span><span class="p">,</span> <span class="n">source_name</span><span class="p">)</span>
<span class="k">continue</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">:</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">[</span><span class="s2">&quot;baseurl&quot;</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="s2">&quot;Removing duplicate repo: </span><span class="si">%s</span><span class="s2"> baseurl=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">source_name</span><span class="p">,</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">remove</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">seen</span><span class="p">[</span><span class="s2">&quot;baseurl&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span><span class="p">:</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">[</span><span class="s2">&quot;mirrorlist&quot;</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="s2">&quot;Removing duplicate repo: </span><span class="si">%s</span><span class="s2"> mirrorlist=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">source_name</span><span class="p">,</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span><span class="p">)</span>
<span class="n">remove</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">seen</span><span class="p">[</span><span class="s2">&quot;mirrorlist&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span><span class="p">:</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">[</span><span class="s2">&quot;metalink&quot;</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="s2">&quot;Removing duplicate repo: </span><span class="si">%s</span><span class="s2"> metalink=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">source_name</span><span class="p">,</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span><span class="p">)</span>
<span class="n">remove</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">seen</span><span class="p">[</span><span class="s2">&quot;metalink&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">metalink</span><span class="p">)</span>
<span class="k">if</span> <span class="n">remove</span><span class="p">:</span>
<span class="k">del</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="p">[</span><span class="n">source_name</span><span class="p">]</span>
<span class="c1"># Update the metadata from the enabled repos to speed up later operations</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Updating repository metadata&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">fill_sack</span><span class="p">(</span><span class="n">load_system_repo</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">read_comps</span><span class="p">()</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">update_cache</span><span class="p">()</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">Error</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Failed to update metadata: </span><span class="si">%s</span><span class="s2">&quot;</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">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Fetching metadata failed: </span><span class="si">%s</span><span class="s2">&quot;</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">return</span> <span class="n">dbo</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,255 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.flask_blueprint &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.flask_blueprint</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.flask_blueprint</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="sd">&quot;&quot;&quot; Flask Blueprints that support skipping routes</span>
<span class="sd">When using Blueprints for API versioning you will usually want to fall back</span>
<span class="sd">to the previous version&#39;s rules for routes that have no new behavior. To do</span>
<span class="sd">this we add a &#39;skip_rule&#39; list to the Blueprint&#39;s options dictionary. It lists</span>
<span class="sd">all of the routes that you do not want to register.</span>
<span class="sd">For example:</span>
<span class="sd"> from pylorax.api.v0 import v0</span>
<span class="sd"> from pylorax.api.v1 import v1</span>
<span class="sd"> server.register_blueprint(v0, url_prefix=&quot;/api/v0/&quot;)</span>
<span class="sd"> server.register_blueprint(v0, url_prefix=&quot;/api/v1/&quot;, skip_rules=[&quot;/blueprints/list&quot;]</span>
<span class="sd"> server.register_blueprint(v1, url_prefix=&quot;/api/v1/&quot;)</span>
<span class="sd">This will register all of v0&#39;s routes under `/api/v0`, and all but `/blueprints/list` under /api/v1,</span>
<span class="sd">and then register v1&#39;s version of `/blueprints/list` under `/api/v1`</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Blueprint</span>
<span class="kn">from</span> <span class="nn">flask.blueprints</span> <span class="kn">import</span> <span class="n">BlueprintSetupState</span>
<div class="viewcode-block" id="BlueprintSetupStateSkip"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.flask_blueprint.BlueprintSetupStateSkip">[docs]</a><span class="k">class</span> <span class="nc">BlueprintSetupStateSkip</span><span class="p">(</span><span class="n">BlueprintSetupState</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">blueprint</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">first_registration</span><span class="p">,</span> <span class="n">skip_rules</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_skip_rules</span> <span class="o">=</span> <span class="n">skip_rules</span>
<span class="nb">super</span><span class="p">(</span><span class="n">BlueprintSetupStateSkip</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">blueprint</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">first_registration</span><span class="p">)</span>
<div class="viewcode-block" id="BlueprintSetupStateSkip.add_url_rule"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.flask_blueprint.BlueprintSetupStateSkip.add_url_rule">[docs]</a> <span class="k">def</span> <span class="nf">add_url_rule</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rule</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">view_func</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">):</span>
<span class="k">if</span> <span class="n">rule</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_skip_rules</span><span class="p">:</span>
<span class="nb">super</span><span class="p">(</span><span class="n">BlueprintSetupStateSkip</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">add_url_rule</span><span class="p">(</span><span class="n">rule</span><span class="p">,</span> <span class="n">endpoint</span><span class="p">,</span> <span class="n">view_func</span><span class="p">,</span> <span class="o">**</span><span class="n">options</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="BlueprintSkip"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.flask_blueprint.BlueprintSkip">[docs]</a><span class="k">class</span> <span class="nc">BlueprintSkip</span><span class="p">(</span><span class="n">Blueprint</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">BlueprintSkip</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="BlueprintSkip.make_setup_state"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.flask_blueprint.BlueprintSkip.make_setup_state">[docs]</a> <span class="k">def</span> <span class="nf">make_setup_state</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">first_registration</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">skip_rules</span> <span class="o">=</span> <span class="n">options</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;skip_rules&quot;</span><span class="p">,</span> <span class="p">[])</span>
<span class="k">return</span> <span class="n">BlueprintSetupStateSkip</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">app</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">first_registration</span><span class="p">,</span> <span class="n">skip_rules</span><span class="p">)</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,423 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.gitrpm &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.gitrpm</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.gitrpm</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="sd">&quot;&quot;&quot; Clone a git repository and package it as an rpm</span>
<span class="sd">This module contains functions for cloning a git repo, creating a tar archive of</span>
<span class="sd">the selected commit, branch, or tag, and packaging the files into an rpm that will</span>
<span class="sd">be installed by anaconda when creating the image.</span>
<span class="sd">&quot;&quot;&quot;</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="s2">&quot;lorax-composer&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">rpmfluff</span> <span class="kn">import</span> <span class="n">SimpleRpmBuild</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">time</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_repo_description"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.get_repo_description">[docs]</a><span class="k">def</span> <span class="nf">get_repo_description</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return a description including the git repo and reference</span>
<span class="sd"> :param gitRepo: A dict with the repository details</span>
<span class="sd"> :type gitRepo: dict</span>
<span class="sd"> :returns: A string with the git repo url and reference</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="s2">&quot;Created from </span><span class="si">%s</span><span class="s2">, reference &#39;</span><span class="si">%s</span><span class="s2">&#39;, on </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">],</span> <span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;ref&quot;</span><span class="p">],</span> <span class="n">time</span><span class="o">.</span><span class="n">ctime</span><span class="p">())</span></div>
<div class="viewcode-block" id="GitArchiveTarball"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitArchiveTarball">[docs]</a><span class="k">class</span> <span class="nc">GitArchiveTarball</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;Create a git archive of the selected git repo and reference&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gitRepo</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span> <span class="o">=</span> <span class="n">gitRepo</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sourceName</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmname&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;.tar.xz&quot;</span>
<div class="viewcode-block" id="GitArchiveTarball.write_file"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitArchiveTarball.write_file">[docs]</a> <span class="k">def</span> <span class="nf">write_file</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sourcesDir</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Create the tar archive</span>
<span class="sd"> :param sourcesDir: Path to use for creating the archive</span>
<span class="sd"> :type sourcesDir: str</span>
<span class="sd"> This clones the git repository and creates a git archive from the specified reference.</span>
<span class="sd"> The result is in RPMNAME.tar.xz under the sourcesDir</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Clone the repository into a temporary location</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;git&quot;</span><span class="p">,</span> <span class="s2">&quot;clone&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">],</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">sourcesDir</span><span class="p">,</span> <span class="s2">&quot;gitrepo&quot;</span><span class="p">)]</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span><span class="p">)</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Failed to clone </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">],</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Failed to clone </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">])</span>
<span class="n">oldcwd</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getcwd</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sourcesDir</span><span class="p">,</span> <span class="s2">&quot;gitrepo&quot;</span><span class="p">))</span>
<span class="c1"># Configure archive to create a .tar.xz</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;git&quot;</span><span class="p">,</span> <span class="s2">&quot;config&quot;</span><span class="p">,</span> <span class="s2">&quot;tar.tar.xz.command&quot;</span><span class="p">,</span> <span class="s2">&quot;xz -c&quot;</span><span class="p">]</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;git&quot;</span><span class="p">,</span> <span class="s2">&quot;archive&quot;</span><span class="p">,</span> <span class="s2">&quot;--prefix&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmname&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="s2">&quot;-o&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">sourcesDir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">sourceName</span><span class="p">),</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;ref&quot;</span><span class="p">]]</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span><span class="p">)</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Failed to archive </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">],</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s1">&#39;Failed to archive </span><span class="si">%s</span><span class="s1"> from ref &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">],</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_gitRepo</span><span class="p">[</span><span class="s2">&quot;ref&quot;</span><span class="p">]))</span>
<span class="k">finally</span><span class="p">:</span>
<span class="c1"># Cleanup even if there was an error</span>
<span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="n">oldcwd</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sourcesDir</span><span class="p">,</span> <span class="s2">&quot;gitrepo&quot;</span><span class="p">))</span></div></div>
<div class="viewcode-block" id="GitRpmBuild"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild">[docs]</a><span class="k">class</span> <span class="nc">GitRpmBuild</span><span class="p">(</span><span class="n">SimpleRpmBuild</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Build an rpm containing files from a git repository&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="GitRpmBuild.check"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild.check">[docs]</a> <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">NotImplementedError</span></div>
<div class="viewcode-block" id="GitRpmBuild.get_base_dir"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild.get_base_dir">[docs]</a> <span class="k">def</span> <span class="nf">get_base_dir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Place all the files under a temporary directory + rpmbuild/</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lorax-git-rpm.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span><span class="p">,</span> <span class="s2">&quot;rpmbuild&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="GitRpmBuild.cleanup_tmpdir"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild.cleanup_tmpdir">[docs]</a> <span class="k">def</span> <span class="nf">cleanup_tmpdir</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Remove the temporary directory and all of its contents</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Invalid base_dir: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_base_dir</span><span class="p">())</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_base_dir</span><span class="p">)</span></div>
<div class="viewcode-block" id="GitRpmBuild.clean"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild.clean">[docs]</a> <span class="k">def</span> <span class="nf">clean</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Remove the base directory from inside the tmpdir&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_base_dir</span><span class="p">())</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Invalid base_dir: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_base_dir</span><span class="p">())</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_base_dir</span><span class="p">(),</span> <span class="n">ignore_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>
<div class="viewcode-block" id="GitRpmBuild.add_git_tarball"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.GitRpmBuild.add_git_tarball">[docs]</a> <span class="k">def</span> <span class="nf">add_git_tarball</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">gitRepo</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add a tar archive of a git repository to the rpm</span>
<span class="sd"> :param gitRepo: A dict with the repository details</span>
<span class="sd"> :type gitRepo: dict</span>
<span class="sd"> This populates the rpm with the URL of the git repository, the summary</span>
<span class="sd"> describing the repo, the description of the repository and reference used,</span>
<span class="sd"> and sets up the rpm to install the archive contents into the destination</span>
<span class="sd"> path.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">addUrl</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_summary</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;summary&quot;</span><span class="p">])</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_description</span><span class="p">(</span><span class="n">get_repo_description</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">addLicense</span><span class="p">(</span><span class="s2">&quot;Unknown&quot;</span><span class="p">)</span>
<span class="n">sourceIndex</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_source</span><span class="p">(</span><span class="n">GitArchiveTarball</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">))</span>
<span class="bp">self</span><span class="o">.</span><span class="n">section_build</span> <span class="o">+=</span> <span class="s2">&quot;tar -xvf </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">[</span><span class="n">sourceIndex</span><span class="p">]</span><span class="o">.</span><span class="n">sourceName</span>
<span class="n">dest</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">normpath</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;destination&quot;</span><span class="p">])</span>
<span class="c1"># Prevent double slash root</span>
<span class="k">if</span> <span class="n">dest</span> <span class="o">==</span> <span class="s2">&quot;/&quot;</span><span class="p">:</span>
<span class="n">dest</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">create_parent_dirs</span><span class="p">(</span><span class="n">dest</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">section_install</span> <span class="o">+=</span> <span class="s2">&quot;cp -r </span><span class="si">%s</span><span class="s2">/. $RPM_BUILD_ROOT/</span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmname&quot;</span><span class="p">],</span> <span class="n">dest</span><span class="p">)</span>
<span class="n">sub</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_subpackage</span><span class="p">(</span><span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">dest</span><span class="p">:</span>
<span class="c1"># / is special, we don&#39;t want to include / itself, just what&#39;s under it</span>
<span class="n">sub</span><span class="o">.</span><span class="n">section_files</span> <span class="o">+=</span> <span class="s2">&quot;/*</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">sub</span><span class="o">.</span><span class="n">section_files</span> <span class="o">+=</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">/</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">dest</span></div></div>
<div class="viewcode-block" id="make_git_rpm"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.make_git_rpm">[docs]</a><span class="k">def</span> <span class="nf">make_git_rpm</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">,</span> <span class="n">dest</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Create an rpm from the specified git repo</span>
<span class="sd"> :param gitRepo: A dict with the repository details</span>
<span class="sd"> :type gitRepo: dict</span>
<span class="sd"> This will clone the git repository, create an archive of the selected reference,</span>
<span class="sd"> and build an rpm that will install the files from the repository under the destination</span>
<span class="sd"> directory. The gitRepo dict should have the following fields::</span>
<span class="sd"> rpmname: &quot;server-config&quot;</span>
<span class="sd"> rpmversion: &quot;1.0&quot;</span>
<span class="sd"> rpmrelease: &quot;1&quot;</span>
<span class="sd"> summary: &quot;Setup files for server deployment&quot;</span>
<span class="sd"> repo: &quot;PATH OF GIT REPO TO CLONE&quot;</span>
<span class="sd"> ref: &quot;v1.0&quot;</span>
<span class="sd"> destination: &quot;/opt/server/&quot;</span>
<span class="sd"> * rpmname: Name of the rpm to create, also used as the prefix name in the tar archive</span>
<span class="sd"> * rpmversion: Version of the rpm, eg. &quot;1.0.0&quot;</span>
<span class="sd"> * rpmrelease: Release of the rpm, eg. &quot;1&quot;</span>
<span class="sd"> * summary: Summary string for the rpm</span>
<span class="sd"> * repo: URL of the get repo to clone and create the archive from</span>
<span class="sd"> * ref: Git reference to check out. eg. origin/branch-name, git tag, or git commit hash</span>
<span class="sd"> * destination: Path to install the / of the git repo at when installing the rpm</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">gitRpm</span> <span class="o">=</span> <span class="n">GitRpmBuild</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmname&quot;</span><span class="p">],</span> <span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmversion&quot;</span><span class="p">],</span> <span class="n">gitRepo</span><span class="p">[</span><span class="s2">&quot;rpmrelease&quot;</span><span class="p">],</span> <span class="p">[</span><span class="s2">&quot;noarch&quot;</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">gitRpm</span><span class="o">.</span><span class="n">add_git_tarball</span><span class="p">(</span><span class="n">gitRepo</span><span class="p">)</span>
<span class="n">gitRpm</span><span class="o">.</span><span class="n">do_make</span><span class="p">()</span>
<span class="n">rpmfile</span> <span class="o">=</span> <span class="n">gitRpm</span><span class="o">.</span><span class="n">get_built_rpm</span><span class="p">(</span><span class="s2">&quot;noarch&quot;</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">rpmfile</span><span class="p">,</span> <span class="n">dest</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Creating git repo rpm: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Creating git repo rpm: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">gitRpm</span><span class="o">.</span><span class="n">cleanup_tmpdir</span><span class="p">()</span>
<span class="k">return</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">rpmfile</span><span class="p">)</span></div>
<span class="c1"># Create the git rpms, if any, and return the path to the repo under results_dir</span>
<div class="viewcode-block" id="create_gitrpm_repo"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.gitrpm.create_gitrpm_repo">[docs]</a><span class="k">def</span> <span class="nf">create_gitrpm_repo</span><span class="p">(</span><span class="n">results_dir</span><span class="p">,</span> <span class="n">recipe</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create a dnf repository with the rpms from the recipe</span>
<span class="sd"> :param results_dir: Path to create the repository under</span>
<span class="sd"> :type results_dir: str</span>
<span class="sd"> :param recipe: The recipe to get the repos.git entries from</span>
<span class="sd"> :type recipe: Recipe</span>
<span class="sd"> :returns: Path to the dnf repository or &quot;&quot;</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> This function creates a dnf repository directory at results_dir+&quot;repo/&quot;,</span>
<span class="sd"> creates rpms for all of the repos.git entries in the recipe, runs createrepo_c</span>
<span class="sd"> on the dnf repository so that Anaconda can use it, and returns the path to the</span>
<span class="sd"> repository to the caller.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="s2">&quot;repos&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">recipe</span> <span class="ow">or</span> <span class="s2">&quot;git&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">recipe</span><span class="p">[</span><span class="s2">&quot;repos&quot;</span><span class="p">]:</span>
<span class="k">return</span> <span class="s2">&quot;&quot;</span>
<span class="n">gitrepo</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">results_dir</span><span class="p">,</span> <span class="s2">&quot;repo/&quot;</span><span class="p">)</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">exists</span><span class="p">(</span><span class="n">gitrepo</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">gitrepo</span><span class="p">)</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">recipe</span><span class="p">[</span><span class="s2">&quot;repos&quot;</span><span class="p">][</span><span class="s2">&quot;git&quot;</span><span class="p">]:</span>
<span class="n">make_git_rpm</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">gitrepo</span><span class="p">)</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;createrepo_c&quot;</span><span class="p">,</span> <span class="n">gitrepo</span><span class="p">]</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span><span class="p">)</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Failed to create repo at </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">gitrepo</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Failed to create repo at </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">gitrepo</span><span class="p">)</span>
<span class="k">return</span> <span class="n">gitrepo</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,898 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.projects &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.projects</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.projects</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;lorax-composer&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">configparser</span> <span class="kn">import</span> <span class="n">ConfigParser</span>
<span class="kn">import</span> <span class="nn">dnf</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">pylorax.api.bisect</span> <span class="kn">import</span> <span class="n">insort_left</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span>
<span class="n">TIME_FORMAT</span> <span class="o">=</span> <span class="s2">&quot;%Y-%m-</span><span class="si">%d</span><span class="s2">T%H:%M:%S&quot;</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">&quot;&quot;&quot;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"> &quot;&quot;&quot;</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">&quot;&quot;&quot;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 &quot;&quot;</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> This returns only the most recent changelog entry.</span>
<span class="sd"> &quot;&quot;&quot;</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="s2">&quot;&quot;</span>
<span class="k">return</span> <span class="n">entry</span></div>
<div class="viewcode-block" id="pkg_to_project"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.pkg_to_project">[docs]</a><span class="k">def</span> <span class="nf">pkg_to_project</span><span class="p">(</span><span class="n">pkg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Extract the details from a hawkey.Package object</span>
<span class="sd"> :param pkgs: hawkey.Package object with package details</span>
<span class="sd"> :type pkgs: hawkey.Package</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"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="s2">&quot;summary&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">summary</span><span class="p">,</span>
<span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">description</span><span class="p">,</span>
<span class="s2">&quot;homepage&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">url</span><span class="p">,</span>
<span class="s2">&quot;upstream_vcs&quot;</span><span class="p">:</span> <span class="s2">&quot;UPSTREAM_VCS&quot;</span><span class="p">}</span></div>
<div class="viewcode-block" id="pkg_to_build"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.pkg_to_build">[docs]</a><span class="k">def</span> <span class="nf">pkg_to_build</span><span class="p">(</span><span class="n">pkg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Extract the build details from a hawkey.Package object</span>
<span class="sd"> :param pkg: hawkey.Package object with package details</span>
<span class="sd"> :type pkg: hawkey.Package</span>
<span class="sd"> :returns: A dict with the build details, 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"> Note that this only returns the build dict, it does not include the name, description, etc.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;epoch&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">epoch</span><span class="p">,</span>
<span class="s2">&quot;release&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">release</span><span class="p">,</span>
<span class="s2">&quot;arch&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span>
<span class="s2">&quot;build_time&quot;</span><span class="p">:</span> <span class="n">api_time</span><span class="p">(</span><span class="n">pkg</span><span class="o">.</span><span class="n">buildtime</span><span class="p">),</span>
<span class="s2">&quot;changelog&quot;</span><span class="p">:</span> <span class="s2">&quot;CHANGELOG_NEEDED&quot;</span><span class="p">,</span> <span class="c1"># XXX Not in hawkey.Package</span>
<span class="s2">&quot;build_config_ref&quot;</span><span class="p">:</span> <span class="s2">&quot;BUILD_CONFIG_REF&quot;</span><span class="p">,</span>
<span class="s2">&quot;build_env_ref&quot;</span><span class="p">:</span> <span class="s2">&quot;BUILD_ENV_REF&quot;</span><span class="p">,</span>
<span class="s2">&quot;metadata&quot;</span><span class="p">:</span> <span class="p">{},</span>
<span class="s2">&quot;source&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;license&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">license</span><span class="p">,</span>
<span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
<span class="s2">&quot;source_ref&quot;</span><span class="p">:</span> <span class="s2">&quot;SOURCE_REF&quot;</span><span class="p">,</span>
<span class="s2">&quot;metadata&quot;</span><span class="p">:</span> <span class="p">{}}}</span></div>
<div class="viewcode-block" id="pkg_to_project_info"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.pkg_to_project_info">[docs]</a><span class="k">def</span> <span class="nf">pkg_to_project_info</span><span class="p">(</span><span class="n">pkg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Extract the details from a hawkey.Package object</span>
<span class="sd"> :param pkg: hawkey.Package object with package details</span>
<span class="sd"> :type pkg: hawkey.Package</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"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="s2">&quot;summary&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">summary</span><span class="p">,</span>
<span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">description</span><span class="p">,</span>
<span class="s2">&quot;homepage&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">url</span><span class="p">,</span>
<span class="s2">&quot;upstream_vcs&quot;</span><span class="p">:</span> <span class="s2">&quot;UPSTREAM_VCS&quot;</span><span class="p">,</span>
<span class="s2">&quot;builds&quot;</span><span class="p">:</span> <span class="p">[</span><span class="n">pkg_to_build</span><span class="p">(</span><span class="n">pkg</span><span class="p">)]}</span></div>
<div class="viewcode-block" id="pkg_to_dep"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.pkg_to_dep">[docs]</a><span class="k">def</span> <span class="nf">pkg_to_dep</span><span class="p">(</span><span class="n">pkg</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Extract the info from a hawkey.Package object</span>
<span class="sd"> :param pkg: A hawkey.Package object</span>
<span class="sd"> :type pkg: hawkey.Package</span>
<span class="sd"> :returns: A dict with name, epoch, version, release, arch</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="s2">&quot;epoch&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">epoch</span><span class="p">,</span>
<span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">version</span><span class="p">,</span>
<span class="s2">&quot;release&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">release</span><span class="p">,</span>
<span class="s2">&quot;arch&quot;</span><span class="p">:</span> <span class="n">pkg</span><span class="o">.</span><span class="n">arch</span><span class="p">}</span></div>
<div class="viewcode-block" id="proj_to_module"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.proj_to_module">[docs]</a><span class="k">def</span> <span class="nf">proj_to_module</span><span class="p">(</span><span class="n">proj</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Extract the name from a project_info dict</span>
<span class="sd"> :param pkg: dict with package details</span>
<span class="sd"> :type pkg: dict</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 &quot;rpm&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">proj</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span>
<span class="s2">&quot;group_type&quot;</span><span class="p">:</span> <span class="s2">&quot;rpm&quot;</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">&quot;&quot;&quot;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"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">dep</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="n">dep</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;-&quot;</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;release&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;.&quot;</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;arch&quot;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="nb">str</span><span class="p">(</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;epoch&quot;</span><span class="p">])</span><span class="o">+</span><span class="s2">&quot;:&quot;</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;version&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;-&quot;</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;release&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;.&quot;</span><span class="o">+</span><span class="n">dep</span><span class="p">[</span><span class="s2">&quot;arch&quot;</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">&quot;&quot;&quot;Return the name-epoch:version-release.arch&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">dep</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span><span class="o">+</span><span class="s2">&quot;-&quot;</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">dbo</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a list of projects</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</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"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">projects_info</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="kc">None</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">dbo</span><span class="p">,</span> <span class="n">project_names</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return details about specific projects</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</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 pkg_to_project as well as epoch, version, release, etc.</span>
<span class="sd"> :rtype: list of dicts</span>
<span class="sd"> If project_names is None it will return the full list of available packages</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">project_names</span><span class="p">:</span>
<span class="n">pkgs</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span><span class="o">.</span><span class="n">available</span><span class="p">()</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">name__glob</span><span class="o">=</span><span class="n">project_names</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">pkgs</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span><span class="o">.</span><span class="n">available</span><span class="p">()</span>
<span class="c1"># iterate over pkgs</span>
<span class="c1"># - if pkg.name isn&#39;t in the results yet, add pkg_to_project_info in sorted position</span>
<span class="c1"># - if pkg.name is already in results, get its builds. If the build for pkg is different</span>
<span class="c1"># in any way (version, arch, etc.) add it to the entry&#39;s builds list. If it is the same,</span>
<span class="c1"># skip it.</span>
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">results_names</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pkgs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results_names</span><span class="p">:</span>
<span class="n">idx</span> <span class="o">=</span> <span class="n">insort_left</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">pkg_to_project_info</span><span class="p">(</span><span class="n">p</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="s2">&quot;name&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
<span class="n">results_names</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]</span> <span class="o">=</span> <span class="n">idx</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">build</span> <span class="o">=</span> <span class="n">pkg_to_build</span><span class="p">(</span><span class="n">p</span><span class="p">)</span>
<span class="k">if</span> <span class="n">build</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">results</span><span class="p">[</span><span class="n">results_names</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]][</span><span class="s2">&quot;builds&quot;</span><span class="p">]:</span>
<span class="n">results</span><span class="p">[</span><span class="n">results_names</span><span class="p">[</span><span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()]][</span><span class="s2">&quot;builds&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">build</span><span class="p">)</span>
<span class="k">return</span> <span class="n">results</span></div>
<span class="k">def</span> <span class="nf">_depsolve</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">groups</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add projects to a new transaction</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</span>
<span class="sd"> :param projects: The projects and version globs to find the dependencies for</span>
<span class="sd"> :type projects: List of tuples</span>
<span class="sd"> :param groups: The groups to include in dependency solving</span>
<span class="sd"> :type groups: List of str</span>
<span class="sd"> :returns: None</span>
<span class="sd"> :rtype: None</span>
<span class="sd"> :raises: ProjectsError if there was a problem installing something</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># This resets the transaction and updates the cache.</span>
<span class="c1"># It is important that the cache always be synchronized because Anaconda will grab its own copy</span>
<span class="c1"># and if that is different the NEVRAs will not match and the build will fail.</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">reset</span><span class="p">(</span><span class="n">goal</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">install_errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">groups</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">group_install</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;mandatory&quot;</span><span class="p">,</span> <span class="s2">&quot;default&quot;</span><span class="p">])</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">MarkingError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">install_errors</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s2">&quot;Group </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</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">for</span> <span class="n">name</span><span class="p">,</span> <span class="n">version</span> <span class="ow">in</span> <span class="n">projects</span><span class="p">:</span>
<span class="c1"># Find the best package matching the name + version glob</span>
<span class="c1"># dnf can return multiple packages if it is in more than 1 repository</span>
<span class="n">query</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span><span class="o">.</span><span class="n">filterm</span><span class="p">(</span><span class="n">provides__glob</span><span class="o">=</span><span class="n">name</span><span class="p">)</span>
<span class="k">if</span> <span class="n">version</span><span class="p">:</span>
<span class="n">query</span><span class="o">.</span><span class="n">filterm</span><span class="p">(</span><span class="n">version__glob</span><span class="o">=</span><span class="n">version</span><span class="p">)</span>
<span class="n">query</span><span class="o">.</span><span class="n">filterm</span><span class="p">(</span><span class="n">latest</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">query</span><span class="p">:</span>
<span class="n">install_errors</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">version</span><span class="p">),</span> <span class="s2">&quot;No match&quot;</span><span class="p">))</span>
<span class="k">continue</span>
<span class="n">sltr</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">selector</span><span class="o">.</span><span class="n">Selector</span><span class="p">(</span><span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="p">)</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">pkg</span><span class="o">=</span><span class="n">query</span><span class="p">)</span>
<span class="c1"># NOTE: dnf says in near future there will be a &quot;goal&quot; attribute of Base class</span>
<span class="c1"># so yes, we&#39;re using a &#39;private&#39; attribute here on purpose and with permission.</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">_goal</span><span class="o">.</span><span class="n">install</span><span class="p">(</span><span class="n">select</span><span class="o">=</span><span class="n">sltr</span><span class="p">,</span> <span class="n">optional</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">install_errors</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s2">&quot;The following package(s) had problems: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> (</span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">pattern</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span> <span class="k">for</span> <span class="n">pattern</span><span class="p">,</span> <span class="n">err</span> <span class="ow">in</span> <span class="n">install_errors</span><span class="p">]))</span>
<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">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">groups</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the dependencies for a list of projects</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</span>
<span class="sd"> :param projects: The projects to find the dependencies for</span>
<span class="sd"> :type projects: List of Strings</span>
<span class="sd"> :param groups: The groups to include in dependency solving</span>
<span class="sd"> :type groups: List of str</span>
<span class="sd"> :returns: NEVRA&#39;s of the project and its dependencies</span>
<span class="sd"> :rtype: list of dicts</span>
<span class="sd"> :raises: ProjectsError if there was a problem installing something</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_depsolve</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">groups</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">DepsolveError</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="s2">&quot;There was a problem depsolving </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">projects</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">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">dbo</span><span class="o">.</span><span class="n">transaction</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</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">pkg_to_dep</span><span class="p">,</span> <span class="n">dbo</span><span class="o">.</span><span class="n">transaction</span><span class="o">.</span><span class="n">install_set</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="s2">&quot;name&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span></div>
<div class="viewcode-block" id="estimate_size"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.estimate_size">[docs]</a><span class="k">def</span> <span class="nf">estimate_size</span><span class="p">(</span><span class="n">packages</span><span class="p">,</span> <span class="n">block_size</span><span class="o">=</span><span class="mi">6144</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Estimate the installed size of a package list</span>
<span class="sd"> :param packages: The packages to be installed</span>
<span class="sd"> :type packages: list of hawkey.Package objects</span>
<span class="sd"> :param block_size: The block size to use for rounding up file sizes.</span>
<span class="sd"> :type block_size: int</span>
<span class="sd"> :returns: The estimated size of installed packages</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> Estimating actual requirements is difficult without the actual file sizes, which</span>
<span class="sd"> dnf doesn&#39;t provide access to. So use the file count and block size to estimate</span>
<span class="sd"> a minimum size for each package.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">installed_size</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">packages</span><span class="p">:</span>
<span class="n">installed_size</span> <span class="o">+=</span> <span class="nb">len</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">files</span><span class="p">)</span> <span class="o">*</span> <span class="n">block_size</span>
<span class="n">installed_size</span> <span class="o">+=</span> <span class="n">p</span><span class="o">.</span><span class="n">installsize</span>
<span class="k">return</span> <span class="n">installed_size</span></div>
<div class="viewcode-block" id="projects_depsolve_with_size"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.projects_depsolve_with_size">[docs]</a><span class="k">def</span> <span class="nf">projects_depsolve_with_size</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">groups</span><span class="p">,</span> <span class="n">with_core</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the dependencies and installed size for a list of projects</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</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"> :param groups: The groups to include in dependency solving</span>
<span class="sd"> :type groups: List of str</span>
<span class="sd"> :returns: installed size and a list of NEVRA&#39;s of the project and its dependencies</span>
<span class="sd"> :rtype: tuple of (int, list of dicts)</span>
<span class="sd"> :raises: ProjectsError if there was a problem installing something</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_depsolve</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span> <span class="n">groups</span><span class="p">)</span>
<span class="k">if</span> <span class="n">with_core</span><span class="p">:</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">group_install</span><span class="p">(</span><span class="s2">&quot;core&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;mandatory&#39;</span><span class="p">,</span> <span class="s1">&#39;default&#39;</span><span class="p">,</span> <span class="s1">&#39;optional&#39;</span><span class="p">])</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">resolve</span><span class="p">()</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">DepsolveError</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="s2">&quot;There was a problem depsolving </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">projects</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">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">dbo</span><span class="o">.</span><span class="n">transaction</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="p">[])</span>
<span class="n">installed_size</span> <span class="o">=</span> <span class="n">estimate_size</span><span class="p">(</span><span class="n">dbo</span><span class="o">.</span><span class="n">transaction</span><span class="o">.</span><span class="n">install_set</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">pkg_to_dep</span><span class="p">,</span> <span class="n">dbo</span><span class="o">.</span><span class="n">transaction</span><span class="o">.</span><span class="n">install_set</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="s2">&quot;name&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">lower</span><span class="p">())</span>
<span class="k">return</span> <span class="p">(</span><span class="n">installed_size</span><span class="p">,</span> <span class="n">deps</span><span class="p">)</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">dbo</span><span class="p">,</span> <span class="n">module_names</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a list of modules</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</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&#39;t exist in RHEL7 so this only returns projects</span>
<span class="sd"> and sets the type to &quot;rpm&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># TODO - Figure out what to do with this for Fedora &#39;modules&#39;</span>
<span class="k">return</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">proj_to_module</span><span class="p">,</span> <span class="n">projects_info</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">module_names</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">dbo</span><span class="p">,</span> <span class="n">module_names</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return details about a module, including dependencies</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</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"> &quot;&quot;&quot;</span>
<span class="n">modules</span> <span class="o">=</span> <span class="n">projects_info</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">module_names</span><span class="p">)</span>
<span class="c1"># 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="s2">&quot;dependencies&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">projects_depsolve</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="p">[(</span><span class="n">module</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">],</span> <span class="s2">&quot;*.*&quot;</span><span class="p">)],</span> <span class="p">[])</span>
<span class="k">return</span> <span class="n">modules</span></div>
<div class="viewcode-block" id="dnf_repo_to_file_repo"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.dnf_repo_to_file_repo">[docs]</a><span class="k">def</span> <span class="nf">dnf_repo_to_file_repo</span><span class="p">(</span><span class="n">repo</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a string representation of a DNF Repo object suitable for writing to a .repo file</span>
<span class="sd"> :param repo: DNF Repository</span>
<span class="sd"> :type repo: dnf.RepoDict</span>
<span class="sd"> :returns: A string</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> The DNF Repo.dump() function does not produce a string that can be used as a dnf .repo file,</span>
<span class="sd"> it ouputs baseurl and gpgkey as python lists which DNF cannot read. So do this manually with</span>
<span class="sd"> only the attributes we care about.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">repo_str</span> <span class="o">=</span> <span class="s2">&quot;[</span><span class="si">%s</span><span class="s2">]</span><span class="se">\n</span><span class="s2">name = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">repo</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;metalink = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;mirrorlist = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;baseurl = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Repo has no baseurl, metalink, or mirrorlist&quot;</span><span class="p">)</span>
<span class="c1"># proxy is optional</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">proxy</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;proxy = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">proxy</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;sslverify = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">sslverify</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;gpgcheck = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">repo</span><span class="o">.</span><span class="n">gpgcheck</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">gpgkey</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;gpgkey = </span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">gpgkey</span><span class="p">)</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">skip_if_unavailable</span><span class="p">:</span>
<span class="n">repo_str</span> <span class="o">+=</span> <span class="s2">&quot;skip_if_unavailable=1</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="k">return</span> <span class="n">repo_str</span></div>
<div class="viewcode-block" id="repo_to_source"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.repo_to_source">[docs]</a><span class="k">def</span> <span class="nf">repo_to_source</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">system_source</span><span class="p">,</span> <span class="n">api</span><span class="o">=</span><span class="mi">1</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a Weldr Source dict created from the DNF Repository</span>
<span class="sd"> :param repo: DNF Repository</span>
<span class="sd"> :type repo: dnf.RepoDict</span>
<span class="sd"> :param system_source: True if this source is an immutable system source</span>
<span class="sd"> :type system_source: bool</span>
<span class="sd"> :param api: Select which api version of the dict to return (default 1)</span>
<span class="sd"> :type api: int</span>
<span class="sd"> :returns: A dict with Weldr Source fields filled in</span>
<span class="sd"> :rtype: dict</span>
<span class="sd"> Example::</span>
<span class="sd"> {</span>
<span class="sd"> &quot;check_gpg&quot;: true,</span>
<span class="sd"> &quot;check_ssl&quot;: true,</span>
<span class="sd"> &quot;gpgkey_url&quot;: [</span>
<span class="sd"> &quot;file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-28-x86_64&quot;</span>
<span class="sd"> ],</span>
<span class="sd"> &quot;id&quot;: &quot;fedora&quot;,</span>
<span class="sd"> &quot;name&quot;: &quot;Fedora $releasever - $basearch&quot;,</span>
<span class="sd"> &quot;proxy&quot;: &quot;http://proxy.brianlane.com:8123&quot;,</span>
<span class="sd"> &quot;system&quot;: true</span>
<span class="sd"> &quot;type&quot;: &quot;yum-metalink&quot;,</span>
<span class="sd"> &quot;url&quot;: &quot;https://mirrors.fedoraproject.org/metalink?repo=fedora-28&amp;arch=x86_64&quot;</span>
<span class="sd"> }</span>
<span class="sd"> The ``name`` field has changed in v1 of the API.</span>
<span class="sd"> In v0 of the API ``name`` is the repo.id, in v1 it is the repo.name and a new field,</span>
<span class="sd"> ``id`` has been added for the repo.id</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">api</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="n">source</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">repo</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="s2">&quot;system&quot;</span><span class="p">:</span> <span class="n">system_source</span><span class="p">}</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">source</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">repo</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="n">repo</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="s2">&quot;system&quot;</span><span class="p">:</span> <span class="n">system_source</span><span class="p">}</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yum-baseurl&quot;</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">metalink</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yum-metalink&quot;</span>
<span class="k">elif</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;yum-mirrorlist&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Repo has no baseurl, metalink, or mirrorlist&quot;</span><span class="p">)</span>
<span class="c1"># proxy is optional</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">proxy</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;proxy&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">proxy</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">repo</span><span class="o">.</span><span class="n">sslverify</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_ssl&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_ssl&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">repo</span><span class="o">.</span><span class="n">gpgcheck</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_gpg&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_gpg&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">gpgkey</span><span class="p">:</span>
<span class="n">source</span><span class="p">[</span><span class="s2">&quot;gpgkey_urls&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">gpgkey</span><span class="p">)</span>
<span class="k">return</span> <span class="n">source</span></div>
<div class="viewcode-block" id="source_to_repodict"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.source_to_repodict">[docs]</a><span class="k">def</span> <span class="nf">source_to_repodict</span><span class="p">(</span><span class="n">source</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a tuple suitable for use with dnf.add_new_repo</span>
<span class="sd"> :param source: A Weldr source dict</span>
<span class="sd"> :type source: dict</span>
<span class="sd"> :returns: A tuple of dnf.Repo attributes</span>
<span class="sd"> :rtype: (str, list, dict)</span>
<span class="sd"> Return a tuple with (id, baseurl|(), kwargs) that can be used</span>
<span class="sd"> with dnf.repos.add_new_repo</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kwargs</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">if</span> <span class="s2">&quot;id&quot;</span> <span class="ow">in</span> <span class="n">source</span><span class="p">:</span>
<span class="c1"># This is an API v1 source definition</span>
<span class="n">repoid</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;id&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;name&quot;</span> <span class="ow">in</span> <span class="n">source</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">repoid</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">]</span>
<span class="c1"># This will allow errors to be raised so we can catch them</span>
<span class="c1"># without this they are logged, but the repo is silently disabled</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;skip_if_unavailable&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;yum-baseurl&quot;</span><span class="p">:</span>
<span class="n">baseurl</span> <span class="o">=</span> <span class="p">[</span><span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]]</span>
<span class="k">elif</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;yum-metalink&quot;</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;metalink&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span>
<span class="n">baseurl</span> <span class="o">=</span> <span class="p">()</span>
<span class="k">elif</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;yum-mirrorlist&quot;</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;mirrorlist&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;url&quot;</span><span class="p">]</span>
<span class="n">baseurl</span> <span class="o">=</span> <span class="p">()</span>
<span class="k">if</span> <span class="s2">&quot;proxy&quot;</span> <span class="ow">in</span> <span class="n">source</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;proxy&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;proxy&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_ssl&quot;</span><span class="p">]:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;sslverify&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;sslverify&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="n">source</span><span class="p">[</span><span class="s2">&quot;check_gpg&quot;</span><span class="p">]:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;gpgcheck&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;gpgcheck&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">if</span> <span class="s2">&quot;gpgkey_urls&quot;</span> <span class="ow">in</span> <span class="n">source</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;gpgkey&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">source</span><span class="p">[</span><span class="s2">&quot;gpgkey_urls&quot;</span><span class="p">])</span>
<span class="k">return</span> <span class="p">(</span><span class="n">repoid</span><span class="p">,</span> <span class="n">baseurl</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="source_to_repo"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.source_to_repo">[docs]</a><span class="k">def</span> <span class="nf">source_to_repo</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">dnf_conf</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a dnf Repo object created from a source dict</span>
<span class="sd"> :param source: A Weldr source dict</span>
<span class="sd"> :type source: dict</span>
<span class="sd"> :param dnf_conf: The dnf Config object</span>
<span class="sd"> :type dnf_conf: dnf.conf</span>
<span class="sd"> :returns: A dnf Repo object</span>
<span class="sd"> :rtype: dnf.Repo</span>
<span class="sd"> Example::</span>
<span class="sd"> {</span>
<span class="sd"> &quot;check_gpg&quot;: True,</span>
<span class="sd"> &quot;check_ssl&quot;: True,</span>
<span class="sd"> &quot;gpgkey_urls&quot;: [</span>
<span class="sd"> &quot;file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-28-x86_64&quot;</span>
<span class="sd"> ],</span>
<span class="sd"> &quot;id&quot;: &quot;fedora&quot;,</span>
<span class="sd"> &quot;name&quot;: &quot;Fedora $releasever - $basearch&quot;,</span>
<span class="sd"> &quot;proxy&quot;: &quot;http://proxy.brianlane.com:8123&quot;,</span>
<span class="sd"> &quot;system&quot;: True</span>
<span class="sd"> &quot;type&quot;: &quot;yum-metalink&quot;,</span>
<span class="sd"> &quot;url&quot;: &quot;https://mirrors.fedoraproject.org/metalink?repo=fedora-28&amp;arch=x86_64&quot;</span>
<span class="sd"> }</span>
<span class="sd"> If the ``id`` field is included it is used for the repo id, otherwise ``name`` is used.</span>
<span class="sd"> v0 of the API only used ``name``, v1 added the distinction between ``id`` and ``name``.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">repoid</span><span class="p">,</span> <span class="n">baseurl</span><span class="p">,</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="n">source_to_repodict</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">repo</span><span class="o">.</span><span class="n">Repo</span><span class="p">(</span><span class="n">repoid</span><span class="p">,</span> <span class="n">dnf_conf</span><span class="p">)</span>
<span class="k">if</span> <span class="n">baseurl</span><span class="p">:</span>
<span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span> <span class="o">=</span> <span class="n">baseurl</span>
<span class="c1"># Apply the rest of the kwargs to the Repo object</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="nb">setattr</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span><span class="p">)</span>
<span class="n">repo</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>
<span class="k">return</span> <span class="n">repo</span></div>
<div class="viewcode-block" id="get_source_ids"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.get_source_ids">[docs]</a><span class="k">def</span> <span class="nf">get_source_ids</span><span class="p">(</span><span class="n">source_path</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a list of the source ids in a file</span>
<span class="sd"> :param source_path: Full path and filename of the source (yum repo) file</span>
<span class="sd"> :type source_path: str</span>
<span class="sd"> :returns: A list of source id strings</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> &quot;&quot;&quot;</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">exists</span><span class="p">(</span><span class="n">source_path</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[]</span>
<span class="n">cfg</span> <span class="o">=</span> <span class="n">ConfigParser</span><span class="p">()</span>
<span class="n">cfg</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">source_path</span><span class="p">)</span>
<span class="k">return</span> <span class="n">cfg</span><span class="o">.</span><span class="n">sections</span><span class="p">()</span></div>
<div class="viewcode-block" id="get_repo_sources"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.get_repo_sources">[docs]</a><span class="k">def</span> <span class="nf">get_repo_sources</span><span class="p">(</span><span class="n">source_glob</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a list of sources from a directory of yum repositories</span>
<span class="sd"> :param source_glob: A glob to use to match the source files, including full path</span>
<span class="sd"> :type source_glob: str</span>
<span class="sd"> :returns: A list of the source ids in all of the matching files</span>
<span class="sd"> :rtype: list of str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">sources</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">glob</span><span class="p">(</span><span class="n">source_glob</span><span class="p">):</span>
<span class="n">sources</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">get_source_ids</span><span class="p">(</span><span class="n">f</span><span class="p">))</span>
<span class="k">return</span> <span class="n">sources</span></div>
<div class="viewcode-block" id="delete_repo_source"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.delete_repo_source">[docs]</a><span class="k">def</span> <span class="nf">delete_repo_source</span><span class="p">(</span><span class="n">source_glob</span><span class="p">,</span> <span class="n">source_id</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete a source from a repo file</span>
<span class="sd"> :param source_glob: A glob of the repo sources to search</span>
<span class="sd"> :type source_glob: str</span>
<span class="sd"> :param source_id: The repo id to delete</span>
<span class="sd"> :type source_id: str</span>
<span class="sd"> :returns: None</span>
<span class="sd"> :raises: ProjectsError if there was a problem</span>
<span class="sd"> A repo file may have multiple sources in it, delete only the selected source.</span>
<span class="sd"> If it is the last one in the file, delete the file.</span>
<span class="sd"> WARNING: This will delete ANY source, the caller needs to ensure that a system</span>
<span class="sd"> source_id isn&#39;t passed to it.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">found</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">glob</span><span class="p">(</span><span class="n">source_glob</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">cfg</span> <span class="o">=</span> <span class="n">ConfigParser</span><span class="p">()</span>
<span class="n">cfg</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="k">if</span> <span class="n">source_id</span> <span class="ow">in</span> <span class="n">cfg</span><span class="o">.</span><span class="n">sections</span><span class="p">():</span>
<span class="n">found</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">cfg</span><span class="o">.</span><span class="n">remove_section</span><span class="p">(</span><span class="n">source_id</span><span class="p">)</span>
<span class="c1"># If there are other sections, rewrite the file without the deleted one</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cfg</span><span class="o">.</span><span class="n">sections</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">cfg_file</span><span class="p">:</span>
<span class="n">cfg</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">cfg_file</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># No sections left, just delete the file</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</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="s2">&quot;Problem deleting repo source </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">source_id</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">if</span> <span class="ow">not</span> <span class="n">found</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">ProjectsError</span><span class="p">(</span><span class="s2">&quot;source </span><span class="si">%s</span><span class="s2"> not found&quot;</span> <span class="o">%</span> <span class="n">source_id</span><span class="p">)</span></div>
<div class="viewcode-block" id="new_repo_source"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.projects.new_repo_source">[docs]</a><span class="k">def</span> <span class="nf">new_repo_source</span><span class="p">(</span><span class="n">dbo</span><span class="p">,</span> <span class="n">repoid</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">repo_dir</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Add a new repo source from a Weldr source dict</span>
<span class="sd"> :param dbo: dnf base object</span>
<span class="sd"> :type dbo: dnf.Base</span>
<span class="sd"> :param id: The repo id (API v0 uses the name, v1 uses the id)</span>
<span class="sd"> :type id: str</span>
<span class="sd"> :param source: A Weldr source dict</span>
<span class="sd"> :type source: dict</span>
<span class="sd"> :returns: None</span>
<span class="sd"> :raises: ...</span>
<span class="sd"> Make sure access to the dbo has been locked before calling this.</span>
<span class="sd"> The `id` parameter will the the &#39;name&#39; field for API v0, and the &#39;id&#39; field for API v1</span>
<span class="sd"> DNF variables will be substituted at load time, and on restart.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="c1"># Remove it from the RepoDict (NOTE that this isn&#39;t explicitly supported by the DNF API)</span>
<span class="c1"># If this repo already exists, delete it and replace it with the new one</span>
<span class="n">repos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">iter_enabled</span><span class="p">())</span>
<span class="k">if</span> <span class="n">repoid</span> <span class="ow">in</span> <span class="n">repos</span><span class="p">:</span>
<span class="k">del</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="p">[</span><span class="n">repoid</span><span class="p">]</span>
<span class="c1"># Add the repo and substitute any dnf variables</span>
<span class="n">_</span><span class="p">,</span> <span class="n">baseurl</span><span class="p">,</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="n">source_to_repodict</span><span class="p">(</span><span class="n">source</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;repoid=</span><span class="si">%s</span><span class="s2">, baseurl=</span><span class="si">%s</span><span class="s2">, kwargs=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repoid</span><span class="p">,</span> <span class="n">baseurl</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">add_new_repo</span><span class="p">(</span><span class="n">repoid</span><span class="p">,</span> <span class="n">dbo</span><span class="o">.</span><span class="n">conf</span><span class="p">,</span> <span class="n">baseurl</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="n">r</span><span class="o">.</span><span class="n">enable</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="s2">&quot;Updating repository metadata after adding </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repoid</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">fill_sack</span><span class="p">(</span><span class="n">load_system_repo</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">read_comps</span><span class="p">()</span>
<span class="c1"># Remove any previous sources with this id, ignore it if it isn&#39;t found</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">delete_repo_source</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">repo_dir</span><span class="p">,</span> <span class="s2">&quot;*.repo&quot;</span><span class="p">),</span> <span class="n">repoid</span><span class="p">)</span>
<span class="k">except</span> <span class="n">ProjectsError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="c1"># Make sure the source id can&#39;t contain a path traversal by taking the basename</span>
<span class="n">source_path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">repo_dir</span><span class="p">,</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="s2">&quot;</span><span class="si">%s</span><span class="s2">.repo&quot;</span> <span class="o">%</span> <span class="n">repoid</span><span class="p">))</span>
<span class="c1"># Write the un-substituted version of the repo to disk</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">source_path</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">source_to_repo</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">dbo</span><span class="o">.</span><span class="n">conf</span><span class="p">)</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">dnf_repo_to_file_repo</span><span class="p">(</span><span class="n">repo</span><span class="p">))</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;(new_repo_source) adding </span><span class="si">%s</span><span class="s2"> failed: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repoid</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="c1"># Cleanup the mess, if loading it failed we don&#39;t want to leave it in memory</span>
<span class="n">repos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">r</span><span class="o">.</span><span class="n">id</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">iter_enabled</span><span class="p">())</span>
<span class="k">if</span> <span class="n">repoid</span> <span class="ow">in</span> <span class="n">repos</span><span class="p">:</span>
<span class="k">del</span> <span class="n">dbo</span><span class="o">.</span><span class="n">repos</span><span class="p">[</span><span class="n">repoid</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="s2">&quot;Updating repository metadata after adding </span><span class="si">%s</span><span class="s2"> failed&quot;</span><span class="p">,</span> <span class="n">repoid</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">fill_sack</span><span class="p">(</span><span class="n">load_system_repo</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">dbo</span><span class="o">.</span><span class="n">read_comps</span><span class="p">()</span>
<span class="k">raise</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,304 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.server &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.server</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.server</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017-2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;lorax-composer&quot;</span><span class="p">)</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">namedtuple</span>
<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span><span class="p">,</span> <span class="n">jsonify</span><span class="p">,</span> <span class="n">redirect</span><span class="p">,</span> <span class="n">send_from_directory</span>
<span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">werkzeug</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">vernum</span>
<span class="kn">from</span> <span class="nn">pylorax.api.errors</span> <span class="kn">import</span> <span class="n">HTTP_ERROR</span>
<span class="kn">from</span> <span class="nn">pylorax.api.v0</span> <span class="kn">import</span> <span class="n">v0_api</span>
<span class="kn">from</span> <span class="nn">pylorax.api.v1</span> <span class="kn">import</span> <span class="n">v1_api</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span>
<span class="n">GitLock</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s2">&quot;GitLock&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;repo&quot;</span><span class="p">,</span> <span class="s2">&quot;lock&quot;</span><span class="p">,</span> <span class="s2">&quot;dir&quot;</span><span class="p">])</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="vm">__name__</span><span class="p">)</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;server&quot;</span><span class="p">,</span> <span class="s2">&quot;GitLock&quot;</span><span class="p">]</span>
<span class="nd">@server</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">server_root</span><span class="p">():</span>
<span class="n">redirect</span><span class="p">(</span><span class="s2">&quot;/api/docs/&quot;</span><span class="p">)</span>
<span class="nd">@server</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/api/docs/&quot;</span><span class="p">)</span>
<span class="nd">@server</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/api/docs/&lt;path:path&gt;&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">api_docs</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="c1"># Find the html docs</span>
<span class="k">try</span><span class="p">:</span>
<span class="c1"># This assumes it is running from the source tree</span>
<span class="n">docs_path</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">joinpaths</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="vm">__file__</span><span class="p">),</span> <span class="s2">&quot;../../../docs/html&quot;</span><span class="p">))</span>
<span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
<span class="n">docs_path</span> <span class="o">=</span> <span class="n">glob</span><span class="p">(</span><span class="s2">&quot;/usr/share/doc/lorax-*/html/&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">path</span><span class="p">:</span>
<span class="n">path</span><span class="o">=</span><span class="s2">&quot;index.html&quot;</span>
<span class="k">return</span> <span class="n">send_from_directory</span><span class="p">(</span><span class="n">docs_path</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
<span class="nd">@server</span><span class="o">.</span><span class="n">route</span><span class="p">(</span><span class="s2">&quot;/api/status&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">api_status</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> `/api/status`</span>
<span class="sd"> ^^^^^^^^^^^^^^^^</span>
<span class="sd"> Return the status of the API Server::</span>
<span class="sd"> { &quot;api&quot;: &quot;0&quot;,</span>
<span class="sd"> &quot;build&quot;: &quot;devel&quot;,</span>
<span class="sd"> &quot;db_supported&quot;: true,</span>
<span class="sd"> &quot;db_version&quot;: &quot;0&quot;,</span>
<span class="sd"> &quot;schema_version&quot;: &quot;0&quot;,</span>
<span class="sd"> &quot;backend&quot;: &quot;lorax-composer&quot;,</span>
<span class="sd"> &quot;msgs&quot;: []}</span>
<span class="sd"> The &#39;msgs&#39; field can be a list of strings describing startup problems or status that</span>
<span class="sd"> should be displayed to the user. eg. if the compose templates are not depsolving properly</span>
<span class="sd"> the errors will be in &#39;msgs&#39;.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">backend</span><span class="o">=</span><span class="s2">&quot;lorax-composer&quot;</span><span class="p">,</span>
<span class="n">build</span><span class="o">=</span><span class="n">vernum</span><span class="p">,</span>
<span class="n">api</span><span class="o">=</span><span class="s2">&quot;1&quot;</span><span class="p">,</span>
<span class="n">db_version</span><span class="o">=</span><span class="s2">&quot;0&quot;</span><span class="p">,</span>
<span class="n">schema_version</span><span class="o">=</span><span class="s2">&quot;0&quot;</span><span class="p">,</span>
<span class="n">db_supported</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">msgs</span><span class="o">=</span><span class="n">server</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;TEMPLATE_ERRORS&quot;</span><span class="p">])</span>
<span class="nd">@server</span><span class="o">.</span><span class="n">errorhandler</span><span class="p">(</span><span class="n">werkzeug</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">HTTPException</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">bad_request</span><span class="p">(</span><span class="n">error</span><span class="p">):</span>
<span class="k">return</span> <span class="n">jsonify</span><span class="p">(</span><span class="n">status</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">errors</span><span class="o">=</span><span class="p">[{</span> <span class="s2">&quot;id&quot;</span><span class="p">:</span> <span class="n">HTTP_ERROR</span><span class="p">,</span> <span class="s2">&quot;code&quot;</span><span class="p">:</span> <span class="n">error</span><span class="o">.</span><span class="n">code</span><span class="p">,</span> <span class="s2">&quot;msg&quot;</span><span class="p">:</span> <span class="n">error</span><span class="o">.</span><span class="n">name</span> <span class="p">}]),</span> <span class="n">error</span><span class="o">.</span><span class="n">code</span>
<span class="c1"># Register the v0 API on /api/v0/</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_blueprint</span><span class="p">(</span><span class="n">v0_api</span><span class="p">,</span> <span class="n">url_prefix</span><span class="o">=</span><span class="s2">&quot;/api/v0/&quot;</span><span class="p">)</span>
<span class="c1"># Register the v1 API on /api/v1/</span>
<span class="c1"># Use v0 routes by default</span>
<span class="n">skip_rules</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;/compose&quot;</span><span class="p">,</span>
<span class="s2">&quot;/compose/queue&quot;</span><span class="p">,</span>
<span class="s2">&quot;/compose/finished&quot;</span><span class="p">,</span>
<span class="s2">&quot;/compose/failed&quot;</span><span class="p">,</span>
<span class="s2">&quot;/compose/status/&lt;uuids&gt;&quot;</span><span class="p">,</span>
<span class="s2">&quot;/compose/info/&lt;uuid&gt;&quot;</span><span class="p">,</span>
<span class="s2">&quot;/projects/source/info/&lt;source_names&gt;&quot;</span><span class="p">,</span>
<span class="s2">&quot;/projects/source/new&quot;</span><span class="p">,</span>
<span class="p">]</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_blueprint</span><span class="p">(</span><span class="n">v0_api</span><span class="p">,</span> <span class="n">url_prefix</span><span class="o">=</span><span class="s2">&quot;/api/v1/&quot;</span><span class="p">,</span> <span class="n">skip_rules</span><span class="o">=</span><span class="n">skip_rules</span><span class="p">)</span>
<span class="n">server</span><span class="o">.</span><span class="n">register_blueprint</span><span class="p">(</span><span class="n">v1_api</span><span class="p">,</span> <span class="n">url_prefix</span><span class="o">=</span><span class="s2">&quot;/api/v1/&quot;</span><span class="p">)</span>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,252 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.timestamp &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.timestamp</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.timestamp</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span>
<span class="kn">import</span> <span class="nn">pylorax.api.toml</span> <span class="k">as</span> <span class="nn">toml</span>
<span class="n">TS_CREATED</span> <span class="o">=</span> <span class="s2">&quot;created&quot;</span>
<span class="n">TS_STARTED</span> <span class="o">=</span> <span class="s2">&quot;started&quot;</span>
<span class="n">TS_FINISHED</span> <span class="o">=</span> <span class="s2">&quot;finished&quot;</span>
<div class="viewcode-block" id="write_timestamp"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.timestamp.write_timestamp">[docs]</a><span class="k">def</span> <span class="nf">write_timestamp</span><span class="p">(</span><span class="n">destdir</span><span class="p">,</span> <span class="n">ty</span><span class="p">):</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">destdir</span><span class="p">,</span> <span class="s2">&quot;times.toml&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">contents</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="n">contents</span> <span class="o">=</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ty</span> <span class="o">==</span> <span class="n">TS_CREATED</span><span class="p">:</span>
<span class="n">contents</span><span class="p">[</span><span class="n">TS_CREATED</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="k">elif</span> <span class="n">ty</span> <span class="o">==</span> <span class="n">TS_STARTED</span><span class="p">:</span>
<span class="n">contents</span><span class="p">[</span><span class="n">TS_STARTED</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="k">elif</span> <span class="n">ty</span> <span class="o">==</span> <span class="n">TS_FINISHED</span><span class="p">:</span>
<span class="n">contents</span><span class="p">[</span><span class="n">TS_FINISHED</span><span class="p">]</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">contents</span><span class="p">))</span></div>
<div class="viewcode-block" id="timestamp_dict"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.timestamp.timestamp_dict">[docs]</a><span class="k">def</span> <span class="nf">timestamp_dict</span><span class="p">(</span><span class="n">destdir</span><span class="p">):</span>
<span class="n">path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">destdir</span><span class="p">,</span> <span class="s2">&quot;times.toml&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,243 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.toml &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.toml</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.toml</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">toml</span>
<div class="viewcode-block" id="TomlError"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.toml.TomlError">[docs]</a><span class="k">class</span> <span class="nc">TomlError</span><span class="p">(</span><span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span><span class="p">):</span>
<span class="k">pass</span></div>
<div class="viewcode-block" id="loads"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.toml.loads">[docs]</a><span class="k">def</span> <span class="nf">loads</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="nb">bytes</span><span class="p">):</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">&#39;utf-8&#39;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">TomlError</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">msg</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">doc</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">pos</span><span class="p">)</span></div>
<div class="viewcode-block" id="dumps"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.toml.dumps">[docs]</a><span class="k">def</span> <span class="nf">dumps</span><span class="p">(</span><span class="n">o</span><span class="p">):</span>
<span class="c1"># strip the result, because `toml.dumps` adds a lot of newlines</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">encoder</span><span class="o">=</span><span class="n">toml</span><span class="o">.</span><span class="n">TomlEncoder</span><span class="p">(</span><span class="nb">dict</span><span class="p">))</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span></div>
<div class="viewcode-block" id="load"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.toml.load">[docs]</a><span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="n">file</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">file</span><span class="p">)</span>
<span class="k">except</span> <span class="n">toml</span><span class="o">.</span><span class="n">TomlDecodeError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">TomlError</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">msg</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">doc</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">pos</span><span class="p">)</span></div>
<div class="viewcode-block" id="dump"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.toml.dump">[docs]</a><span class="k">def</span> <span class="nf">dump</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">file</span><span class="p">):</span>
<span class="k">return</span> <span class="n">toml</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">o</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,250 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.utils &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.utils</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.utils</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="sd">&quot;&quot;&quot; API utility functions</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="kn">import</span> <span class="n">RecipeError</span><span class="p">,</span> <span class="n">RecipeFileError</span><span class="p">,</span> <span class="n">read_recipe_commit</span>
<div class="viewcode-block" id="take_limits"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.utils.take_limits">[docs]</a><span class="k">def</span> <span class="nf">take_limits</span><span class="p">(</span><span class="n">iterable</span><span class="p">,</span> <span class="n">offset</span><span class="p">,</span> <span class="n">limit</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Apply offset and limit to an iterable object</span>
<span class="sd"> :param iterable: The object to limit</span>
<span class="sd"> :type iterable: iter</span>
<span class="sd"> :param offset: The number of items to skip</span>
<span class="sd"> :type offset: int</span>
<span class="sd"> :param limit: The total number of items to return</span>
<span class="sd"> :type limit: int</span>
<span class="sd"> :returns: A subset of the iterable</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">iterable</span><span class="p">[</span><span class="n">offset</span><span class="p">:][:</span><span class="n">limit</span><span class="p">]</span></div>
<div class="viewcode-block" id="blueprint_exists"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.utils.blueprint_exists">[docs]</a><span class="k">def</span> <span class="nf">blueprint_exists</span><span class="p">(</span><span class="n">api</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return True if the blueprint exists</span>
<span class="sd"> :param api: flask object</span>
<span class="sd"> :type api: Flask</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe_name: Recipe name to read</span>
<span class="sd"> :type recipe_name: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">with</span> <span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;GITLOCK&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">lock</span><span class="p">:</span>
<span class="n">read_recipe_commit</span><span class="p">(</span><span class="n">api</span><span class="o">.</span><span class="n">config</span><span class="p">[</span><span class="s2">&quot;GITLOCK&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">blueprint_name</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="k">except</span> <span class="p">(</span><span class="n">RecipeError</span><span class="p">,</span> <span class="n">RecipeFileError</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">False</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,330 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.api.workspace &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/language_data.js"></script>
<script type="text/javascript" src="../../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html">Docs</a> &raquo;</li>
<li><a href="../../index.html">Module code</a> &raquo;</li>
<li><a href="../../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.api.workspace</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.api.workspace</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2017 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">from</span> <span class="nn">pylorax.api.recipes</span> <span class="kn">import</span> <span class="n">recipe_filename</span><span class="p">,</span> <span class="n">recipe_from_toml</span><span class="p">,</span> <span class="n">RecipeFileError</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="workspace_dir"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_dir">[docs]</a><span class="k">def</span> <span class="nf">workspace_dir</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create the workspace&#39;s path from a Repository and branch</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :returns: The path to the branch&#39;s workspace directory</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">repo_path</span> <span class="o">=</span> <span class="n">repo</span><span class="o">.</span><span class="n">get_location</span><span class="p">()</span><span class="o">.</span><span class="n">get_path</span><span class="p">()</span>
<span class="k">return</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">repo_path</span><span class="p">,</span> <span class="s2">&quot;workspace&quot;</span><span class="p">,</span> <span class="n">branch</span><span class="p">)</span></div>
<div class="viewcode-block" id="workspace_read"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_read">[docs]</a><span class="k">def</span> <span class="nf">workspace_read</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Read a Recipe from the branch&#39;s workspace</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe_name: The name of the recipe</span>
<span class="sd"> :type recipe_name: str</span>
<span class="sd"> :returns: The workspace copy of the recipe, or None if it doesn&#39;t exist</span>
<span class="sd"> :rtype: Recipe or None</span>
<span class="sd"> :raises: RecipeFileError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ws_dir</span> <span class="o">=</span> <span class="n">workspace_dir</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">)</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">ws_dir</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">ws_dir</span><span class="p">)</span>
<span class="n">filename</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">ws_dir</span><span class="p">,</span> <span class="n">recipe_filename</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">))</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">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;rb&#39;</span><span class="p">)</span>
<span class="n">recipe</span> <span class="o">=</span> <span class="n">recipe_from_toml</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;UTF-8&quot;</span><span class="p">))</span>
<span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">RecipeFileError</span>
<span class="k">return</span> <span class="n">recipe</span></div>
<div class="viewcode-block" id="workspace_write"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_write">[docs]</a><span class="k">def</span> <span class="nf">workspace_write</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Write a recipe to the workspace</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe: The recipe to write to the workspace</span>
<span class="sd"> :type recipe: Recipe</span>
<span class="sd"> :returns: None</span>
<span class="sd"> :raises: IO related errors</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ws_dir</span> <span class="o">=</span> <span class="n">workspace_dir</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">)</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">ws_dir</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">ws_dir</span><span class="p">)</span>
<span class="n">filename</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">ws_dir</span><span class="p">,</span> <span class="n">recipe</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;wb&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">recipe</span><span class="o">.</span><span class="n">toml</span><span class="p">()</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;UTF-8&quot;</span><span class="p">))</span></div>
<div class="viewcode-block" id="workspace_filename"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_filename">[docs]</a><span class="k">def</span> <span class="nf">workspace_filename</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return the path and filename of the workspace recipe</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe_name: The name of the recipe</span>
<span class="sd"> :type recipe_name: str</span>
<span class="sd"> :returns: workspace recipe path and filename</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ws_dir</span> <span class="o">=</span> <span class="n">workspace_dir</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">)</span>
<span class="k">return</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">ws_dir</span><span class="p">,</span> <span class="n">recipe_filename</span><span class="p">(</span><span class="n">recipe_name</span><span class="p">))</span></div>
<div class="viewcode-block" id="workspace_exists"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_exists">[docs]</a><span class="k">def</span> <span class="nf">workspace_exists</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return true of the workspace recipe exists</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe_name: The name of the recipe</span>
<span class="sd"> :type recipe_name: str</span>
<span class="sd"> :returns: True if the file exists</span>
<span class="sd"> :rtype: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">workspace_filename</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">))</span></div>
<div class="viewcode-block" id="workspace_delete"><a class="viewcode-back" href="../../../pylorax.api.html#pylorax.api.workspace.workspace_delete">[docs]</a><span class="k">def</span> <span class="nf">workspace_delete</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Delete the recipe from the workspace</span>
<span class="sd"> :param repo: Open repository</span>
<span class="sd"> :type repo: Git.Repository</span>
<span class="sd"> :param branch: Branch name</span>
<span class="sd"> :type branch: str</span>
<span class="sd"> :param recipe_name: The name of the recipe</span>
<span class="sd"> :type recipe_name: str</span>
<span class="sd"> :returns: None</span>
<span class="sd"> :raises: IO related errors</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">filename</span> <span class="o">=</span> <span class="n">workspace_filename</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">branch</span><span class="p">,</span> <span class="n">recipe_name</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,268 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.base &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.base</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.base</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># base.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2009-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABCMeta</span><span class="p">,</span> <span class="n">abstractmethod</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">pylorax.output</span> <span class="k">as</span> <span class="nn">output</span>
<div class="viewcode-block" id="BaseLoraxClass"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass">[docs]</a><span class="k">class</span> <span class="nc">BaseLoraxClass</span><span class="p">(</span><span class="nb">object</span><span class="p">,</span> <span class="n">metaclass</span><span class="o">=</span><span class="n">ABCMeta</span><span class="p">):</span>
<span class="nd">@abstractmethod</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">LoraxOutput</span><span class="p">()</span>
<div class="viewcode-block" id="BaseLoraxClass.pcritical"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass.pcritical">[docs]</a> <span class="k">def</span> <span class="nf">pcritical</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="p">)</span></div>
<div class="viewcode-block" id="BaseLoraxClass.perror"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass.perror">[docs]</a> <span class="k">def</span> <span class="nf">perror</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="p">)</span></div>
<div class="viewcode-block" id="BaseLoraxClass.pwarning"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass.pwarning">[docs]</a> <span class="k">def</span> <span class="nf">pwarning</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="p">)</span></div>
<div class="viewcode-block" id="BaseLoraxClass.pinfo"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass.pinfo">[docs]</a> <span class="k">def</span> <span class="nf">pinfo</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="p">)</span></div>
<div class="viewcode-block" id="BaseLoraxClass.pdebug"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.BaseLoraxClass.pdebug">[docs]</a> <span class="k">def</span> <span class="nf">pdebug</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="o">=</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">fobj</span><span class="p">)</span></div></div>
<div class="viewcode-block" id="DataHolder"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.DataHolder">[docs]</a><span class="k">class</span> <span class="nc">DataHolder</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="nb">dict</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span>
<span class="k">for</span> <span class="n">attr</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="bp">self</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
<span class="k">def</span> <span class="fm">__getattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">):</span>
<span class="k">if</span> <span class="n">attr</span> <span class="ow">in</span> <span class="bp">self</span><span class="p">:</span>
<span class="k">return</span> <span class="bp">self</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">AttributeError</span>
<span class="k">def</span> <span class="fm">__setattr__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">attr</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="bp">self</span><span class="p">[</span><span class="n">attr</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span>
<div class="viewcode-block" id="DataHolder.copy"><a class="viewcode-back" href="../../pylorax.html#pylorax.base.DataHolder.copy">[docs]</a> <span class="k">def</span> <span class="nf">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">DataHolder</span><span class="p">(</span><span class="o">**</span><span class="nb">dict</span><span class="o">.</span><span class="n">copy</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,267 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.buildstamp &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.buildstamp</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.buildstamp</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># buildstamp.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2010-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.buildstamp&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">datetime</span>
<span class="kn">import</span> <span class="nn">os</span>
<div class="viewcode-block" id="BuildStamp"><a class="viewcode-back" href="../../pylorax.html#pylorax.buildstamp.BuildStamp">[docs]</a><span class="k">class</span> <span class="nc">BuildStamp</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">version</span><span class="p">,</span> <span class="n">bugurl</span><span class="p">,</span> <span class="n">isfinal</span><span class="p">,</span> <span class="n">buildarch</span><span class="p">,</span> <span class="n">variant</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">product</span> <span class="o">=</span> <span class="n">product</span>
<span class="bp">self</span><span class="o">.</span><span class="n">version</span> <span class="o">=</span> <span class="n">version</span>
<span class="bp">self</span><span class="o">.</span><span class="n">bugurl</span> <span class="o">=</span> <span class="n">bugurl</span>
<span class="bp">self</span><span class="o">.</span><span class="n">isfinal</span> <span class="o">=</span> <span class="n">isfinal</span>
<span class="bp">self</span><span class="o">.</span><span class="n">variant</span> <span class="o">=</span> <span class="n">variant</span>
<span class="k">if</span> <span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span>
<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">utcfromtimestamp</span><span class="p">(</span>
<span class="nb">int</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span><span class="p">]))</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">now</span><span class="p">()</span>
<span class="n">now</span> <span class="o">=</span> <span class="n">now</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">%H%M&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">uuid</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">.</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">now</span><span class="p">,</span> <span class="n">buildarch</span><span class="p">)</span>
<div class="viewcode-block" id="BuildStamp.write"><a class="viewcode-back" href="../../pylorax.html#pylorax.buildstamp.BuildStamp.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="c1"># get lorax version</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">pylorax.version</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="n">vernum</span> <span class="o">=</span> <span class="s2">&quot;devel&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">vernum</span> <span class="o">=</span> <span class="n">pylorax</span><span class="o">.</span><span class="n">version</span><span class="o">.</span><span class="n">num</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;writing .buildstamp file&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fobj</span><span class="p">:</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;[Main]</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Product=</span><span class="si">{0.product}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Version=</span><span class="si">{0.version}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;BugURL=</span><span class="si">{0.bugurl}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;IsFinal=</span><span class="si">{0.isfinal}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;UUID=</span><span class="si">{0.uuid}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">variant</span><span class="p">:</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Variant=</span><span class="si">{0.variant}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;[Compose]</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Lorax=</span><span class="si">{0}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">vernum</span><span class="p">))</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,522 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.cmdline &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.cmdline</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.cmdline</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># cmdline.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2016 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Brian C. Lane &lt;bcl@redhat.com&gt;</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">vernum</span>
<span class="n">version</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{0}</span><span class="s2">-</span><span class="si">{1}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</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">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="n">vernum</span><span class="p">)</span>
<div class="viewcode-block" id="lorax_parser"><a class="viewcode-back" href="../../pylorax.html#pylorax.cmdline.lorax_parser">[docs]</a><span class="k">def</span> <span class="nf">lorax_parser</span><span class="p">(</span><span class="n">dracut_default</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return the ArgumentParser for lorax&quot;&quot;&quot;</span>
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">&quot;Create the Anaconda boot.iso&quot;</span><span class="p">)</span>
<span class="c1"># required arguments for image creation</span>
<span class="n">required</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;required arguments&quot;</span><span class="p">)</span>
<span class="n">required</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-p&quot;</span><span class="p">,</span> <span class="s2">&quot;--product&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;product name&quot;</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;PRODUCT&quot;</span><span class="p">)</span>
<span class="n">required</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-v&quot;</span><span class="p">,</span> <span class="s2">&quot;--version&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;version identifier&quot;</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;VERSION&quot;</span><span class="p">)</span>
<span class="n">required</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-r&quot;</span><span class="p">,</span> <span class="s2">&quot;--release&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;release information&quot;</span><span class="p">,</span> <span class="n">required</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;RELEASE&quot;</span><span class="p">)</span>
<span class="n">required</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="s2">&quot;--source&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;source repository (may be listed multiple times)&quot;</span><span class="p">,</span>
<span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;REPOSITORY&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">required</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--repo&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;source dnf repository file&quot;</span><span class="p">,</span> <span class="nb">type</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">dest</span><span class="o">=</span><span class="s2">&quot;repos&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;REPOSITORY&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="c1"># optional arguments</span>
<span class="n">optional</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;optional arguments&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-m&quot;</span><span class="p">,</span> <span class="s2">&quot;--mirrorlist&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;mirrorlist repository (may be listed multiple times)&quot;</span><span class="p">,</span>
<span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;REPOSITORY&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-t&quot;</span><span class="p">,</span> <span class="s2">&quot;--variant&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;variant name&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;VARIANT&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-b&quot;</span><span class="p">,</span> <span class="s2">&quot;--bugurl&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;bug reporting URL for the product&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;URL&quot;</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="s2">&quot;your distribution provided bug reporting tool&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--isfinal&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;isfinal&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-c&quot;</span><span class="p">,</span> <span class="s2">&quot;--config&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/etc/lorax/lorax.conf&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;config file&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;CONFIGFILE&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--proxy&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;repo proxy url:port&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;HOST&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-i&quot;</span><span class="p">,</span> <span class="s2">&quot;--installpkgs&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;PACKAGE&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;package glob to install before runtime-install.tmpl runs. (may be listed multiple times)&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-e&quot;</span><span class="p">,</span> <span class="s2">&quot;--excludepkgs&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;PACKAGE&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;package glob to remove before runtime-install.tmpl runs. (may be listed multiple times)&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--buildarch&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;build architecture&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;ARCH&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--volid&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;volume id&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;VOLID&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--macboot&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;domacboot&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--nomacboot&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_false&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;domacboot&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--noupgrade&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_false&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;doupgrade&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--logfile&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;./lorax.log&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Path to logfile&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--tmp&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/var/tmp/lorax&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Top level temporary directory&quot;</span> <span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--cachedir&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;DNF cache directory. Default is a temporary dir.&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--workdir&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Work directory, overrides --tmp. Default is a temporary dir under /var/tmp/lorax&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--force&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Run even when the destination directory exists&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--add-template&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;add_templates&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Additional template for runtime image&quot;</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--add-template-var&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;add_template_vars&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Set variable for runtime image template&quot;</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--add-arch-template&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;add_arch_templates&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Additional template for architecture-specific image&quot;</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--add-arch-template-var&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;add_arch_template_vars&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Set variable for architecture-specific image&quot;</span><span class="p">,</span>
<span class="n">default</span><span class="o">=</span><span class="p">[])</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--noverify&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_false&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;verify&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Do not verify the install root&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--sharedir&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;SHAREDIR&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Directory containing all the templates. Overrides config file sharedir&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--enablerepo&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;enablerepos&quot;</span><span class="p">,</span>
<span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;[repo]&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Names of repos to enable&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--disablerepo&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;disablerepos&quot;</span><span class="p">,</span>
<span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;[repo]&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Names of repos to disable&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--rootfs-size&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Size of root filesystem in GiB. Defaults to 2.&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--noverifyssl&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Do not verify SSL certificates&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--dnfplugin&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;dnfplugins&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Enable a DNF plugin by name/glob, or * to enable all of them.&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--squashfs-only&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Use a plain squashfs filesystem for the runtime.&quot;</span><span class="p">)</span>
<span class="n">optional</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--skip-branding&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Disable automatic branding package selection. Use --installpkgs to add custom branding.&quot;</span><span class="p">)</span>
<span class="c1"># dracut arguments</span>
<span class="n">dracut_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;dracut arguments: (default: </span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="n">dracut_default</span><span class="p">)</span>
<span class="n">dracut_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--dracut-conf&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to a dracut.conf file to use instead of the &quot;</span>
<span class="s2">&quot;default arguments. See the dracut.conf(5) manpage.&quot;</span><span class="p">)</span>
<span class="n">dracut_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--dracut-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;dracut_args&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Argument to pass to dracut when &quot;</span>
<span class="s2">&quot;rebuilding the initramfs. Pass this &quot;</span>
<span class="s2">&quot;once for each argument. NOTE: this &quot;</span>
<span class="s2">&quot;overrides the defaults.&quot;</span><span class="p">)</span>
<span class="c1"># add the show version option</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-V&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;show program&#39;s version number and exit&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;version&quot;</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">version</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;outputdir&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;Output directory&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;OUTPUTDIR&quot;</span><span class="p">,</span> <span class="nb">type</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="k">return</span> <span class="n">parser</span></div>
<div class="viewcode-block" id="lmc_parser"><a class="viewcode-back" href="../../pylorax.html#pylorax.cmdline.lmc_parser">[docs]</a><span class="k">def</span> <span class="nf">lmc_parser</span><span class="p">(</span><span class="n">dracut_default</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return a ArgumentParser object for live-media-creator.&quot;&quot;&quot;</span>
<span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s2">&quot;Create Live Install Media&quot;</span><span class="p">,</span>
<span class="n">fromfile_prefix_chars</span><span class="o">=</span><span class="s2">&quot;@&quot;</span><span class="p">)</span>
<span class="c1"># These are mutually exclusive, one is required</span>
<span class="n">action</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_mutually_exclusive_group</span><span class="p">(</span><span class="n">required</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-iso&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a live iso&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-disk&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a partitioned disk image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-fsimage&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a filesystem image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-appliance&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build an appliance image and XML description&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-ami&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build an ami image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-tar&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a tar of the root filesystem&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-tar-disk&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a tar of a partitioned disk image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-pxe-live&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a live pxe boot squashfs image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-ostree-live&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a live pxe boot squashfs image of Atomic Host&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-oci&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build an Open Container Initiative image&quot;</span><span class="p">)</span>
<span class="n">action</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--make-vagrant&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Build a Vagrant Box image&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--iso&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Anaconda installation .iso path to use for qemu&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--iso-only&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Remove all iso creation artifacts except the boot.iso, &quot;</span>
<span class="s2">&quot;combine with --iso-name to rename the boot.iso&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--iso-name&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Name of output iso file for --iso-only. Default is boot.iso&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--ks&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Kickstart file defining the install.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--image-only&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Exit after creating fs/disk image.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--no-virt&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Run anaconda directly on host instead of using qemu&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--proxy&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;proxy URL to use for the install&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--anaconda-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;anaconda_args&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Additional argument to pass to anaconda (no-virt &quot;</span>
<span class="s2">&quot;mode). Pass once for each argument&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--armplatform&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;the platform to use when creating images for ARM, &quot;</span>
<span class="s2">&quot;i.e., highbank, mvebu, omap, tegra, etc.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--location&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;location of iso directory tree with initrd.img &quot;</span>
<span class="s2">&quot;and vmlinuz. Used to run qemu with a newer initrd &quot;</span>
<span class="s2">&quot;than the iso.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--logfile&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;./livemedia.log&quot;</span><span class="p">,</span>
<span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Name and path for primary logfile, other logs will &quot;</span>
<span class="s2">&quot;be created in the same directory.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--lorax-templates&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Path to mako templates for lorax&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--tmp&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/var/tmp&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Top level temporary directory&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--resultdir&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;result_dir&quot;</span><span class="p">,</span>
<span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Directory to copy the resulting images and iso into. &quot;</span>
<span class="s2">&quot;Defaults to the temporary working directory&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--macboot&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">dest</span><span class="o">=</span><span class="s2">&quot;domacboot&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--nomacboot&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_false&quot;</span><span class="p">,</span>
<span class="n">dest</span><span class="o">=</span><span class="s2">&quot;domacboot&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--extra-boot-args&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;extra_boot_args&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Extra arguments to add to the bootloader kernel cmdline in the templates&quot;</span><span class="p">)</span>
<span class="n">image_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;disk/fs image arguments&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--disk-image&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Path to existing disk image to use for creating final image.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--keep-image&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Keep raw disk image after .iso creation&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--fs-image&quot;</span><span class="p">,</span> <span class="nb">type</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">help</span><span class="o">=</span><span class="s2">&quot;Path to existing filesystem image to use for creating final image.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--image-name&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Name of output file to create. Used for tar, fs and disk image. Default is a random name.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--tar-disk-name&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Name of the archive member for make-tar-disk.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--fs-label&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;Anaconda&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Label to set on fsimage, default is &#39;Anaconda&#39;&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--image-size-align&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Create a disk image with a size that is a multiple of this value in MiB.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--image-type&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Create an image with qemu-img. See qemu-img --help for supported formats.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--qemu-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;qemu_args&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Arguments to pass to qemu-img. Pass once for each argument, they will be used for ALL calls to qemu-img.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--qcow2&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Create qcow2 image instead of raw sparse image when making disk images.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--qcow2-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;qemu_args&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Arguments to pass to qemu-img. Pass once for each argument, they will be used for ALL calls to qemu-img.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--compression&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Compression binary for make-tar. xz, lzma, gzip, and bzip2 are supported. xz is the default.&quot;</span><span class="p">)</span>
<span class="n">image_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--compress-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;compress_args&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="p">[],</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Arguments to pass to compression. Pass once for each argument&quot;</span><span class="p">)</span>
<span class="c1"># Group of arguments for appliance creation</span>
<span class="n">app_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;appliance arguments&quot;</span><span class="p">)</span>
<span class="n">app_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--app-name&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Name of appliance to pass to template&quot;</span><span class="p">)</span>
<span class="n">app_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--app-template&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to template to use for appliance data.&quot;</span><span class="p">)</span>
<span class="n">app_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--app-file&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;appliance.xml&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Appliance template results file.&quot;</span><span class="p">)</span>
<span class="c1"># Group of arguments to pass to qemu</span>
<span class="n">virt_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;qemu arguments&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--ram&quot;</span><span class="p">,</span> <span class="n">metavar</span><span class="o">=</span><span class="s2">&quot;MEMORY&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">2048</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Memory to allocate for installer in megabytes.&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--vcpus&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Passed to qemu -smp command&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--vnc&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Passed to qemu -display command. eg. vnc=127.0.0.1:5, default is to &quot;</span>
<span class="s2">&quot;choose the first unused vnc port.&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--arch&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;System arch to build for. Used to select qemu-system-* command. &quot;</span>
<span class="s2">&quot;Defaults to qemu-system-&lt;arch&gt;&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--kernel-args&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Additional argument to pass to the installation kernel&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--ovmf-path&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/usr/share/edk2/ovmf/&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to OVMF firmware&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--virt-uefi&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Use OVMF firmware to boot the VM in UEFI mode&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--no-kvm&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Skip using kvm with qemu even if it is available.&quot;</span><span class="p">)</span>
<span class="n">virt_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--with-rng&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;/dev/random&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;RNG device for QEMU (none for no RNG)&quot;</span><span class="p">)</span>
<span class="c1"># dracut arguments</span>
<span class="n">dracut_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;dracut arguments: (default: </span><span class="si">%s</span><span class="s2">)&quot;</span> <span class="o">%</span> <span class="n">dracut_default</span><span class="p">)</span>
<span class="n">dracut_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--dracut-conf&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Path to a dracut.conf file to use instead of the &quot;</span>
<span class="s2">&quot;default arguments. See the dracut.conf(5) manpage.&quot;</span><span class="p">)</span>
<span class="n">dracut_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--dracut-arg&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;append&quot;</span><span class="p">,</span> <span class="n">dest</span><span class="o">=</span><span class="s2">&quot;dracut_args&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Argument to pass to dracut when &quot;</span>
<span class="s2">&quot;rebuilding the initramfs. Pass this &quot;</span>
<span class="s2">&quot;once for each argument. NOTE: this &quot;</span>
<span class="s2">&quot;overrides the defaults.&quot;</span><span class="p">)</span>
<span class="c1"># pxe to live arguments</span>
<span class="n">pxelive_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;pxe to live arguments&quot;</span><span class="p">)</span>
<span class="n">pxelive_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--live-rootfs-size&quot;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Size of root filesystem of live image in GiB&quot;</span><span class="p">)</span>
<span class="n">pxelive_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--live-rootfs-keep-size&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Keep the original size of root filesystem in live image&quot;</span><span class="p">)</span>
<span class="c1"># OCI specific commands</span>
<span class="n">oci_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;OCI arguments&quot;</span><span class="p">)</span>
<span class="n">oci_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--oci-config&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;config.json OCI configuration file&quot;</span><span class="p">)</span>
<span class="n">oci_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--oci-runtime&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;runtime.json OCI configuration file&quot;</span><span class="p">)</span>
<span class="c1"># Vagrant specific commands</span>
<span class="n">vagrant_group</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">add_argument_group</span><span class="p">(</span><span class="s2">&quot;Vagrant arguments&quot;</span><span class="p">)</span>
<span class="n">vagrant_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--vagrant-metadata&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;optional metadata.json file&quot;</span><span class="p">)</span>
<span class="n">vagrant_group</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--vagrantfile&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;optional vagrantfile&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--project&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;Linux&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;substituted for @PROJECT@ in bootloader config files&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--releasever&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s2">&quot;32&quot;</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;substituted for @VERSION@ in bootloader config files&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--volid&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;volume id&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--squashfs-only&quot;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s2">&quot;store_true&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Use a plain squashfs filesystem for the runtime.&quot;</span><span class="p">)</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;--timeout&quot;</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span>
<span class="n">help</span><span class="o">=</span><span class="s2">&quot;Cancel installer after X minutes&quot;</span><span class="p">)</span>
<span class="c1"># add the show version option</span>
<span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s2">&quot;-V&quot;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s2">&quot;show program&#39;s version number and exit&quot;</span><span class="p">,</span>
<span class="n">action</span><span class="o">=</span><span class="s2">&quot;version&quot;</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">version</span><span class="p">)</span>
<span class="k">return</span> <span class="n">parser</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,957 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.creator &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.creator</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.creator</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;pylorax&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">hashlib</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="c1"># Use Mako templates for appliance builder descriptions</span>
<span class="kn">from</span> <span class="nn">mako.template</span> <span class="kn">import</span> <span class="n">Template</span>
<span class="kn">from</span> <span class="nn">mako.exceptions</span> <span class="kn">import</span> <span class="n">text_error_template</span>
<span class="c1"># Use pykickstart to calculate disk image size</span>
<span class="kn">from</span> <span class="nn">pykickstart.parser</span> <span class="kn">import</span> <span class="n">KickstartParser</span>
<span class="kn">from</span> <span class="nn">pykickstart.constants</span> <span class="kn">import</span> <span class="n">KS_SHUTDOWN</span>
<span class="kn">from</span> <span class="nn">pykickstart.version</span> <span class="kn">import</span> <span class="n">makeVersion</span>
<span class="c1"># Use the Lorax treebuilder branch for iso creation</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">ArchData</span>
<span class="kn">from</span> <span class="nn">pylorax.base</span> <span class="kn">import</span> <span class="n">DataHolder</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">execWithRedirect</span><span class="p">,</span> <span class="n">runcmd</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">PartitionMount</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">mount</span><span class="p">,</span> <span class="n">umount</span><span class="p">,</span> <span class="n">Mount</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">mksquashfs</span><span class="p">,</span> <span class="n">mkrootfsimg</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">copytree</span>
<span class="kn">from</span> <span class="nn">pylorax.installer</span> <span class="kn">import</span> <span class="n">novirt_install</span><span class="p">,</span> <span class="n">virt_install</span><span class="p">,</span> <span class="n">InstallError</span>
<span class="kn">from</span> <span class="nn">pylorax.treebuilder</span> <span class="kn">import</span> <span class="n">TreeBuilder</span><span class="p">,</span> <span class="n">RuntimeBuilder</span>
<span class="kn">from</span> <span class="nn">pylorax.treebuilder</span> <span class="kn">import</span> <span class="n">findkernels</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span><span class="p">,</span> <span class="n">remove</span>
<span class="c1"># Default parameters for rebuilding initramfs, override with --dracut-arg or --dracut-conf</span>
<span class="n">DRACUT_DEFAULT</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;--xz&quot;</span><span class="p">,</span> <span class="s2">&quot;--add&quot;</span><span class="p">,</span> <span class="s2">&quot;livenet dmsquash-live dmsquash-live-ntfs convertfs pollcdrom qemu qemu-net&quot;</span><span class="p">,</span>
<span class="s2">&quot;--omit&quot;</span><span class="p">,</span> <span class="s2">&quot;plymouth&quot;</span><span class="p">,</span> <span class="s2">&quot;--no-hostonly&quot;</span><span class="p">,</span> <span class="s2">&quot;--debug&quot;</span><span class="p">,</span> <span class="s2">&quot;--no-early-microcode&quot;</span><span class="p">]</span>
<span class="n">RUNTIME</span> <span class="o">=</span> <span class="s2">&quot;images/install.img&quot;</span>
<div class="viewcode-block" id="FakeDNF"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.FakeDNF">[docs]</a><span class="k">class</span> <span class="nc">FakeDNF</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> A minimal DNF object suitable for passing to RuntimeBuilder</span>
<span class="sd"> lmc uses RuntimeBuilder to run the arch specific iso creation</span>
<span class="sd"> templates, so the the installroot config value is the important part of</span>
<span class="sd"> this. Everything else should be a nop.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">conf</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">conf</span> <span class="o">=</span> <span class="n">conf</span>
<div class="viewcode-block" id="FakeDNF.reset"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.FakeDNF.reset">[docs]</a> <span class="k">def</span> <span class="nf">reset</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">pass</span></div></div>
<div class="viewcode-block" id="is_image_mounted"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.is_image_mounted">[docs]</a><span class="k">def</span> <span class="nf">is_image_mounted</span><span class="p">(</span><span class="n">disk_img</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Check to see if the disk_img is mounted</span>
<span class="sd"> :returns: True if disk_img is in /proc/mounts</span>
<span class="sd"> :rtype: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;/proc/mounts&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">mounts</span><span class="p">:</span>
<span class="k">for</span> <span class="n">mnt</span> <span class="ow">in</span> <span class="n">mounts</span><span class="p">:</span>
<span class="n">fields</span> <span class="o">=</span> <span class="n">mnt</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">fields</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">fields</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="n">disk_img</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="k">return</span> <span class="kc">False</span></div>
<div class="viewcode-block" id="find_ostree_root"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.find_ostree_root">[docs]</a><span class="k">def</span> <span class="nf">find_ostree_root</span><span class="p">(</span><span class="n">phys_root</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Find root of ostree deployment</span>
<span class="sd"> :param str phys_root: Path to physical root</span>
<span class="sd"> :returns: Relative path of ostree deployment root</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> :raise Exception: More than one deployment roots were found</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">ostree_root</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">ostree_sysroots</span> <span class="o">=</span> <span class="n">glob</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">phys_root</span><span class="p">,</span> <span class="s2">&quot;ostree/boot.?/*/*/0&quot;</span><span class="p">))</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;ostree_sysroots = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">ostree_sysroots</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ostree_sysroots</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">ostree_sysroots</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Too many deployment roots found: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">ostree_sysroots</span><span class="p">)</span>
<span class="n">ostree_root</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">relpath</span><span class="p">(</span><span class="n">ostree_sysroots</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">phys_root</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ostree_root</span></div>
<div class="viewcode-block" id="get_arch"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.get_arch">[docs]</a><span class="k">def</span> <span class="nf">get_arch</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get the kernel arch</span>
<span class="sd"> :returns: Arch of first kernel found at mount_dir/boot/ or i386</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kernels</span> <span class="o">=</span> <span class="n">findkernels</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">kernels</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;i386&quot;</span>
<span class="k">return</span> <span class="n">kernels</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">arch</span></div>
<div class="viewcode-block" id="squashfs_args"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.squashfs_args">[docs]</a><span class="k">def</span> <span class="nf">squashfs_args</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Returns the compression type and args to use when making squashfs</span>
<span class="sd"> :param opts: ArgumentParser object with compression and compressopts</span>
<span class="sd"> :returns: tuple of compression type and args</span>
<span class="sd"> :rtype: tuple</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">compression</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span> <span class="ow">or</span> <span class="s2">&quot;xz&quot;</span>
<span class="n">arch</span> <span class="o">=</span> <span class="n">ArchData</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">arch</span> <span class="ow">or</span> <span class="n">os</span><span class="o">.</span><span class="n">uname</span><span class="p">()</span><span class="o">.</span><span class="n">machine</span><span class="p">)</span>
<span class="k">if</span> <span class="n">compression</span> <span class="o">==</span> <span class="s2">&quot;xz&quot;</span> <span class="ow">and</span> <span class="n">arch</span><span class="o">.</span><span class="n">bcj</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="c1"># default to bcj when using xz</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;-Xbcj&quot;</span><span class="p">,</span> <span class="n">arch</span><span class="o">.</span><span class="n">bcj</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compressargs</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">return</span> <span class="p">(</span><span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="dracut_args"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.dracut_args">[docs]</a><span class="k">def</span> <span class="nf">dracut_args</span><span class="p">(</span><span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Return a list of the args to pass to dracut</span>
<span class="sd"> Return the default argument list unless one of the dracut cmdline arguments</span>
<span class="sd"> has been used.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">dracut_conf</span><span class="p">:</span>
<span class="k">return</span> <span class="p">[</span><span class="s2">&quot;--conf&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">dracut_conf</span><span class="p">]</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">dracut_args</span><span class="p">:</span>
<span class="n">args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">dracut_args</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">return</span> <span class="n">args</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">DRACUT_DEFAULT</span></div>
<div class="viewcode-block" id="make_appliance"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.make_appliance">[docs]</a><span class="k">def</span> <span class="nf">make_appliance</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">template</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">networks</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">ram</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span>
<span class="n">vcpus</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">arch</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">title</span><span class="o">=</span><span class="s2">&quot;Linux&quot;</span><span class="p">,</span> <span class="n">project</span><span class="o">=</span><span class="s2">&quot;Linux&quot;</span><span class="p">,</span>
<span class="n">releasever</span><span class="o">=</span><span class="s2">&quot;32&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Generate an appliance description file</span>
<span class="sd"> :param str disk_img: Full path of the disk image</span>
<span class="sd"> :param str name: Name of the appliance, passed to the template</span>
<span class="sd"> :param str template: Full path of Mako template</span>
<span class="sd"> :param str outfile: Full path of file to write, using template</span>
<span class="sd"> :param list networks: List of networks(str) from the kickstart</span>
<span class="sd"> :param int ram: Ram, in MiB, passed to template. Default is 1024</span>
<span class="sd"> :param int vcpus: CPUs, passed to template. Default is 1</span>
<span class="sd"> :param str arch: CPU architecture. Default is &#39;x86_64&#39;</span>
<span class="sd"> :param str title: Title, passed to template. Default is &#39;Linux&#39;</span>
<span class="sd"> :param str project: Project, passed to template. Default is &#39;Linux&#39;</span>
<span class="sd"> :param str releasever: Release version, passed to template. Default is 32</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">disk_img</span> <span class="ow">and</span> <span class="n">template</span> <span class="ow">and</span> <span class="n">outfile</span><span class="p">):</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Creating appliance definition using </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">template</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">arch</span><span class="p">:</span>
<span class="n">arch</span> <span class="o">=</span> <span class="s2">&quot;x86_64&quot;</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Calculating SHA256 checksum of </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="n">sha256</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">sha256</span><span class="p">()</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">sha256</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">data</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="s2">&quot;SHA256 of </span><span class="si">%s</span><span class="s2"> is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">sha256</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">())</span>
<span class="n">disk_info</span> <span class="o">=</span> <span class="n">DataHolder</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">disk_img</span><span class="p">),</span> <span class="nb">format</span><span class="o">=</span><span class="s2">&quot;raw&quot;</span><span class="p">,</span>
<span class="n">checksum_type</span><span class="o">=</span><span class="s2">&quot;sha256&quot;</span><span class="p">,</span> <span class="n">checksum</span><span class="o">=</span><span class="n">sha256</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">())</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">template</span><span class="p">)</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">disks</span><span class="o">=</span><span class="p">[</span><span class="n">disk_info</span><span class="p">],</span> <span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span>
<span class="n">arch</span><span class="o">=</span><span class="n">arch</span><span class="p">,</span> <span class="n">memory</span><span class="o">=</span><span class="n">ram</span><span class="p">,</span> <span class="n">vcpus</span><span class="o">=</span><span class="n">vcpus</span><span class="p">,</span> <span class="n">networks</span><span class="o">=</span><span class="n">networks</span><span class="p">,</span>
<span class="n">title</span><span class="o">=</span><span class="n">title</span><span class="p">,</span> <span class="n">project</span><span class="o">=</span><span class="n">project</span><span class="p">,</span> <span class="n">releasever</span><span class="o">=</span><span class="n">releasever</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">text_error_template</span><span class="p">()</span><span class="o">.</span><span class="n">render</span><span class="p">())</span>
<span class="k">raise</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">result</span><span class="p">)</span></div>
<div class="viewcode-block" id="make_runtime"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.make_runtime">[docs]</a><span class="k">def</span> <span class="nf">make_runtime</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Make the squashfs image from a directory</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str mount_dir: Directory tree to compress</span>
<span class="sd"> :param str work_dir: Output compressed image to work_dir+images/install.img</span>
<span class="sd"> :param int size: Size of disk image, in GiB</span>
<span class="sd"> :returns: rc of squashfs creation</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kernel_arch</span> <span class="o">=</span> <span class="n">get_arch</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="c1"># Fake dnf object</span>
<span class="n">fake_dbo</span> <span class="o">=</span> <span class="n">FakeDNF</span><span class="p">(</span><span class="n">conf</span><span class="o">=</span><span class="n">DataHolder</span><span class="p">(</span><span class="n">installroot</span><span class="o">=</span><span class="n">mount_dir</span><span class="p">))</span>
<span class="c1"># Fake arch with only basearch set</span>
<span class="n">arch</span> <span class="o">=</span> <span class="n">ArchData</span><span class="p">(</span><span class="n">kernel_arch</span><span class="p">)</span>
<span class="c1"># TODO: Need to get release info from someplace...</span>
<span class="n">product</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">project</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">releasever</span><span class="p">,</span> <span class="n">release</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">variant</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">bugurl</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">isfinal</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">rb</span> <span class="o">=</span> <span class="n">RuntimeBuilder</span><span class="p">(</span><span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="p">,</span> <span class="n">fake_dbo</span><span class="p">)</span>
<span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span> <span class="o">=</span> <span class="n">squashfs_args</span><span class="p">(</span><span class="n">opts</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">squashfs_only</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="s2">&quot;Creating a squashfs only runtime&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rb</span><span class="o">.</span><span class="n">create_squashfs_runtime</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">work_dir</span><span class="p">,</span> <span class="n">RUNTIME</span><span class="p">),</span> <span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">,</span>
<span class="n">compression</span><span class="o">=</span><span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="n">compressargs</span><span class="p">)</span>
<span class="k">else</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="s2">&quot;Creating a squashfs+ext4 runtime&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rb</span><span class="o">.</span><span class="n">create_ext4_runtime</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">work_dir</span><span class="p">,</span> <span class="n">RUNTIME</span><span class="p">),</span> <span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">,</span>
<span class="n">compression</span><span class="o">=</span><span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="rebuild_initrds_for_live"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.rebuild_initrds_for_live">[docs]</a><span class="k">def</span> <span class="nf">rebuild_initrds_for_live</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">sys_root_dir</span><span class="p">,</span> <span class="n">results_dir</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Rebuild intrds for pxe live image (root=live:http://)</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str sys_root_dir: Path to root of the system</span>
<span class="sd"> :param str results_dir: Path of directory for storing results</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># cmdline dracut args override the defaults, but need to be parsed</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;dracut args = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">dracut_args</span><span class="p">(</span><span class="n">opts</span><span class="p">))</span>
<span class="n">dracut</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;dracut&quot;</span><span class="p">,</span> <span class="s2">&quot;--nomdadmconf&quot;</span><span class="p">,</span> <span class="s2">&quot;--nolvmconf&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">dracut_args</span><span class="p">(</span><span class="n">opts</span><span class="p">)</span>
<span class="n">kdir</span> <span class="o">=</span> <span class="s2">&quot;boot&quot;</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="n">kernels_dir</span> <span class="o">=</span> <span class="n">glob</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">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;boot/ostree/*&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="n">kernels_dir</span><span class="p">:</span>
<span class="n">kdir</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">relpath</span><span class="p">(</span><span class="n">kernels_dir</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">sys_root_dir</span><span class="p">)</span>
<span class="n">kernels</span> <span class="o">=</span> <span class="p">[</span><span class="n">kernel</span> <span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="n">findkernels</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="n">kdir</span><span class="p">)]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">kernels</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;No initrds found, cannot rebuild_initrds&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="c1"># Dracut assumes to have some dirs in disk image</span>
<span class="c1"># /var/tmp for temp files</span>
<span class="n">vartmp_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;var/tmp&quot;</span><span class="p">)</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">vartmp_dir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">vartmp_dir</span><span class="p">)</span>
<span class="c1"># /root (maybe not fatal)</span>
<span class="n">root_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;var/roothome&quot;</span><span class="p">)</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">root_dir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">root_dir</span><span class="p">)</span>
<span class="c1"># /tmp (maybe not fatal)</span>
<span class="n">tmp_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;sysroot/tmp&quot;</span><span class="p">)</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">tmp_dir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">tmp_dir</span><span class="p">)</span>
<span class="c1"># Write the new initramfs directly to the results directory</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;results&quot;</span><span class="p">))</span>
<span class="n">mount</span><span class="p">(</span><span class="n">results_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;bind&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;results&quot;</span><span class="p">))</span>
<span class="c1"># Dracut runs out of space inside the minimal rootfs image</span>
<span class="n">mount</span><span class="p">(</span><span class="s2">&quot;/var/tmp&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;bind&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;var/tmp&quot;</span><span class="p">))</span>
<span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="n">kernels</span><span class="p">:</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">kernel</span><span class="p">,</span> <span class="s2">&quot;initrd&quot;</span><span class="p">):</span>
<span class="n">outfile</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">kernel</span><span class="o">.</span><span class="n">initrd</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Construct an initrd from the kernel name</span>
<span class="n">outfile</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">kernel</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;vmlinuz-&quot;</span><span class="p">,</span> <span class="s2">&quot;initrd-&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;.img&quot;</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="s2">&quot;rebuilding </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">outfile</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="s2">&quot;dracut warnings about /proc are safe to ignore&quot;</span><span class="p">)</span>
<span class="n">kver</span> <span class="o">=</span> <span class="n">kernel</span><span class="o">.</span><span class="n">version</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="n">dracut</span> <span class="o">+</span> <span class="p">[</span><span class="s2">&quot;/results/&quot;</span><span class="o">+</span><span class="n">outfile</span><span class="p">,</span> <span class="n">kver</span><span class="p">]</span>
<span class="n">runcmd</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">sys_root_dir</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="n">kernel</span><span class="o">.</span><span class="n">path</span><span class="p">),</span> <span class="n">results_dir</span><span class="p">)</span>
<span class="n">umount</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;var/tmp&quot;</span><span class="p">),</span> <span class="n">delete</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">umount</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">sys_root_dir</span><span class="p">,</span> <span class="s2">&quot;results&quot;</span><span class="p">),</span> <span class="n">delete</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>
<div class="viewcode-block" id="create_pxe_config"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.create_pxe_config">[docs]</a><span class="k">def</span> <span class="nf">create_pxe_config</span><span class="p">(</span><span class="n">template</span><span class="p">,</span> <span class="n">images_dir</span><span class="p">,</span> <span class="n">live_image_name</span><span class="p">,</span> <span class="n">add_args</span> <span class="o">=</span> <span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create template for pxe to live configuration</span>
<span class="sd"> :param str images_dir: Path of directory with images to be used</span>
<span class="sd"> :param str live_image_name: Name of live rootfs image file</span>
<span class="sd"> :param list add_args: Arguments to be added to initrd= pxe config</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">add_args</span> <span class="o">=</span> <span class="n">add_args</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="n">kernels</span> <span class="o">=</span> <span class="p">[</span><span class="n">kernel</span> <span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="n">findkernels</span><span class="p">(</span><span class="n">images_dir</span><span class="p">,</span> <span class="n">kdir</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">kernel</span><span class="p">,</span> <span class="s2">&quot;initrd&quot;</span><span class="p">)]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">kernels</span><span class="p">:</span>
<span class="k">return</span>
<span class="n">kernel</span> <span class="o">=</span> <span class="n">kernels</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">add_args_str</span> <span class="o">=</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">add_args</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">result</span> <span class="o">=</span> <span class="n">Template</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">template</span><span class="p">)</span><span class="o">.</span><span class="n">render</span><span class="p">(</span><span class="n">kernel</span><span class="o">=</span><span class="n">kernel</span><span class="o">.</span><span class="n">path</span><span class="p">,</span>
<span class="n">initrd</span><span class="o">=</span><span class="n">kernel</span><span class="o">.</span><span class="n">initrd</span><span class="o">.</span><span class="n">path</span><span class="p">,</span> <span class="n">liveimg</span><span class="o">=</span><span class="n">live_image_name</span><span class="p">,</span>
<span class="n">addargs</span><span class="o">=</span><span class="n">add_args_str</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">text_error_template</span><span class="p">()</span><span class="o">.</span><span class="n">render</span><span class="p">())</span>
<span class="k">raise</span>
<span class="k">with</span> <span class="nb">open</span> <span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">images_dir</span><span class="p">,</span> <span class="s2">&quot;PXE_CONFIG&quot;</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">result</span><span class="p">)</span></div>
<div class="viewcode-block" id="make_livecd"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.make_livecd">[docs]</a><span class="k">def</span> <span class="nf">make_livecd</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Take the content from the disk image and make a livecd out of it</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str mount_dir: Directory tree to compress</span>
<span class="sd"> :param str work_dir: Output compressed image to work_dir+images/install.img</span>
<span class="sd"> This uses wwood&#39;s squashfs live initramfs method:</span>
<span class="sd"> * put the real / into LiveOS/rootfs.img</span>
<span class="sd"> * make a squashfs of the LiveOS/rootfs.img tree</span>
<span class="sd"> * This is loaded by dracut when the cmdline is passed to the kernel:</span>
<span class="sd"> root=live:CDLABEL=&lt;volid&gt; rd.live.image</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kernel_arch</span> <span class="o">=</span> <span class="n">get_arch</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="n">arch</span> <span class="o">=</span> <span class="n">ArchData</span><span class="p">(</span><span class="n">kernel_arch</span><span class="p">)</span>
<span class="c1"># TODO: Need to get release info from someplace...</span>
<span class="n">product</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">project</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">releasever</span><span class="p">,</span> <span class="n">release</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="n">variant</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">bugurl</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">isfinal</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="c1"># Link /images to work_dir/images to make the templates happy</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">islink</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">,</span> <span class="s2">&quot;images&quot;</span><span class="p">)):</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">,</span> <span class="s2">&quot;images&quot;</span><span class="p">))</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;/bin/ln&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">work_dir</span><span class="p">,</span> <span class="s2">&quot;images&quot;</span><span class="p">),</span>
<span class="n">joinpaths</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">,</span> <span class="s2">&quot;images&quot;</span><span class="p">)])</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Failed to symlink images from mount_dir to work_dir&quot;</span><span class="p">)</span>
<span class="c1"># The templates expect the config files to be in /tmp/config_files</span>
<span class="c1"># I think these should be release specific, not from lorax, but for now</span>
<span class="n">configdir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">lorax_templates</span><span class="p">,</span><span class="s2">&quot;live/config_files/&quot;</span><span class="p">)</span>
<span class="n">configdir_path</span> <span class="o">=</span> <span class="s2">&quot;tmp/config_files&quot;</span>
<span class="n">fullpath</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">configdir_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">fullpath</span><span class="p">):</span>
<span class="n">remove</span><span class="p">(</span><span class="n">fullpath</span><span class="p">)</span>
<span class="n">copytree</span><span class="p">(</span><span class="n">configdir</span><span class="p">,</span> <span class="n">fullpath</span><span class="p">)</span>
<span class="n">isolabel</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">volid</span> <span class="ow">or</span> <span class="s2">&quot;</span><span class="si">{0.name}</span><span class="s2">-</span><span class="si">{0.version}</span><span class="s2">-</span><span class="si">{1.basearch}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">isolabel</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">32</span><span class="p">:</span>
<span class="n">isolabel</span> <span class="o">=</span> <span class="n">isolabel</span><span class="p">[:</span><span class="mi">32</span><span class="p">]</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Truncating isolabel to 32 chars: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">isolabel</span><span class="p">)</span>
<span class="n">tb</span> <span class="o">=</span> <span class="n">TreeBuilder</span><span class="p">(</span><span class="n">product</span><span class="o">=</span><span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="o">=</span><span class="n">arch</span><span class="p">,</span> <span class="n">domacboot</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">domacboot</span><span class="p">,</span>
<span class="n">inroot</span><span class="o">=</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">outroot</span><span class="o">=</span><span class="n">work_dir</span><span class="p">,</span>
<span class="n">runtime</span><span class="o">=</span><span class="n">RUNTIME</span><span class="p">,</span> <span class="n">isolabel</span><span class="o">=</span><span class="n">isolabel</span><span class="p">,</span>
<span class="n">templatedir</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">lorax_templates</span><span class="p">,</span><span class="s2">&quot;live/&quot;</span><span class="p">),</span>
<span class="n">extra_boot_args</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">extra_boot_args</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="s2">&quot;Rebuilding initrds&quot;</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="s2">&quot;dracut args = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">dracut_args</span><span class="p">(</span><span class="n">opts</span><span class="p">))</span>
<span class="n">tb</span><span class="o">.</span><span class="n">rebuild_initrds</span><span class="p">(</span><span class="n">add_args</span><span class="o">=</span><span class="n">dracut_args</span><span class="p">(</span><span class="n">opts</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="s2">&quot;Building boot.iso&quot;</span><span class="p">)</span>
<span class="n">tb</span><span class="o">.</span><span class="n">build</span><span class="p">()</span>
<span class="k">return</span> <span class="n">work_dir</span></div>
<div class="viewcode-block" id="mount_boot_part_over_root"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.mount_boot_part_over_root">[docs]</a><span class="k">def</span> <span class="nf">mount_boot_part_over_root</span><span class="p">(</span><span class="n">img_mount</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mount boot partition to /boot of root fs mounted in img_mount</span>
<span class="sd"> Used for OSTree so it finds deployment configurations on live rootfs</span>
<span class="sd"> param img_mount: object with mounted disk image root partition</span>
<span class="sd"> type img_mount: imgutils.PartitionMount</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">root_dir</span> <span class="o">=</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span>
<span class="n">is_boot_part</span> <span class="o">=</span> <span class="k">lambda</span> <span class="nb">dir</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="nb">dir</span><span class="o">+</span><span class="s2">&quot;/loader.0&quot;</span><span class="p">)</span>
<span class="n">tmp_mount_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-tmpdir-&quot;</span><span class="p">)</span>
<span class="n">sysroot_boot_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">for</span> <span class="n">dev</span><span class="p">,</span> <span class="n">_size</span> <span class="ow">in</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">loop_devices</span><span class="p">:</span>
<span class="k">if</span> <span class="n">dev</span> <span class="ow">is</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dev</span><span class="p">:</span>
<span class="k">continue</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">mount</span><span class="p">(</span><span class="s2">&quot;/dev/mapper/&quot;</span><span class="o">+</span><span class="n">dev</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">tmp_mount_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="n">is_boot_part</span><span class="p">(</span><span class="n">tmp_mount_dir</span><span class="p">):</span>
<span class="n">umount</span><span class="p">(</span><span class="n">tmp_mount_dir</span><span class="p">)</span>
<span class="n">sysroot_boot_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">root_dir</span><span class="p">,</span> <span class="s2">&quot;boot&quot;</span><span class="p">)</span>
<span class="n">mount</span><span class="p">(</span><span class="s2">&quot;/dev/mapper/&quot;</span><span class="o">+</span><span class="n">dev</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">sysroot_boot_dir</span><span class="p">)</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="n">tmp_mount_dir</span><span class="p">)</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Looking for boot partition error: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="n">remove</span><span class="p">(</span><span class="n">tmp_mount_dir</span><span class="p">)</span>
<span class="k">return</span> <span class="n">sysroot_boot_dir</span></div>
<div class="viewcode-block" id="calculate_disk_size"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.calculate_disk_size">[docs]</a><span class="k">def</span> <span class="nf">calculate_disk_size</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Calculate the disk size from the kickstart</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str ks: Path to the kickstart to use for the installation</span>
<span class="sd"> :returns: Disk size in MiB</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> Also takes into account the use of reqpart or reqpart --add-boot</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Disk size for a filesystem image should only be the size of /</span>
<span class="c1"># to prevent surprises when using the same kickstart for different installations.</span>
<span class="n">unique_partitions</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">((</span><span class="n">p</span><span class="o">.</span><span class="n">mountpoint</span><span class="p">,</span> <span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">partition</span><span class="o">.</span><span class="n">partitions</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span> <span class="ow">and</span> <span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">make_iso</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span><span class="p">):</span>
<span class="n">disk_size</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">+</span> <span class="nb">sum</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">unique_partitions</span><span class="o">.</span><span class="n">values</span><span class="p">()</span> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">mountpoint</span> <span class="o">==</span> <span class="s2">&quot;/&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">disk_size</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">+</span> <span class="nb">sum</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">size</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">unique_partitions</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="c1"># reqpart can add 1M, 2M, 200M based on platform. Add 500M to be sure</span>
<span class="k">if</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">reqpart</span><span class="o">.</span><span class="n">seen</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="s2">&quot;Adding 500M for reqpart&quot;</span><span class="p">)</span>
<span class="n">disk_size</span> <span class="o">+=</span> <span class="mi">500</span>
<span class="c1"># It can also request adding /boot which is 1G</span>
<span class="k">if</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">reqpart</span><span class="o">.</span><span class="n">addBoot</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="s2">&quot;Adding 1024M for reqpart --addboot&quot;</span><span class="p">)</span>
<span class="n">disk_size</span> <span class="o">+=</span> <span class="mi">1024</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_size_align</span><span class="p">:</span>
<span class="n">disk_size</span> <span class="o">+=</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_size_align</span> <span class="o">-</span> <span class="p">(</span><span class="n">disk_size</span> <span class="o">%</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_size_align</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="s2">&quot;Using disk size of </span><span class="si">%s</span><span class="s2">MiB&quot;</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">)</span>
<span class="k">return</span> <span class="n">disk_size</span></div>
<div class="viewcode-block" id="make_image"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.make_image">[docs]</a><span class="k">def</span> <span class="nf">make_image</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Install to a disk image</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str ks: Path to the kickstart to use for the installation</span>
<span class="sd"> :param cancel_func: Function that returns True to cancel build</span>
<span class="sd"> :type cancel_func: function</span>
<span class="sd"> :returns: Path of the image created</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> Use qemu+boot.iso or anaconda to install to a disk image.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># For make_tar_disk, opts.image_name is the name of the final tarball.</span>
<span class="c1"># Use opts.tar_disk_name as the name of the disk image</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar_disk</span><span class="p">:</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">tar_disk_name</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_name</span><span class="p">:</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_name</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-disk-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.img&quot;</span><span class="p">,</span> <span class="nb">dir</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">result_dir</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="s2">&quot;disk_img = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="n">disk_size</span> <span class="o">=</span> <span class="n">calculate_disk_size</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">)</span>
<span class="c1"># For make_tar_disk, pass a second path parameter for the final tarball</span>
<span class="c1"># not the final output file.</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar_disk</span><span class="p">:</span>
<span class="n">tar_img</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_name</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">tar_img</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span><span class="p">:</span>
<span class="n">novirt_install</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="n">cancel_func</span><span class="p">,</span> <span class="n">tar_img</span><span class="o">=</span><span class="n">tar_img</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">install_log</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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">logfile</span><span class="p">))</span><span class="o">+</span><span class="s2">&quot;/virt-install.log&quot;</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;install_log = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">install_log</span><span class="p">)</span>
<span class="n">virt_install</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">install_log</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="n">cancel_func</span><span class="p">,</span> <span class="n">tar_img</span><span class="o">=</span><span class="n">tar_img</span><span class="p">)</span>
<span class="k">except</span> <span class="n">InstallError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Install failed: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">keep_image</span><span class="p">:</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">disk_img</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="s2">&quot;Removing bad disk image&quot;</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">disk_img</span><span class="p">)</span>
<span class="k">if</span> <span class="n">tar_img</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">tar_img</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="s2">&quot;Removing bad tar file&quot;</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">tar_img</span><span class="p">)</span>
<span class="k">raise</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Disk Image install successful&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar_disk</span><span class="p">:</span>
<span class="k">return</span> <span class="n">tar_img</span>
<span class="k">return</span> <span class="n">disk_img</span></div>
<div class="viewcode-block" id="make_live_images"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.make_live_images">[docs]</a><span class="k">def</span> <span class="nf">make_live_images</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Create live images from direcory or rootfs image</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str work_dir: Directory for storing results</span>
<span class="sd"> :param str disk_img: Path to disk image (fsimage or partitioned)</span>
<span class="sd"> :returns: Path of directory with created images or None</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> fsck.ext4 is run on the rootfs_image to make sure there are no errors and to zero</span>
<span class="sd"> out any deleted blocks to make it compress better. If this fails for any reason</span>
<span class="sd"> it will return None and log the error.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">sys_root</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">squashfs_root_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">work_dir</span><span class="p">,</span> <span class="s2">&quot;squashfs_root&quot;</span><span class="p">)</span>
<span class="n">liveos_dir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">squashfs_root_dir</span><span class="p">,</span> <span class="s2">&quot;LiveOS&quot;</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">liveos_dir</span><span class="p">)</span>
<span class="n">rootfs_img</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">liveos_dir</span><span class="p">,</span> <span class="s2">&quot;rootfs.img&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span><span class="p">:</span>
<span class="c1"># Find the ostree root in the fsimage</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="k">with</span> <span class="n">Mount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;loop&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">mnt_dir</span><span class="p">:</span>
<span class="n">sys_root</span> <span class="o">=</span> <span class="n">find_ostree_root</span><span class="p">(</span><span class="n">mnt_dir</span><span class="p">)</span>
<span class="c1"># Try to hardlink the image, if that fails, copy it</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;/bin/ln&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">rootfs_img</span><span class="p">])</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">rootfs_img</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">is_root_part</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="n">is_root_part</span> <span class="o">=</span> <span class="k">lambda</span> <span class="nb">dir</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="nb">dir</span><span class="o">+</span><span class="s2">&quot;/ostree/deploy&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">mount_ok</span><span class="o">=</span><span class="n">is_root_part</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="n">img_mount</span> <span class="ow">and</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">mounted_sysroot_boot_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="n">sys_root</span> <span class="o">=</span> <span class="n">find_ostree_root</span><span class="p">(</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="n">mounted_sysroot_boot_dir</span> <span class="o">=</span> <span class="n">mount_boot_part_over_root</span><span class="p">(</span><span class="n">img_mount</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">live_rootfs_keep_size</span><span class="p">:</span>
<span class="n">size</span> <span class="o">=</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_size</span> <span class="o">/</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">3</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">size</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">live_rootfs_size</span> <span class="ow">or</span> <span class="kc">None</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Creating live rootfs image&quot;</span><span class="p">)</span>
<span class="n">mkrootfsimg</span><span class="p">(</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">rootfs_img</span><span class="p">,</span> <span class="s2">&quot;LiveOS&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">,</span> <span class="n">sysroot</span><span class="o">=</span><span class="n">sys_root</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="k">if</span> <span class="n">mounted_sysroot_boot_dir</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="n">mounted_sysroot_boot_dir</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;sys_root = </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">sys_root</span><span class="p">)</span>
<span class="c1"># Make sure free blocks are actually zeroed so it will compress</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;/usr/sbin/fsck.ext4&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-y&quot;</span><span class="p">,</span> <span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="s2">&quot;-E&quot;</span><span class="p">,</span> <span class="s2">&quot;discard&quot;</span><span class="p">,</span> <span class="n">rootfs_img</span><span class="p">])</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Problem zeroing free blocks of </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Packing live rootfs image&quot;</span><span class="p">)</span>
<span class="n">add_pxe_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">live_image_name</span> <span class="o">=</span> <span class="s2">&quot;live-rootfs.squashfs.img&quot;</span>
<span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span> <span class="o">=</span> <span class="n">squashfs_args</span><span class="p">(</span><span class="n">opts</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mksquashfs</span><span class="p">(</span><span class="n">squashfs_root_dir</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">work_dir</span><span class="p">,</span> <span class="n">live_image_name</span><span class="p">),</span> <span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;mksquashfs failed to create </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">live_image_name</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Rebuilding initramfs for live&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Mount</span><span class="p">(</span><span class="n">rootfs_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;loop&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">mnt_dir</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">mount</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">mnt_dir</span><span class="p">,</span> <span class="s2">&quot;boot&quot;</span><span class="p">),</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;bind&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">mnt_dir</span><span class="p">,</span> <span class="n">sys_root</span><span class="p">,</span> <span class="s2">&quot;boot&quot;</span><span class="p">))</span>
<span class="n">rebuild_initrds_for_live</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">mnt_dir</span><span class="p">,</span> <span class="n">sys_root</span><span class="p">),</span> <span class="n">work_dir</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">mnt_dir</span><span class="p">,</span> <span class="n">sys_root</span><span class="p">,</span> <span class="s2">&quot;boot&quot;</span><span class="p">),</span> <span class="n">delete</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">remove</span><span class="p">(</span><span class="n">squashfs_root_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ostree</span><span class="p">:</span>
<span class="n">add_pxe_args</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;ostree=/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">sys_root</span><span class="p">)</span>
<span class="n">template</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">lorax_templates</span><span class="p">,</span> <span class="s2">&quot;pxe-live/pxe-config.tmpl&quot;</span><span class="p">)</span>
<span class="n">create_pxe_config</span><span class="p">(</span><span class="n">template</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">live_image_name</span><span class="p">,</span> <span class="n">add_pxe_args</span><span class="p">)</span>
<span class="k">return</span> <span class="n">work_dir</span></div>
<div class="viewcode-block" id="check_kickstart"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.check_kickstart">[docs]</a><span class="k">def</span> <span class="nf">check_kickstart</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="n">opts</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Check the parsed kickstart object for errors</span>
<span class="sd"> :param ks: Parsed Kickstart object</span>
<span class="sd"> :type ks: pykickstart.parser.KickstartParser</span>
<span class="sd"> :param opts: Commandline options to control the process</span>
<span class="sd"> :type opts: Either a DataHolder or ArgumentParser</span>
<span class="sd"> :returns: List of error strings or empty list</span>
<span class="sd"> :rtype: list</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">errors</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span> <span class="ow">and</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">method</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;url&quot;</span><span class="p">,</span> <span class="s2">&quot;nfs&quot;</span><span class="p">)</span> \
<span class="ow">and</span> <span class="ow">not</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">ostreesetup</span><span class="o">.</span><span class="n">seen</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Only url, nfs and ostreesetup install methods are currently supported.&quot;</span>
<span class="s2">&quot;Please fix your kickstart file.&quot;</span> <span class="p">)</span>
<span class="k">if</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">repo</span><span class="o">.</span><span class="n">seen</span> <span class="ow">and</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">method</span> <span class="o">!=</span> <span class="s2">&quot;url&quot;</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;repo can only be used with the url install method. Add url to your &quot;</span>
<span class="s2">&quot;kickstart file.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">method</span><span class="o">.</span><span class="n">method</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;url&quot;</span><span class="p">,</span> <span class="s2">&quot;nfs&quot;</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">seen</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;The kickstart must activate networking if &quot;</span>
<span class="s2">&quot;the url or nfs install method is used.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">displaymode</span><span class="o">.</span><span class="n">displayMode</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;The kickstart must not set a display mode (text, cmdline, &quot;</span>
<span class="s2">&quot;graphical), this will interfere with livemedia-creator.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span> <span class="ow">or</span> <span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">make_pxe_live</span> <span class="ow">and</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span><span class="p">):</span>
<span class="c1"># Make sure the kickstart isn&#39;t using autopart and only has a / mountpoint</span>
<span class="n">part_ok</span> <span class="o">=</span> <span class="ow">not</span> <span class="nb">any</span><span class="p">(</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">partition</span><span class="o">.</span><span class="n">partitions</span>
<span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">mountpoint</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="s2">&quot;swap&quot;</span><span class="p">])</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">part_ok</span> <span class="ow">or</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">autopart</span><span class="o">.</span><span class="n">seen</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;Filesystem images must use a single / part, not autopart or &quot;</span>
<span class="s2">&quot;multiple partitions. swap is allowed but not used.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span> <span class="ow">and</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">reboot</span><span class="o">.</span><span class="n">action</span> <span class="o">!=</span> <span class="n">KS_SHUTDOWN</span><span class="p">:</span>
<span class="n">errors</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;The kickstart must include shutdown when using virt installation.&quot;</span><span class="p">)</span>
<span class="k">return</span> <span class="n">errors</span></div>
<div class="viewcode-block" id="run_creator"><a class="viewcode-back" href="../../pylorax.html#pylorax.creator.run_creator">[docs]</a><span class="k">def</span> <span class="nf">run_creator</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Run the image creator process</span>
<span class="sd"> :param opts: Commandline options to control the process</span>
<span class="sd"> :type opts: Either a DataHolder or ArgumentParser</span>
<span class="sd"> :param cancel_func: Function that returns True to cancel build</span>
<span class="sd"> :type cancel_func: function</span>
<span class="sd"> :returns: The result directory and the disk image path.</span>
<span class="sd"> :rtype: Tuple of str</span>
<span class="sd"> This function takes the opts arguments and creates the selected output image.</span>
<span class="sd"> See the cmdline --help for livemedia-creator for the possible options</span>
<span class="sd"> (Yes, this is not ideal, but we can fix that later)</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1"># Parse the kickstart</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">:</span>
<span class="n">ks_version</span> <span class="o">=</span> <span class="n">makeVersion</span><span class="p">()</span>
<span class="n">ks</span> <span class="o">=</span> <span class="n">KickstartParser</span><span class="p">(</span><span class="n">ks_version</span><span class="p">,</span> <span class="n">errorsAreFatal</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">missingIncludeIsFatal</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">ks</span><span class="o">.</span><span class="n">readKickstart</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="c1"># live iso usually needs dracut-live so warn the user if it is missing</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span> <span class="ow">and</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_iso</span><span class="p">:</span>
<span class="k">if</span> <span class="s2">&quot;dracut-live&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">packages</span><span class="o">.</span><span class="n">packageList</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;dracut-live package is missing from the kickstart.&quot;</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;dracut-live package is missing from the kickstart.&quot;</span><span class="p">)</span>
<span class="c1"># Make the disk or filesystem image</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Image creation requires a kickstart file&quot;</span><span class="p">)</span>
<span class="c1"># Check the kickstart for problems</span>
<span class="n">errors</span> <span class="o">=</span> <span class="n">check_kickstart</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="n">opts</span><span class="p">)</span>
<span class="k">if</span> <span class="n">errors</span><span class="p">:</span>
<span class="nb">list</span><span class="p">(</span><span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">errors</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">errors</span><span class="p">))</span>
<span class="c1"># Make the image. Output of this is either a partitioned disk image or a fsimage</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">make_image</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="n">cancel_func</span><span class="p">)</span>
<span class="k">except</span> <span class="n">InstallError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;ERROR: Image creation failed: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Image creation failed: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_only</span><span class="p">:</span>
<span class="k">return</span> <span class="p">(</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_iso</span><span class="p">:</span>
<span class="n">work_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-work-&quot;</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="s2">&quot;working dir is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">)</span>
<span class="k">if</span> <span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_virt</span><span class="p">)</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span><span class="p">:</span>
<span class="c1"># Create iso from a filesystem image</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span> <span class="ow">or</span> <span class="n">disk_img</span>
<span class="k">with</span> <span class="n">Mount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;loop&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">mount_dir</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">make_runtime</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">calculate_disk_size</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">)</span><span class="o">/</span><span class="mf">1024.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;make_runtime failed with rc = </span><span class="si">%d</span><span class="s2">. See program.log&quot;</span><span class="p">,</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;make_runtime failed with rc = </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">if</span> <span class="n">cancel_func</span> <span class="ow">and</span> <span class="n">cancel_func</span><span class="p">():</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;ISO creation canceled&quot;</span><span class="p">)</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="n">make_livecd</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Create iso from a partitioned disk image</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span> <span class="ow">or</span> <span class="n">disk_img</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="n">img_mount</span> <span class="ow">and</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">make_runtime</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">calculate_disk_size</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">ks</span><span class="p">)</span><span class="o">/</span><span class="mf">1024.0</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;make_runtime failed with rc = </span><span class="si">%d</span><span class="s2">. See program.log&quot;</span><span class="p">,</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;make_runtime failed with rc = </span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="n">make_livecd</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">)</span>
<span class="c1"># --iso-only removes the extra build artifacts, keeping only the boot.iso</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">iso_only</span> <span class="ow">and</span> <span class="n">result_dir</span><span class="p">:</span>
<span class="n">boot_iso</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">result_dir</span><span class="p">,</span> <span class="s2">&quot;images/boot.iso&quot;</span><span class="p">)</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">exists</span><span class="p">(</span><span class="n">boot_iso</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is missing, skipping --iso-only.&quot;</span><span class="p">,</span> <span class="n">boot_iso</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">iso_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-result-&quot;</span><span class="p">)</span>
<span class="n">dest_file</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">iso_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">iso_name</span> <span class="ow">or</span> <span class="s2">&quot;boot.iso&quot;</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">move</span><span class="p">(</span><span class="n">boot_iso</span><span class="p">,</span> <span class="n">dest_file</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">result_dir</span><span class="p">)</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="n">iso_dir</span>
<span class="c1"># cleanup the mess</span>
<span class="c1"># cleanup work_dir?</span>
<span class="k">if</span> <span class="n">disk_img</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">keep_image</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">disk_img</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="s2">&quot;Disk image erased&quot;</span><span class="p">)</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_appliance</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">:</span>
<span class="n">networks</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">networks</span> <span class="o">=</span> <span class="n">ks</span><span class="o">.</span><span class="n">handler</span><span class="o">.</span><span class="n">network</span><span class="o">.</span><span class="n">network</span>
<span class="n">make_appliance</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span> <span class="ow">or</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">app_name</span><span class="p">,</span>
<span class="n">opts</span><span class="o">.</span><span class="n">app_template</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">app_file</span><span class="p">,</span> <span class="n">networks</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">ram</span><span class="p">,</span>
<span class="n">opts</span><span class="o">.</span><span class="n">vcpus</span> <span class="ow">or</span> <span class="mi">1</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">project</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">releasever</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_pxe_live</span><span class="p">:</span>
<span class="n">work_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-work-&quot;</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="s2">&quot;working dir is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">)</span>
<span class="n">disk_img</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">fs_image</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">disk_image</span> <span class="ow">or</span> <span class="n">disk_img</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;disk image is </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="n">make_live_images</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">work_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="k">if</span> <span class="n">result_dir</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Creating PXE live image failed.&quot;</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Creating PXE live image failed.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">result_dir</span> <span class="o">!=</span> <span class="n">opts</span><span class="o">.</span><span class="n">tmp</span> <span class="ow">and</span> <span class="n">result_dir</span><span class="p">:</span>
<span class="n">copytree</span><span class="p">(</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">preserve</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">result_dir</span><span class="p">)</span>
<span class="n">result_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">return</span> <span class="p">(</span><span class="n">result_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,231 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.decorators &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.decorators</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.decorators</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># decorators.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2009-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<div class="viewcode-block" id="singleton"><a class="viewcode-back" href="../../pylorax.html#pylorax.decorators.singleton">[docs]</a><span class="k">def</span> <span class="nf">singleton</span><span class="p">(</span><span class="bp">cls</span><span class="p">):</span>
<span class="n">instances</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">def</span> <span class="nf">get_instance</span><span class="p">():</span>
<span class="k">if</span> <span class="bp">cls</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">instances</span><span class="p">:</span>
<span class="n">instances</span><span class="p">[</span><span class="bp">cls</span><span class="p">]</span> <span class="o">=</span> <span class="bp">cls</span><span class="p">()</span>
<span class="k">return</span> <span class="n">instances</span><span class="p">[</span><span class="bp">cls</span><span class="p">]</span>
<span class="k">return</span> <span class="n">get_instance</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,246 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.discinfo &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.discinfo</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.discinfo</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># discinfo.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2010-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.discinfo&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">time</span>
<div class="viewcode-block" id="DiscInfo"><a class="viewcode-back" href="../../pylorax.html#pylorax.discinfo.DiscInfo">[docs]</a><span class="k">class</span> <span class="nc">DiscInfo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">release</span><span class="p">,</span> <span class="n">basearch</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">release</span> <span class="o">=</span> <span class="n">release</span>
<span class="bp">self</span><span class="o">.</span><span class="n">basearch</span> <span class="o">=</span> <span class="n">basearch</span>
<div class="viewcode-block" id="DiscInfo.write"><a class="viewcode-back" href="../../pylorax.html#pylorax.discinfo.DiscInfo.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="k">if</span> <span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span>
<span class="n">timestamp</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span><span class="p">])</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">timestamp</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;writing .discinfo file&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fobj</span><span class="p">:</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0:f}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">timestamp</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0.release}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0.basearch}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">))</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,388 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.dnfbase &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.dnfbase</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.dnfbase</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright (C) 2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;pylorax&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">dnf</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">from</span> <span class="nn">pylorax</span> <span class="kn">import</span> <span class="n">DEFAULT_PLATFORM_ID</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">flatconfig</span>
<div class="viewcode-block" id="get_dnf_base_object"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfbase.get_dnf_base_object">[docs]</a><span class="k">def</span> <span class="nf">get_dnf_base_object</span><span class="p">(</span><span class="n">installroot</span><span class="p">,</span> <span class="n">sources</span><span class="p">,</span> <span class="n">mirrorlists</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">repos</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">enablerepos</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">disablerepos</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">tempdir</span><span class="o">=</span><span class="s2">&quot;/var/tmp&quot;</span><span class="p">,</span> <span class="n">proxy</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">releasever</span><span class="o">=</span><span class="s2">&quot;32&quot;</span><span class="p">,</span>
<span class="n">cachedir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">logdir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">sslverify</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">dnfplugins</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Create a dnf Base object and setup the repositories and installroot</span>
<span class="sd"> :param string installroot: Full path to the installroot</span>
<span class="sd"> :param list sources: List of source repo urls to use for the installation</span>
<span class="sd"> :param list enablerepos: List of repo names to enable</span>
<span class="sd"> :param list disablerepos: List of repo names to disable</span>
<span class="sd"> :param list mirrorlist: List of mirrors to use</span>
<span class="sd"> :param string tempdir: Path of temporary directory</span>
<span class="sd"> :param string proxy: http proxy to use when fetching packages</span>
<span class="sd"> :param string releasever: Release version to pass to dnf</span>
<span class="sd"> :param string cachedir: Directory to use for caching packages</span>
<span class="sd"> :param bool noverifyssl: Set to True to ignore the CA of ssl certs. eg. use self-signed ssl for https repos.</span>
<span class="sd"> If tempdir is not set /var/tmp is used.</span>
<span class="sd"> If cachedir is None a dnf.cache directory is created inside tmpdir</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">sanitize_repo</span><span class="p">(</span><span class="n">repo</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Convert bare paths to file:/// URIs, and silently reject protocols unhandled by yum&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">repo</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="s2">&quot;file://</span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">repo</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">any</span><span class="p">(</span><span class="n">repo</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="n">p</span><span class="p">)</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">(</span><span class="s1">&#39;http://&#39;</span><span class="p">,</span> <span class="s1">&#39;https://&#39;</span><span class="p">,</span> <span class="s1">&#39;ftp://&#39;</span><span class="p">,</span> <span class="s1">&#39;file://&#39;</span><span class="p">)):</span>
<span class="k">return</span> <span class="n">repo</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="n">mirrorlists</span> <span class="o">=</span> <span class="n">mirrorlists</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="c1"># sanitize the repositories</span>
<span class="n">sources</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">sanitize_repo</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">sources</span><span class="p">)</span>
<span class="n">mirrorlists</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">sanitize_repo</span><span class="p">(</span><span class="n">r</span><span class="p">)</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">mirrorlists</span><span class="p">)</span>
<span class="c1"># remove invalid repositories</span>
<span class="n">sources</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">r</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">sources</span> <span class="k">if</span> <span class="n">r</span><span class="p">)</span>
<span class="n">mirrorlists</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">r</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">mirrorlists</span> <span class="k">if</span> <span class="n">r</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">cachedir</span><span class="p">:</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">join</span><span class="p">(</span><span class="n">tempdir</span><span class="p">,</span> <span class="s2">&quot;dnf.cache&quot;</span><span class="p">)</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">cachedir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">cachedir</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">logdir</span><span class="p">:</span>
<span class="n">logdir</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">join</span><span class="p">(</span><span class="n">tempdir</span><span class="p">,</span> <span class="s2">&quot;dnf.logs&quot;</span><span class="p">)</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">logdir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">logdir</span><span class="p">)</span>
<span class="n">dnfbase</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">Base</span><span class="p">()</span>
<span class="c1"># Enable DNF pluings</span>
<span class="c1"># NOTE: These come from the HOST system&#39;s environment</span>
<span class="k">if</span> <span class="n">dnfplugins</span><span class="p">:</span>
<span class="k">if</span> <span class="n">dnfplugins</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s2">&quot;*&quot;</span><span class="p">:</span>
<span class="c1"># Enable them all</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">init_plugins</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Only enable the listed plugins</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">init_plugins</span><span class="p">(</span><span class="n">disabled_glob</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;*&quot;</span><span class="p">],</span> <span class="n">enable_plugins</span><span class="o">=</span><span class="n">dnfplugins</span><span class="p">)</span>
<span class="n">conf</span> <span class="o">=</span> <span class="n">dnfbase</span><span class="o">.</span><span class="n">conf</span>
<span class="n">conf</span><span class="o">.</span><span class="n">logdir</span> <span class="o">=</span> <span class="n">logdir</span>
<span class="n">conf</span><span class="o">.</span><span class="n">cachedir</span> <span class="o">=</span> <span class="n">cachedir</span>
<span class="n">conf</span><span class="o">.</span><span class="n">install_weak_deps</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">conf</span><span class="o">.</span><span class="n">releasever</span> <span class="o">=</span> <span class="n">releasever</span>
<span class="n">conf</span><span class="o">.</span><span class="n">installroot</span> <span class="o">=</span> <span class="n">installroot</span>
<span class="n">conf</span><span class="o">.</span><span class="n">prepend_installroot</span><span class="p">(</span><span class="s1">&#39;persistdir&#39;</span><span class="p">)</span>
<span class="c1"># this is a weird &#39;AppendOption&#39; thing that, when you set it,</span>
<span class="c1"># actually appends. Doing this adds &#39;nodocs&#39; to the existing list</span>
<span class="c1"># of values, over in libdnf, it does not replace the existing values.</span>
<span class="n">conf</span><span class="o">.</span><span class="n">tsflags</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;nodocs&#39;</span><span class="p">]</span>
<span class="c1"># Log details about the solver</span>
<span class="n">conf</span><span class="o">.</span><span class="n">debug_solver</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">if</span> <span class="n">proxy</span><span class="p">:</span>
<span class="n">conf</span><span class="o">.</span><span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span>
<span class="k">if</span> <span class="n">sslverify</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
<span class="n">conf</span><span class="o">.</span><span class="n">sslverify</span> <span class="o">=</span> <span class="kc">False</span>
<span class="c1"># DNF 3.2 needs to have module_platform_id set, otherwise depsolve won&#39;t work correctly</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">exists</span><span class="p">(</span><span class="s2">&quot;/etc/os-release&quot;</span><span class="p">):</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;/etc/os-release is missing, cannot determine platform id, falling back to </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">DEFAULT_PLATFORM_ID</span><span class="p">)</span>
<span class="n">platform_id</span> <span class="o">=</span> <span class="n">DEFAULT_PLATFORM_ID</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">os_release</span> <span class="o">=</span> <span class="n">flatconfig</span><span class="p">(</span><span class="s2">&quot;/etc/os-release&quot;</span><span class="p">)</span>
<span class="n">platform_id</span> <span class="o">=</span> <span class="n">os_release</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PLATFORM_ID&quot;</span><span class="p">,</span> <span class="n">DEFAULT_PLATFORM_ID</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="s2">&quot;Using </span><span class="si">%s</span><span class="s2"> for module_platform_id&quot;</span><span class="p">,</span> <span class="n">platform_id</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">module_platform_id</span> <span class="o">=</span> <span class="n">platform_id</span>
<span class="c1"># Add .repo files</span>
<span class="k">if</span> <span class="n">repos</span><span class="p">:</span>
<span class="n">reposdir</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">join</span><span class="p">(</span><span class="n">tempdir</span><span class="p">,</span> <span class="s2">&quot;dnf.repos&quot;</span><span class="p">)</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">reposdir</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">reposdir</span><span class="p">)</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">repos</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">r</span><span class="p">,</span> <span class="n">reposdir</span><span class="p">)</span>
<span class="n">conf</span><span class="o">.</span><span class="n">reposdir</span> <span class="o">=</span> <span class="p">[</span><span class="n">reposdir</span><span class="p">]</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">read_all_repos</span><span class="p">()</span>
<span class="c1"># add the sources</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">sources</span><span class="p">):</span>
<span class="k">if</span> <span class="s2">&quot;SRPM&quot;</span> <span class="ow">in</span> <span class="n">r</span> <span class="ow">or</span> <span class="s2">&quot;srpm&quot;</span> <span class="ow">in</span> <span class="n">r</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="s2">&quot;Skipping source repo: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">repo_name</span> <span class="o">=</span> <span class="s2">&quot;lorax-repo-</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">repo</span><span class="o">.</span><span class="n">Repo</span><span class="p">(</span><span class="n">repo_name</span><span class="p">,</span> <span class="n">conf</span><span class="p">)</span>
<span class="n">repo</span><span class="o">.</span><span class="n">baseurl</span> <span class="o">=</span> <span class="p">[</span><span class="n">r</span><span class="p">]</span>
<span class="k">if</span> <span class="n">proxy</span><span class="p">:</span>
<span class="n">repo</span><span class="o">.</span><span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span>
<span class="n">repo</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">repo</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="s2">&quot;Added &#39;</span><span class="si">%s</span><span class="s2">&#39;: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repo_name</span><span class="p">,</span> <span class="n">r</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="s2">&quot;Fetching metadata...&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">repo</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">RepoError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Error fetching metadata for </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repo_name</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="c1"># add the mirrorlists</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">mirrorlists</span><span class="p">):</span>
<span class="k">if</span> <span class="s2">&quot;SRPM&quot;</span> <span class="ow">in</span> <span class="n">r</span> <span class="ow">or</span> <span class="s2">&quot;srpm&quot;</span> <span class="ow">in</span> <span class="n">r</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="s2">&quot;Skipping source repo: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">repo_name</span> <span class="o">=</span> <span class="s2">&quot;lorax-mirrorlist-</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">i</span>
<span class="n">repo</span> <span class="o">=</span> <span class="n">dnf</span><span class="o">.</span><span class="n">repo</span><span class="o">.</span><span class="n">Repo</span><span class="p">(</span><span class="n">repo_name</span><span class="p">,</span> <span class="n">conf</span><span class="p">)</span>
<span class="n">repo</span><span class="o">.</span><span class="n">mirrorlist</span> <span class="o">=</span> <span class="n">r</span>
<span class="k">if</span> <span class="n">proxy</span><span class="p">:</span>
<span class="n">repo</span><span class="o">.</span><span class="n">proxy</span> <span class="o">=</span> <span class="n">proxy</span>
<span class="n">repo</span><span class="o">.</span><span class="n">enable</span><span class="p">()</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">repo</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="s2">&quot;Added &#39;</span><span class="si">%s</span><span class="s2">&#39;: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repo_name</span><span class="p">,</span> <span class="n">r</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="s2">&quot;Fetching metadata...&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">repo</span><span class="o">.</span><span class="n">load</span><span class="p">()</span>
<span class="k">except</span> <span class="n">dnf</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">RepoError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Error fetching metadata for </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">repo_name</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="c1"># Enable repos listed on the cmdline</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">enablerepos</span><span class="p">:</span>
<span class="n">repolist</span> <span class="o">=</span> <span class="n">dnfbase</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">get_matching</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">repolist</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is an unknown repo, not enabling it&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">repolist</span><span class="o">.</span><span class="n">enable</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="s2">&quot;Enabled repo </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="c1"># Disable repos listed on the cmdline</span>
<span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="n">disablerepos</span><span class="p">:</span>
<span class="n">repolist</span> <span class="o">=</span> <span class="n">dnfbase</span><span class="o">.</span><span class="n">repos</span><span class="o">.</span><span class="n">get_matching</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">repolist</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> is an unknown repo, not disabling it&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">repolist</span><span class="o">.</span><span class="n">disable</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="s2">&quot;Disabled repo </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">r</span><span class="p">)</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">fill_sack</span><span class="p">(</span><span class="n">load_system_repo</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="n">dnfbase</span><span class="o">.</span><span class="n">read_comps</span><span class="p">()</span>
<span class="k">return</span> <span class="n">dnfbase</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,311 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.dnfhelper &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.dnfhelper</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.dnfhelper</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># dnfhelper.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2010-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1"># Brian C. Lane &lt;bcl@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.dnfhelper&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">dnf</span>
<span class="kn">import</span> <span class="nn">dnf.transaction</span>
<span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">pylorax.output</span> <span class="k">as</span> <span class="nn">output</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;LoraxDownloadCallback&#39;</span><span class="p">,</span> <span class="s1">&#39;LoraxRpmCallback&#39;</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">_paced</span><span class="p">(</span><span class="n">fn</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Execute `fn` no more often then every 2 seconds.&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">paced_fn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">):</span>
<span class="n">now</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="k">if</span> <span class="n">now</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">last_time</span> <span class="o">&lt;</span> <span class="mi">2</span><span class="p">:</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">last_time</span> <span class="o">=</span> <span class="n">now</span>
<span class="k">return</span> <span class="n">fn</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">)</span>
<span class="k">return</span> <span class="n">paced_fn</span>
<div class="viewcode-block" id="LoraxDownloadCallback"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxDownloadCallback">[docs]</a><span class="k">class</span> <span class="nc">LoraxDownloadCallback</span><span class="p">(</span><span class="n">dnf</span><span class="o">.</span><span class="n">callback</span><span class="o">.</span><span class="n">DownloadProgress</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">downloads</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">defaultdict</span><span class="p">(</span><span class="nb">int</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">last_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">total_files</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">total_size</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pkgno</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">total</span> <span class="o">=</span> <span class="mi">0</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">LoraxOutput</span><span class="p">()</span>
<span class="nd">@_paced</span>
<span class="k">def</span> <span class="nf">_update</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;Downloading </span><span class="si">%(pkgno)s</span><span class="s2"> / </span><span class="si">%(total_files)s</span><span class="s2"> RPMs, &quot;</span> \
<span class="s2">&quot;</span><span class="si">%(downloaded)s</span><span class="s2"> / </span><span class="si">%(total_size)s</span><span class="s2"> (</span><span class="si">%(percent)d%%</span><span class="s2">) done.</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="n">downloaded</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">downloads</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="n">vals</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;downloaded&#39;</span> <span class="p">:</span> <span class="n">downloaded</span><span class="p">,</span>
<span class="s1">&#39;percent&#39;</span> <span class="p">:</span> <span class="nb">int</span><span class="p">(</span><span class="mi">100</span> <span class="o">*</span> <span class="n">downloaded</span><span class="o">/</span><span class="bp">self</span><span class="o">.</span><span class="n">total_size</span><span class="p">),</span>
<span class="s1">&#39;pkgno&#39;</span> <span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">pkgno</span><span class="p">,</span>
<span class="s1">&#39;total_files&#39;</span> <span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_files</span><span class="p">,</span>
<span class="s1">&#39;total_size&#39;</span> <span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">total_size</span>
<span class="p">}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">output</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">msg</span> <span class="o">%</span> <span class="n">vals</span><span class="p">)</span>
<div class="viewcode-block" id="LoraxDownloadCallback.end"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxDownloadCallback.end">[docs]</a> <span class="k">def</span> <span class="nf">end</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">payload</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
<span class="n">nevra</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span>
<span class="k">if</span> <span class="n">status</span> <span class="ow">is</span> <span class="n">dnf</span><span class="o">.</span><span class="n">callback</span><span class="o">.</span><span class="n">STATUS_OK</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">downloads</span><span class="p">[</span><span class="n">nevra</span><span class="p">]</span> <span class="o">=</span> <span class="n">payload</span><span class="o">.</span><span class="n">download_size</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pkgno</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update</span><span class="p">()</span>
<span class="k">return</span>
<span class="n">logger</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="s2">&quot;Failed to download &#39;</span><span class="si">%s</span><span class="s2">&#39;: </span><span class="si">%d</span><span class="s2"> - </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">nevra</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span></div>
<div class="viewcode-block" id="LoraxDownloadCallback.progress"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxDownloadCallback.progress">[docs]</a> <span class="k">def</span> <span class="nf">progress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">payload</span><span class="p">,</span> <span class="n">done</span><span class="p">):</span>
<span class="n">nevra</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">payload</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">downloads</span><span class="p">[</span><span class="n">nevra</span><span class="p">]</span> <span class="o">=</span> <span class="n">done</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_update</span><span class="p">()</span></div>
<span class="c1"># dnf 2.5.0 adds a new argument, accept it if it is passed</span>
<span class="c1"># pylint: disable=arguments-differ</span>
<div class="viewcode-block" id="LoraxDownloadCallback.start"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxDownloadCallback.start">[docs]</a> <span class="k">def</span> <span class="nf">start</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">total_files</span><span class="p">,</span> <span class="n">total_size</span><span class="p">,</span> <span class="n">total_drpms</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">total_files</span> <span class="o">=</span> <span class="n">total_files</span>
<span class="bp">self</span><span class="o">.</span><span class="n">total_size</span> <span class="o">=</span> <span class="n">total_size</span></div></div>
<div class="viewcode-block" id="LoraxRpmCallback"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxRpmCallback">[docs]</a><span class="k">class</span> <span class="nc">LoraxRpmCallback</span><span class="p">(</span><span class="n">dnf</span><span class="o">.</span><span class="n">callback</span><span class="o">.</span><span class="n">TransactionProgress</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">LoraxRpmCallback</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_last_ts</span> <span class="o">=</span> <span class="kc">None</span>
<div class="viewcode-block" id="LoraxRpmCallback.progress"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxRpmCallback.progress">[docs]</a> <span class="k">def</span> <span class="nf">progress</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">package</span><span class="p">,</span> <span class="n">action</span><span class="p">,</span> <span class="n">ti_done</span><span class="p">,</span> <span class="n">ti_total</span><span class="p">,</span> <span class="n">ts_done</span><span class="p">,</span> <span class="n">ts_total</span><span class="p">):</span>
<span class="k">if</span> <span class="n">action</span> <span class="o">==</span> <span class="n">dnf</span><span class="o">.</span><span class="n">transaction</span><span class="o">.</span><span class="n">PKG_INSTALL</span><span class="p">:</span>
<span class="c1"># do not report same package twice</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_ts</span> <span class="o">==</span> <span class="n">ts_done</span><span class="p">:</span>
<span class="k">return</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_last_ts</span> <span class="o">=</span> <span class="n">ts_done</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s1">&#39;(</span><span class="si">%d</span><span class="s1">/</span><span class="si">%d</span><span class="s1">) </span><span class="si">%s</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">ts_done</span><span class="p">,</span> <span class="n">ts_total</span><span class="p">,</span> <span class="n">package</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">action</span> <span class="o">==</span> <span class="n">dnf</span><span class="o">.</span><span class="n">transaction</span><span class="o">.</span><span class="n">TRANS_POST</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;Performing post-installation setup tasks&quot;</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span></div>
<div class="viewcode-block" id="LoraxRpmCallback.error"><a class="viewcode-back" href="../../pylorax.html#pylorax.dnfhelper.LoraxRpmCallback.error">[docs]</a> <span class="k">def</span> <span class="nf">error</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="n">message</span><span class="p">)</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,550 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.executils &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.executils</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.executils</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># executil.py - subprocess execution utility functions</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 1999-2015</span>
<span class="c1"># Red Hat, Inc. All rights reserved.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">TimeoutExpired</span>
<span class="kn">import</span> <span class="nn">signal</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="s2">&quot;pylorax&quot;</span><span class="p">)</span>
<span class="n">program_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="s2">&quot;program&quot;</span><span class="p">)</span>
<span class="c1"># pylint: disable=not-context-manager</span>
<span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Lock</span>
<span class="n">program_log_lock</span> <span class="o">=</span> <span class="n">Lock</span><span class="p">()</span>
<span class="n">_child_env</span> <span class="o">=</span> <span class="p">{}</span>
<div class="viewcode-block" id="setenv"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.setenv">[docs]</a><span class="k">def</span> <span class="nf">setenv</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Set an environment variable to be used by child processes.</span>
<span class="sd"> This method does not modify os.environ for the running process, which</span>
<span class="sd"> is not thread-safe. If setenv has already been called for a particular</span>
<span class="sd"> variable name, the old value is overwritten.</span>
<span class="sd"> :param str name: The name of the environment variable</span>
<span class="sd"> :param str value: The value of the environment variable</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">_child_env</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">value</span></div>
<div class="viewcode-block" id="augmentEnv"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.augmentEnv">[docs]</a><span class="k">def</span> <span class="nf">augmentEnv</span><span class="p">():</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">env</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">_child_env</span><span class="p">)</span>
<span class="k">return</span> <span class="n">env</span></div>
<div class="viewcode-block" id="ExecProduct"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.ExecProduct">[docs]</a><span class="k">class</span> <span class="nc">ExecProduct</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rc</span><span class="p">,</span> <span class="n">stdout</span><span class="p">,</span> <span class="n">stderr</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">rc</span> <span class="o">=</span> <span class="n">rc</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">stdout</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stderr</span> <span class="o">=</span> <span class="n">stderr</span></div>
<div class="viewcode-block" id="startProgram"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.startProgram">[docs]</a><span class="k">def</span> <span class="nf">startProgram</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span><span class="p">,</span>
<span class="n">env_prune</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">env_add</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Start an external program and return the Popen object.</span>
<span class="sd"> The root and reset_handlers arguments are handled by passing a</span>
<span class="sd"> preexec_fn argument to subprocess.Popen, but an additional preexec_fn</span>
<span class="sd"> can still be specified and will be run. The user preexec_fn will be run</span>
<span class="sd"> last.</span>
<span class="sd"> :param argv: The command to run and argument</span>
<span class="sd"> :param root: The directory to chroot to before running command.</span>
<span class="sd"> :param stdin: The file object to read stdin from.</span>
<span class="sd"> :param stdout: The file object to write stdout to.</span>
<span class="sd"> :param stderr: The file object to write stderr to.</span>
<span class="sd"> :param env_prune: environment variables to remove before execution</span>
<span class="sd"> :param env_add: environment variables to add before execution</span>
<span class="sd"> :param reset_handlers: whether to reset to SIG_DFL any signal handlers set to SIG_IGN</span>
<span class="sd"> :param reset_lang: whether to set the locale of the child process to C</span>
<span class="sd"> :param kwargs: Additional parameters to pass to subprocess.Popen</span>
<span class="sd"> :return: A Popen object for the running command.</span>
<span class="sd"> :keyword preexec_fn: A function to run before execution starts.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">env_prune</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">env_prune</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># Check for and save a preexec_fn argument</span>
<span class="n">preexec_fn</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;preexec_fn&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">preexec</span><span class="p">():</span>
<span class="c1"># If a target root was specificed, chroot into it</span>
<span class="k">if</span> <span class="n">root</span> <span class="ow">and</span> <span class="n">root</span> <span class="o">!=</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">chroot</span><span class="p">(</span><span class="n">root</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">chdir</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">)</span>
<span class="c1"># Signal handlers set to SIG_IGN persist across exec. Reset</span>
<span class="c1"># these to SIG_DFL if requested. In particular this will include the</span>
<span class="c1"># SIGPIPE handler set by python.</span>
<span class="k">if</span> <span class="n">reset_handlers</span><span class="p">:</span>
<span class="k">for</span> <span class="n">signum</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">NSIG</span><span class="p">):</span>
<span class="k">if</span> <span class="n">signal</span><span class="o">.</span><span class="n">getsignal</span><span class="p">(</span><span class="n">signum</span><span class="p">)</span> <span class="o">==</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIG_IGN</span><span class="p">:</span>
<span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signum</span><span class="p">,</span> <span class="n">signal</span><span class="o">.</span><span class="n">SIG_DFL</span><span class="p">)</span>
<span class="c1"># If the user specified an additional preexec_fn argument, run it</span>
<span class="k">if</span> <span class="n">preexec_fn</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">preexec_fn</span><span class="p">()</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Running... </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">argv</span><span class="p">))</span>
<span class="n">env</span> <span class="o">=</span> <span class="n">augmentEnv</span><span class="p">()</span>
<span class="k">for</span> <span class="n">var</span> <span class="ow">in</span> <span class="n">env_prune</span><span class="p">:</span>
<span class="n">env</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">var</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="n">reset_lang</span><span class="p">:</span>
<span class="n">env</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;LC_ALL&quot;</span><span class="p">:</span> <span class="s2">&quot;C&quot;</span><span class="p">})</span>
<span class="k">if</span> <span class="n">env_add</span><span class="p">:</span>
<span class="n">env</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">env_add</span><span class="p">)</span>
<span class="c1"># pylint: disable=subprocess-popen-preexec-fn</span>
<span class="k">return</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span>
<span class="n">stdin</span><span class="o">=</span><span class="n">stdin</span><span class="p">,</span>
<span class="n">stdout</span><span class="o">=</span><span class="n">stdout</span><span class="p">,</span>
<span class="n">stderr</span><span class="o">=</span><span class="n">stderr</span><span class="p">,</span>
<span class="n">close_fds</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">preexec_fn</span><span class="o">=</span><span class="n">preexec</span><span class="p">,</span> <span class="n">cwd</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">env</span><span class="o">=</span><span class="n">env</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<span class="k">def</span> <span class="nf">_run_program</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">env_prune</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">log_output</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">binary_output</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">filter_stderr</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">env_add</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Run an external program, log the output and return it to the caller</span>
<span class="sd"> :param argv: The command to run and argument</span>
<span class="sd"> :param root: The directory to chroot to before running command.</span>
<span class="sd"> :param stdin: The file object to read stdin from.</span>
<span class="sd"> :param stdout: Optional file object to write the output to.</span>
<span class="sd"> :param env_prune: environment variable to remove before execution</span>
<span class="sd"> :param log_output: whether to log the output of command</span>
<span class="sd"> :param binary_output: whether to treat the output of command as binary data</span>
<span class="sd"> :param filter_stderr: whether to exclude the contents of stderr from the returned output</span>
<span class="sd"> :param raise_err: whether to raise a CalledProcessError if the returncode is non-zero</span>
<span class="sd"> :param callback: method to call while waiting for process to finish, passed Popen object</span>
<span class="sd"> :param env_add: environment variables to add before execution</span>
<span class="sd"> :param reset_handlers: whether to reset to SIG_DFL any signal handlers set to SIG_IGN</span>
<span class="sd"> :param reset_lang: whether to set the locale of the child process to C</span>
<span class="sd"> :return: The return code of the command and the output</span>
<span class="sd"> :raises: OSError or CalledProcessError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">if</span> <span class="n">filter_stderr</span><span class="p">:</span>
<span class="n">stderr</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">stderr</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span>
<span class="n">proc</span> <span class="o">=</span> <span class="n">startProgram</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">stderr</span><span class="p">,</span>
<span class="n">env_prune</span><span class="o">=</span><span class="n">env_prune</span><span class="p">,</span> <span class="n">universal_newlines</span><span class="o">=</span><span class="ow">not</span> <span class="n">binary_output</span><span class="p">,</span>
<span class="n">env_add</span><span class="o">=</span><span class="n">env_add</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="n">reset_handlers</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="n">reset_lang</span><span class="p">)</span>
<span class="n">output_string</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">err_string</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">if</span> <span class="n">callback</span><span class="p">:</span>
<span class="k">while</span> <span class="n">callback</span><span class="p">(</span><span class="n">proc</span><span class="p">)</span> <span class="ow">and</span> <span class="n">proc</span><span class="o">.</span><span class="n">poll</span><span class="p">()</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="p">(</span><span class="n">output_string</span><span class="p">,</span> <span class="n">err_string</span><span class="p">)</span> <span class="o">=</span> <span class="n">proc</span><span class="o">.</span><span class="n">communicate</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="k">break</span>
<span class="k">except</span> <span class="n">TimeoutExpired</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">else</span><span class="p">:</span>
<span class="p">(</span><span class="n">output_string</span><span class="p">,</span> <span class="n">err_string</span><span class="p">)</span> <span class="o">=</span> <span class="n">proc</span><span class="o">.</span><span class="n">communicate</span><span class="p">()</span>
<span class="k">if</span> <span class="n">output_string</span><span class="p">:</span>
<span class="k">if</span> <span class="n">binary_output</span><span class="p">:</span>
<span class="n">output_lines</span> <span class="o">=</span> <span class="p">[</span><span class="n">output_string</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="n">output_string</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">!=</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">:</span>
<span class="n">output_string</span> <span class="o">=</span> <span class="n">output_string</span> <span class="o">+</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span>
<span class="n">output_lines</span> <span class="o">=</span> <span class="n">output_string</span><span class="o">.</span><span class="n">splitlines</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="n">log_output</span><span class="p">:</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">output_lines</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="k">if</span> <span class="n">stdout</span><span class="p">:</span>
<span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">output_string</span><span class="p">)</span>
<span class="c1"># If stderr was filtered, log it separately</span>
<span class="k">if</span> <span class="n">filter_stderr</span> <span class="ow">and</span> <span class="n">err_string</span> <span class="ow">and</span> <span class="n">log_output</span><span class="p">:</span>
<span class="n">err_lines</span> <span class="o">=</span> <span class="n">err_string</span><span class="o">.</span><span class="n">splitlines</span><span class="p">(</span><span class="kc">True</span><span class="p">)</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">err_lines</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span>
<span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Error running </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">)</span>
<span class="k">raise</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Return code: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">proc</span><span class="o">.</span><span class="n">returncode</span><span class="p">)</span>
<span class="k">if</span> <span class="n">proc</span><span class="o">.</span><span class="n">returncode</span> <span class="ow">and</span> <span class="n">raise_err</span><span class="p">:</span>
<span class="n">output</span> <span class="o">=</span> <span class="p">(</span><span class="n">output_string</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="n">err_string</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span><span class="p">(</span><span class="n">proc</span><span class="o">.</span><span class="n">returncode</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">output</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">proc</span><span class="o">.</span><span class="n">returncode</span><span class="p">,</span> <span class="n">output_string</span><span class="p">)</span>
<div class="viewcode-block" id="execWithRedirect"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.execWithRedirect">[docs]</a><span class="k">def</span> <span class="nf">execWithRedirect</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">env_prune</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">log_output</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">binary_output</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">env_add</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Run an external program and redirect the output to a file.</span>
<span class="sd"> :param command: The command to run</span>
<span class="sd"> :param argv: The argument list</span>
<span class="sd"> :param stdin: The file object to read stdin from.</span>
<span class="sd"> :param stdout: Optional file object to redirect stdout and stderr to.</span>
<span class="sd"> :param root: The directory to chroot to before running command.</span>
<span class="sd"> :param env_prune: environment variable to remove before execution</span>
<span class="sd"> :param log_output: whether to log the output of command</span>
<span class="sd"> :param binary_output: whether to treat the output of command as binary data</span>
<span class="sd"> :param raise_err: whether to raise a CalledProcessError if the returncode is non-zero</span>
<span class="sd"> :param callback: method to call while waiting for process to finish, passed Popen object</span>
<span class="sd"> :param env_add: environment variables to add before execution</span>
<span class="sd"> :param reset_handlers: whether to reset to SIG_DFL any signal handlers set to SIG_IGN</span>
<span class="sd"> :param reset_lang: whether to set the locale of the child process to C</span>
<span class="sd"> :return: The return code of the command</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">argv</span> <span class="o">=</span> <span class="p">[</span><span class="n">command</span><span class="p">]</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span>
<span class="k">return</span> <span class="n">_run_program</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">stdout</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">env_prune</span><span class="o">=</span><span class="n">env_prune</span><span class="p">,</span>
<span class="n">log_output</span><span class="o">=</span><span class="n">log_output</span><span class="p">,</span> <span class="n">binary_output</span><span class="o">=</span><span class="n">binary_output</span><span class="p">,</span> <span class="n">raise_err</span><span class="o">=</span><span class="n">raise_err</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">,</span>
<span class="n">env_add</span><span class="o">=</span><span class="n">env_add</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="n">reset_handlers</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="n">reset_lang</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>
<div class="viewcode-block" id="execWithCapture"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.execWithCapture">[docs]</a><span class="k">def</span> <span class="nf">execWithCapture</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">log_output</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">filter_stderr</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">raise_err</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">env_add</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Run an external program and capture standard out and err.</span>
<span class="sd"> :param command: The command to run</span>
<span class="sd"> :param argv: The argument list</span>
<span class="sd"> :param stdin: The file object to read stdin from.</span>
<span class="sd"> :param root: The directory to chroot to before running command.</span>
<span class="sd"> :param log_output: Whether to log the output of command</span>
<span class="sd"> :param filter_stderr: Whether stderr should be excluded from the returned output</span>
<span class="sd"> :param callback: method to call while waiting for process to finish, passed Popen object</span>
<span class="sd"> :param env_add: environment variables to add before execution</span>
<span class="sd"> :param reset_handlers: whether to reset to SIG_DFL any signal handlers set to SIG_IGN</span>
<span class="sd"> :param reset_lang: whether to set the locale of the child process to C</span>
<span class="sd"> :return: The output of the command</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">argv</span> <span class="o">=</span> <span class="p">[</span><span class="n">command</span><span class="p">]</span> <span class="o">+</span> <span class="nb">list</span><span class="p">(</span><span class="n">argv</span><span class="p">)</span>
<span class="k">return</span> <span class="n">_run_program</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">stdin</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">log_output</span><span class="o">=</span><span class="n">log_output</span><span class="p">,</span> <span class="n">filter_stderr</span><span class="o">=</span><span class="n">filter_stderr</span><span class="p">,</span>
<span class="n">raise_err</span><span class="o">=</span><span class="n">raise_err</span><span class="p">,</span> <span class="n">callback</span><span class="o">=</span><span class="n">callback</span><span class="p">,</span> <span class="n">env_add</span><span class="o">=</span><span class="n">env_add</span><span class="p">,</span>
<span class="n">reset_handlers</span><span class="o">=</span><span class="n">reset_handlers</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="n">reset_lang</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span></div>
<div class="viewcode-block" id="execReadlines"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.execReadlines">[docs]</a><span class="k">def</span> <span class="nf">execReadlines</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="n">env_prune</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">filter_stderr</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">callback</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="kc">True</span><span class="p">,</span> <span class="n">env_add</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Execute an external command and return the line output of the command</span>
<span class="sd"> in real-time.</span>
<span class="sd"> This method assumes that there is a reasonably low delay between the</span>
<span class="sd"> end of output and the process exiting. If the child process closes</span>
<span class="sd"> stdout and then keeps on truckin&#39; there will be problems.</span>
<span class="sd"> NOTE/WARNING: UnicodeDecodeError will be raised if the output of the</span>
<span class="sd"> external command can&#39;t be decoded as UTF-8.</span>
<span class="sd"> :param command: The command to run</span>
<span class="sd"> :param argv: The argument list</span>
<span class="sd"> :param stdin: The file object to read stdin from.</span>
<span class="sd"> :param stdout: Optional file object to redirect stdout and stderr to.</span>
<span class="sd"> :param root: The directory to chroot to before running command.</span>
<span class="sd"> :param env_prune: environment variable to remove before execution</span>
<span class="sd"> :param filter_stderr: Whether stderr should be excluded from the returned output</span>
<span class="sd"> :param callback: method to call while waiting for process to finish, passed Popen object</span>
<span class="sd"> :param env_add: environment variables to add before execution</span>
<span class="sd"> :param reset_handlers: whether to reset to SIG_DFL any signal handlers set to SIG_IGN</span>
<span class="sd"> :param reset_lang: whether to set the locale of the child process to C</span>
<span class="sd"> :return: Iterator of the lines from the command</span>
<span class="sd"> Output from the file is not logged to program.log</span>
<span class="sd"> This returns an iterator with the lines from the command until it has finished</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">class</span> <span class="nc">ExecLineReader</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Iterator class for returning lines from a process and cleaning</span>
<span class="sd"> up the process when the output is no longer needed.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">proc</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">callback</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_proc</span> <span class="o">=</span> <span class="n">proc</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_argv</span> <span class="o">=</span> <span class="n">argv</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_callback</span> <span class="o">=</span> <span class="n">callback</span>
<span class="k">def</span> <span class="fm">__iter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="bp">self</span>
<span class="k">def</span> <span class="fm">__del__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># See if the process is still running</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">poll</span><span class="p">()</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="c1"># Stop the process and ignore any problems that might arise</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">def</span> <span class="fm">__next__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># Read the next line, blocking if a line is not yet available</span>
<span class="n">line</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">line</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_callback</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="p">):</span>
<span class="c1"># Output finished, wait for the process to end</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">communicate</span><span class="p">()</span>
<span class="c1"># Check for successful exit</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">returncode</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">OSError</span><span class="p">(</span><span class="s2">&quot;process &#39;</span><span class="si">%s</span><span class="s2">&#39; was killed by signal </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span>
<span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_argv</span><span class="p">,</span> <span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">returncode</span><span class="p">))</span>
<span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">returncode</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">OSError</span><span class="p">(</span><span class="s2">&quot;process &#39;</span><span class="si">%s</span><span class="s2">&#39; exited with status </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span>
<span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_argv</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_proc</span><span class="o">.</span><span class="n">returncode</span><span class="p">))</span>
<span class="k">raise</span> <span class="ne">StopIteration</span>
<span class="k">return</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="n">argv</span> <span class="o">=</span> <span class="p">[</span><span class="n">command</span><span class="p">]</span> <span class="o">+</span> <span class="n">argv</span>
<span class="k">if</span> <span class="n">filter_stderr</span><span class="p">:</span>
<span class="n">stderr</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">DEVNULL</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">stderr</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">STDOUT</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">proc</span> <span class="o">=</span> <span class="n">startProgram</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stderr</span><span class="o">=</span><span class="n">stderr</span><span class="p">,</span>
<span class="n">env_prune</span><span class="o">=</span><span class="n">env_prune</span><span class="p">,</span> <span class="n">env_add</span><span class="o">=</span><span class="n">env_add</span><span class="p">,</span> <span class="n">reset_handlers</span><span class="o">=</span><span class="n">reset_handlers</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="n">reset_lang</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">with</span> <span class="n">program_log_lock</span><span class="p">:</span>
<span class="n">program_log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Error running </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">e</span><span class="o">.</span><span class="n">strerror</span><span class="p">)</span>
<span class="k">raise</span>
<span class="k">return</span> <span class="n">ExecLineReader</span><span class="p">(</span><span class="n">proc</span><span class="p">,</span> <span class="n">argv</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span></div>
<div class="viewcode-block" id="runcmd"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.runcmd">[docs]</a><span class="k">def</span> <span class="nf">runcmd</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; run execWithRedirect with raise_err=True</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;raise_err&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">return</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="n">cmd</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cmd</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="runcmd_output"><a class="viewcode-back" href="../../pylorax.html#pylorax.executils.runcmd_output">[docs]</a><span class="k">def</span> <span class="nf">runcmd_output</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; run execWithCapture with raise_err=True</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s2">&quot;raise_err&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">return</span> <span class="n">execWithCapture</span><span class="p">(</span><span class="n">cmd</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">cmd</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,755 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.imgutils &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.imgutils</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.imgutils</h1><div class="highlight"><pre>
<span></span><span class="c1"># imgutils.py - utility functions/classes for building disk images</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Author(s): Will Woods &lt;wwoods@redhat.com&gt;</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.imgutils&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">tempfile</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">dirname</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">Popen</span><span class="p">,</span> <span class="n">PIPE</span><span class="p">,</span> <span class="n">CalledProcessError</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">import</span> <span class="nn">traceback</span>
<span class="kn">import</span> <span class="nn">multiprocessing</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">sleep</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">cpfile</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">execWithRedirect</span><span class="p">,</span> <span class="n">execWithCapture</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">runcmd</span><span class="p">,</span> <span class="n">runcmd_output</span>
<span class="c1">######## Functions for making container images (cpio, tar, squashfs) ##########</span>
<div class="viewcode-block" id="compress"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.compress">[docs]</a><span class="k">def</span> <span class="nf">compress</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Make a compressed archive of the given rootdir or file.</span>
<span class="sd"> command is a list of the archiver commands to run</span>
<span class="sd"> compression should be &quot;xz&quot;, &quot;gzip&quot;, &quot;lzma&quot;, &quot;bzip2&quot;, or None.</span>
<span class="sd"> compressargs will be used on the compression commandline.&#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">compression</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="s2">&quot;gzip&quot;</span><span class="p">,</span> <span class="s2">&quot;lzma&quot;</span><span class="p">,</span> <span class="s2">&quot;bzip2&quot;</span><span class="p">):</span>
<span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Unknown compression type </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">compression</span><span class="p">)</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</span> <span class="p">[</span><span class="s2">&quot;-9&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">compression</span> <span class="o">==</span> <span class="s2">&quot;xz&quot;</span><span class="p">:</span>
<span class="n">compressargs</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;--check=crc32&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">compression</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">compression</span> <span class="o">=</span> <span class="s2">&quot;cat&quot;</span> <span class="c1"># this is a little silly</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="c1"># make compression run with multiple threads if possible</span>
<span class="k">if</span> <span class="n">compression</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="s2">&quot;lzma&quot;</span><span class="p">):</span>
<span class="n">compressargs</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;-T</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">())</span>
<span class="k">elif</span> <span class="n">compression</span> <span class="o">==</span> <span class="s2">&quot;gzip&quot;</span><span class="p">:</span>
<span class="n">compression</span> <span class="o">=</span> <span class="s2">&quot;pigz&quot;</span>
<span class="n">compressargs</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;-p</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">())</span>
<span class="k">elif</span> <span class="n">compression</span> <span class="o">==</span> <span class="s2">&quot;bzip2&quot;</span><span class="p">:</span>
<span class="n">compression</span> <span class="o">=</span> <span class="s2">&quot;pbzip2&quot;</span>
<span class="n">compressargs</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;-p</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">cpu_count</span><span class="p">())</span>
<span class="n">find</span><span class="p">,</span> <span class="n">archive</span><span class="p">,</span> <span class="n">comp</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">,</span> <span class="kc">None</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">if</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">root</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;find </span><span class="si">%s</span><span class="s2"> -print0 |</span><span class="si">%s</span><span class="s2"> | </span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> &gt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">root</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">command</span><span class="p">),</span>
<span class="n">compression</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">compressargs</span><span class="p">),</span> <span class="n">outfile</span><span class="p">)</span>
<span class="n">find</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">([</span><span class="s2">&quot;find&quot;</span><span class="p">,</span> <span class="s2">&quot;.&quot;</span><span class="p">,</span> <span class="s2">&quot;-print0&quot;</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">cwd</span><span class="o">=</span><span class="n">root</span><span class="p">)</span>
<span class="n">archive</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">find</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">cwd</span><span class="o">=</span><span class="n">root</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;echo </span><span class="si">%s</span><span class="s2"> |</span><span class="si">%s</span><span class="s2"> | </span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2"> &gt; </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">root</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">command</span><span class="p">),</span>
<span class="n">compression</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">compressargs</span><span class="p">),</span> <span class="n">outfile</span><span class="p">)</span>
<span class="n">archive</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">(</span><span class="n">command</span><span class="p">,</span> <span class="n">stdin</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="n">PIPE</span><span class="p">,</span> <span class="n">cwd</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">dirname</span><span class="p">(</span><span class="n">root</span><span class="p">))</span>
<span class="n">archive</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">write</span><span class="p">(</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">root</span><span class="p">)</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">&quot;utf-8&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="sa">b</span><span class="s2">&quot;</span><span class="se">\0</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">archive</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="n">comp</span> <span class="o">=</span> <span class="n">Popen</span><span class="p">([</span><span class="n">compression</span><span class="p">]</span> <span class="o">+</span> <span class="n">compressargs</span><span class="p">,</span>
<span class="n">stdin</span><span class="o">=</span><span class="n">archive</span><span class="o">.</span><span class="n">stdout</span><span class="p">,</span> <span class="n">stdout</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;wb&quot;</span><span class="p">))</span>
<span class="n">comp</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
<span class="k">return</span> <span class="n">comp</span><span class="o">.</span><span class="n">returncode</span>
<span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
<span class="c1"># Kill off any hanging processes</span>
<span class="nb">list</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">kill</span><span class="p">()</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="p">(</span><span class="n">find</span><span class="p">,</span> <span class="n">archive</span><span class="p">,</span> <span class="n">comp</span><span class="p">)</span> <span class="k">if</span> <span class="n">p</span><span class="p">)</span>
<span class="k">return</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="mkcpio"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkcpio">[docs]</a><span class="k">def</span> <span class="nf">mkcpio</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</span> <span class="p">[</span><span class="s2">&quot;-9&quot;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">compress</span><span class="p">([</span><span class="s2">&quot;cpio&quot;</span><span class="p">,</span> <span class="s2">&quot;--null&quot;</span><span class="p">,</span> <span class="s2">&quot;--quiet&quot;</span><span class="p">,</span> <span class="s2">&quot;-H&quot;</span><span class="p">,</span> <span class="s2">&quot;newc&quot;</span><span class="p">,</span> <span class="s2">&quot;-o&quot;</span><span class="p">],</span>
<span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="mktar"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mktar">[docs]</a><span class="k">def</span> <span class="nf">mktar</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">selinux</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</span> <span class="p">[</span><span class="s2">&quot;-9&quot;</span><span class="p">]</span>
<span class="n">tar_cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;tar&quot;</span><span class="p">,</span> <span class="s2">&quot;--no-recursion&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">selinux</span><span class="p">:</span>
<span class="n">tar_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--selinux&quot;</span><span class="p">,</span> <span class="s2">&quot;--acls&quot;</span><span class="p">,</span> <span class="s2">&quot;--xattrs&quot;</span><span class="p">]</span>
<span class="n">tar_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-cf-&quot;</span><span class="p">,</span> <span class="s2">&quot;--null&quot;</span><span class="p">,</span> <span class="s2">&quot;-T-&quot;</span><span class="p">]</span>
<span class="k">return</span> <span class="n">compress</span><span class="p">(</span><span class="n">tar_cmd</span><span class="p">,</span> <span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="mksquashfs"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mksquashfs">[docs]</a><span class="k">def</span> <span class="nf">mksquashfs</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;default&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Make a squashfs image containing the given rootdir.&#39;&#39;&#39;</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="k">if</span> <span class="n">compression</span> <span class="o">!=</span> <span class="s2">&quot;default&quot;</span><span class="p">:</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;-comp&quot;</span><span class="p">,</span> <span class="n">compression</span><span class="p">]</span> <span class="o">+</span> <span class="n">compressargs</span>
<span class="k">return</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;mksquashfs&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">]</span> <span class="o">+</span> <span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkrootfsimg"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkrootfsimg">[docs]</a><span class="k">def</span> <span class="nf">mkrootfsimg</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span> <span class="n">sysroot</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Make rootfs image from a directory</span>
<span class="sd"> :param str rootdir: Root directory</span>
<span class="sd"> :param str outfile: Path of output image file</span>
<span class="sd"> :param str label: Filesystem label</span>
<span class="sd"> :param int size: Size of the image in GiB, if None computed automatically</span>
<span class="sd"> :param str sysroot: path to system (deployment) root relative to physical root</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">size</span><span class="p">:</span>
<span class="n">fssize</span> <span class="o">=</span> <span class="n">size</span> <span class="o">*</span> <span class="p">(</span><span class="mi">1024</span><span class="o">*</span><span class="mi">1024</span><span class="o">*</span><span class="mi">1024</span><span class="p">)</span> <span class="c1"># 2GB sparse file compresses down to nothin&#39;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">fssize</span> <span class="o">=</span> <span class="kc">None</span> <span class="c1"># Let mkext4img figure out the needed size</span>
<span class="n">mkext4img</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">fssize</span><span class="p">)</span></div>
<span class="c1">######## Utility functions ###############################################</span>
<div class="viewcode-block" id="mksparse"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mksparse">[docs]</a><span class="k">def</span> <span class="nf">mksparse</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;use os.ftruncate to create a sparse file of the given size.&#39;&#39;&#39;</span>
<span class="n">fobj</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">ftruncate</span><span class="p">(</span><span class="n">fobj</span><span class="o">.</span><span class="n">fileno</span><span class="p">(),</span> <span class="n">size</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkqcow2"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkqcow2">[docs]</a><span class="k">def</span> <span class="nf">mkqcow2</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;use qemu-img to create a file of the given size.</span>
<span class="sd"> options is a list of options passed to qemu-img</span>
<span class="sd"> Default format is qcow2, override by passing &quot;-f&quot;, fmt</span>
<span class="sd"> in options.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">mkqemu_img</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkqemu_img"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkqemu_img">[docs]</a><span class="k">def</span> <span class="nf">mkqemu_img</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;use qemu-img to create a file of the given size.</span>
<span class="sd"> options is a list of options passed to qemu-img</span>
<span class="sd"> Default format is qcow2, override by passing &quot;-f&quot;, fmt</span>
<span class="sd"> in options.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">options</span> <span class="o">=</span> <span class="n">options</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="k">if</span> <span class="s2">&quot;-f&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">options</span><span class="p">:</span>
<span class="n">options</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="s2">&quot;qcow2&quot;</span><span class="p">])</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;qemu-img&quot;</span><span class="p">,</span> <span class="s2">&quot;create&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">options</span> <span class="o">+</span> <span class="p">[</span><span class="n">outfile</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">size</span><span class="p">)])</span></div>
<div class="viewcode-block" id="loop_waitfor"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.loop_waitfor">[docs]</a><span class="k">def</span> <span class="nf">loop_waitfor</span><span class="p">(</span><span class="n">loop_dev</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Make sure the loop device is attached to the outfile.</span>
<span class="sd"> It seems that on rare occasions losetup can return before the /dev/loopX is</span>
<span class="sd"> ready for use, causing problems with mkfs. This tries to make sure that the</span>
<span class="sd"> loop device really is associated with the backing file before continuing.</span>
<span class="sd"> Raise RuntimeError if it isn&#39;t setup after 5 tries.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">_x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">5</span><span class="p">):</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;udevadm&quot;</span><span class="p">,</span> <span class="s2">&quot;settle&quot;</span><span class="p">,</span> <span class="s2">&quot;--timeout&quot;</span><span class="p">,</span> <span class="s2">&quot;300&quot;</span><span class="p">])</span>
<span class="c1">## XXX Note that losetup --list output can be truncated to 64 bytes in some</span>
<span class="c1">## situations. Don&#39;t use it to lookup backing file, go the other way</span>
<span class="c1">## and lookup the loop for the backing file. See util-linux lib/loopdev.c</span>
<span class="c1">## loopcxt_get_backing_file()</span>
<span class="k">if</span> <span class="n">get_loop_name</span><span class="p">(</span><span class="n">outfile</span><span class="p">)</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">loop_dev</span><span class="p">):</span>
<span class="k">return</span>
<span class="c1"># If this really is a race, give it some time to settle down</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;Unable to setup </span><span class="si">%s</span><span class="s2"> on </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">loop_dev</span><span class="p">,</span> <span class="n">outfile</span><span class="p">))</span></div>
<div class="viewcode-block" id="loop_attach"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.loop_attach">[docs]</a><span class="k">def</span> <span class="nf">loop_attach</span><span class="p">(</span><span class="n">outfile</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Attach a loop device to the given file. Return the loop device name.</span>
<span class="sd"> On rare occasions it appears that the device never shows up, some experiments</span>
<span class="sd"> seem to indicate that it may be a race with another process using /dev/loop* devices.</span>
<span class="sd"> So we now try 3 times before actually failing.</span>
<span class="sd"> Raises CalledProcessError if losetup fails.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">retries</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">retries</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">dev</span> <span class="o">=</span> <span class="n">runcmd_output</span><span class="p">([</span><span class="s2">&quot;losetup&quot;</span><span class="p">,</span> <span class="s2">&quot;--find&quot;</span><span class="p">,</span> <span class="s2">&quot;--show&quot;</span><span class="p">,</span> <span class="n">outfile</span><span class="p">])</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="c1"># Sometimes the loop device isn&#39;t ready yet, make extra sure before returning</span>
<span class="n">loop_waitfor</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">outfile</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">RuntimeError</span><span class="p">:</span>
<span class="c1"># Try to setup the loop device 3 times</span>
<span class="k">if</span> <span class="n">retries</span> <span class="o">==</span> <span class="mi">3</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;loop_attach failed, retries exhausted.&quot;</span><span class="p">)</span>
<span class="k">raise</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Try </span><span class="si">%d</span><span class="s2"> failed, </span><span class="si">%s</span><span class="s2"> did not appear.&quot;</span><span class="p">,</span> <span class="n">retries</span><span class="p">,</span> <span class="n">dev</span><span class="p">)</span>
<span class="k">break</span>
<span class="k">return</span> <span class="n">dev</span></div>
<div class="viewcode-block" id="loop_detach"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.loop_detach">[docs]</a><span class="k">def</span> <span class="nf">loop_detach</span><span class="p">(</span><span class="n">loopdev</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Detach the given loop device. Return False on failure.&#39;&#39;&#39;</span>
<span class="k">return</span> <span class="p">(</span><span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;losetup&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;--detach&quot;</span><span class="p">,</span> <span class="n">loopdev</span><span class="p">])</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span></div>
<div class="viewcode-block" id="get_loop_name"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.get_loop_name">[docs]</a><span class="k">def</span> <span class="nf">get_loop_name</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Return the loop device associated with the path.</span>
<span class="sd"> Raises RuntimeError if more than one loop is associated&#39;&#39;&#39;</span>
<span class="n">buf</span> <span class="o">=</span> <span class="n">runcmd_output</span><span class="p">([</span><span class="s2">&quot;losetup&quot;</span><span class="p">,</span> <span class="s2">&quot;-j&quot;</span><span class="p">,</span> <span class="n">path</span><span class="p">])</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">buf</span><span class="o">.</span><span class="n">splitlines</span><span class="p">())</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="c1"># there should never be more than one loop device listed</span>
<span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s2">&quot;multiple loops associated with </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">path</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">buf</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;:&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
<span class="k">return</span> <span class="n">name</span></div>
<div class="viewcode-block" id="dm_attach"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.dm_attach">[docs]</a><span class="k">def</span> <span class="nf">dm_attach</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Attach a devicemapper device to the given device, with the given size.</span>
<span class="sd"> If name is None, a random name will be chosen. Returns the device name.</span>
<span class="sd"> raises CalledProcessError if dmsetup fails.&#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">name</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">name</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lorax.imgutils.&quot;</span><span class="p">,</span> <span class="nb">dir</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;dmsetup&quot;</span><span class="p">,</span> <span class="s2">&quot;create&quot;</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="s2">&quot;--table&quot;</span><span class="p">,</span>
<span class="s2">&quot;0 </span><span class="si">%i</span><span class="s2"> linear </span><span class="si">%s</span><span class="s2"> 0&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">size</span><span class="o">/</span><span class="mi">512</span><span class="p">,</span> <span class="n">dev</span><span class="p">)])</span>
<span class="k">return</span> <span class="n">name</span></div>
<div class="viewcode-block" id="dm_detach"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.dm_detach">[docs]</a><span class="k">def</span> <span class="nf">dm_detach</span><span class="p">(</span><span class="n">dev</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Detach the named devicemapper device. Returns False if dmsetup fails.&#39;&#39;&#39;</span>
<span class="n">dev</span> <span class="o">=</span> <span class="n">dev</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;/dev/mapper/&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="c1"># strip prefix, if it&#39;s there</span>
<span class="k">return</span> <span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;dmsetup&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;remove&quot;</span><span class="p">,</span> <span class="n">dev</span><span class="p">])</span></div>
<div class="viewcode-block" id="mount"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mount">[docs]</a><span class="k">def</span> <span class="nf">mount</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Mount the given device at the given mountpoint, using the given opts.</span>
<span class="sd"> opts should be a comma-separated string of mount options.</span>
<span class="sd"> if mnt is none, a temporary directory will be created and its path will be</span>
<span class="sd"> returned.</span>
<span class="sd"> raises CalledProcessError if mount fails.&#39;&#39;&#39;</span>
<span class="k">if</span> <span class="n">mnt</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mnt</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lorax.imgutils.&quot;</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;make tmp mountdir </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="p">)</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;mount&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">opts</span><span class="p">:</span>
<span class="n">cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-o&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="p">]</span>
<span class="n">cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="n">dev</span><span class="p">,</span> <span class="n">mnt</span><span class="p">]</span>
<span class="n">runcmd</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="k">return</span> <span class="n">mnt</span></div>
<div class="viewcode-block" id="umount"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.umount">[docs]</a><span class="k">def</span> <span class="nf">umount</span><span class="p">(</span><span class="n">mnt</span><span class="p">,</span> <span class="n">lazy</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">maxretry</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">retrysleep</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <span class="n">delete</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Unmount the given mountpoint. If lazy is True, do a lazy umount (-l).</span>
<span class="sd"> If the mount was a temporary dir created by mount, it will be deleted.</span>
<span class="sd"> raises CalledProcessError if umount fails.&#39;&#39;&#39;</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;umount&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">lazy</span><span class="p">:</span> <span class="n">cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-l&quot;</span><span class="p">]</span>
<span class="n">cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="n">mnt</span><span class="p">]</span>
<span class="n">count</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">maxretry</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">rv</span> <span class="o">=</span> <span class="n">runcmd</span><span class="p">(</span><span class="n">cmd</span><span class="p">)</span>
<span class="k">except</span> <span class="n">CalledProcessError</span><span class="p">:</span>
<span class="n">count</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">if</span> <span class="n">count</span> <span class="o">==</span> <span class="n">maxretry</span><span class="p">:</span>
<span class="k">raise</span>
<span class="n">logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;failed to unmount </span><span class="si">%s</span><span class="s2">. retrying (</span><span class="si">%d</span><span class="s2">/</span><span class="si">%d</span><span class="s2">)...&quot;</span><span class="p">,</span>
<span class="n">mnt</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">maxretry</span><span class="p">)</span>
<span class="k">if</span> <span class="n">logger</span><span class="o">.</span><span class="n">getEffectiveLevel</span><span class="p">()</span> <span class="o">&lt;=</span> <span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">:</span>
<span class="n">fuser</span> <span class="o">=</span> <span class="n">execWithCapture</span><span class="p">(</span><span class="s2">&quot;fuser&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-vm&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="p">])</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;fuser -vm:</span><span class="se">\n</span><span class="si">%s</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">fuser</span><span class="p">)</span>
<span class="n">sleep</span><span class="p">(</span><span class="n">retrysleep</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">break</span>
<span class="k">if</span> <span class="n">delete</span> <span class="ow">and</span> <span class="s1">&#39;lorax.imgutils&#39;</span> <span class="ow">in</span> <span class="n">mnt</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">mnt</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;remove tmp mountdir </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="p">)</span>
<span class="k">return</span> <span class="p">(</span><span class="n">rv</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span></div>
<div class="viewcode-block" id="copytree"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.copytree">[docs]</a><span class="k">def</span> <span class="nf">copytree</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dest</span><span class="p">,</span> <span class="n">preserve</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Copy a tree of files using cp -a, thus preserving modes, timestamps,</span>
<span class="sd"> links, acls, sparse files, xattrs, selinux contexts, etc.</span>
<span class="sd"> If preserve is False, uses cp -R (useful for modeless filesystems)</span>
<span class="sd"> raises CalledProcessError if copy fails.&#39;&#39;&#39;</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;copytree </span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dest</span><span class="p">)</span>
<span class="n">cp</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;cp&quot;</span><span class="p">,</span> <span class="s2">&quot;-a&quot;</span><span class="p">]</span> <span class="k">if</span> <span class="n">preserve</span> <span class="k">else</span> <span class="p">[</span><span class="s2">&quot;cp&quot;</span><span class="p">,</span> <span class="s2">&quot;-R&quot;</span><span class="p">,</span> <span class="s2">&quot;-L&quot;</span><span class="p">,</span> <span class="s2">&quot;--preserve=timestamps&quot;</span><span class="p">]</span>
<span class="n">cp</span> <span class="o">+=</span> <span class="p">[</span><span class="n">join</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="s2">&quot;.&quot;</span><span class="p">),</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">dest</span><span class="p">)]</span>
<span class="n">runcmd</span><span class="p">(</span><span class="n">cp</span><span class="p">)</span></div>
<div class="viewcode-block" id="do_grafts"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.do_grafts">[docs]</a><span class="k">def</span> <span class="nf">do_grafts</span><span class="p">(</span><span class="n">grafts</span><span class="p">,</span> <span class="n">dest</span><span class="p">,</span> <span class="n">preserve</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Copy each of the items listed in grafts into dest.</span>
<span class="sd"> If the key ends with &#39;/&#39; it&#39;s assumed to be a directory which should be</span>
<span class="sd"> created, otherwise just the leading directories will be created.&#39;&#39;&#39;</span>
<span class="k">for</span> <span class="n">imgpath</span><span class="p">,</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">grafts</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="n">imgpath</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;/&#39;</span><span class="p">:</span>
<span class="n">targetdir</span> <span class="o">=</span> <span class="n">join</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">imgpath</span><span class="p">)</span>
<span class="n">imgpath</span> <span class="o">=</span> <span class="n">imgpath</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">targetdir</span> <span class="o">=</span> <span class="n">join</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">dirname</span><span class="p">(</span><span class="n">imgpath</span><span class="p">))</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">targetdir</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">targetdir</span><span class="p">)</span>
<span class="k">if</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">filename</span><span class="p">):</span>
<span class="n">copytree</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">join</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">imgpath</span><span class="p">),</span> <span class="n">preserve</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">cpfile</span><span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">join</span><span class="p">(</span><span class="n">dest</span><span class="p">,</span> <span class="n">imgpath</span><span class="p">))</span></div>
<div class="viewcode-block" id="round_to_blocks"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.round_to_blocks">[docs]</a><span class="k">def</span> <span class="nf">round_to_blocks</span><span class="p">(</span><span class="n">size</span><span class="p">,</span> <span class="n">blocksize</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;If size isn&#39;t a multiple of blocksize, round up to the next multiple&#39;&#39;&#39;</span>
<span class="n">diff</span> <span class="o">=</span> <span class="n">size</span> <span class="o">%</span> <span class="n">blocksize</span>
<span class="k">if</span> <span class="n">diff</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">size</span><span class="p">:</span>
<span class="n">size</span> <span class="o">+=</span> <span class="n">blocksize</span> <span class="o">-</span> <span class="n">diff</span>
<span class="k">return</span> <span class="n">size</span></div>
<span class="c1"># TODO: move filesystem data outside this function</span>
<div class="viewcode-block" id="estimate_size"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.estimate_size">[docs]</a><span class="k">def</span> <span class="nf">estimate_size</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">fstype</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">blocksize</span><span class="o">=</span><span class="mi">4096</span><span class="p">,</span> <span class="n">overhead</span><span class="o">=</span><span class="mi">256</span><span class="p">):</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">getsize</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">f</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">lstat</span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span>
<span class="k">if</span> <span class="n">fstype</span> <span class="o">==</span> <span class="s2">&quot;btrfs&quot;</span><span class="p">:</span>
<span class="n">overhead</span> <span class="o">=</span> <span class="mi">64</span><span class="o">*</span><span class="mi">1024</span> <span class="c1"># don&#39;t worry, it&#39;s all sparse</span>
<span class="k">if</span> <span class="n">fstype</span> <span class="o">==</span> <span class="s2">&quot;hfsplus&quot;</span><span class="p">:</span>
<span class="n">overhead</span> <span class="o">=</span> <span class="mi">200</span> <span class="c1"># hack to deal with two bootloader copies</span>
<span class="k">if</span> <span class="n">fstype</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;vfat&quot;</span><span class="p">,</span> <span class="s2">&quot;msdos&quot;</span><span class="p">):</span>
<span class="n">blocksize</span> <span class="o">=</span> <span class="mi">2048</span>
<span class="n">getsize</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">f</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="c1"># no symlinks, count as copies</span>
<span class="n">total</span> <span class="o">=</span> <span class="n">overhead</span><span class="o">*</span><span class="n">blocksize</span>
<span class="n">dirlist</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">graft</span><span class="o">.</span><span class="n">values</span><span class="p">())</span>
<span class="k">if</span> <span class="n">rootdir</span><span class="p">:</span>
<span class="n">dirlist</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">rootdir</span><span class="p">)</span>
<span class="k">for</span> <span class="n">root</span> <span class="ow">in</span> <span class="n">dirlist</span><span class="p">:</span>
<span class="k">for</span> <span class="n">top</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">root</span><span class="p">):</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">files</span> <span class="o">+</span> <span class="n">dirs</span><span class="p">:</span>
<span class="n">total</span> <span class="o">+=</span> <span class="n">round_to_blocks</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">top</span><span class="p">,</span><span class="n">f</span><span class="p">)),</span> <span class="n">blocksize</span><span class="p">)</span>
<span class="k">if</span> <span class="n">fstype</span> <span class="o">==</span> <span class="s2">&quot;btrfs&quot;</span><span class="p">:</span>
<span class="n">total</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="mi">256</span><span class="o">*</span><span class="mi">1024</span><span class="o">*</span><span class="mi">1024</span><span class="p">,</span> <span class="n">total</span><span class="p">)</span> <span class="c1"># btrfs minimum size: 256MB</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Size of </span><span class="si">%s</span><span class="s2"> block </span><span class="si">%s</span><span class="s2"> fs at </span><span class="si">%s</span><span class="s2"> estimated to be </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">blocksize</span><span class="p">,</span> <span class="n">fstype</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">total</span><span class="p">)</span>
<span class="k">return</span> <span class="n">total</span></div>
<span class="c1">######## Execution contexts - use with the &#39;with&#39; statement ##############</span>
<div class="viewcode-block" id="LoopDev"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.LoopDev">[docs]</a><span class="k">class</span> <span class="nc">LoopDev</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loopdev</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">filename</span> <span class="o">=</span> <span class="n">filename</span>
<span class="k">if</span> <span class="n">size</span><span class="p">:</span>
<span class="n">mksparse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loopdev</span> <span class="o">=</span> <span class="n">loop_attach</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">loopdev</span>
<span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tracebk</span><span class="p">):</span>
<span class="n">loop_detach</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">loopdev</span><span class="p">)</span></div>
<div class="viewcode-block" id="DMDev"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.DMDev">[docs]</a><span class="k">class</span> <span class="nc">DMDev</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dev</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mapperdev</span> <span class="o">=</span> <span class="kc">None</span>
<span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">name</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mapperdev</span> <span class="o">=</span> <span class="n">dm_attach</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">size</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mapperdev</span>
<span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tracebk</span><span class="p">):</span>
<span class="n">dm_detach</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mapperdev</span><span class="p">)</span></div>
<div class="viewcode-block" id="Mount"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.Mount">[docs]</a><span class="k">class</span> <span class="nc">Mount</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dev</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">opts</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mnt</span><span class="p">)</span> <span class="o">=</span> <span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">opts</span><span class="p">,</span> <span class="n">mnt</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mnt</span> <span class="o">=</span> <span class="n">mount</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dev</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">opts</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mnt</span><span class="p">)</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">mnt</span>
<span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tracebk</span><span class="p">):</span>
<span class="n">umount</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mnt</span><span class="p">)</span></div>
<div class="viewcode-block" id="kpartx_disk_img"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.kpartx_disk_img">[docs]</a><span class="k">def</span> <span class="nf">kpartx_disk_img</span><span class="p">(</span><span class="n">disk_img</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Attach a disk image&#39;s partitions to /dev/loopX using kpartx</span>
<span class="sd"> :param disk_img: The full path to a partitioned disk image</span>
<span class="sd"> :type disk_img: str</span>
<span class="sd"> :returns: list of (loopXpN, size)</span>
<span class="sd"> :rtype: list of tuples</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Example kpartx output</span>
<span class="c1"># kpartx -p p -v -a /tmp/diskV2DiCW.im</span>
<span class="c1"># add map loop2p1 (253:2): 0 3481600 linear /dev/loop2 2048</span>
<span class="c1"># add map loop2p2 (253:3): 0 614400 linear /dev/loop2 3483648</span>
<span class="n">kpartx_output</span> <span class="o">=</span> <span class="n">runcmd_output</span><span class="p">([</span><span class="s2">&quot;kpartx&quot;</span><span class="p">,</span> <span class="s2">&quot;-v&quot;</span><span class="p">,</span> <span class="s2">&quot;-a&quot;</span><span class="p">,</span> <span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">])</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">kpartx_output</span><span class="p">)</span>
<span class="c1"># list of (deviceName, sizeInBytes)</span>
<span class="n">loop_devices</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">kpartx_output</span><span class="o">.</span><span class="n">splitlines</span><span class="p">():</span>
<span class="c1"># add map loop2p3 (253:4): 0 7139328 linear /dev/loop2 528384</span>
<span class="c1"># 3rd element is size in 512 byte blocks</span>
<span class="k">if</span> <span class="n">line</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;add map &quot;</span><span class="p">):</span>
<span class="n">fields</span> <span class="o">=</span> <span class="n">line</span><span class="p">[</span><span class="mi">8</span><span class="p">:]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
<span class="n">loop_devices</span><span class="o">.</span><span class="n">append</span><span class="p">(</span> <span class="p">(</span><span class="n">fields</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="nb">int</span><span class="p">(</span><span class="n">fields</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span><span class="o">*</span><span class="mi">512</span><span class="p">)</span> <span class="p">)</span>
<span class="k">return</span> <span class="n">loop_devices</span></div>
<div class="viewcode-block" id="PartitionMount"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.PartitionMount">[docs]</a><span class="k">class</span> <span class="nc">PartitionMount</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Mount a partitioned image file using kpartx &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">mount_ok</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">submount</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param str disk_img: The full path to a partitioned disk image</span>
<span class="sd"> :param mount_ok: A function that is passed the mount point and</span>
<span class="sd"> returns True if it should be mounted.</span>
<span class="sd"> :param str submount: Directory inside mount_dir to mount at</span>
<span class="sd"> If mount_ok is not set it will look for /etc/passwd</span>
<span class="sd"> If the partition is found it will be mounted under a temporary</span>
<span class="sd"> directory and self.temp_dir set to it. If submount is passed it will be</span>
<span class="sd"> created and mounted there instead, with self.mount_dir set to point to</span>
<span class="sd"> it. self.mount_dev is set to the loop device, and self.mount_size is</span>
<span class="sd"> set to the size of the partition.</span>
<span class="sd"> When no subdir is passed self.temp_dir and self.mount_dir will be the same.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dev</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_size</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">disk_img</span> <span class="o">=</span> <span class="n">disk_img</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_ok</span> <span class="o">=</span> <span class="n">mount_ok</span>
<span class="bp">self</span><span class="o">.</span><span class="n">submount</span> <span class="o">=</span> <span class="n">submount</span>
<span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="c1"># Default is to mount partition with /etc/passwd</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_ok</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_ok</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">mount_dir</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">mount_dir</span><span class="o">+</span><span class="s2">&quot;/etc/passwd&quot;</span><span class="p">)</span>
<span class="c1"># list of (deviceName, sizeInBytes)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">loop_devices</span> <span class="o">=</span> <span class="n">kpartx_disk_img</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">disk_img</span><span class="p">)</span>
<span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># Mount the device selected by mount_ok, if possible</span>
<span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">()</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">submount</span><span class="p">:</span>
<span class="n">mount_dir</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">normpath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">sep</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">submount</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">mount_dir</span><span class="p">,</span> <span class="n">mode</span><span class="o">=</span><span class="mo">0o755</span><span class="p">,</span> <span class="n">exist_ok</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">mount_dir</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span>
<span class="k">for</span> <span class="n">dev</span><span class="p">,</span> <span class="n">size</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">loop_devices</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">mount</span><span class="p">(</span> <span class="s2">&quot;/dev/mapper/&quot;</span><span class="o">+</span><span class="n">dev</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">mount_dir</span> <span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_ok</span><span class="p">(</span><span class="n">mount_dir</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span> <span class="o">=</span> <span class="n">mount_dir</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dev</span> <span class="o">=</span> <span class="n">dev</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_size</span> <span class="o">=</span> <span class="n">size</span>
<span class="k">break</span>
<span class="n">umount</span><span class="p">(</span> <span class="n">mount_dir</span> <span class="p">)</span>
<span class="k">except</span> <span class="n">CalledProcessError</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">traceback</span><span class="o">.</span><span class="n">format_exc</span><span class="p">())</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Partition mounted on </span><span class="si">%s</span><span class="s2"> size=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_size</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Unable to mount anything from </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">disk_img</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">return</span> <span class="bp">self</span>
<span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_value</span><span class="p">,</span> <span class="n">tracebk</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">temp_dir</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;kpartx&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-d&quot;</span><span class="p">,</span> <span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">disk_img</span><span class="p">])</span></div>
<span class="c1">######## Functions for making filesystem images ##########################</span>
<div class="viewcode-block" id="mkfsimage"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkfsimage">[docs]</a><span class="k">def</span> <span class="nf">mkfsimage</span><span class="p">(</span><span class="n">fstype</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mkfsargs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Generic filesystem image creation function.</span>
<span class="sd"> fstype should be a filesystem type - &quot;mkfs.${fstype}&quot; must exist.</span>
<span class="sd"> graft should be a dict: {&quot;some/path/in/image&quot;: &quot;local/file/or/dir&quot;};</span>
<span class="sd"> if the path ends with a &#39;/&#39; it&#39;s assumed to be a directory.</span>
<span class="sd"> Will raise CalledProcessError if something goes wrong.&#39;&#39;&#39;</span>
<span class="n">mkfsargs</span> <span class="o">=</span> <span class="n">mkfsargs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">preserve</span> <span class="o">=</span> <span class="p">(</span><span class="n">fstype</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;msdos&quot;</span><span class="p">,</span> <span class="s2">&quot;vfat&quot;</span><span class="p">))</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">size</span><span class="p">:</span>
<span class="n">size</span> <span class="o">=</span> <span class="n">estimate_size</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">graft</span><span class="p">,</span> <span class="n">fstype</span><span class="p">)</span>
<span class="k">with</span> <span class="n">LoopDev</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span> <span class="k">as</span> <span class="n">loopdev</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;mkfs.</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">fstype</span><span class="p">]</span> <span class="o">+</span> <span class="n">mkfsargs</span> <span class="o">+</span> <span class="p">[</span><span class="n">loopdev</span><span class="p">])</span>
<span class="k">except</span> <span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;mkfs exited with a non-zero return code: </span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">returncode</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">output</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">returncode</span><span class="p">)</span>
<span class="k">with</span> <span class="n">Mount</span><span class="p">(</span><span class="n">loopdev</span><span class="p">,</span> <span class="n">mountargs</span><span class="p">)</span> <span class="k">as</span> <span class="n">mnt</span><span class="p">:</span>
<span class="k">if</span> <span class="n">rootdir</span><span class="p">:</span>
<span class="n">copytree</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">mnt</span><span class="p">,</span> <span class="n">preserve</span><span class="p">)</span>
<span class="n">do_grafts</span><span class="p">(</span><span class="n">graft</span><span class="p">,</span> <span class="n">mnt</span><span class="p">,</span> <span class="n">preserve</span><span class="p">)</span>
<span class="c1"># Save information about filesystem usage</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;df&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">mnt</span><span class="p">])</span>
<span class="c1"># Make absolutely sure that the data has been written</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;sync&quot;</span><span class="p">])</span></div>
<span class="c1"># convenience functions with useful defaults</span>
<div class="viewcode-block" id="mkdosimg"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkdosimg">[docs]</a><span class="k">def</span> <span class="nf">mkdosimg</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="s2">&quot;shortname=winnt,umask=0077&quot;</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">mkfsargs</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;-n&quot;</span><span class="p">,</span> <span class="n">label</span><span class="p">]</span>
<span class="k">if</span> <span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span>
<span class="n">mkfsargs</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;-i&quot;</span><span class="p">,</span>
<span class="s2">&quot;</span><span class="si">{:x}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span><span class="p">]))])</span>
<span class="n">mkfsimage</span><span class="p">(</span><span class="s2">&quot;msdos&quot;</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="n">mountargs</span><span class="p">,</span>
<span class="n">mkfsargs</span><span class="o">=</span><span class="n">mkfsargs</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="n">graft</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkext4img"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkext4img">[docs]</a><span class="k">def</span> <span class="nf">mkext4img</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">mkfsimage</span><span class="p">(</span><span class="s2">&quot;ext4&quot;</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="n">mountargs</span><span class="p">,</span>
<span class="n">mkfsargs</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-L&quot;</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="s2">&quot;-b&quot;</span><span class="p">,</span> <span class="s2">&quot;4096&quot;</span><span class="p">,</span> <span class="s2">&quot;-m&quot;</span><span class="p">,</span> <span class="s2">&quot;0&quot;</span><span class="p">],</span> <span class="n">graft</span><span class="o">=</span><span class="n">graft</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkbtrfsimg"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkbtrfsimg">[docs]</a><span class="k">def</span> <span class="nf">mkbtrfsimg</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">mkfsimage</span><span class="p">(</span><span class="s2">&quot;btrfs&quot;</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="n">mountargs</span><span class="p">,</span>
<span class="n">mkfsargs</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-L&quot;</span><span class="p">,</span> <span class="n">label</span><span class="p">],</span> <span class="n">graft</span><span class="o">=</span><span class="n">graft</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkhfsimg"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkhfsimg">[docs]</a><span class="k">def</span> <span class="nf">mkhfsimg</span><span class="p">(</span><span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">graft</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="n">graft</span> <span class="o">=</span> <span class="n">graft</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="n">mkfsimage</span><span class="p">(</span><span class="s2">&quot;hfsplus&quot;</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">size</span><span class="p">,</span> <span class="n">mountargs</span><span class="o">=</span><span class="n">mountargs</span><span class="p">,</span>
<span class="n">mkfsargs</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;-v&quot;</span><span class="p">,</span> <span class="n">label</span><span class="p">],</span> <span class="n">graft</span><span class="o">=</span><span class="n">graft</span><span class="p">)</span></div>
<div class="viewcode-block" id="mkfsimage_from_disk"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.mkfsimage_from_disk">[docs]</a><span class="k">def</span> <span class="nf">mkfsimage_from_disk</span><span class="p">(</span><span class="n">diskimage</span><span class="p">,</span> <span class="n">fsimage</span><span class="p">,</span> <span class="n">img_size</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="s2">&quot;Anaconda&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Copy the / partition of a partitioned disk image to an un-partitioned</span>
<span class="sd"> disk image.</span>
<span class="sd"> :param str diskimage: The full path to partitioned disk image with a /</span>
<span class="sd"> :param str fsimage: The full path of the output fs image file</span>
<span class="sd"> :param int img_size: Optional size of the fsimage in MiB or None to make</span>
<span class="sd"> it as small as possible</span>
<span class="sd"> :param str label: The label to apply to the image. Defaults to &quot;Anaconda&quot;</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">diskimage</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">img_mount</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">None</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Creating fsimage </span><span class="si">%s</span><span class="s2"> (</span><span class="si">%s</span><span class="s2">)&quot;</span><span class="p">,</span> <span class="n">fsimage</span><span class="p">,</span> <span class="n">img_size</span> <span class="ow">or</span> <span class="s2">&quot;minimized&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">img_size</span><span class="p">:</span>
<span class="c1"># convert to Bytes</span>
<span class="n">img_size</span> <span class="o">*=</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span>
<span class="n">mkext4img</span><span class="p">(</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">fsimage</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">img_size</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span></div>
<div class="viewcode-block" id="default_image_name"><a class="viewcode-back" href="../../pylorax.html#pylorax.imgutils.default_image_name">[docs]</a><span class="k">def</span> <span class="nf">default_image_name</span><span class="p">(</span><span class="n">compression</span><span class="p">,</span> <span class="n">basename</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return a default image name with the correct suffix for the compression type.</span>
<span class="sd"> :param str compression: Compression type</span>
<span class="sd"> :param str basename: Base filename</span>
<span class="sd"> :returns: basename with compression suffix</span>
<span class="sd"> If the compression is unknown it defaults to xz</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">SUFFIXES</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;xz&quot;</span><span class="p">:</span> <span class="s2">&quot;.xz&quot;</span><span class="p">,</span> <span class="s2">&quot;gzip&quot;</span><span class="p">:</span> <span class="s2">&quot;.gz&quot;</span><span class="p">,</span> <span class="s2">&quot;bzip2&quot;</span><span class="p">:</span> <span class="s2">&quot;.bz2&quot;</span><span class="p">,</span> <span class="s2">&quot;lzma&quot;</span><span class="p">:</span> <span class="s2">&quot;.lzma&quot;</span><span class="p">}</span>
<span class="k">return</span> <span class="n">basename</span> <span class="o">+</span> <span class="n">SUFFIXES</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">compression</span><span class="p">,</span> <span class="s2">&quot;.xz&quot;</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,879 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.installer &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.installer</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.installer</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2018 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</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="s2">&quot;pylorax&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">from</span> <span class="nn">math</span> <span class="kn">import</span> <span class="n">ceil</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">subprocess</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">socket</span>
<span class="kn">import</span> <span class="nn">tempfile</span>
<span class="c1"># Use the Lorax treebuilder branch for iso creation</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">execWithRedirect</span><span class="p">,</span> <span class="n">execReadlines</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">PartitionMount</span><span class="p">,</span> <span class="n">mksparse</span><span class="p">,</span> <span class="n">mkext4img</span><span class="p">,</span> <span class="n">loop_detach</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">get_loop_name</span><span class="p">,</span> <span class="n">dm_detach</span><span class="p">,</span> <span class="n">mount</span><span class="p">,</span> <span class="n">umount</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">mkqemu_img</span><span class="p">,</span> <span class="n">mktar</span><span class="p">,</span> <span class="n">mkcpio</span><span class="p">,</span> <span class="n">mkfsimage_from_disk</span>
<span class="kn">from</span> <span class="nn">pylorax.monitor</span> <span class="kn">import</span> <span class="n">LogMonitor</span>
<span class="kn">from</span> <span class="nn">pylorax.mount</span> <span class="kn">import</span> <span class="n">IsoMountpoint</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span>
<span class="kn">from</span> <span class="nn">pylorax.treebuilder</span> <span class="kn">import</span> <span class="n">udev_escape</span>
<span class="n">ROOT_PATH</span> <span class="o">=</span> <span class="s2">&quot;/mnt/sysimage/&quot;</span>
<div class="viewcode-block" id="InstallError"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.InstallError">[docs]</a><span class="k">class</span> <span class="nc">InstallError</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="create_vagrant_metadata"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.create_vagrant_metadata">[docs]</a><span class="k">def</span> <span class="nf">create_vagrant_metadata</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Create a default Vagrant metadata.json file</span>
<span class="sd"> :param str path: Path to metadata.json file</span>
<span class="sd"> :param int size: Disk size in MiB</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">metadata</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">&quot;provider&quot;</span><span class="p">:</span><span class="s2">&quot;libvirt&quot;</span><span class="p">,</span> <span class="s2">&quot;format&quot;</span><span class="p">:</span><span class="s2">&quot;qcow2&quot;</span><span class="p">,</span> <span class="s2">&quot;virtual_size&quot;</span><span class="p">:</span> <span class="n">ceil</span><span class="p">(</span><span class="n">size</span> <span class="o">/</span> <span class="mi">1024</span><span class="p">)</span> <span class="p">}</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span></div>
<div class="viewcode-block" id="update_vagrant_metadata"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.update_vagrant_metadata">[docs]</a><span class="k">def</span> <span class="nf">update_vagrant_metadata</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Update the Vagrant metadata.json file</span>
<span class="sd"> :param str path: Path to metadata.json file</span>
<span class="sd"> :param int size: Disk size in MiB</span>
<span class="sd"> This function makes sure that the provider, format and virtual size of the</span>
<span class="sd"> metadata file are set correctly. All other values are left untouched.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">metadata</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">ValueError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Problem reading metadata file </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">path</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">return</span>
<span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;provider&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;libvirt&quot;</span>
<span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;format&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;qcow2&quot;</span>
<span class="n">metadata</span><span class="p">[</span><span class="s2">&quot;virtual_size&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">ceil</span><span class="p">(</span><span class="n">size</span> <span class="o">/</span> <span class="mi">1024</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;wt&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">metadata</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">indent</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span></div>
<div class="viewcode-block" id="find_free_port"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.find_free_port">[docs]</a><span class="k">def</span> <span class="nf">find_free_port</span><span class="p">(</span><span class="n">start</span><span class="o">=</span><span class="mi">5900</span><span class="p">,</span> <span class="n">end</span><span class="o">=</span><span class="mi">5999</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="s2">&quot;127.0.0.1&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return first free port in range.</span>
<span class="sd"> :param int start: Starting port number</span>
<span class="sd"> :param int end: Ending port number</span>
<span class="sd"> :param str host: Host IP to search</span>
<span class="sd"> :returns: First free port or -1 if none found</span>
<span class="sd"> :rtype: int</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">socket</span><span class="o">.</span><span class="n">socket</span><span class="p">(</span><span class="n">socket</span><span class="o">.</span><span class="n">AF_INET</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">SOCK_STREAM</span><span class="p">)</span>
<span class="k">for</span> <span class="n">port</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">end</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">s</span><span class="o">.</span><span class="n">bind</span><span class="p">((</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">))</span>
<span class="n">s</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">return</span> <span class="n">port</span>
<span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">return</span> <span class="o">-</span><span class="mi">1</span></div>
<div class="viewcode-block" id="append_initrd"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.append_initrd">[docs]</a><span class="k">def</span> <span class="nf">append_initrd</span><span class="p">(</span><span class="n">initrd</span><span class="p">,</span> <span class="n">files</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Append files to an initrd.</span>
<span class="sd"> :param str initrd: Path to initrd</span>
<span class="sd"> :param list files: list of file paths to add</span>
<span class="sd"> :returns: Path to a new initrd</span>
<span class="sd"> :rtype: str</span>
<span class="sd"> The files are added to the initrd by creating a cpio image</span>
<span class="sd"> of the files (stored at /) and writing the cpio to the end of a</span>
<span class="sd"> copy of the initrd.</span>
<span class="sd"> The initrd is not changed, a copy is made before appending the</span>
<span class="sd"> cpio archive.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">qemu_initrd</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-initrd-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.img&quot;</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">initrd</span><span class="p">,</span> <span class="n">qemu_initrd</span><span class="p">)</span>
<span class="n">ks_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-ksdir-&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ks</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">ks</span><span class="p">,</span> <span class="n">ks_dir</span><span class="p">)</span>
<span class="n">ks_initrd</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-ks-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.img&quot;</span><span class="p">)</span>
<span class="n">mkcpio</span><span class="p">(</span><span class="n">ks_dir</span><span class="p">,</span> <span class="n">ks_initrd</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">ks_dir</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">qemu_initrd</span><span class="p">,</span> <span class="s2">&quot;ab&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">initrd_fp</span><span class="p">:</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">ks_initrd</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">ks_fp</span><span class="p">:</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">ks_fp</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">data</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">initrd_fp</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">ks_initrd</span><span class="p">)</span>
<span class="k">return</span> <span class="n">qemu_initrd</span></div>
<div class="viewcode-block" id="QEMUInstall"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.QEMUInstall">[docs]</a><span class="k">class</span> <span class="nc">QEMUInstall</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Run qemu using an iso and a kickstart</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Mapping of arch to qemu command</span>
<span class="n">QEMU_CMDS</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;x86_64&quot;</span><span class="p">:</span> <span class="s2">&quot;qemu-system-x86_64&quot;</span><span class="p">,</span>
<span class="s2">&quot;i386&quot;</span><span class="p">:</span> <span class="s2">&quot;qemu-system-i386&quot;</span><span class="p">,</span>
<span class="s2">&quot;arm&quot;</span><span class="p">:</span> <span class="s2">&quot;qemu-system-arm&quot;</span><span class="p">,</span>
<span class="s2">&quot;aarch64&quot;</span><span class="p">:</span> <span class="s2">&quot;qemu-system-aarch64&quot;</span><span class="p">,</span>
<span class="s2">&quot;ppc64le&quot;</span><span class="p">:</span> <span class="s2">&quot;qemu-system-ppc64&quot;</span>
<span class="p">}</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">opts</span><span class="p">,</span> <span class="n">iso</span><span class="p">,</span> <span class="n">ks_paths</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">img_size</span><span class="o">=</span><span class="mi">2048</span><span class="p">,</span>
<span class="n">kernel_args</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">memory</span><span class="o">=</span><span class="mi">1024</span><span class="p">,</span> <span class="n">vcpus</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">vnc</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">arch</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">cancel_func</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">virtio_host</span><span class="o">=</span><span class="s2">&quot;127.0.0.1&quot;</span><span class="p">,</span> <span class="n">virtio_port</span><span class="o">=</span><span class="mi">6080</span><span class="p">,</span>
<span class="n">image_type</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">boot_uefi</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">ovmf_path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Start the installation</span>
<span class="sd"> :param iso: Information about the iso to use for the installation</span>
<span class="sd"> :type iso: IsoMountpoint</span>
<span class="sd"> :param list ks_paths: Paths to kickstart files. All are injected, the</span>
<span class="sd"> first one is the one executed.</span>
<span class="sd"> :param str disk_img: Path to a disk image, created it it doesn&#39;t exist</span>
<span class="sd"> :param int img_size: The image size, in MiB, to create if it doesn&#39;t exist</span>
<span class="sd"> :param str kernel_args: Extra kernel arguments to pass on the kernel cmdline</span>
<span class="sd"> :param int memory: Amount of RAM to assign to the virt, in MiB</span>
<span class="sd"> :param int vcpus: Number of virtual cpus</span>
<span class="sd"> :param str vnc: Arguments to pass to qemu -display</span>
<span class="sd"> :param str arch: Optional architecture to use in the virt</span>
<span class="sd"> :param cancel_func: Function that returns True if the installation fails</span>
<span class="sd"> :type cancel_func: function</span>
<span class="sd"> :param str virtio_host: Hostname to connect virtio log to</span>
<span class="sd"> :param int virtio_port: Port to connect virtio log to</span>
<span class="sd"> :param str image_type: Type of qemu-img disk to create, or None.</span>
<span class="sd"> :param bool boot_uefi: Use OVMF to boot the VM in UEFI mode</span>
<span class="sd"> :param str ovmf_path: Path to the OVMF firmware</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Lookup qemu-system- for arch if passed, or try to guess using host arch</span>
<span class="n">qemu_cmd</span> <span class="o">=</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">QEMU_CMDS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">arch</span> <span class="ow">or</span> <span class="n">os</span><span class="o">.</span><span class="n">uname</span><span class="p">()</span><span class="o">.</span><span class="n">machine</span><span class="p">,</span> <span class="s2">&quot;qemu-system-&quot;</span><span class="o">+</span><span class="n">os</span><span class="o">.</span><span class="n">uname</span><span class="p">()</span><span class="o">.</span><span class="n">machine</span><span class="p">)]</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">exists</span><span class="p">(</span><span class="s2">&quot;/usr/bin/&quot;</span><span class="o">+</span><span class="n">qemu_cmd</span><span class="p">[</span><span class="mi">0</span><span class="p">]):</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> does not exist, cannot run qemu&quot;</span> <span class="o">%</span> <span class="n">qemu_cmd</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-no-user-config&quot;</span><span class="p">]</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-m&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">memory</span><span class="p">)]</span>
<span class="k">if</span> <span class="n">vcpus</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-smp&quot;</span><span class="p">,</span> <span class="nb">str</span><span class="p">(</span><span class="n">vcpus</span><span class="p">)]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">no_kvm</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s2">&quot;/dev/kvm&quot;</span><span class="p">):</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-machine&quot;</span><span class="p">,</span> <span class="s2">&quot;accel=kvm&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">boot_uefi</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-machine&quot;</span><span class="p">,</span> <span class="s2">&quot;q35,smm=on&quot;</span><span class="p">]</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-global&quot;</span><span class="p">,</span> <span class="s2">&quot;driver=cfi.pflash01,property=secure,value=on&quot;</span><span class="p">]</span>
<span class="c1"># Copy the initrd from the iso, create a cpio archive of the kickstart files</span>
<span class="c1"># and append it to the temporary initrd.</span>
<span class="n">qemu_initrd</span> <span class="o">=</span> <span class="n">append_initrd</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">initrd</span><span class="p">,</span> <span class="n">ks_paths</span><span class="p">)</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-kernel&quot;</span><span class="p">,</span> <span class="n">iso</span><span class="o">.</span><span class="n">kernel</span><span class="p">]</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-initrd&quot;</span><span class="p">,</span> <span class="n">qemu_initrd</span><span class="p">]</span>
<span class="c1"># Add the disk and cdrom</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">isfile</span><span class="p">(</span><span class="n">disk_img</span><span class="p">):</span>
<span class="n">mksparse</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">img_size</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="n">drive_args</span> <span class="o">=</span> <span class="s2">&quot;file=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">disk_img</span>
<span class="n">drive_args</span> <span class="o">+=</span> <span class="s2">&quot;,cache=unsafe,discard=unmap&quot;</span>
<span class="k">if</span> <span class="n">image_type</span><span class="p">:</span>
<span class="n">drive_args</span> <span class="o">+=</span> <span class="s2">&quot;,format=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">image_type</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">drive_args</span> <span class="o">+=</span> <span class="s2">&quot;,format=raw&quot;</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-drive&quot;</span><span class="p">,</span> <span class="n">drive_args</span><span class="p">]</span>
<span class="n">drive_args</span> <span class="o">=</span> <span class="s2">&quot;file=</span><span class="si">%s</span><span class="s2">,media=cdrom,readonly=on&quot;</span> <span class="o">%</span> <span class="n">iso</span><span class="o">.</span><span class="n">iso_path</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-drive&quot;</span><span class="p">,</span> <span class="n">drive_args</span><span class="p">]</span>
<span class="c1"># Setup the cmdline args</span>
<span class="c1"># ======================</span>
<span class="n">cmdline_args</span> <span class="o">=</span> <span class="s2">&quot;ks=file:/</span><span class="si">%s</span><span class="s2">&quot;</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">ks_paths</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">cmdline_args</span> <span class="o">+=</span> <span class="s2">&quot; inst.stage2=hd:LABEL=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">udev_escape</span><span class="p">(</span><span class="n">iso</span><span class="o">.</span><span class="n">label</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">proxy</span><span class="p">:</span>
<span class="n">cmdline_args</span> <span class="o">+=</span> <span class="s2">&quot; inst.proxy=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">opts</span><span class="o">.</span><span class="n">proxy</span>
<span class="k">if</span> <span class="n">kernel_args</span><span class="p">:</span>
<span class="n">cmdline_args</span> <span class="o">+=</span> <span class="s2">&quot; &quot;</span><span class="o">+</span><span class="n">kernel_args</span>
<span class="n">cmdline_args</span> <span class="o">+=</span> <span class="s2">&quot; inst.text inst.cmdline&quot;</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-append&quot;</span><span class="p">,</span> <span class="n">cmdline_args</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">vnc</span><span class="p">:</span>
<span class="n">vnc_port</span> <span class="o">=</span> <span class="n">find_free_port</span><span class="p">()</span>
<span class="k">if</span> <span class="n">vnc_port</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;No free VNC ports&quot;</span><span class="p">)</span>
<span class="n">display_args</span> <span class="o">=</span> <span class="s2">&quot;vnc=127.0.0.1:</span><span class="si">%d</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">vnc_port</span> <span class="o">-</span> <span class="mi">5900</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">display_args</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">vnc</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;qemu </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">display_args</span><span class="p">)</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-nographic&quot;</span><span class="p">,</span> <span class="s2">&quot;-monitor&quot;</span><span class="p">,</span> <span class="s2">&quot;none&quot;</span><span class="p">,</span> <span class="s2">&quot;-serial&quot;</span><span class="p">,</span> <span class="s2">&quot;null&quot;</span><span class="p">,</span> <span class="s2">&quot;-display&quot;</span><span class="p">,</span> <span class="n">display_args</span> <span class="p">]</span>
<span class="c1"># Setup the virtio log port</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-device&quot;</span><span class="p">,</span> <span class="s2">&quot;virtio-serial-pci,id=virtio-serial0&quot;</span><span class="p">]</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-device&quot;</span><span class="p">,</span> <span class="s2">&quot;virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0&quot;</span>
<span class="s2">&quot;,id=channel0,name=org.fedoraproject.anaconda.log.0&quot;</span><span class="p">]</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-chardev&quot;</span><span class="p">,</span> <span class="s2">&quot;socket,id=charchannel0,host=</span><span class="si">%s</span><span class="s2">,port=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">virtio_host</span><span class="p">,</span> <span class="n">virtio_port</span><span class="p">)]</span>
<span class="c1"># Pass through rng from host</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">with_rng</span> <span class="o">!=</span> <span class="s2">&quot;none&quot;</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-object&quot;</span><span class="p">,</span> <span class="s2">&quot;rng-random,id=virtio-rng0,filename=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">opts</span><span class="o">.</span><span class="n">with_rng</span><span class="p">]</span>
<span class="k">if</span> <span class="n">boot_uefi</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-device&quot;</span><span class="p">,</span> <span class="s2">&quot;virtio-rng-pci,rng=virtio-rng0,id=rng0,bus=pcie.0,addr=0x9&quot;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-device&quot;</span><span class="p">,</span> <span class="s2">&quot;virtio-rng-pci,rng=virtio-rng0,id=rng0,bus=pci.0,addr=0x9&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">boot_uefi</span> <span class="ow">and</span> <span class="n">ovmf_path</span><span class="p">:</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-drive&quot;</span><span class="p">,</span> <span class="s2">&quot;file=</span><span class="si">%s</span><span class="s2">/OVMF_CODE.secboot.fd,if=pflash,format=raw,unit=0,readonly=on&quot;</span> <span class="o">%</span> <span class="n">ovmf_path</span><span class="p">]</span>
<span class="c1"># Make a copy of the OVMF_VARS.secboot.fd for this run</span>
<span class="n">ovmf_vars</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-OVMF_VARS-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.fd&quot;</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">ovmf_path</span><span class="p">,</span> <span class="s2">&quot;/OVMF_VARS.secboot.fd&quot;</span><span class="p">),</span> <span class="n">ovmf_vars</span><span class="p">)</span>
<span class="n">qemu_cmd</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-drive&quot;</span><span class="p">,</span> <span class="s2">&quot;file=</span><span class="si">%s</span><span class="s2">,if=pflash,format=raw,unit=1&quot;</span> <span class="o">%</span> <span class="n">ovmf_vars</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="s2">&quot;Running qemu&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">qemu_cmd</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="n">qemu_cmd</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">qemu_cmd</span><span class="p">[</span><span class="mi">1</span><span class="p">:],</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">callback</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="ow">not</span> <span class="p">(</span><span class="n">cancel_func</span> <span class="ow">and</span> <span class="n">cancel_func</span><span class="p">()))</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Running qemu failed:&quot;</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;cmd: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">cmd</span><span class="p">))</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;output: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;QEMUInstall failed&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">OSError</span><span class="p">,</span> <span class="ne">KeyboardInterrupt</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Running qemu failed: </span><span class="si">%s</span><span class="s2">&quot;</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">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;QEMUInstall failed&quot;</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">qemu_initrd</span><span class="p">)</span>
<span class="k">if</span> <span class="n">boot_uefi</span> <span class="ow">and</span> <span class="n">ovmf_path</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">ovmf_vars</span><span class="p">)</span>
<span class="k">if</span> <span class="n">cancel_func</span> <span class="ow">and</span> <span class="n">cancel_func</span><span class="p">():</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Installation error detected. See logfile for details.&quot;</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;QEMUInstall failed&quot;</span><span class="p">)</span>
<span class="k">else</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="s2">&quot;Installation finished without errors.&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="novirt_cancel_check"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.novirt_cancel_check">[docs]</a><span class="k">def</span> <span class="nf">novirt_cancel_check</span><span class="p">(</span><span class="n">cancel_funcs</span><span class="p">,</span> <span class="n">proc</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Check to see if there has been an error in the logs</span>
<span class="sd"> :param cancel_funcs: list of functions to call, True from any one cancels the build</span>
<span class="sd"> :type cancel_funcs: list</span>
<span class="sd"> :param proc: Popen object for the anaconda process</span>
<span class="sd"> :type proc: subprocess.Popen</span>
<span class="sd"> :returns: True if the process has been terminated</span>
<span class="sd"> The cancel_funcs functions should return a True if an error has been detected.</span>
<span class="sd"> When an error is detected the process is terminated and this returns True</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">cancel_funcs</span><span class="p">:</span>
<span class="k">if</span> <span class="n">f</span><span class="p">():</span>
<span class="n">proc</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="k">return</span> <span class="kc">False</span></div>
<div class="viewcode-block" id="anaconda_cleanup"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.anaconda_cleanup">[docs]</a><span class="k">def</span> <span class="nf">anaconda_cleanup</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Cleanup any leftover mounts from anaconda</span>
<span class="sd"> :param str dirinstall_path: Path where anaconda mounts things</span>
<span class="sd"> :returns: True if cleanups were successful. False if any of them failed.</span>
<span class="sd"> If anaconda crashes it may leave things mounted under this path. It will</span>
<span class="sd"> typically be set to /mnt/sysimage/</span>
<span class="sd"> Attempts to cleanup may also fail. Catch these and continue trying the</span>
<span class="sd"> other mountpoints.</span>
<span class="sd"> Anaconda may also leave /run/anaconda.pid behind, clean that up as well.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="c1"># Anaconda may not clean up its /var/run/anaconda.pid file</span>
<span class="c1"># Make sure the process is really finished (it should be, since it was started from a subprocess call)</span>
<span class="c1"># and then remove the pid file.</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="s2">&quot;/var/run/anaconda.pid&quot;</span><span class="p">):</span>
<span class="c1"># lorax-composer runs anaconda using unshare so the pid is always 1</span>
<span class="k">if</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;/var/run/anaconda.pid&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">==</span> <span class="s2">&quot;1&quot;</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="s2">&quot;/var/run/anaconda.pid&quot;</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">dirinstall_path</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">dirinstall_path</span><span class="p">)</span>
<span class="c1"># unmount filesystems</span>
<span class="k">for</span> <span class="n">mounted</span> <span class="ow">in</span> <span class="nb">reversed</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="s2">&quot;/proc/mounts&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">readlines</span><span class="p">()):</span>
<span class="p">(</span><span class="n">_device</span><span class="p">,</span> <span class="n">mountpoint</span><span class="p">,</span> <span class="n">_rest</span><span class="p">)</span> <span class="o">=</span> <span class="n">mounted</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="k">if</span> <span class="n">mountpoint</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">)</span> <span class="ow">and</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">ismount</span><span class="p">(</span><span class="n">mountpoint</span><span class="p">):</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="n">mountpoint</span><span class="p">)</span>
<span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Cleanup of </span><span class="si">%s</span><span class="s2"> failed. See program.log for details&quot;</span><span class="p">,</span> <span class="n">mountpoint</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="novirt_install"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.novirt_install">[docs]</a><span class="k">def</span> <span class="nf">novirt_install</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tar_img</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Use Anaconda to install to a disk image</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str disk_img: The full path to the disk image to be created</span>
<span class="sd"> :param int disk_size: The size of the disk_img in MiB</span>
<span class="sd"> :param cancel_func: Function that returns True to cancel build</span>
<span class="sd"> :type cancel_func: function</span>
<span class="sd"> :param str tar_img: For make_tar_disk, the path to final tarball to be created</span>
<span class="sd"> This method runs anaconda to create the image and then based on the opts</span>
<span class="sd"> passed creates a qemu disk image or tarfile.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dirinstall_path</span> <span class="o">=</span> <span class="n">ROOT_PATH</span>
<span class="c1"># Clean up /tmp/ from previous runs to prevent stale info from being used</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;/tmp/yum.repos.d/&quot;</span><span class="p">,</span> <span class="s2">&quot;/tmp/yum.cache/&quot;</span><span class="p">]:</span>
<span class="k">if</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">path</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;--kickstart&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="s2">&quot;--cmdline&quot;</span><span class="p">,</span> <span class="s2">&quot;--loglevel&quot;</span><span class="p">,</span> <span class="s2">&quot;debug&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">anaconda_args</span><span class="p">:</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">anaconda_args</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">proxy</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--proxy&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">proxy</span><span class="p">]</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">armplatform</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--armplatform&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">armplatform</span><span class="p">]</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_iso</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_pxe_live</span><span class="p">:</span>
<span class="c1"># Make a blank fs image</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--dirinstall&quot;</span><span class="p">]</span>
<span class="n">mkext4img</span><span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">fs_label</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">disk_size</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</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">dirinstall_path</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">)</span>
<span class="n">mount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;loop&quot;</span><span class="p">,</span> <span class="n">mnt</span><span class="o">=</span><span class="n">dirinstall_path</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_oci</span><span class="p">:</span>
<span class="c1"># Install under dirinstall_path, make sure it starts clean</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_oci</span><span class="p">:</span>
<span class="c1"># OCI installs under /rootfs/</span>
<span class="n">dirinstall_path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">,</span> <span class="s2">&quot;rootfs&quot;</span><span class="p">)</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--dirinstall&quot;</span><span class="p">,</span> <span class="n">dirinstall_path</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--dirinstall&quot;</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">dirinstall_path</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--image&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">]</span>
<span class="c1"># Create the sparse image</span>
<span class="n">mksparse</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span> <span class="o">*</span> <span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="n">log_monitor</span> <span class="o">=</span> <span class="n">LogMonitor</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">timeout</span><span class="p">)</span>
<span class="n">args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--remotelog&quot;</span><span class="p">,</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">:</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">log_monitor</span><span class="o">.</span><span class="n">host</span><span class="p">,</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">port</span><span class="p">)]</span>
<span class="n">cancel_funcs</span> <span class="o">=</span> <span class="p">[</span><span class="n">log_monitor</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_check</span><span class="p">]</span>
<span class="k">if</span> <span class="n">cancel_func</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">cancel_funcs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cancel_func</span><span class="p">)</span>
<span class="c1"># Make sure anaconda has the right product and release</span>
<span class="c1"># Preload libgomp.so.1 to workaround rhbz#1722181</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Running anaconda.&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">unshare_args</span> <span class="o">=</span> <span class="p">[</span> <span class="s2">&quot;--pid&quot;</span><span class="p">,</span> <span class="s2">&quot;--kill-child&quot;</span><span class="p">,</span> <span class="s2">&quot;--mount&quot;</span><span class="p">,</span> <span class="s2">&quot;--propagation&quot;</span><span class="p">,</span> <span class="s2">&quot;unchanged&quot;</span><span class="p">,</span> <span class="s2">&quot;anaconda&quot;</span> <span class="p">]</span> <span class="o">+</span> <span class="n">args</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">execReadlines</span><span class="p">(</span><span class="s2">&quot;unshare&quot;</span><span class="p">,</span> <span class="n">unshare_args</span><span class="p">,</span> <span class="n">reset_lang</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">env_add</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;ANACONDA_PRODUCTNAME&quot;</span><span class="p">:</span> <span class="n">opts</span><span class="o">.</span><span class="n">project</span><span class="p">,</span>
<span class="s2">&quot;ANACONDA_PRODUCTVERSION&quot;</span><span class="p">:</span> <span class="n">opts</span><span class="o">.</span><span class="n">releasever</span><span class="p">,</span>
<span class="s2">&quot;LD_PRELOAD&quot;</span><span class="p">:</span> <span class="s2">&quot;libgomp.so.1&quot;</span><span class="p">},</span>
<span class="n">callback</span><span class="o">=</span><span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="ow">not</span> <span class="n">novirt_cancel_check</span><span class="p">(</span><span class="n">cancel_funcs</span><span class="p">,</span> <span class="n">p</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="n">line</span><span class="p">)</span>
<span class="c1"># Make sure the new filesystem is correctly labeled</span>
<span class="n">setfiles_args</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;-e&quot;</span><span class="p">,</span> <span class="s2">&quot;/proc&quot;</span><span class="p">,</span> <span class="s2">&quot;-e&quot;</span><span class="p">,</span> <span class="s2">&quot;/sys&quot;</span><span class="p">,</span>
<span class="s2">&quot;/etc/selinux/targeted/contexts/files/file_contexts&quot;</span><span class="p">,</span> <span class="s2">&quot;/&quot;</span><span class="p">]</span>
<span class="k">if</span> <span class="s2">&quot;--dirinstall&quot;</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
<span class="c1"># setfiles may not be available, warn instead of fail</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;setfiles&quot;</span><span class="p">,</span> <span class="n">setfiles_args</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">dirinstall_path</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span><span class="p">,</span> <span class="ne">OSError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Running setfiles on install tree failed: </span><span class="si">%s</span><span class="s2">&quot;</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">else</span><span class="p">:</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">disk_img</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="n">img_mount</span> <span class="ow">and</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;setfiles&quot;</span><span class="p">,</span> <span class="n">setfiles_args</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">)</span>
<span class="k">except</span> <span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span><span class="p">,</span> <span class="ne">OSError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">&quot;Running setfiles on install tree failed: </span><span class="si">%s</span><span class="s2">&quot;</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="c1"># For image installs, run fstrim to discard unused blocks. This way</span>
<span class="c1"># unused blocks do not need to be allocated for sparse image types</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;fstrim&quot;</span><span class="p">,</span> <span class="p">[</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">])</span>
<span class="k">except</span> <span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span><span class="p">,</span> <span class="ne">OSError</span><span class="p">)</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Running anaconda failed: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install failed&quot;</span><span class="p">)</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">log_monitor</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
<span class="c1"># Move the anaconda logs over to a log directory</span>
<span class="n">log_dir</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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">logfile</span><span class="p">))</span>
<span class="n">log_anaconda</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">log_dir</span><span class="p">,</span> <span class="s2">&quot;anaconda&quot;</span><span class="p">)</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">log_anaconda</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">mkdir</span><span class="p">(</span><span class="n">log_anaconda</span><span class="p">)</span>
<span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;/tmp/*log&quot;</span><span class="p">)</span><span class="o">+</span><span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;/tmp/anaconda-tb-*&quot;</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">log_anaconda</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">l</span><span class="p">)</span>
<span class="c1"># Make sure any leftover anaconda mounts have been cleaned up</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">anaconda_cleanup</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install cleanup of anaconda mounts failed.&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_iso</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_pxe_live</span><span class="p">:</span>
<span class="n">dm_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">splitext</span><span class="p">(</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">disk_img</span><span class="p">))[</span><span class="mi">0</span><span class="p">]</span>
<span class="c1"># Remove device-mapper for partitions and disk</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Removing device-mapper setup on </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">dm_name</span><span class="p">)</span>
<span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;/dev/mapper/&quot;</span><span class="o">+</span><span class="n">dm_name</span><span class="o">+</span><span class="s2">&quot;*&quot;</span><span class="p">),</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
<span class="n">dm_detach</span><span class="p">(</span><span class="n">d</span><span class="p">)</span>
<span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Removing loop device for </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">)</span>
<span class="n">loop_detach</span><span class="p">(</span><span class="s2">&quot;/dev/&quot;</span><span class="o">+</span><span class="n">get_loop_name</span><span class="p">(</span><span class="n">disk_img</span><span class="p">))</span>
<span class="c1"># qemu disk image is used by bare qcow2 images and by Vagrant</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_type</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="s2">&quot;Converting </span><span class="si">%s</span><span class="s2"> to </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_type</span><span class="p">)</span>
<span class="n">qemu_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">qemu_args</span><span class="p">:</span>
<span class="n">qemu_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="c1"># convert the image to the selected format</span>
<span class="k">if</span> <span class="s2">&quot;-O&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">qemu_args</span><span class="p">:</span>
<span class="n">qemu_args</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="s2">&quot;-O&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_type</span><span class="p">])</span>
<span class="n">qemu_img</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-disk-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.img&quot;</span><span class="p">)</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;qemu-img&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;convert&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">qemu_args</span> <span class="o">+</span> <span class="p">[</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">qemu_img</span><span class="p">],</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_vagrant</span><span class="p">:</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;mv&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="n">qemu_img</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">],</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Take the new qcow2 image and package it up for Vagrant</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">vagrant_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-tmpdir-&quot;</span><span class="p">)</span>
<span class="n">metadata_path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;metadata.json&quot;</span><span class="p">)</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;mv&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="n">qemu_img</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;box.img&quot;</span><span class="p">)],</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">vagrant_metadata</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">vagrant_metadata</span><span class="p">,</span> <span class="n">metadata_path</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">create_vagrant_metadata</span><span class="p">(</span><span class="n">metadata_path</span><span class="p">)</span>
<span class="n">update_vagrant_metadata</span><span class="p">(</span><span class="n">metadata_path</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">vagrantfile</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">vagrantfile</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;vagrantfile&quot;</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="s2">&quot;Creating Vagrant image&quot;</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">,</span> <span class="n">selinux</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install mktar failed: rc=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">dirinstall_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install mktar failed: rc=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_oci</span><span class="p">:</span>
<span class="c1"># An OCI image places the filesystem under /rootfs/ and adds the json files at the top</span>
<span class="c1"># And then creates a tar of the whole thing.</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">oci_config</span><span class="p">,</span> <span class="n">ROOT_PATH</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">oci_runtime</span><span class="p">,</span> <span class="n">ROOT_PATH</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">ROOT_PATH</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install mktar failed: rc=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># For raw disk images, use fallocate to deallocate unused space</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;fallocate&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;--dig-holes&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">],</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="c1"># For make_tar_disk, wrap the result in a tar file, and remove the original disk image.</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar_disk</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">tar_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">,</span> <span class="n">selinux</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;novirt_install mktar failed: rc=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">disk_img</span><span class="p">)</span></div>
<div class="viewcode-block" id="virt_install"><a class="viewcode-back" href="../../pylorax.html#pylorax.installer.virt_install">[docs]</a><span class="k">def</span> <span class="nf">virt_install</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">install_log</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span> <span class="n">cancel_func</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">tar_img</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Use qemu to install to a disk image</span>
<span class="sd"> :param opts: options passed to livemedia-creator</span>
<span class="sd"> :type opts: argparse options</span>
<span class="sd"> :param str install_log: The path to write the log from qemu</span>
<span class="sd"> :param str disk_img: The full path to the disk image to be created</span>
<span class="sd"> :param int disk_size: The size of the disk_img in MiB</span>
<span class="sd"> :param cancel_func: Function that returns True to cancel build</span>
<span class="sd"> :type cancel_func: function</span>
<span class="sd"> :param str tar_img: For make_tar_disk, the path to final tarball to be created</span>
<span class="sd"> This uses qemu with a boot.iso and a kickstart to create a disk</span>
<span class="sd"> image and then optionally, based on the opts passed, creates tarfile.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">iso_mount</span> <span class="o">=</span> <span class="n">IsoMountpoint</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">iso</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">location</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">iso_mount</span><span class="o">.</span><span class="n">stage2</span><span class="p">:</span>
<span class="n">iso_mount</span><span class="o">.</span><span class="n">umount</span><span class="p">()</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;ISO is missing stage2, cannot continue&quot;</span><span class="p">)</span>
<span class="n">log_monitor</span> <span class="o">=</span> <span class="n">LogMonitor</span><span class="p">(</span><span class="n">install_log</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">timeout</span><span class="p">)</span>
<span class="n">cancel_funcs</span> <span class="o">=</span> <span class="p">[</span><span class="n">log_monitor</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_check</span><span class="p">]</span>
<span class="k">if</span> <span class="n">cancel_func</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">cancel_funcs</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">cancel_func</span><span class="p">)</span>
<span class="n">kernel_args</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">kernel_args</span><span class="p">:</span>
<span class="n">kernel_args</span> <span class="o">+=</span> <span class="n">opts</span><span class="o">.</span><span class="n">kernel_args</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">proxy</span><span class="p">:</span>
<span class="n">kernel_args</span> <span class="o">+=</span> <span class="s2">&quot; proxy=&quot;</span><span class="o">+</span><span class="n">opts</span><span class="o">.</span><span class="n">proxy</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_type</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span><span class="p">:</span>
<span class="n">qemu_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">qemu_args</span><span class="p">:</span>
<span class="n">qemu_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="s2">&quot;-f&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">qemu_args</span><span class="p">:</span>
<span class="n">qemu_args</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">image_type</span><span class="p">]</span>
<span class="n">mkqemu_img</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="o">*</span><span class="mi">1024</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">qemu_args</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_oci</span><span class="p">:</span>
<span class="n">diskimg_path</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mktemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-disk-&quot;</span><span class="p">,</span> <span class="n">suffix</span><span class="o">=</span><span class="s2">&quot;.img&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">diskimg_path</span> <span class="o">=</span> <span class="n">disk_img</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">QEMUInstall</span><span class="p">(</span><span class="n">opts</span><span class="p">,</span> <span class="n">iso_mount</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">ks</span><span class="p">,</span> <span class="n">diskimg_path</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span>
<span class="n">kernel_args</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">ram</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">vcpus</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">vnc</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">arch</span><span class="p">,</span>
<span class="n">cancel_func</span> <span class="o">=</span> <span class="k">lambda</span> <span class="p">:</span> <span class="nb">any</span><span class="p">(</span><span class="n">f</span><span class="p">()</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">cancel_funcs</span><span class="p">),</span>
<span class="n">virtio_host</span> <span class="o">=</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">host</span><span class="p">,</span>
<span class="n">virtio_port</span> <span class="o">=</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">port</span><span class="p">,</span>
<span class="n">image_type</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">image_type</span><span class="p">,</span> <span class="n">boot_uefi</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">virt_uefi</span><span class="p">,</span>
<span class="n">ovmf_path</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">ovmf_path</span><span class="p">)</span>
<span class="n">log_monitor</span><span class="o">.</span><span class="n">shutdown</span><span class="p">()</span>
<span class="k">except</span> <span class="n">InstallError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;VirtualInstall failed: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">raise</span>
<span class="k">finally</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="s2">&quot;unmounting the iso&quot;</span><span class="p">)</span>
<span class="n">iso_mount</span><span class="o">.</span><span class="n">umount</span><span class="p">()</span>
<span class="k">if</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_check</span><span class="p">():</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">error_line</span> <span class="ow">and</span> <span class="n">opts</span><span class="o">.</span><span class="n">timeout</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;virt_install failed due to timeout&quot;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;virt_install failed on line: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">log_monitor</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">error_line</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">cancel_func</span> <span class="ow">and</span> <span class="n">cancel_func</span><span class="p">():</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;virt_install canceled by cancel_func&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_fsimage</span><span class="p">:</span>
<span class="n">mkfsimage_from_disk</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">fs_label</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="n">img_mount</span> <span class="ow">and</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">img_mount</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;virt_install failed&quot;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_oci</span><span class="p">:</span>
<span class="c1"># An OCI image places the filesystem under /rootfs/ and adds the json files at the top</span>
<span class="c1"># And then creates a tar of the whole thing.</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="k">with</span> <span class="n">PartitionMount</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">,</span> <span class="n">submount</span><span class="o">=</span><span class="s2">&quot;rootfs&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">img_mount</span><span class="p">:</span>
<span class="k">if</span> <span class="n">img_mount</span> <span class="ow">and</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">oci_config</span><span class="p">,</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">oci_runtime</span><span class="p">,</span> <span class="n">img_mount</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">img_mount</span><span class="o">.</span><span class="n">temp_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">rc</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">diskimg_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;virt_install failed&quot;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_vagrant</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">vagrant_dir</span> <span class="o">=</span> <span class="n">tempfile</span><span class="o">.</span><span class="n">mkdtemp</span><span class="p">(</span><span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;lmc-tmpdir-&quot;</span><span class="p">)</span>
<span class="n">metadata_path</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;metadata.json&quot;</span><span class="p">)</span>
<span class="n">execWithRedirect</span><span class="p">(</span><span class="s2">&quot;mv&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;-f&quot;</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;box.img&quot;</span><span class="p">)],</span> <span class="n">raise_err</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">vagrant_metadata</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">vagrant_metadata</span><span class="p">,</span> <span class="n">metadata_path</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">create_vagrant_metadata</span><span class="p">(</span><span class="n">metadata_path</span><span class="p">)</span>
<span class="n">update_vagrant_metadata</span><span class="p">(</span><span class="n">metadata_path</span><span class="p">,</span> <span class="n">disk_size</span><span class="p">)</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">vagrantfile</span><span class="p">:</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">opts</span><span class="o">.</span><span class="n">vagrantfile</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="s2">&quot;vagrantfile&quot;</span><span class="p">))</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">,</span> <span class="n">disk_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">,</span> <span class="n">selinux</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;virt_install failed&quot;</span><span class="p">)</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">vagrant_dir</span><span class="p">)</span>
<span class="c1"># For make_tar_disk, wrap the result in a tar file, and remove the original disk image.</span>
<span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">make_tar_disk</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="o">.</span><span class="n">compress_args</span><span class="p">:</span>
<span class="n">compress_args</span> <span class="o">+=</span> <span class="n">arg</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">mktar</span><span class="p">(</span><span class="n">disk_img</span><span class="p">,</span> <span class="n">tar_img</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">compression</span><span class="p">,</span> <span class="n">compress_args</span><span class="p">,</span> <span class="n">selinux</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<span class="k">if</span> <span class="n">rc</span><span class="p">:</span>
<span class="k">raise</span> <span class="n">InstallError</span><span class="p">(</span><span class="s2">&quot;virt_install mktar failed: rc=</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">rc</span><span class="p">)</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">disk_img</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,404 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.monitor &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.monitor</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.monitor</h1><div class="highlight"><pre>
<span></span><span class="c1"># monitor.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Author(s): Brian C. Lane &lt;bcl@redhat.com&gt;</span>
<span class="c1">#</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="s2">&quot;livemedia-creator&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">socket</span>
<span class="kn">import</span> <span class="nn">socketserver</span>
<span class="kn">import</span> <span class="nn">threading</span>
<span class="kn">import</span> <span class="nn">time</span>
<div class="viewcode-block" id="LogRequestHandler"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogRequestHandler">[docs]</a><span class="k">class</span> <span class="nc">LogRequestHandler</span><span class="p">(</span><span class="n">socketserver</span><span class="o">.</span><span class="n">BaseRequestHandler</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Handle monitoring and saving the logfiles from the virtual install</span>
<span class="sd"> Incoming data is written to self.server.log_path and each line is checked</span>
<span class="sd"> for patterns that would indicate that the installation failed.</span>
<span class="sd"> self.server.log_error is set True when this happens.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">simple_tests</span> <span class="o">=</span> <span class="p">[</span>
<span class="s2">&quot;Traceback (&quot;</span><span class="p">,</span>
<span class="s2">&quot;traceback script(s) have been run&quot;</span><span class="p">,</span>
<span class="s2">&quot;Out of memory:&quot;</span><span class="p">,</span>
<span class="s2">&quot;Call Trace:&quot;</span><span class="p">,</span>
<span class="s2">&quot;insufficient disk space:&quot;</span><span class="p">,</span>
<span class="s2">&quot;Not enough disk space to download the packages&quot;</span><span class="p">,</span>
<span class="s2">&quot;error populating transaction after&quot;</span><span class="p">,</span>
<span class="s2">&quot;crashed on signal&quot;</span><span class="p">,</span>
<span class="s2">&quot;packaging: Missed: NoSuchPackage&quot;</span><span class="p">,</span>
<span class="s2">&quot;packaging: Installation failed&quot;</span><span class="p">,</span>
<span class="s2">&quot;The following error occurred while installing. This is a fatal error&quot;</span>
<span class="p">]</span>
<span class="n">re_tests</span> <span class="o">=</span> <span class="p">[</span>
<span class="sa">r</span><span class="s2">&quot;packaging: base repo .* not valid&quot;</span><span class="p">,</span>
<span class="sa">r</span><span class="s2">&quot;packaging: .* requires .*&quot;</span>
<span class="p">]</span>
<div class="viewcode-block" id="LogRequestHandler.setup"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogRequestHandler.setup">[docs]</a> <span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Start writing to self.server.log_path&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_path</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_path</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="c1"># pylint: disable=attribute-defined-outside-init</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fp</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">settimeout</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span></div>
<div class="viewcode-block" id="LogRequestHandler.handle"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogRequestHandler.handle">[docs]</a> <span class="k">def</span> <span class="nf">handle</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Write incoming data to a logfile and check for errors</span>
<span class="sd"> Split incoming data into lines and check for any Tracebacks or other</span>
<span class="sd"> errors that indicate that the install failed.</span>
<span class="sd"> Loops until self.server.kill is True</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;Processing logs from </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">client_address</span><span class="p">)</span>
<span class="n">line</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">kill</span><span class="p">:</span>
<span class="k">break</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">4096</span><span class="p">),</span> <span class="s2">&quot;utf8&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fp</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fp</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fp</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>
<span class="c1"># check the data for errors and set error flag</span>
<span class="c1"># need to assemble it into lines so we can test for the error</span>
<span class="c1"># string.</span>
<span class="k">while</span> <span class="n">data</span><span class="p">:</span>
<span class="n">more</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="n">line</span> <span class="o">+=</span> <span class="n">more</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">more</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">1</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">iserror</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="n">line</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">more</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">timeout</span><span class="p">:</span>
<span class="k">pass</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> <span class="c1"># pylint: disable=broad-except</span>
<span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;log processing killed by exception: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span>
<span class="k">break</span></div>
<div class="viewcode-block" id="LogRequestHandler.finish"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogRequestHandler.finish">[docs]</a> <span class="k">def</span> <span class="nf">finish</span><span class="p">(</span><span class="bp">self</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="s2">&quot;Shutting down log processing&quot;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">fp</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">fp</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
<div class="viewcode-block" id="LogRequestHandler.iserror"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogRequestHandler.iserror">[docs]</a> <span class="k">def</span> <span class="nf">iserror</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">line</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Check a line to see if it contains an error indicating installation failure</span>
<span class="sd"> :param str line: log line to check for failure</span>
<span class="sd"> If the line contains IGNORED it will be skipped.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="s2">&quot;IGNORED&quot;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
<span class="k">return</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">simple_tests</span><span class="p">:</span>
<span class="k">if</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_error</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">error_line</span> <span class="o">=</span> <span class="n">line</span>
<span class="k">return</span>
<span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">re_tests</span><span class="p">:</span>
<span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">line</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">log_error</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">error_line</span> <span class="o">=</span> <span class="n">line</span>
<span class="k">return</span></div></div>
<div class="viewcode-block" id="LogServer"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogServer">[docs]</a><span class="k">class</span> <span class="nc">LogServer</span><span class="p">(</span><span class="n">socketserver</span><span class="o">.</span><span class="n">TCPServer</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;A TCP Server that listens for log data&quot;&quot;&quot;</span>
<span class="c1"># Number of seconds to wait for a connection after startup</span>
<span class="n">timeout</span> <span class="o">=</span> <span class="mi">60</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">log_path</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Setup the log server</span>
<span class="sd"> :param str log_path: Path to the log file to write</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kill</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">log_error</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">error_line</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">log_path</span> <span class="o">=</span> <span class="n">log_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s2">&quot;timeout&quot;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_start_time</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span>
<span class="n">socketserver</span><span class="o">.</span><span class="n">TCPServer</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<div class="viewcode-block" id="LogServer.log_check"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogServer.log_check">[docs]</a> <span class="k">def</span> <span class="nf">log_check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Check to see if an error has been found in the log</span>
<span class="sd"> :returns: True if there has been an error</span>
<span class="sd"> :rtype: bool</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span><span class="p">:</span>
<span class="n">taking_too_long</span> <span class="o">=</span> <span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()</span> <span class="o">&gt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">_start_time</span> <span class="o">+</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_timeout</span> <span class="o">*</span> <span class="mi">60</span><span class="p">)</span>
<span class="k">if</span> <span class="n">taking_too_long</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Canceling installation due to timeout&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">taking_too_long</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log_error</span> <span class="ow">or</span> <span class="n">taking_too_long</span></div></div>
<div class="viewcode-block" id="LogMonitor"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogMonitor">[docs]</a><span class="k">class</span> <span class="nc">LogMonitor</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Setup a server to monitor the logs output by the installation</span>
<span class="sd"> This needs to be running before the virt-install runs, it expects</span>
<span class="sd"> there to be a listener on the port used for the virtio log port.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">log_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">host</span><span class="o">=</span><span class="s2">&quot;localhost&quot;</span><span class="p">,</span> <span class="n">port</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">log_request_handler_class</span><span class="o">=</span><span class="n">LogRequestHandler</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Start a thread to monitor the logs.</span>
<span class="sd"> :param str log_path: Path to the logfile to write</span>
<span class="sd"> :param str host: Host to bind to. Default is localhost.</span>
<span class="sd"> :param int port: Port to listen to or 0 to pick a port</span>
<span class="sd"> If 0 is passed for the port the dynamically assigned port will be</span>
<span class="sd"> available as self.port</span>
<span class="sd"> If log_path isn&#39;t set then it only monitors the logs, instead of</span>
<span class="sd"> also writing them to disk.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span> <span class="o">=</span> <span class="n">LogServer</span><span class="p">(</span><span class="n">log_path</span><span class="p">,</span> <span class="p">(</span><span class="n">host</span><span class="p">,</span> <span class="n">port</span><span class="p">),</span> <span class="n">log_request_handler_class</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="n">timeout</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">port</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">server_address</span>
<span class="bp">self</span><span class="o">.</span><span class="n">log_path</span> <span class="o">=</span> <span class="n">log_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server_thread</span> <span class="o">=</span> <span class="n">threading</span><span class="o">.</span><span class="n">Thread</span><span class="p">(</span><span class="n">target</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">handle_request</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server_thread</span><span class="o">.</span><span class="n">daemon</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server_thread</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<div class="viewcode-block" id="LogMonitor.shutdown"><a class="viewcode-back" href="../../pylorax.html#pylorax.monitor.LogMonitor.shutdown">[docs]</a> <span class="k">def</span> <span class="nf">shutdown</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Force shutdown of the monitoring thread&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server</span><span class="o">.</span><span class="n">kill</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">server_thread</span><span class="o">.</span><span class="n">join</span><span class="p">()</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,305 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.mount &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.mount</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.mount</h1><div class="highlight"><pre>
<span></span><span class="c1"># mount.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Author(s): Brian C. Lane &lt;bcl@redhat.com&gt;</span>
<span class="c1">#</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="s2">&quot;livemedia-creator&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">pycdlib</span>
<span class="kn">from</span> <span class="nn">pycdlib.pycdlibexception</span> <span class="kn">import</span> <span class="n">PyCdlibException</span>
<span class="kn">from</span> <span class="nn">pylorax.imgutils</span> <span class="kn">import</span> <span class="n">mount</span><span class="p">,</span> <span class="n">umount</span>
<div class="viewcode-block" id="IsoMountpoint"><a class="viewcode-back" href="../../pylorax.html#pylorax.mount.IsoMountpoint">[docs]</a><span class="k">class</span> <span class="nc">IsoMountpoint</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mount the iso and check to make sure the vmlinuz and initrd.img files exist</span>
<span class="sd"> Also check the iso for a a stage2 image and set a flag and extract the</span>
<span class="sd"> iso&#39;s label.</span>
<span class="sd"> stage2 can be either LiveOS/squashfs.img or images/install.img</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">iso_path</span><span class="p">,</span> <span class="n">initrd_path</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Mount the iso</span>
<span class="sd"> :param str iso_path: Path to the iso to mount</span>
<span class="sd"> :param str initrd_path: Optional path to initrd</span>
<span class="sd"> initrd_path can be used to point to a tree with a newer</span>
<span class="sd"> initrd.img than the iso has. The iso is still used for stage2.</span>
<span class="sd"> self.kernel and self.initrd point to the kernel and initrd.</span>
<span class="sd"> self.stage2 is set to True if there is a stage2 image.</span>
<span class="sd"> self.repo is the path to the mounted iso if there is a /repodata dir.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">iso_path</span> <span class="o">=</span> <span class="n">iso_path</span>
<span class="bp">self</span><span class="o">.</span><span class="n">initrd_path</span> <span class="o">=</span> <span class="n">initrd_path</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">initrd_path</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span> <span class="o">=</span> <span class="n">mount</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">iso_path</span><span class="p">,</span> <span class="n">opts</span><span class="o">=</span><span class="s2">&quot;loop&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">initrd_path</span>
<span class="n">kernel_list</span> <span class="o">=</span> <span class="p">[(</span><span class="s2">&quot;/isolinux/vmlinuz&quot;</span><span class="p">,</span> <span class="s2">&quot;/isolinux/initrd.img&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;/ppc/ppc64/vmlinuz&quot;</span><span class="p">,</span> <span class="s2">&quot;/ppc/ppc64/initrd.img&quot;</span><span class="p">),</span>
<span class="p">(</span><span class="s2">&quot;/images/pxeboot/vmlinuz&quot;</span><span class="p">,</span> <span class="s2">&quot;/images/pxeboot/initrd.img&quot;</span><span class="p">)]</span>
<span class="k">if</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="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="s2">&quot;/repodata&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">repo</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span>
<span class="k">else</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">repo</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">stage2</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">exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="s2">&quot;/LiveOS/squashfs.img&quot;</span><span class="p">)</span> <span class="ow">or</span> \
<span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="s2">&quot;/images/install.img&quot;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">for</span> <span class="n">kernel</span><span class="p">,</span> <span class="n">initrd</span> <span class="ow">in</span> <span class="n">kernel_list</span><span class="p">:</span>
<span class="k">if</span> <span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="n">kernel</span><span class="p">)</span> <span class="ow">and</span>
<span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="n">initrd</span><span class="p">)):</span>
<span class="bp">self</span><span class="o">.</span><span class="n">kernel</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="n">kernel</span>
<span class="bp">self</span><span class="o">.</span><span class="n">initrd</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="o">+</span><span class="n">initrd</span>
<span class="k">break</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Missing kernel and initrd file in iso, failed&quot;</span>
<span class="s2">&quot; to search under: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">kernel_list</span><span class="p">))</span>
<span class="k">except</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">umount</span><span class="p">()</span>
<span class="k">raise</span>
<span class="bp">self</span><span class="o">.</span><span class="n">get_iso_label</span><span class="p">()</span>
<div class="viewcode-block" id="IsoMountpoint.umount"><a class="viewcode-back" href="../../pylorax.html#pylorax.mount.IsoMountpoint.umount">[docs]</a> <span class="k">def</span> <span class="nf">umount</span><span class="p">(</span> <span class="bp">self</span> <span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Unmount the iso&quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">initrd_path</span><span class="p">:</span>
<span class="n">umount</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mount_dir</span><span class="p">)</span></div>
<div class="viewcode-block" id="IsoMountpoint.get_iso_label"><a class="viewcode-back" href="../../pylorax.html#pylorax.mount.IsoMountpoint.get_iso_label">[docs]</a> <span class="k">def</span> <span class="nf">get_iso_label</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get the iso&#39;s label using isoinfo</span>
<span class="sd"> Sets self.label if one is found</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">iso</span> <span class="o">=</span> <span class="n">pycdlib</span><span class="o">.</span><span class="n">PyCdlib</span><span class="p">()</span>
<span class="n">iso</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">iso_path</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">label</span> <span class="o">=</span> <span class="n">iso</span><span class="o">.</span><span class="n">pvd</span><span class="o">.</span><span class="n">volume_identifier</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;UTF-8&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="k">except</span> <span class="n">PyCdlibException</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Problem reading label from </span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">iso_path</span><span class="p">,</span> <span class="n">e</span><span class="p">)</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,361 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.sysutils &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.sysutils</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.sysutils</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># sysutils.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2009-2019 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;joinpaths&quot;</span><span class="p">,</span> <span class="s2">&quot;touch&quot;</span><span class="p">,</span> <span class="s2">&quot;replace&quot;</span><span class="p">,</span> <span class="s2">&quot;chown_&quot;</span><span class="p">,</span> <span class="s2">&quot;chmod_&quot;</span><span class="p">,</span> <span class="s2">&quot;remove&quot;</span><span class="p">,</span>
<span class="s2">&quot;linktree&quot;</span><span class="p">]</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">fileinput</span>
<span class="kn">import</span> <span class="nn">pwd</span>
<span class="kn">import</span> <span class="nn">grp</span>
<span class="kn">import</span> <span class="nn">glob</span>
<span class="kn">import</span> <span class="nn">shutil</span>
<span class="kn">import</span> <span class="nn">shlex</span>
<span class="kn">from</span> <span class="nn">configparser</span> <span class="kn">import</span> <span class="n">ConfigParser</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">runcmd</span>
<div class="viewcode-block" id="joinpaths"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.joinpaths">[docs]</a><span class="k">def</span> <span class="nf">joinpaths</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">path</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">sep</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;follow_symlinks&quot;</span><span class="p">):</span>
<span class="k">return</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">realpath</span><span class="p">(</span><span class="n">path</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">path</span></div>
<div class="viewcode-block" id="touch"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.touch">[docs]</a><span class="k">def</span> <span class="nf">touch</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>
<span class="c1"># python closes the file when it goes out of scope</span>
<span class="nb">open</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="replace"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.replace">[docs]</a><span class="k">def</span> <span class="nf">replace</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">find</span><span class="p">,</span> <span class="n">sub</span><span class="p">):</span>
<span class="n">fin</span> <span class="o">=</span> <span class="n">fileinput</span><span class="o">.</span><span class="n">input</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">inplace</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">pattern</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="n">find</span><span class="p">)</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">fin</span><span class="p">:</span>
<span class="n">line</span> <span class="o">=</span> <span class="n">pattern</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="n">sub</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="n">fin</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
<div class="viewcode-block" id="chown_"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.chown_">[docs]</a><span class="k">def</span> <span class="nf">chown_</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">user</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">group</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">uid</span> <span class="o">=</span> <span class="n">gid</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="k">if</span> <span class="n">user</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">uid</span> <span class="o">=</span> <span class="n">pwd</span><span class="o">.</span><span class="n">getpwnam</span><span class="p">(</span><span class="n">user</span><span class="p">)[</span><span class="mi">2</span><span class="p">]</span>
<span class="k">if</span> <span class="n">group</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">gid</span> <span class="o">=</span> <span class="n">grp</span><span class="o">.</span><span class="n">getgrnam</span><span class="p">(</span><span class="n">group</span><span class="p">)[</span><span class="mi">2</span><span class="p">]</span>
<span class="k">for</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">chown</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">uid</span><span class="p">,</span> <span class="n">gid</span><span class="p">)</span>
<span class="k">if</span> <span class="n">recursive</span> <span class="ow">and</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">fname</span><span class="p">):</span>
<span class="k">for</span> <span class="n">nested</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>
<span class="n">nested</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">nested</span><span class="p">)</span>
<span class="n">chown_</span><span class="p">(</span><span class="n">nested</span><span class="p">,</span> <span class="n">user</span><span class="p">,</span> <span class="n">group</span><span class="p">,</span> <span class="n">recursive</span><span class="p">)</span></div>
<div class="viewcode-block" id="chmod_"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.chmod_">[docs]</a><span class="k">def</span> <span class="nf">chmod_</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">mode</span><span class="p">,</span> <span class="n">recursive</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="k">for</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">glob</span><span class="o">.</span><span class="n">iglob</span><span class="p">(</span><span class="n">path</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">chmod</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">mode</span><span class="p">)</span>
<span class="k">if</span> <span class="n">recursive</span> <span class="ow">and</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">fname</span><span class="p">):</span>
<span class="k">for</span> <span class="n">nested</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">fname</span><span class="p">):</span>
<span class="n">nested</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="n">nested</span><span class="p">)</span>
<span class="n">chmod_</span><span class="p">(</span><span class="n">nested</span><span class="p">,</span> <span class="n">mode</span><span class="p">,</span> <span class="n">recursive</span><span class="p">)</span></div>
<span class="k">def</span> <span class="nf">cpfile</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">copy2</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)</span>
<span class="k">if</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">dst</span><span class="p">):</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">dst</span><span class="p">,</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">src</span><span class="p">))</span>
<span class="k">return</span> <span class="n">dst</span>
<span class="k">def</span> <span class="nf">mvfile</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">):</span>
<span class="k">if</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">dst</span><span class="p">):</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">dst</span><span class="p">,</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">src</span><span class="p">))</span>
<span class="n">os</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)</span>
<span class="k">return</span> <span class="n">dst</span>
<div class="viewcode-block" id="remove"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.remove">[docs]</a><span class="k">def</span> <span class="nf">remove</span><span class="p">(</span><span class="n">target</span><span class="p">):</span>
<span class="k">if</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">target</span><span class="p">)</span> <span class="ow">and</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">islink</span><span class="p">(</span><span class="n">target</span><span class="p">):</span>
<span class="n">shutil</span><span class="o">.</span><span class="n">rmtree</span><span class="p">(</span><span class="n">target</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">os</span><span class="o">.</span><span class="n">unlink</span><span class="p">(</span><span class="n">target</span><span class="p">)</span></div>
<div class="viewcode-block" id="linktree"><a class="viewcode-back" href="../../pylorax.html#pylorax.sysutils.linktree">[docs]</a><span class="k">def</span> <span class="nf">linktree</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">):</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;/bin/cp&quot;</span><span class="p">,</span> <span class="s2">&quot;-alx&quot;</span><span class="p">,</span> <span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">])</span></div>
<span class="k">def</span> <span class="nf">unquote</span><span class="p">(</span><span class="n">s</span><span class="p">):</span>
<span class="k">return</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">shlex</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="n">s</span><span class="p">))</span>
<span class="k">class</span> <span class="nc">UnquotingConfigParser</span><span class="p">(</span><span class="n">ConfigParser</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;A ConfigParser, only with unquoting of the values.&quot;&quot;&quot;</span>
<span class="c1"># pylint: disable=arguments-differ</span>
<span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">ret</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
<span class="k">if</span> <span class="n">ret</span><span class="p">:</span>
<span class="n">ret</span> <span class="o">=</span> <span class="n">unquote</span><span class="p">(</span><span class="n">ret</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span>
<span class="k">def</span> <span class="nf">flatconfig</span><span class="p">(</span><span class="n">filename</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Use UnquotingConfigParser to read a flat config file (without</span>
<span class="sd"> section headers) by adding a section header.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="nb">open</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">conffh</span><span class="p">:</span>
<span class="n">conftext</span> <span class="o">=</span> <span class="s2">&quot;[main]</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span> <span class="n">conffh</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">UnquotingConfigParser</span><span class="p">()</span>
<span class="n">config</span><span class="o">.</span><span class="n">read_string</span><span class="p">(</span><span class="n">conftext</span><span class="p">)</span>
<span class="k">return</span> <span class="n">config</span><span class="p">[</span><span class="s1">&#39;main&#39;</span><span class="p">]</span>
<span class="k">def</span> <span class="nf">read_tail</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Read up to `size` kibibytes from the end of a file&quot;&quot;&quot;</span>
<span class="c1"># NOTE: In py3 text files are unicode, not bytes so we have to open it as bytes</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">return</span> <span class="n">_read_file_end</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_read_file_end</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">size</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Read the end of a file</span>
<span class="sd"> This skips to the next line to avoid starting in the middle of a unicode character.</span>
<span class="sd"> And returns &quot;&quot; in the case of a UnicodeDecodeError</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">f</span><span class="o">.</span><span class="n">seek</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="n">end</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">tell</span><span class="p">()</span>
<span class="k">if</span> <span class="n">end</span> <span class="o">&lt;</span> <span class="mi">1024</span> <span class="o">*</span> <span class="n">size</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">f</span><span class="o">.</span><span class="n">seek</span><span class="p">(</span><span class="n">end</span> <span class="o">-</span> <span class="p">(</span><span class="mi">1024</span> <span class="o">*</span> <span class="n">size</span><span class="p">))</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
<span class="k">try</span><span class="p">:</span>
<span class="c1"># Find the first newline in the block</span>
<span class="n">newline</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="n">data</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">),</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="n">text</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">newline</span><span class="p">:]</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s2">&quot;UTF-8&quot;</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">UnicodeDecodeError</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;&quot;</span>
<span class="k">return</span> <span class="n">text</span>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,624 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.treebuilder &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.treebuilder</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.treebuilder</h1><div class="highlight"><pre>
<span></span><span class="c1"># treebuilder.py - handle arch-specific tree building stuff using templates</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2011-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Author(s): Will Woods &lt;wwoods@redhat.com&gt;</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.treebuilder&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">basename</span>
<span class="kn">from</span> <span class="nn">shutil</span> <span class="kn">import</span> <span class="n">copytree</span><span class="p">,</span> <span class="n">copy2</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">CalledProcessError</span>
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">from</span> <span class="nn">pylorax.sysutils</span> <span class="kn">import</span> <span class="n">joinpaths</span><span class="p">,</span> <span class="n">remove</span>
<span class="kn">from</span> <span class="nn">pylorax.base</span> <span class="kn">import</span> <span class="n">DataHolder</span>
<span class="kn">from</span> <span class="nn">pylorax.ltmpl</span> <span class="kn">import</span> <span class="n">LoraxTemplateRunner</span>
<span class="kn">import</span> <span class="nn">pylorax.imgutils</span> <span class="k">as</span> <span class="nn">imgutils</span>
<span class="kn">from</span> <span class="nn">pylorax.executils</span> <span class="kn">import</span> <span class="n">runcmd</span><span class="p">,</span> <span class="n">runcmd_output</span><span class="p">,</span> <span class="n">execWithCapture</span>
<span class="n">templatemap</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;i386&#39;</span><span class="p">:</span> <span class="s1">&#39;x86.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;x86_64&#39;</span><span class="p">:</span> <span class="s1">&#39;x86.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;ppc64le&#39;</span><span class="p">:</span> <span class="s1">&#39;ppc64le.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;s390&#39;</span><span class="p">:</span> <span class="s1">&#39;s390.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;s390x&#39;</span><span class="p">:</span> <span class="s1">&#39;s390.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;aarch64&#39;</span><span class="p">:</span> <span class="s1">&#39;aarch64.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;arm&#39;</span><span class="p">:</span> <span class="s1">&#39;arm.tmpl&#39;</span><span class="p">,</span>
<span class="s1">&#39;armhfp&#39;</span><span class="p">:</span> <span class="s1">&#39;arm.tmpl&#39;</span><span class="p">,</span>
<span class="p">}</span>
<div class="viewcode-block" id="generate_module_info"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.generate_module_info">[docs]</a><span class="k">def</span> <span class="nf">generate_module_info</span><span class="p">(</span><span class="n">moddir</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">module_desc</span><span class="p">(</span><span class="n">mod</span><span class="p">):</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">runcmd_output</span><span class="p">([</span><span class="s2">&quot;modinfo&quot;</span><span class="p">,</span> <span class="s2">&quot;-F&quot;</span><span class="p">,</span> <span class="s2">&quot;description&quot;</span><span class="p">,</span> <span class="n">mod</span><span class="p">])</span>
<span class="k">return</span> <span class="n">output</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">read_module_set</span><span class="p">(</span><span class="n">name</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">set</span><span class="p">(</span><span class="n">l</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">moddir</span><span class="p">,</span><span class="n">name</span><span class="p">))</span> <span class="k">if</span> <span class="s2">&quot;.ko&quot;</span> <span class="ow">in</span> <span class="n">l</span><span class="p">)</span>
<span class="n">modsets</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;scsi&#39;</span><span class="p">:</span><span class="n">read_module_set</span><span class="p">(</span><span class="s2">&quot;modules.block&quot;</span><span class="p">),</span>
<span class="s1">&#39;eth&#39;</span><span class="p">:</span><span class="n">read_module_set</span><span class="p">(</span><span class="s2">&quot;modules.networking&quot;</span><span class="p">)}</span>
<span class="n">modinfo</span> <span class="o">=</span> <span class="nb">list</span><span class="p">()</span>
<span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">_dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">moddir</span><span class="p">):</span>
<span class="k">for</span> <span class="n">modtype</span><span class="p">,</span> <span class="n">modset</span> <span class="ow">in</span> <span class="n">modsets</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">for</span> <span class="n">mod</span> <span class="ow">in</span> <span class="n">modset</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">files</span><span class="p">):</span> <span class="c1"># modules in this dir</span>
<span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">_ext</span><span class="p">)</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">splitext</span><span class="p">(</span><span class="n">mod</span><span class="p">)</span> <span class="c1"># foo.ko -&gt; (foo, .ko)</span>
<span class="n">desc</span> <span class="o">=</span> <span class="n">module_desc</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root</span><span class="p">,</span><span class="n">mod</span><span class="p">))</span> <span class="ow">or</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> driver&quot;</span> <span class="o">%</span> <span class="n">name</span>
<span class="n">modinfo</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">dict</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="n">modtype</span><span class="p">,</span> <span class="n">desc</span><span class="o">=</span><span class="n">desc</span><span class="p">))</span>
<span class="n">out</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span> <span class="ow">or</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">moddir</span><span class="p">,</span><span class="s2">&quot;module-info&quot;</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;Version 0</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">mod</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">modinfo</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">m</span><span class="p">:</span> <span class="n">m</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;name&#39;</span><span class="p">)):</span>
<span class="n">out</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{name}</span><span class="se">\n\t</span><span class="si">{type}</span><span class="se">\n\t</span><span class="s1">&quot;</span><span class="si">{desc:.65}</span><span class="s1">&quot;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="n">mod</span><span class="p">))</span></div>
<div class="viewcode-block" id="RuntimeBuilder"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder">[docs]</a><span class="k">class</span> <span class="nc">RuntimeBuilder</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Builds the anaconda runtime image.&#39;&#39;&#39;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="p">,</span> <span class="n">dbo</span><span class="p">,</span> <span class="n">templatedir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">installpkgs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">excludepkgs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_templates</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">add_template_vars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">skip_branding</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
<span class="n">root</span> <span class="o">=</span> <span class="n">dbo</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">installroot</span>
<span class="c1"># use a copy of product so we can modify it locally</span>
<span class="n">product</span> <span class="o">=</span> <span class="n">product</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="n">product</span><span class="o">.</span><span class="n">name</span> <span class="o">=</span> <span class="n">product</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vars</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">arch</span><span class="o">=</span><span class="n">arch</span><span class="p">,</span> <span class="n">product</span><span class="o">=</span><span class="n">product</span><span class="p">,</span> <span class="n">dbo</span><span class="o">=</span><span class="n">dbo</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">,</span>
<span class="n">basearch</span><span class="o">=</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">,</span> <span class="n">libdir</span><span class="o">=</span><span class="n">arch</span><span class="o">.</span><span class="n">libdir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dbo</span> <span class="o">=</span> <span class="n">dbo</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span> <span class="o">=</span> <span class="n">LoraxTemplateRunner</span><span class="p">(</span><span class="n">inroot</span><span class="o">=</span><span class="n">root</span><span class="p">,</span> <span class="n">outroot</span><span class="o">=</span><span class="n">root</span><span class="p">,</span>
<span class="n">dbo</span><span class="o">=</span><span class="n">dbo</span><span class="p">,</span> <span class="n">templatedir</span><span class="o">=</span><span class="n">templatedir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_templates</span> <span class="o">=</span> <span class="n">add_templates</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_template_vars</span> <span class="o">=</span> <span class="n">add_template_vars</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_installpkgs</span> <span class="o">=</span> <span class="n">installpkgs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_excludepkgs</span> <span class="o">=</span> <span class="n">excludepkgs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">defaults</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vars</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">reset</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_skip_branding</span> <span class="o">=</span> <span class="n">skip_branding</span>
<span class="k">def</span> <span class="nf">_install_branding</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Select the branding from the available &#39;system-release&#39; packages</span>
<span class="sd"> The *best* way to control this is to have a single package in the repo provide &#39;system-release&#39;</span>
<span class="sd"> When there are more than 1 package it will:</span>
<span class="sd"> - Make a list of the available packages</span>
<span class="sd"> - If variant is set look for a package ending with lower(variant) and use that</span>
<span class="sd"> - If there are one or more non-generic packages, use the first one after sorting</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_skip_branding</span><span class="p">:</span>
<span class="k">return</span>
<span class="n">release</span> <span class="o">=</span> <span class="kc">None</span>
<span class="n">q</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span>
<span class="n">a</span> <span class="o">=</span> <span class="n">q</span><span class="o">.</span><span class="n">available</span><span class="p">()</span>
<span class="n">pkgs</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">([</span><span class="n">p</span><span class="o">.</span><span class="n">name</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">a</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">provides</span><span class="o">=</span><span class="s1">&#39;system-release&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">p</span><span class="o">.</span><span class="n">name</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;generic&quot;</span><span class="p">)])</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">pkgs</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;No system-release packages found, could not get the release&quot;</span><span class="p">)</span>
<span class="k">return</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;system-release packages: </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">pkgs</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">variant</span><span class="p">:</span>
<span class="n">variant</span> <span class="o">=</span> <span class="p">[</span><span class="n">p</span> <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">pkgs</span> <span class="k">if</span> <span class="n">p</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="o">+</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">product</span><span class="o">.</span><span class="n">variant</span><span class="o">.</span><span class="n">lower</span><span class="p">())]</span>
<span class="k">if</span> <span class="n">variant</span><span class="p">:</span>
<span class="n">release</span> <span class="o">=</span> <span class="n">variant</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">release</span><span class="p">:</span>
<span class="n">release</span> <span class="o">=</span> <span class="n">pkgs</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="c1"># release</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;got release: </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">release</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">installpkg</span><span class="p">(</span><span class="n">release</span><span class="p">)</span>
<span class="c1"># logos</span>
<span class="n">release</span><span class="p">,</span> <span class="n">_suffix</span> <span class="o">=</span> <span class="n">release</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">installpkg</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">-logos&#39;</span> <span class="o">%</span> <span class="n">release</span><span class="p">)</span>
<div class="viewcode-block" id="RuntimeBuilder.install"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.install">[docs]</a> <span class="k">def</span> <span class="nf">install</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Install packages and do initial setup with runtime-install.tmpl&#39;&#39;&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_install_branding</span><span class="p">()</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_installpkgs</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">installpkg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_installpkgs</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_excludepkgs</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">removepkg</span><span class="p">(</span><span class="o">*</span><span class="bp">self</span><span class="o">.</span><span class="n">_excludepkgs</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;runtime-install.tmpl&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">tmpl</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_templates</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">tmpl</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">add_template_vars</span><span class="p">)</span></div>
<div class="viewcode-block" id="RuntimeBuilder.writepkglists"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.writepkglists">[docs]</a> <span class="k">def</span> <span class="nf">writepkglists</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pkglistdir</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;debugging data: write out lists of package contents&#39;&#39;&#39;</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">pkglistdir</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">pkglistdir</span><span class="p">)</span>
<span class="n">q</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span>
<span class="k">for</span> <span class="n">pkgobj</span> <span class="ow">in</span> <span class="n">q</span><span class="o">.</span><span class="n">installed</span><span class="p">():</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">pkglistdir</span><span class="p">,</span> <span class="n">pkgobj</span><span class="o">.</span><span class="n">name</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fobj</span><span class="p">:</span>
<span class="k">for</span> <span class="n">fname</span> <span class="ow">in</span> <span class="n">pkgobj</span><span class="o">.</span><span class="n">files</span><span class="p">:</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">fname</span><span class="p">))</span></div>
<div class="viewcode-block" id="RuntimeBuilder.postinstall"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.postinstall">[docs]</a> <span class="k">def</span> <span class="nf">postinstall</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Do some post-install setup work with runtime-postinstall.tmpl&#39;&#39;&#39;</span>
<span class="c1"># copy configdir into runtime root beforehand</span>
<span class="n">configdir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">templatedir</span><span class="p">,</span><span class="s2">&quot;config_files&quot;</span><span class="p">)</span>
<span class="n">configdir_path</span> <span class="o">=</span> <span class="s2">&quot;tmp/config_files&quot;</span>
<span class="n">fullpath</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="n">configdir_path</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">fullpath</span><span class="p">):</span>
<span class="n">remove</span><span class="p">(</span><span class="n">fullpath</span><span class="p">)</span>
<span class="n">copytree</span><span class="p">(</span><span class="n">configdir</span><span class="p">,</span> <span class="n">fullpath</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;runtime-postinstall.tmpl&quot;</span><span class="p">,</span> <span class="n">configdir</span><span class="o">=</span><span class="n">configdir_path</span><span class="p">)</span></div>
<div class="viewcode-block" id="RuntimeBuilder.cleanup"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.cleanup">[docs]</a> <span class="k">def</span> <span class="nf">cleanup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Remove unneeded packages and files with runtime-cleanup.tmpl&#39;&#39;&#39;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="s2">&quot;runtime-cleanup.tmpl&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="RuntimeBuilder.verify"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.verify">[docs]</a> <span class="k">def</span> <span class="nf">verify</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Ensure that contents of the installroot can run&#39;&#39;&#39;</span>
<span class="n">status</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">ELF_MAGIC</span> <span class="o">=</span> <span class="sa">b</span><span class="s1">&#39;</span><span class="se">\x7f</span><span class="s1">ELF&#39;</span>
<span class="c1"># Iterate over all files in /usr/bin and /usr/sbin</span>
<span class="c1"># For ELF files, gather them into a list and we&#39;ll check them all at</span>
<span class="c1"># the end. For files with a #!, check them as we go</span>
<span class="n">elf_files</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">usr_bin</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span> <span class="o">+</span> <span class="s1">&#39;/usr/bin&#39;</span><span class="p">)</span>
<span class="n">usr_sbin</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span> <span class="o">+</span> <span class="s1">&#39;/usr/sbin&#39;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">path</span> <span class="ow">in</span> <span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="p">(</span><span class="n">usr_bin</span><span class="o">.</span><span class="n">iterdir</span><span class="p">(),</span> <span class="n">usr_sbin</span><span class="o">.</span><span class="n">iterdir</span><span class="p">())</span> \
<span class="k">if</span> <span class="n">x</span><span class="o">.</span><span class="n">is_file</span><span class="p">()):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;rb&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="n">magic</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span>
<span class="k">if</span> <span class="n">magic</span> <span class="o">==</span> <span class="n">ELF_MAGIC</span><span class="p">:</span>
<span class="c1"># Save the path, minus the chroot prefix</span>
<span class="n">elf_files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">path</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">):])</span>
<span class="k">elif</span> <span class="n">magic</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="sa">b</span><span class="s1">&#39;#!&#39;</span><span class="p">:</span>
<span class="c1"># Reopen the file as text and read the first line.</span>
<span class="c1"># Open as latin-1 so that stray 8-bit characters don&#39;t make</span>
<span class="c1"># things blow up. We only really care about ASCII parts.</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">path</span><span class="p">,</span> <span class="s2">&quot;rt&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;latin-1&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f_text</span><span class="p">:</span>
<span class="c1"># Remove the #!, split on space, and take the first part</span>
<span class="n">shabang</span> <span class="o">=</span> <span class="n">f_text</span><span class="o">.</span><span class="n">readline</span><span class="p">()[</span><span class="mi">2</span><span class="p">:]</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
<span class="c1"># Does the path exist?</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">exists</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span> <span class="o">+</span> <span class="n">shabang</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">, needed by </span><span class="si">%s</span><span class="s1">, does not exist&#39;</span><span class="p">,</span> <span class="n">shabang</span><span class="p">,</span> <span class="n">path</span><span class="p">)</span>
<span class="n">status</span> <span class="o">=</span> <span class="kc">False</span>
<span class="c1"># Now, run ldd on all the ELF files</span>
<span class="c1"># Just run ldd once on everything so it isn&#39;t logged a million times.</span>
<span class="c1"># At least one thing in the list isn&#39;t going to be a dynamic executable,</span>
<span class="c1"># so use execWithCapture to ignore the exit code.</span>
<span class="n">filename</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">execWithCapture</span><span class="p">(</span><span class="s1">&#39;ldd&#39;</span><span class="p">,</span> <span class="n">elf_files</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">,</span>
<span class="n">log_output</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">filter_stderr</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">):</span>
<span class="k">if</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">isspace</span><span class="p">():</span>
<span class="c1"># New filename header, strip the : at the end and save</span>
<span class="n">filename</span> <span class="o">=</span> <span class="n">line</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">elif</span> <span class="s1">&#39;not found&#39;</span> <span class="ow">in</span> <span class="n">line</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%s</span><span class="s1">, needed by </span><span class="si">%s</span><span class="s1">, not found&#39;</span><span class="p">,</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">],</span> <span class="n">filename</span><span class="p">)</span>
<span class="n">status</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">return</span> <span class="n">status</span></div>
<div class="viewcode-block" id="RuntimeBuilder.writepkgsizes"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.writepkgsizes">[docs]</a> <span class="k">def</span> <span class="nf">writepkgsizes</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">pkgsizefile</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;debugging data: write a big list of pkg sizes&#39;&#39;&#39;</span>
<span class="n">fobj</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">pkgsizefile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span>
<span class="n">getsize</span> <span class="o">=</span> <span class="k">lambda</span> <span class="n">f</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">lstat</span><span class="p">(</span><span class="n">f</span><span class="p">)</span><span class="o">.</span><span class="n">st_size</span> <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">else</span> <span class="mi">0</span>
<span class="n">q</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">sack</span><span class="o">.</span><span class="n">query</span><span class="p">()</span>
<span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">q</span><span class="o">.</span><span class="n">installed</span><span class="p">()):</span>
<span class="n">pkgsize</span> <span class="o">=</span> <span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">,</span><span class="n">f</span><span class="p">))</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">p</span><span class="o">.</span><span class="n">files</span><span class="p">)</span>
<span class="n">fobj</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{0.name}</span><span class="s2">.</span><span class="si">{0.arch}</span><span class="s2">: </span><span class="si">{1}</span><span class="se">\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">pkgsize</span><span class="p">))</span></div>
<div class="viewcode-block" id="RuntimeBuilder.generate_module_data"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.generate_module_data">[docs]</a> <span class="k">def</span> <span class="nf">generate_module_data</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">root</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span>
<span class="n">moddir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s2">&quot;lib/modules/&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="n">findkernels</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="n">root</span><span class="p">):</span>
<span class="n">ksyms</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s2">&quot;boot/System.map-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;doing depmod and module-info for </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="p">)</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;depmod&quot;</span><span class="p">,</span> <span class="s2">&quot;-a&quot;</span><span class="p">,</span> <span class="s2">&quot;-F&quot;</span><span class="p">,</span> <span class="n">ksyms</span><span class="p">,</span> <span class="s2">&quot;-b&quot;</span><span class="p">,</span> <span class="n">root</span><span class="p">,</span> <span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="p">])</span>
<span class="n">generate_module_info</span><span class="p">(</span><span class="n">moddir</span><span class="o">+</span><span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="n">moddir</span><span class="o">+</span><span class="s2">&quot;module-info&quot;</span><span class="p">)</span></div>
<div class="viewcode-block" id="RuntimeBuilder.create_squashfs_runtime"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.create_squashfs_runtime">[docs]</a> <span class="k">def</span> <span class="nf">create_squashfs_runtime</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s2">&quot;/var/tmp/squashfs.img&quot;</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create a plain squashfs runtime&quot;&quot;&quot;</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</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">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">outfile</span><span class="p">))</span>
<span class="c1"># squash the rootfs</span>
<span class="k">return</span> <span class="n">imgutils</span><span class="o">.</span><span class="n">mksquashfs</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span></div>
<div class="viewcode-block" id="RuntimeBuilder.create_ext4_runtime"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.create_ext4_runtime">[docs]</a> <span class="k">def</span> <span class="nf">create_ext4_runtime</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="o">=</span><span class="s2">&quot;/var/tmp/squashfs.img&quot;</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">&quot;xz&quot;</span><span class="p">,</span> <span class="n">compressargs</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">2</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Create a squashfs compressed ext4 runtime&quot;&quot;&quot;</span>
<span class="c1"># make live rootfs image - must be named &quot;LiveOS/rootfs.img&quot; for dracut</span>
<span class="n">compressargs</span> <span class="o">=</span> <span class="n">compressargs</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="n">workdir</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">outfile</span><span class="p">),</span> <span class="s2">&quot;runtime-workdir&quot;</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">joinpaths</span><span class="p">(</span><span class="n">workdir</span><span class="p">,</span> <span class="s2">&quot;LiveOS&quot;</span><span class="p">))</span>
<span class="c1"># Catch problems with the rootfs being too small and clearly log them</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">imgutils</span><span class="o">.</span><span class="n">mkrootfsimg</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">root</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">workdir</span><span class="p">,</span> <span class="s2">&quot;LiveOS/rootfs.img&quot;</span><span class="p">),</span>
<span class="s2">&quot;Anaconda&quot;</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">size</span><span class="p">)</span>
<span class="k">except</span> <span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
<span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">stdout</span> <span class="ow">and</span> <span class="s2">&quot;No space left on device&quot;</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">stdout</span><span class="p">:</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;The rootfs ran out of space with size=</span><span class="si">%d</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">size</span><span class="p">)</span>
<span class="k">raise</span>
<span class="c1"># squash the live rootfs and clean up workdir</span>
<span class="n">rc</span> <span class="o">=</span> <span class="n">imgutils</span><span class="o">.</span><span class="n">mksquashfs</span><span class="p">(</span><span class="n">workdir</span><span class="p">,</span> <span class="n">outfile</span><span class="p">,</span> <span class="n">compression</span><span class="p">,</span> <span class="n">compressargs</span><span class="p">)</span>
<span class="n">remove</span><span class="p">(</span><span class="n">workdir</span><span class="p">)</span>
<span class="k">return</span> <span class="n">rc</span></div>
<div class="viewcode-block" id="RuntimeBuilder.finished"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.finished">[docs]</a> <span class="k">def</span> <span class="nf">finished</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Done using RuntimeBuilder</span>
<span class="sd"> Close the dnf base object</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">dbo</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div></div>
<div class="viewcode-block" id="TreeBuilder"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.TreeBuilder">[docs]</a><span class="k">class</span> <span class="nc">TreeBuilder</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Builds the arch-specific boot images.</span>
<span class="sd"> inroot should be the installtree root (the newly-built runtime dir)&#39;&#39;&#39;</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">arch</span><span class="p">,</span> <span class="n">inroot</span><span class="p">,</span> <span class="n">outroot</span><span class="p">,</span> <span class="n">runtime</span><span class="p">,</span> <span class="n">isolabel</span><span class="p">,</span> <span class="n">domacboot</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">doupgrade</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="n">templatedir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">add_templates</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">add_template_vars</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">workdir</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">extra_boot_args</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="c1"># NOTE: if you pass an arg named &quot;runtime&quot; to a mako template it&#39;ll</span>
<span class="c1"># clobber some mako internal variables - hence &quot;runtime_img&quot;.</span>
<span class="bp">self</span><span class="o">.</span><span class="n">vars</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">arch</span><span class="o">=</span><span class="n">arch</span><span class="p">,</span> <span class="n">product</span><span class="o">=</span><span class="n">product</span><span class="p">,</span> <span class="n">runtime_img</span><span class="o">=</span><span class="n">runtime</span><span class="p">,</span>
<span class="n">runtime_base</span><span class="o">=</span><span class="n">basename</span><span class="p">(</span><span class="n">runtime</span><span class="p">),</span>
<span class="n">inroot</span><span class="o">=</span><span class="n">inroot</span><span class="p">,</span> <span class="n">outroot</span><span class="o">=</span><span class="n">outroot</span><span class="p">,</span>
<span class="n">basearch</span><span class="o">=</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">,</span> <span class="n">libdir</span><span class="o">=</span><span class="n">arch</span><span class="o">.</span><span class="n">libdir</span><span class="p">,</span>
<span class="n">isolabel</span><span class="o">=</span><span class="n">isolabel</span><span class="p">,</span> <span class="n">udev</span><span class="o">=</span><span class="n">udev_escape</span><span class="p">,</span> <span class="n">domacboot</span><span class="o">=</span><span class="n">domacboot</span><span class="p">,</span> <span class="n">doupgrade</span><span class="o">=</span><span class="n">doupgrade</span><span class="p">,</span>
<span class="n">workdir</span><span class="o">=</span><span class="n">workdir</span><span class="p">,</span> <span class="n">lower</span><span class="o">=</span><span class="n">string_lower</span><span class="p">,</span>
<span class="n">extra_boot_args</span><span class="o">=</span><span class="n">extra_boot_args</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span> <span class="o">=</span> <span class="n">LoraxTemplateRunner</span><span class="p">(</span><span class="n">inroot</span><span class="p">,</span> <span class="n">outroot</span><span class="p">,</span> <span class="n">templatedir</span><span class="o">=</span><span class="n">templatedir</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">defaults</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">vars</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_templates</span> <span class="o">=</span> <span class="n">add_templates</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">add_template_vars</span> <span class="o">=</span> <span class="n">add_template_vars</span> <span class="ow">or</span> <span class="p">{}</span>
<span class="bp">self</span><span class="o">.</span><span class="n">templatedir</span> <span class="o">=</span> <span class="n">templatedir</span>
<span class="bp">self</span><span class="o">.</span><span class="n">treeinfo_data</span> <span class="o">=</span> <span class="kc">None</span>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">kernels</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">return</span> <span class="n">findkernels</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">inroot</span><span class="p">)</span>
<div class="viewcode-block" id="TreeBuilder.rebuild_initrds"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.TreeBuilder.rebuild_initrds">[docs]</a> <span class="k">def</span> <span class="nf">rebuild_initrds</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">add_args</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">backup</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;Rebuild all the initrds in the tree. If backup is specified, each</span>
<span class="sd"> initrd will be renamed with backup as a suffix before rebuilding.</span>
<span class="sd"> If backup is empty, the existing initrd files will be overwritten.</span>
<span class="sd"> If suffix is specified, the existing initrd is untouched and a new</span>
<span class="sd"> image is built with the filename &quot;${prefix}-${kernel.version}.img&quot;</span>
<span class="sd"> If the initrd doesn&#39;t exist its name will be created based on the</span>
<span class="sd"> name of the kernel.</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">add_args</span> <span class="o">=</span> <span class="n">add_args</span> <span class="ow">or</span> <span class="p">[]</span>
<span class="n">dracut</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;dracut&quot;</span><span class="p">,</span> <span class="s2">&quot;--nomdadmconf&quot;</span><span class="p">,</span> <span class="s2">&quot;--nolvmconf&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">add_args</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">backup</span><span class="p">:</span>
<span class="n">dracut</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;--force&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernels</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;No kernels found, cannot rebuild_initrds&quot;</span><span class="p">)</span>
<span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kernels</span><span class="p">:</span>
<span class="k">if</span> <span class="n">prefix</span><span class="p">:</span>
<span class="n">idir</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">dirname</span><span class="p">(</span><span class="n">kernel</span><span class="o">.</span><span class="n">path</span><span class="p">)</span>
<span class="n">outfile</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="n">idir</span><span class="p">,</span> <span class="n">prefix</span><span class="o">+</span><span class="s1">&#39;-&#39;</span><span class="o">+</span><span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="o">+</span><span class="s1">&#39;.img&#39;</span><span class="p">)</span>
<span class="k">elif</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">kernel</span><span class="p">,</span> <span class="s2">&quot;initrd&quot;</span><span class="p">):</span>
<span class="c1"># If there is an existing initrd, use that</span>
<span class="n">outfile</span> <span class="o">=</span> <span class="n">kernel</span><span class="o">.</span><span class="n">initrd</span><span class="o">.</span><span class="n">path</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># Construct an initrd from the kernel name</span>
<span class="n">outfile</span> <span class="o">=</span> <span class="n">kernel</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;vmlinuz-&quot;</span><span class="p">,</span> <span class="s2">&quot;initrd-&quot;</span><span class="p">)</span> <span class="o">+</span> <span class="s2">&quot;.img&quot;</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;rebuilding </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">outfile</span><span class="p">)</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;dracut warnings about /proc are safe to ignore&quot;</span><span class="p">)</span>
<span class="k">if</span> <span class="n">backup</span><span class="p">:</span>
<span class="n">initrd</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">inroot</span><span class="p">,</span> <span class="n">outfile</span><span class="p">)</span>
<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">initrd</span><span class="p">):</span>
<span class="n">os</span><span class="o">.</span><span class="n">rename</span><span class="p">(</span><span class="n">initrd</span><span class="p">,</span> <span class="n">initrd</span> <span class="o">+</span> <span class="n">backup</span><span class="p">)</span>
<span class="n">cmd</span> <span class="o">=</span> <span class="n">dracut</span> <span class="o">+</span> <span class="p">[</span><span class="n">outfile</span><span class="p">,</span> <span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="p">]</span>
<span class="n">runcmd</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">root</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">inroot</span><span class="p">)</span></div>
<div class="viewcode-block" id="TreeBuilder.build"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.TreeBuilder.build">[docs]</a> <span class="k">def</span> <span class="nf">build</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">templatefile</span> <span class="o">=</span> <span class="n">templatemap</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">arch</span><span class="o">.</span><span class="n">basearch</span><span class="p">]</span>
<span class="k">for</span> <span class="n">tmpl</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">add_templates</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">tmpl</span><span class="p">,</span> <span class="o">**</span><span class="bp">self</span><span class="o">.</span><span class="n">add_template_vars</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">templatefile</span><span class="p">,</span> <span class="n">kernels</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">kernels</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">treeinfo_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_runner</span><span class="o">.</span><span class="n">results</span><span class="o">.</span><span class="n">treeinfo</span>
<span class="bp">self</span><span class="o">.</span><span class="n">implantisomd5</span><span class="p">()</span></div>
<div class="viewcode-block" id="TreeBuilder.implantisomd5"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.TreeBuilder.implantisomd5">[docs]</a> <span class="k">def</span> <span class="nf">implantisomd5</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">for</span> <span class="n">_section</span><span class="p">,</span> <span class="n">data</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">treeinfo_data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="s1">&#39;boot.iso&#39;</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
<span class="n">iso</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">outroot</span><span class="p">,</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;boot.iso&#39;</span><span class="p">])</span>
<span class="n">runcmd</span><span class="p">([</span><span class="s2">&quot;implantisomd5&quot;</span><span class="p">,</span> <span class="n">iso</span><span class="p">])</span></div>
<span class="nd">@property</span>
<span class="k">def</span> <span class="nf">dracut_hooks_path</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return the path to the lorax dracut hooks scripts</span>
<span class="sd"> Use the configured share dir if it is setup,</span>
<span class="sd"> otherwise default to /usr/share/lorax/dracut_hooks</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">templatedir</span><span class="p">:</span>
<span class="k">return</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">templatedir</span><span class="p">,</span> <span class="s2">&quot;dracut_hooks&quot;</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="s2">&quot;/usr/share/lorax/dracut_hooks&quot;</span>
<div class="viewcode-block" id="TreeBuilder.copy_dracut_hooks"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.TreeBuilder.copy_dracut_hooks">[docs]</a> <span class="k">def</span> <span class="nf">copy_dracut_hooks</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">hooks</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Copy the hook scripts in hooks into the installroot&#39;s /tmp/</span>
<span class="sd"> and return a list of commands to pass to dracut when creating the</span>
<span class="sd"> initramfs</span>
<span class="sd"> hooks is a list of tuples with the name of the hook script and the</span>
<span class="sd"> target dracut hook directory</span>
<span class="sd"> (eg. [(&quot;99anaconda-copy-ks.sh&quot;, &quot;/lib/dracut/hooks/pre-pivot&quot;)])</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">dracut_commands</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">hook_script</span><span class="p">,</span> <span class="n">dracut_path</span> <span class="ow">in</span> <span class="n">hooks</span><span class="p">:</span>
<span class="n">src</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dracut_hooks_path</span><span class="p">,</span> <span class="n">hook_script</span><span class="p">)</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">exists</span><span class="p">(</span><span class="n">src</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s2">&quot;Missing lorax dracut hook script </span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="p">(</span><span class="n">src</span><span class="p">))</span>
<span class="k">continue</span>
<span class="n">dst</span> <span class="o">=</span> <span class="n">joinpaths</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">vars</span><span class="o">.</span><span class="n">inroot</span><span class="p">,</span> <span class="s2">&quot;/tmp/&quot;</span><span class="p">,</span> <span class="n">hook_script</span><span class="p">)</span>
<span class="n">copy2</span><span class="p">(</span><span class="n">src</span><span class="p">,</span> <span class="n">dst</span><span class="p">)</span>
<span class="n">dracut_commands</span> <span class="o">+=</span> <span class="p">[</span><span class="s2">&quot;--include&quot;</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="s2">&quot;/tmp/&quot;</span><span class="p">,</span> <span class="n">hook_script</span><span class="p">),</span>
<span class="n">dracut_path</span><span class="p">]</span>
<span class="k">return</span> <span class="n">dracut_commands</span></div></div>
<span class="c1">#### TreeBuilder helper functions</span>
<div class="viewcode-block" id="findkernels"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.findkernels">[docs]</a><span class="k">def</span> <span class="nf">findkernels</span><span class="p">(</span><span class="n">root</span><span class="o">=</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="n">kdir</span><span class="o">=</span><span class="s2">&quot;boot&quot;</span><span class="p">):</span>
<span class="c1"># To find possible flavors, awk &#39;/BuildKernel/ { print $4 }&#39; kernel.spec</span>
<span class="n">flavors</span> <span class="o">=</span> <span class="p">(</span><span class="s1">&#39;debug&#39;</span><span class="p">,</span> <span class="s1">&#39;PAE&#39;</span><span class="p">,</span> <span class="s1">&#39;PAEdebug&#39;</span><span class="p">,</span> <span class="s1">&#39;smp&#39;</span><span class="p">,</span> <span class="s1">&#39;xen&#39;</span><span class="p">,</span> <span class="s1">&#39;lpae&#39;</span><span class="p">)</span>
<span class="n">kre</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;vmlinuz-(?P&lt;version&gt;.+?\.(?P&lt;arch&gt;[a-z0-9_]+)&quot;</span>
<span class="sa">r</span><span class="s2">&quot;(.(?P&lt;flavor&gt;</span><span class="si">{0}</span><span class="s2">))?)$&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot;|&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">flavors</span><span class="p">)))</span>
<span class="n">kernels</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">bootfiles</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">kdir</span><span class="p">))</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">bootfiles</span><span class="p">:</span>
<span class="n">match</span> <span class="o">=</span> <span class="n">kre</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
<span class="k">if</span> <span class="n">match</span><span class="p">:</span>
<span class="n">kernel</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">kdir</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span>
<span class="n">kernel</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">match</span><span class="o">.</span><span class="n">groupdict</span><span class="p">())</span> <span class="c1"># sets version, arch, flavor</span>
<span class="n">kernels</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">kernel</span><span class="p">)</span>
<span class="c1"># look for associated initrd/initramfs/etc.</span>
<span class="k">for</span> <span class="n">kernel</span> <span class="ow">in</span> <span class="n">kernels</span><span class="p">:</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">bootfiles</span><span class="p">:</span>
<span class="k">if</span> <span class="n">f</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="o">+</span><span class="n">kernel</span><span class="o">.</span><span class="n">version</span><span class="o">+</span><span class="s1">&#39;.img&#39;</span><span class="p">):</span>
<span class="n">imgtype</span><span class="p">,</span> <span class="n">_rest</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="c1"># special backwards-compat case</span>
<span class="k">if</span> <span class="n">imgtype</span> <span class="o">==</span> <span class="s1">&#39;initramfs&#39;</span><span class="p">:</span>
<span class="n">imgtype</span> <span class="o">=</span> <span class="s1">&#39;initrd&#39;</span>
<span class="n">kernel</span><span class="p">[</span><span class="n">imgtype</span><span class="p">]</span> <span class="o">=</span> <span class="n">DataHolder</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="n">joinpaths</span><span class="p">(</span><span class="n">kdir</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span>
<span class="n">logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;kernels=</span><span class="si">%s</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">kernels</span><span class="p">)</span>
<span class="k">return</span> <span class="n">kernels</span></div>
<span class="c1"># udev whitelist: &#39;a-zA-Z0-9#+.:=@_-&#39; (see is_whitelisted in libudev-util.c)</span>
<span class="n">udev_blacklist</span><span class="o">=</span><span class="s1">&#39; !&quot;$%&amp;</span><span class="se">\&#39;</span><span class="s1">()*,/;&lt;&gt;?[</span><span class="se">\\</span><span class="s1">]^`{|}~&#39;</span> <span class="c1"># ASCII printable, minus whitelist</span>
<span class="n">udev_blacklist</span> <span class="o">+=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">chr</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">32</span><span class="p">))</span> <span class="c1"># ASCII non-printable</span>
<div class="viewcode-block" id="udev_escape"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.udev_escape">[docs]</a><span class="k">def</span> <span class="nf">udev_escape</span><span class="p">(</span><span class="n">label</span><span class="p">):</span>
<span class="n">out</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="k">for</span> <span class="n">ch</span> <span class="ow">in</span> <span class="n">label</span><span class="p">:</span>
<span class="n">out</span> <span class="o">+=</span> <span class="n">ch</span> <span class="k">if</span> <span class="n">ch</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">udev_blacklist</span> <span class="k">else</span> <span class="s1">&#39;</span><span class="se">\\</span><span class="s1">x</span><span class="si">%02x</span><span class="s1">&#39;</span> <span class="o">%</span> <span class="nb">ord</span><span class="p">(</span><span class="n">ch</span><span class="p">)</span>
<span class="k">return</span> <span class="n">out</span></div>
<div class="viewcode-block" id="string_lower"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.string_lower">[docs]</a><span class="k">def</span> <span class="nf">string_lower</span><span class="p">(</span><span class="n">string</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot; Return a lowercase string.</span>
<span class="sd"> :param string: String to lowercase</span>
<span class="sd"> This is used as a filter in the templates.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">string</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,264 @@
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pylorax.treeinfo &mdash; Lorax 33.10 documentation</title>
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/language_data.js"></script>
<script type="text/javascript" src="../../_static/js/theme.js"></script>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> Lorax
</a>
<div class="version">
33.10
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html">Introduction to Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../intro.html#before-lorax">Before Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax.html">Lorax</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../livemedia-creator.html">livemedia-creator</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../lorax-composer.html">lorax-composer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../composer-cli.html">composer-cli</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../mkksiso.html">mkksiso</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../product-images.html">Product and Updates Images</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../modules.html">src</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">Lorax</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li><a href="../pylorax.html">pylorax</a> &raquo;</li>
<li>pylorax.treeinfo</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for pylorax.treeinfo</h1><div class="highlight"><pre>
<span></span><span class="c1">#</span>
<span class="c1"># treeinfo.py</span>
<span class="c1">#</span>
<span class="c1"># Copyright (C) 2010-2015 Red Hat, Inc.</span>
<span class="c1">#</span>
<span class="c1"># This program is free software; you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU General Public License as published by</span>
<span class="c1"># the Free Software Foundation; either version 2 of the License, or</span>
<span class="c1"># (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># This program is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<span class="c1"># GNU General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU General Public License</span>
<span class="c1"># along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
<span class="c1">#</span>
<span class="c1"># Red Hat Author(s): Martin Gracik &lt;mgracik@redhat.com&gt;</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logger</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="s2">&quot;pylorax.treeinfo&quot;</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">configparser</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">time</span>
<div class="viewcode-block" id="TreeInfo"><a class="viewcode-back" href="../../pylorax.html#pylorax.treeinfo.TreeInfo">[docs]</a><span class="k">class</span> <span class="nc">TreeInfo</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">product</span><span class="p">,</span> <span class="n">version</span><span class="p">,</span> <span class="n">variant</span><span class="p">,</span> <span class="n">basearch</span><span class="p">,</span>
<span class="n">packagedir</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</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="k">if</span> <span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span>
<span class="n">timestamp</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s1">&#39;SOURCE_DATE_EPOCH&#39;</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">timestamp</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">())</span>
<span class="n">section</span> <span class="o">=</span> <span class="s2">&quot;general&quot;</span>
<span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;timestamp&quot;</span><span class="p">:</span> <span class="n">timestamp</span><span class="p">,</span>
<span class="s2">&quot;family&quot;</span><span class="p">:</span> <span class="n">product</span><span class="p">,</span>
<span class="s2">&quot;version&quot;</span><span class="p">:</span> <span class="n">version</span><span class="p">,</span>
<span class="s2">&quot;name&quot;</span><span class="p">:</span> <span class="s2">&quot;</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">product</span><span class="p">,</span> <span class="n">version</span><span class="p">),</span>
<span class="s2">&quot;variant&quot;</span><span class="p">:</span> <span class="n">variant</span> <span class="ow">or</span> <span class="s2">&quot;&quot;</span><span class="p">,</span>
<span class="s2">&quot;arch&quot;</span><span class="p">:</span> <span class="n">basearch</span><span class="p">,</span>
<span class="s2">&quot;packagedir&quot;</span><span class="p">:</span> <span class="n">packagedir</span><span class="p">}</span>
<span class="bp">self</span><span class="o">.</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">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</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="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<div class="viewcode-block" id="TreeInfo.add_section"><a class="viewcode-back" href="../../pylorax.html#pylorax.treeinfo.TreeInfo.add_section">[docs]</a> <span class="k">def</span> <span class="nf">add_section</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">has_section</span><span class="p">(</span><span class="n">section</span><span class="p">):</span>
<span class="bp">self</span><span class="o">.</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">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</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="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">())</span></div>
<div class="viewcode-block" id="TreeInfo.write"><a class="viewcode-back" href="../../pylorax.html#pylorax.treeinfo.TreeInfo.write">[docs]</a> <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">outfile</span><span class="p">):</span>
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">&quot;writing .treeinfo file&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">outfile</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fobj</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">c</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">fobj</span><span class="p">)</span></div></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2018, Red Hat, Inc.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>

View File

@ -0,0 +1,203 @@
composer-cli
============
:Authors:
Brian C. Lane <bcl@redhat.com>
``composer-cli`` is an interactive tool for use with a WELDR API server,
managing blueprints, exploring available packages, and building new images.
`lorax-composer <lorax-composer.html>` and `osbuild-composer
<https://osbuild.org>` both implement compatible servers.
It requires the server to be installed on the local system, and the user
running it needs to be a member of the ``weldr`` group. They do not need to be
root, but all of the `security precautions <lorax-composer.html#security>`_
apply.
composer-cli cmdline arguments
------------------------------
.. argparse::
:ref: composer.cli.cmdline.composer_cli_parser
:prog: composer-cli
Edit a Blueprint
----------------
Start out by listing the available blueprints using ``composer-cli blueprints
list``, pick one and save it to the local directory by running ``composer-cli
blueprints save http-server``. If there are no blueprints available you can
copy one of the examples `from the test suite
<https://github.com/weldr/lorax/tree/master/tests/pylorax/blueprints/>`_.
Edit the file (it will be saved with a .toml extension) and change the
description, add a package or module to it. Send it back to the server by
running ``composer-cli blueprints push http-server.toml``. You can verify that it was
saved by viewing the changelog - ``composer-cli blueprints changes http-server``.
Build an image
----------------
Build a ``qcow2`` disk image from this blueprint by running ``composer-cli
compose start http-server qcow2``. It will print a UUID that you can use to
keep track of the build. You can also cancel the build if needed.
The available types of images is displayed by ``composer-cli compose types``.
Currently this consists of: alibaba, ami, ext4-filesystem, google, hyper-v,
live-iso, openstack, partitioned-disk, qcow2, tar, vhd, vmdk
You can optionally start an upload of the finished image, see `Image Uploads`_ for
more information.
Monitor the build status
------------------------
Monitor it using ``composer-cli compose status``, which will show the status of
all the builds on the system. You can view the end of the anaconda build logs
once it is in the ``RUNNING`` state using ``composer-cli compose log UUID``
where UUID is the UUID returned by the start command.
Once the build is in the ``FINISHED`` state you can download the image.
Download the image
------------------
Downloading the final image is done with ``composer-cli compose image UUID`` and it will
save the qcow2 image as ``UUID-disk.qcow2`` which you can then use to boot a VM like this::
qemu-kvm --name test-image -m 1024 -hda ./UUID-disk.qcow2
Image Uploads
-------------
``composer-cli`` can upload the images to a number of services, including AWS,
OpenStack, and vSphere. The upload can be started when the build is finished,
by using ``composer-cli compose start ...`` or an existing image can be uploaded
with ``composer-cli upload start ...``. In order to access the service you need
to pass authentication details to composer-cli using a TOML file, or reference
a previously saved profile.
``lorax-composer`` and ``osbuild-composer`` handle this differently, with
``osbuild-composer`` you can currently only specify upload targets during the
compose process.
Providers
---------
Providers are the services providers with Ansible playbook support under
``/usr/share/lorax/lifted/providers/``, you will need to gather some provider
specific information in order to authenticate with it. You can view the
required fields using ``composer-cli providers template <PROVIDER>``, eg. for AWS
you would run::
composer-cli upload template aws
The output looks like this::
provider = "aws"
[settings]
aws_access_key = "AWS Access Key"
aws_bucket = "AWS Bucket"
aws_region = "AWS Region"
aws_secret_key = "AWS Secret Key"
Save this into an ``aws-credentials.toml`` file and use it when running ``start``.
AWS
^^^
The access key and secret key can be created by going to the
``IAM->Users->Security Credentials`` section and creating a new access key. The
secret key will only be shown when it is first created so make sure to record
it in a secure place. The region should be the region that you want to use the
AMI in, and the bucket can be an existing bucket, or a new one, following the
normal AWS bucket naming rules. It will be created if it doesn't already exist.
When uploading the image it is first uploaded to the s3 bucket, and then
converted to an AMI. If the conversion is successful the s3 object will be
deleted. If it fails, re-trying after correcting the problem will re-use the
object if you have not deleted it in the meantime, speeding up the process.
Profiles
--------
Profiles store the authentication settings associated with a specific provider.
Providers can have multiple profiles, as long as their names are unique. For
example, you may have one profile for testing and another for production
uploads.
Profiles are created by pushing the provider settings template to the server using
``composer-cli providers push <PROFILE.TOML>`` where ``PROFILE.TOML`` is the same as the
provider template, but with the addition of a ``profile`` field. For example, an AWS
profile named ``test-uploads`` would look like this::
provider = "aws"
profile = "test-uploads"
[settings]
aws_access_key = "AWS Access Key"
aws_bucket = "AWS Bucket"
aws_region = "AWS Region"
aws_secret_key = "AWS Secret Key"
You can view the profile by using ``composer-cli providers aws test-uploads``.
Build an image and upload results
---------------------------------
If you have a profile named ``test-uploads``::
composer-cli compose start example-http-server ami "http image" aws test-uploads
Or if you have the settings stored in a TOML file::
composer-cli compose start example-http-server ami "http image" aws-settings.toml
It will return the UUID of the image build, and the UUID of the upload. Once
the build has finished successfully it will start the upload process, which you
can monitor with ``composer-cli upload info <UPLOAD-UUID>``
You can also view the upload logs from the Ansible playbook with::
``composer-cli upload log <UPLOAD-UUID>``
The type of the image must match the type supported by the provider.
Upload an existing image
------------------------
You can upload previously built images, as long as they are in the ``FINISHED`` state, using ``composer-cli upload start ...```. If you have a profile named ``test-uploads``::
composer-cli upload start <UUID> "http-image" aws test-uploads
Or if you have the settings stored in a TOML file::
composer-cli upload start <UUID> "http-image" aws-settings.toml
This will output the UUID of the upload, which can then be used to monitor the status in the same way
described above.
Debugging
---------
There are a couple of arguments that can be helpful when debugging problems.
These are only meant for debugging and should not be used to script access to
the API. If you need to do that you can communicate with it directly in the
language of your choice.
``--json`` will return the server's response as a nicely formatted json output
instead of printing what the command would usually print.
``--test=1`` will cause a compose start to start creating an image, and then
end with a failed state.
``--test=2`` will cause a compose to start and then end with a finished state,
without actually composing anything.

View File

@ -0,0 +1,101 @@
composer.cli package
====================
Submodules
----------
composer.cli.blueprints module
------------------------------
.. automodule:: composer.cli.blueprints
:members:
:undoc-members:
:show-inheritance:
composer.cli.cmdline module
---------------------------
.. automodule:: composer.cli.cmdline
:members:
:undoc-members:
:show-inheritance:
composer.cli.compose module
---------------------------
.. automodule:: composer.cli.compose
:members:
:undoc-members:
:show-inheritance:
composer.cli.help module
------------------------
.. automodule:: composer.cli.help
:members:
:undoc-members:
:show-inheritance:
composer.cli.modules module
---------------------------
.. automodule:: composer.cli.modules
:members:
:undoc-members:
:show-inheritance:
composer.cli.projects module
----------------------------
.. automodule:: composer.cli.projects
:members:
:undoc-members:
:show-inheritance:
composer.cli.providers module
-----------------------------
.. automodule:: composer.cli.providers
:members:
:undoc-members:
:show-inheritance:
composer.cli.sources module
---------------------------
.. automodule:: composer.cli.sources
:members:
:undoc-members:
:show-inheritance:
composer.cli.status module
--------------------------
.. automodule:: composer.cli.status
:members:
:undoc-members:
:show-inheritance:
composer.cli.upload module
--------------------------
.. automodule:: composer.cli.upload
:members:
:undoc-members:
:show-inheritance:
composer.cli.utilities module
-----------------------------
.. automodule:: composer.cli.utilities
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: composer.cli
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,37 @@
composer package
================
Subpackages
-----------
.. toctree::
:maxdepth: 4
composer.cli
Submodules
----------
composer.http\_client module
----------------------------
.. automodule:: composer.http_client
:members:
:undoc-members:
:show-inheritance:
composer.unix\_socket module
----------------------------
.. automodule:: composer.unix_socket
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: composer
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,40 @@
.. Lorax documentation master file, created by
sphinx-quickstart on Wed Apr 8 13:46:00 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to Lorax's documentation!
=================================
Contents:
.. toctree::
:maxdepth: 1
intro
lorax
livemedia-creator
lorax-composer
composer-cli
mkksiso
product-images
modules
Documentation for other Lorax Branches
======================================
* `Fedora 32 <f32-branch/>`_
* `Fedora 31 <f31-branch/>`_
* `Fedora 30 <f30-branch/>`_
* `Fedora 29 <f29-branch/>`_
* `Fedora 28 <f28-branch/>`_
* `RHEL8 lorax-composer <rhel8-branch/>`_
* `RHEL7 lorax-composer <lorax-composer/>`_
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

View File

@ -0,0 +1,67 @@
Introduction to Lorax
=====================
I am the Lorax. I speak for the trees [and images].
Lorax is used to build the Anaconda Installer boot.iso, it consists of a
library, pylorax, a set of templates, and the lorax script. Its operation
is driven by a customized set of Mako templates that lists the packages
to be installed, steps to execute to remove unneeded files, and creation
of the iso for all of the supported architectures.
Before Lorax
============
Tree building tools such as pungi and revisor rely on 'buildinstall' in
anaconda/scripts/ to produce the boot images and other such control files
in the final tree. The existing buildinstall scripts written in a mix of
bash and Python are unmaintainable. Lorax is an attempt to replace them
with something more flexible.
EXISTING WORKFLOW:
pungi and other tools call scripts/buildinstall, which in turn call other
scripts to do the image building and data generation. Here's how it
currently looks:
-> buildinstall
* process command line options
* write temporary yum.conf to point to correct repo
* find anaconda release RPM
* unpack RPM, pull in those versions of upd-instroot, mk-images,
maketreeinfo.py, makestamp.py, and buildinstall
-> call upd-instroot
-> call maketreeinfo.py
-> call mk-images (which figures out which mk-images.ARCH to call)
-> call makestamp.py
* clean up
PROBLEMS:
The existing workflow presents some problems with maintaining the scripts.
First, almost all knowledge of what goes in to the stage 1 and stage 2
images lives in upd-instroot. The mk-images* scripts copy things from the
root created by upd-instroot in order to build the stage 1 image, though
it's not completely clear from reading the scripts.
NEW IDEAS:
Create a new central driver with all information living in Python modules.
Configuration files will provide the knowledge previously contained in the
upd-instroot and mk-images* scripts.

View File

@ -0,0 +1,46 @@
lifted package
==============
Submodules
----------
lifted.config module
--------------------
.. automodule:: lifted.config
:members:
:undoc-members:
:show-inheritance:
lifted.providers module
-----------------------
.. automodule:: lifted.providers
:members:
:undoc-members:
:show-inheritance:
lifted.queue module
-------------------
.. automodule:: lifted.queue
:members:
:undoc-members:
:show-inheritance:
lifted.upload module
--------------------
.. automodule:: lifted.upload
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: lifted
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,670 @@
livemedia-creator
=================
:Authors:
Brian C. Lane <bcl@redhat.com>
livemedia-creator uses `Anaconda <https://github.com/rhinstaller/anaconda>`_,
`kickstart <https://github.com/rhinstaller/pykickstart>`_ and `Lorax
<https://github.com/rhinstaller/lorax>`_ to create bootable media that use the
same install path as a normal system installation. It can be used to make live
isos, bootable (partitioned) disk images, tarfiles, and filesystem images for
use with virtualization and container solutions like libvirt, docker, and
OpenStack.
The general idea is to use qemu with kickstart and an Anaconda boot.iso to
install into a disk image and then use the disk image to create the bootable
media.
livemedia-creator --help will describe all of the options available. At the
minimum you need:
``--make-iso`` to create a final bootable .iso or one of the other ``--make-*`` options.
``--iso`` to specify the Anaconda install media to use with qemu.
``--ks`` to select the kickstart file describing what to install.
To use livemedia-creator with virtualization you will need to have qemu installed.
If you are going to be using Anaconda directly, with ``--no-virt`` mode, make sure
you have the anaconda-tui package installed.
Conventions used in this document:
``lmc`` is an abbreviation for livemedia-creator.
``builder`` is the system where livemedia-creator is being run
``image`` is the disk image being created by running livemedia-creator
livemedia-creator cmdline arguments
-----------------------------------
.. argparse::
:ref: pylorax.cmdline.lmc_parser
:prog: livemedia-creator
--macboot : @replace
Make the iso bootable on UEFI based Mac systems
Default: True
--nomacboot : @replace
Do not create a Mac bootable iso
Default: False
Quickstart
----------
Run this to create a bootable live iso::
sudo livemedia-creator --make-iso \
--iso=/extra/iso/boot.iso --ks=./docs/fedora-livemedia.ks
You can run it directly from the lorax git repo like this::
sudo PATH=./src/sbin/:$PATH PYTHONPATH=./src/ ./src/sbin/livemedia-creator \
--make-iso --iso=/extra/iso/boot.iso \
--ks=./docs/fedora-livemedia.ks --lorax-templates=./share/
You can observe the installation using vnc. The logs will show what port was
chosen, or you can use a specific port by passing it. eg. ``--vnc vnc:127.0.0.1:5``
This is usually a good idea when testing changes to the kickstart. lmc tries
to monitor the logs for fatal errors, but may not catch everything.
How ISO creation works
----------------------
There are 2 stages, the install stage which produces a disk or filesystem image
as its output, and the boot media creation which uses the image as its input.
Normally you would run both stages, but it is possible to stop after the
install stage, by using ``--image-only``, or to skip the install stage and use
a previously created disk image by passing ``--disk-image`` or ``--fs-image``
When creating an iso qemu boots using the passed Anaconda installer iso
and installs the system based on the kickstart. The ``%post`` section of the
kickstart is used to customize the installed system in the same way that
current spin-kickstarts do.
livemedia-creator monitors the install process for problems by watching the
install logs. They are written to the current directory or to the base
directory specified by the --logfile command. You can also monitor the install
by using a vnc client. This is recommended when first modifying a kickstart,
since there are still places where Anaconda may get stuck without the log
monitor catching it.
The output from this process is a partitioned disk image. kpartx can be used
to mount and examine it when there is a problem with the install. It can also
be booted using kvm.
When creating an iso the disk image's / partition is copied into a formatted
filesystem image which is then used as the input to lorax for creation of the
final media.
The final image is created by lorax, using the templates in /usr/share/lorax/live/
or the live directory below the directory specified by ``--lorax-templates``. The
templates are written using the Mako template system with some extra commands
added by lorax.
.. note::
The output from --make-iso includes the artifacts used to create the boot.iso;
the kernel, initrd, the squashfs filesystem, etc. If you only want the
boot.iso you can pass ``--iso-only`` and the other files will be removed. You
can also name the iso by using ``--iso-name my-live.iso``.
Kickstarts
----------
The docs/ directory includes several example kickstarts, one to create a live
desktop iso using GNOME, and another to create a minimal disk image. When
creating your own kickstarts you should start with the minimal example, it
includes several needed packages that are not always included by dependencies.
Or you can use existing spin kickstarts to create live media with a few
changes. Here are the steps I used to convert the Fedora XFCE spin.
1. Flatten the xfce kickstart using ksflatten
2. Add zerombr so you don't get the disk init dialog
3. Add clearpart --all
4. Add swap partition
5. bootloader target
6. Add shutdown to the kickstart
7. Add network --bootproto=dhcp --activate to activate the network
This works for F16 builds but for F15 and before you need to pass
something on the cmdline that activate the network, like sshd:
``livemedia-creator --kernel-args="sshd"``
8. Add a root password::
rootpw rootme
network --bootproto=dhcp --activate
zerombr
clearpart --all
bootloader --location=mbr
part swap --size=512
shutdown
9. In the livesys script section of the %post remove the root password. This
really depends on how the spin wants to work. You could add the live user
that you create to the %wheel group so that sudo works if you wanted to.
``passwd -d root > /dev/null``
10. Remove /etc/fstab in %post, dracut handles mounting the rootfs
``cat /dev/null > /dev/fstab``
Do this only for live iso's, the filesystem will be mounted read only if
there is no /etc/fstab
11. Don't delete initramfs files from /boot in %post
12. When creating live iso's you need to have, at least, these packages in the %package section::
dracut-config-generic
dracut-live
-dracut-config-rescue
grub2-efi
memtest86+
syslinux
User created repositories
~~~~~~~~~~~~~~~~~~~~~~~~~
If you are using your own repositories and installing groups (eg. @core) make
sure you create the repodata with groups like this ``createrepo -g
/path/to/groups.xml /path/to/rpms``
Using a Proxy with repos
~~~~~~~~~~~~~~~~~~~~~~~~
One drawback to using qemu is that it pulls the packages from the repo each
time you run it. To speed things up you either need a local mirror of the
packages, or you can use a caching proxy. When using a proxy you pass it to
livemedia-creator like this:
``--proxy=http://proxy.yourdomain.com:3128``
You also need to use a specific mirror instead of mirrormanager so that the
packages will get cached, so your kickstart url would look like:
``url --url="http://dl.fedoraproject.org/pub/fedora/linux/development/rawhide/x86_64/os/"``
You can also add an update repo, but don't name it updates. Add --proxy to it
as well. You can use all of the `kickstart commands <https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#chapter-2-kickstart-commands-in-fedora>`_ in your kickstart. Make sure there
is only one ``url`` command, other repos have to use the ``repo`` command and cannot be
named ``updates`` which is reserved for Anaconda's use. eg.::
url --url=PRIMARY-REPO-URL --proxy=PROXY-URL
repo --name="repo1" --baseurl=FIRST-REPO-URL --proxy=PROXY-URL
repo --name="repo2" --baseurl=SECOND-REPO_URL --proxy=PROXY-URL
Anaconda image install (no-virt)
--------------------------------
You can create images without using qemu by passing ``--no-virt`` on the
cmdline. This will use Anaconda's directory install feature to handle the
install. There are a couple of things to keep in mind when doing this:
1. It will be most reliable when building images for the same release that the
host is running. Because Anaconda has expectations about the system it is
running under you may encounter strange bugs if you try to build newer or
older releases.
2. It may totally trash your host. So far I haven't had this happen, but the
possibility exists that a bug in Anaconda could result in it operating on
real devices. I recommend running it in a virt or on a system that you can
afford to lose all data from.
The logs from anaconda will be placed in an ./anaconda/ directory in either
the current directory or in the directory used for --logfile
Example cmdline:
``sudo livemedia-creator --make-iso --no-virt --ks=./fedora-livemedia.ks``
.. note::
Using no-virt to create a partitioned disk image (eg. --make-disk or
--make-vagrant) will only create disks usable on the host platform (BIOS
or UEFI). You can create BIOS partitioned disk images on UEFI by using
virt.
.. note::
As of version 30.7 SELinux can be set to Enforcing. The current state is
logged for debugging purposes and if there are SELinux denials they should
be reported as a bug.
AMI Images
----------
Amazon EC2 images can be created by using the --make-ami switch and an appropriate
kickstart file. All of the work to customize the image is handled by the kickstart.
The example currently included was modified from the cloud-kickstarts version so
that it would work with livemedia-creator.
Example cmdline:
``sudo livemedia-creator --make-ami --iso=/path/to/boot.iso --ks=./docs/fedora-livemedia-ec2.ks``
This will produce an ami-root.img file in the working directory.
At this time I have not tested the image with EC2. Feedback would be welcome.
Appliance Creation
------------------
livemedia-creator can now replace appliance-tools by using the --make-appliance
switch. This will create the partitioned disk image and an XML file that can be
used with virt-image to setup a virtual system.
The XML is generated using the Mako template from
/usr/share/lorax/appliance/libvirt.xml You can use a different template by
passing ``--app-template <template path>``
Documentation on the Mako template system can be found at the `Mako site
<http://docs.makotemplates.org/en/latest/index.html>`_
The name of the final output XML is appliance.xml, this can be changed with
``--app-file <file path>``
The following variables are passed to the template:
``disks``
A list of disk_info about each disk.
Each entry has the following attributes:
``name``
base name of the disk image file
``format``
"raw"
``checksum_type``
"sha256"
``checksum``
sha256 checksum of the disk image
``name``
Name of appliance, from --app-name argument
``arch``
Architecture
``memory``
Memory in KB (from ``--ram``)
``vcpus``
from ``--vcpus``
``networks``
list of networks from the kickstart or []
``project``
from ``--project``
``releasever``
from ``--releasever``
The created image can be imported into libvirt using:
``virt-image appliance.xml``
You can also create qcow2 appliance images using ``--image-type=qcow2``, for example::
sudo livemedia-creator --make-appliance --iso=/path/to/boot.iso --ks=./docs/fedora-minimal.ks \
--image-type=qcow2 --app-file=minimal-test.xml --image-name=minimal-test.img
Filesystem Image Creation
-------------------------
livemedia-creator can be used to create un-partitined filesystem images using
the ``--make-fsimage`` option. As of version 21.8 this works with both qemu and
no-virt modes of operation. Previously it was only available with no-virt.
Kickstarts should have a single / partition with no extra mountpoints.
``livemedia-creator --make-fsimage --iso=/path/to/boot.iso --ks=./docs/fedora-minimal.ks``
You can name the output image with ``--image-name`` and set a label on the filesystem with ``--fs-label``
TAR File Creation
-----------------
The ``--make-tar`` command can be used to create a tar of the root filesystem. By
default it is compressed using xz, but this can be changed using the
``--compression`` and ``--compress-arg`` options. This option works with both virt and
no-virt install methods.
As with ``--make-fsimage`` the kickstart should be limited to a single / partition.
For example::
livemedia-creator --make-tar --iso=/path/to/boot.iso --ks=./docs/fedora-minimal.ks \
--image-name=fedora-root.tar.xz
Live Image for PXE Boot
-----------------------
The ``--make-pxe-live`` command will produce squashfs image containing live root
filesystem that can be used for pxe boot. Directory with results will contain
the live image, kernel image, initrd image and template of pxe configuration
for the images.
Atomic Live Image for PXE Boot
------------------------------
The ``--make-ostree-live`` command will produce the same result as ``--make-pxe-live``
for installations of Atomic Host. Example kickstart for such an installation
using Atomic installer iso with local repo included in the image can be found
in docs/rhel-atomic-pxe-live.ks.
The PXE images can also be created with ``--no-virt`` by using the example
kickstart in docs/fedora-atomic-pxe-live-novirt.ks. This also works inside the
mock environment.
Using Mock and --no-virt to Create Images
-----------------------------------------
As of lorax version 22.2 you can use livemedia-creator and anaconda version
22.15 inside of a mock chroot with --make-iso and --make-fsimage.
.. note::
As of mock version 2.0 you no longer need to pass ``--old-chroot``. You will,
however, need to pass ``--enable-network`` so that the mock container can download
packages.
Older versions of mock, between 1.3.4 and 2.0, will need to pass
``--old-chroot`` with mock. These versions of mock now default to using
systemd-nspawn which cannot create the needed loop device nodes. Passing
``--old-chroot`` will use the old system where ``/dev/loop*`` is setup for
you.
On the host system:
1. yum install -y mock
2. Add a user to the mock group to use for running mock. eg. builder
3. Create a new /etc/mock/ config file based on the rawhide one, or modify the
existing one so that the following options are setup::
config_opts['chroot_setup_cmd'] = 'install @buildsys-build anaconda-tui lorax'
# build results go into /home/builder/results/
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('/home/builder/results','/results/'))
If you are creating images for a branched release of Fedora you should also enable
the updates-testing repository so that you get the latest builds in your mock chroot.
The following steps are run as the builder user who is a member of the mock
group.
4. Make a directory for results matching the bind mount above
``mkdir ~/results/``
5. Copy the example kickstarts
``cp /usr/share/docs/lorax/*ks .``
6. Make sure tar and dracut-network are in the %packages section and that the
``url points to the correct repo``
7. Init the mock
``mock -r fedora-rawhide-x86_64 --init``
8. Copy the kickstart inside the mock
``mock -r fedora-rawhide-x86_64 --copyin ./fedora-minimal.ks /root/``
9. Make a minimal iso::
mock -r fedora-rawhide-x86_64 --enable-network --chroot -- livemedia-creator --no-virt \
--resultdir=/results/try-1 --logfile=/results/logs/try-1/try-1.log \
--make-iso --ks /root/fedora-minimal.ks
Results will be in ./results/try-1 and logs under /results/logs/try-1/
including anaconda logs and livemedia-creator logs. The new iso will be
located at ~/results/try-1/images/boot.iso, and the ~/results/try-1/
directory tree will also contain the vmlinuz, initrd, etc.
Using Mock and qemu to Create Images
------------------------------------
Version 25.0 of livemedia-creator switches to using qemu for virtualization.
This allows creation of all image types, and use of the KVM on the host if
/dev/kvm is present in the mock environment.
On the host system:
1. yum install -y mock
2. Add a user to the mock group to use for running mock. eg. builder
3. Create a new /etc/mock/ config file based on the rawhide one, or modify the
existing one so that the following options are setup::
config_opts['chroot_setup_cmd'] = 'install @buildsys-build lorax qemu'
# build results go into /home/builder/results/
config_opts['plugin_conf']['bind_mount_opts']['dirs'].append(('/home/builder/results','/results/'))
If you are creating images for a branched release of Fedora you should also enable
the updates-testing repository so that you get the latest builds in your mock chroot.
The following steps are run as the builder user who is a member of the mock
group.
4. Make a directory for results matching the bind mount above
``mkdir ~/results/``
5. Copy the example kickstarts
``cp /usr/share/docs/lorax/*ks .``
6. Make sure tar and dracut-network are in the %packages section and that the
``url points to the correct repo``
7. Init the mock
``mock -r fedora-rawhide-x86_64 --init``
8. Copy the kickstart inside the mock
``mock -r fedora-rawhide-x86_64 --copyin ./fedora-minimal.ks /root/``
9. Copy the Anaconda boot.iso inside the mock
``mock -r fedora-rawhide-x86_64 --copyin ./boot.iso /root/``
10. Make a minimal iso::
mock -r fedora-rawhide-x86_64 --enable-network --chroot -- livemedia-creator \
--resultdir=/results/try-1 --logfile=/results/logs/try-1/try-1.log \
--make-iso --ks /root/fedora-minimal.ks --iso /root/boot.iso
Results will be in ./results/try-1 and logs under /results/logs/try-1/
including anaconda logs and livemedia-creator logs. The new iso will be
located at ~/results/try-1/images/boot.iso, and the ~/results/try-1/
directory tree will also contain the vmlinuz, initrd, etc.
This will run qemu without kvm support, which is going to be very slow. You can
add ``mknod /dev/kvm c 10 232;`` to create the device node before running lmc.
OpenStack Image Creation
------------------------
OpenStack supports partitioned disk images so ``--make-disk`` can be used to
create images for importing into glance, OpenStack's image storage component.
You need to have access to an OpenStack provider that allows image uploads, or
setup your own using the instructions from the `RDO Project
<https://www.rdoproject.org/Quickstart>`_.
The example kickstart, fedora-openstack.ks, is only slightly different than the
fedora-minimal.ks one. It adds the cloud-init and cloud-utils-growpart
packages. OpenStack supports setting up the image using cloud-init, and
cloud-utils-growpart will grow the image to fit the instance's disk size.
Create a qcow2 image using the kickstart like this:
``sudo livemedia-creator --make-disk --iso=/path/to/boot.iso --ks=/path/to/fedora-openstack.ks --image-type=qcow2``
.. note::
On the RHEL7 version of lmc ``--image-type`` isn't supported. You can only create a bare partitioned disk image.
Import the resulting disk image into the OpenStack system, either via the web UI, or glance on the cmdline::
glance image-create --name "fedora-openstack" --is-public true --disk-format qcow2 \
--container-format bare --file ./fedora-openstack.qcow2
If qcow2 wasn't used then ``--disk-format`` should be set to raw.
Docker Image Creation
---------------------
Use lmc to create a tarfile as described in the `TAR File Creation`_ section, but substitute the
fedora-docker.ks example kickstart which removes the requirement for core files and the kernel.
You can then import the tarfile into docker like this (as root):
``cat /var/tmp/fedora-root.tar.xz | docker import - fedora-root``
And then run bash inside of it:
``sudo docker run -i -t fedora-root /bin/bash``
Open Container Initiative Image Creation
----------------------------------------
The OCI is a new specification that is still being worked on. You can read more about it at
`the Open Container Initiative website <https://www.opencontainers.org/>`_. You can create
OCI images using the following command::
sudo livemedia-creator --make-oci --oci-config /path/to/config.json --oci-runtime /path/to/runtime.json \
--iso=/path/to/boot.iso --ks=/path/to/fedora-minimal.ks
You must provide the config.json and runtime.json files to be included in the bundle,
their specifications can be found `on the OCI github project <https://github.com/opencontainers/specs>`_
output will be in the results directory with a default name of bundle.tar.xz
This will work with ``--no-virt`` and inside a mock since it doesn't use any
partitioned disk images.
Vagrant Image Creation
----------------------
`Vagrant <https://www.vagrantup.com/>`_ images can be created using the following command::
sudo livemedia-creator --make-vagrant --vagrant-metadata /path/to/metadata.json \
--iso=/path/to/boot.iso --ks=/path/to/fedora-vagrant.ks
The image created is a `vagrant-libvirt
<https://github.com/pradels/vagrant-libvirt>`_ provider image and needs to have
vagrant setup with libvirt before you can use it.
The ``--vagrant-metadata`` file is optional, it will create a minimal one by
default, and if one is passed it will make sure the disk size is setup
correctly. If you pass a ``--vagrant-vagrantfile`` it will be included in the
image verbatim. By default no vagrantfile is created.
There is an example Vagrant kickstart file in the docs directory that sets up
the vagrant user with the default insecure SSH pubkey and a few useful
utilities.
This also works with ``--no-virt``, but will not work inside a mock due to its
use of partitioned disk images and qcow2.
Creating UEFI disk images with virt
-----------------------------------
Partitioned disk images can only be created for the same platform as the host system (BIOS or
UEFI). You can use virt to create BIOS images on UEFI systems, and it is also possible
to create UEFI images on BIOS systems using OVMF firmware and qemu.
Install the lorax-lmc-virt package, this will install qemu and the OVMF
firmware files.
Now you can run livemedia-creator with ``--virt-uefi`` to boot and install using UEFI::
sudo livemedia-creator --make-disk --virt-uefi --iso=/path/to/boot.iso \
--ks=/path/to/fedora-minimal.ks
Make sure that the kickstart you are using creates a /boot/efi partition by including this::
part /boot/efi --fstype="efi" --size=500
Or use ``reqpart`` in the kickstart and Anaconda will create the required partitions.
.. note::
The --virt-uefi method is currently only supported on the x86_64 architecture.
Debugging problems
------------------
Sometimes an installation will get stuck. When using qemu the logs will
be written to ./virt-install.log and most of the time any problems that happen
will be near the end of the file. lmc tries to detect common errors and will
cancel the installation when they happen. But not everything can be caught.
When creating a new kickstart it is helpful to use vnc so that you can monitor
the installation as it happens, and if it gets stuck without lmc detecting the
problem you can switch to tty1 and examine the system directly.
If you suspect problems with %pre or %post sections you can redirect the output
to the terminal and examine it by logging into the VM. eg.::
%pre
chvt
exec < /dev/tty3 > /dev/tty3 2>/dev/tty3
#do stuff
echo hello world
%end
If it does get stuck the best way to cancel is to use kill -9 on the qemu pid,
lmc will detect that the process died and cleanup.
If lmc didn't handle the cleanup for some reason you can do this:
1. ``sudo umount /tmp/lmc-XXXX`` to unmount the iso from its mountpoint.
2. ``sudo rm -rf /tmp/lmc-XXXX``
3. ``sudo rm /var/tmp/lmc-disk-XXXXX`` to remove the disk image.
Note that lmc uses the lmc- prefix for all of its temporary files and
directories to make it easier to find and clean up leftovers.
The logs from the qemu run are stored in virt-install.log, logs from
livemedia-creator are in livemedia.log and program.log
You can add ``--image-only`` to skip the .iso creation and examine the resulting
disk image. Or you can pass ``--keep-image`` to keep it around after the iso has
been created.
Cleaning up aborted ``--no-virt`` installs can sometimes be accomplished by
running the ``anaconda-cleanup`` script. As of Fedora 18 anaconda is
multi-threaded and it can sometimes become stuck and refuse to exit. When this
happens you can usually clean up by first killing the anaconda process then
running ``anaconda-cleanup``.
Hacking
-------
Development on this will take place as part of the lorax project, and on the
anaconda-devel-list mailing list, and `on github <https://github.com/rhinstaller/lorax>`_
Feedback, enhancements and bugs are welcome. You can use `bugzilla
<https://bugzilla.redhat.com/enter_bug.cgi?product=Fedora&component=lorax>`_ to
report bugs against the lorax component.

View File

@ -0,0 +1,535 @@
lorax-composer
==============
:Authors:
Brian C. Lane <bcl@redhat.com>
``lorax-composer`` is a WELDR API server that allows you to build disk images using
`Blueprints`_ to describe the package versions to be installed into the image.
It is compatible with the Weldr project's bdcs-api REST protocol. More
information on Weldr can be found `on the Weldr blog <http://www.weldr.io>`_.
Behind the scenes it uses `livemedia-creator <livemedia-creator.html>`_ and
`Anaconda <https://anaconda-installer.readthedocs.io/en/latest/>`_ to handle the
installation and configuration of the images.
.. note::
``lorax-composer`` is now deprecated. It is being replaced by the
``osbuild-composer`` WELDR API server which implements more features (eg.
ostree, image uploads, etc.) You can still use ``composer-cli`` and
``cockpit-composer`` with ``osbuild-composer``. See the documentation or
the `osbuild website <https://www.osbuild.org/>`_ for more information.
Important Things To Note
------------------------
* As of version 30.7 SELinux can be set to Enforcing. The current state is
logged for debugging purposes and if there are SELinux denials they should
be reported as a bug.
* All image types lock the root account, except for live-iso. You will need to either
use one of the `Customizations`_ methods for setting a ssh key/password, install a
package that creates a user, or use something like `cloud-init` to setup access at
boot time.
Installation
------------
The best way to install ``lorax-composer`` is to use ``sudo dnf install
lorax-composer composer-cli``, this will setup the weldr user and install the
systemd socket activation service. You will then need to enable it with ``sudo
systemctl enable lorax-composer.socket && sudo systemctl start
lorax-composer.socket``. This will leave the server off until the first request
is made. Systemd will then launch the server and it will remain running until
the system is rebooted. This will cause some delay in responding to the first
request from the UI or `composer-cli`.
.. note::
If you want lorax-composer to respond immediately to the first request you can
start and enable `lorax-composer.service` instead of `lorax-composer.socket`
Quickstart
----------
1. Create a ``weldr`` user and group by running ``useradd weldr``
2. Remove any pre-existing socket directory with ``rm -rf /run/weldr/``
A new directory with correct permissions will be created the first time the server runs.
3. Enable the socket activation with ``systemctl enable lorax-composer.socket
&& sudo systemctl start lorax-composer.socket``.
NOTE: You can also run it directly with ``lorax-composer /path/to/blueprints``. However,
``lorax-composer`` does not react well to being started both on the command line and via
socket activation at the same time. It is therefore recommended that you run it directly
on the command line only for testing or development purposes. For real use or development
of other projects that simply use the API, you should stick to socket activation only.
The ``/path/to/blueprints/`` directory is where the blueprints' git repo will
be created, and all the blueprints created with the ``/api/v0/blueprints/new``
route will be stored. If there are blueprint ``.toml`` files in the top level
of the directory they will be imported into the blueprint git storage when
``lorax-composer`` starts.
Logs
----
Logs are stored under ``/var/log/lorax-composer/`` and include all console
messages as well as extra debugging info and API requests.
Security
--------
Some security related issues that you should be aware of before running ``lorax-composer``:
* One of the API server threads needs to retain root privileges in order to run Anaconda.
* Only allow authorized users access to the ``weldr`` group and socket.
Since Anaconda kickstarts are used there is the possibility that a user could
inject commands into a blueprint that would result in the kickstart executing
arbitrary code on the host. Only authorized users should be allowed to build
images using ``lorax-composer``.
lorax-composer cmdline arguments
--------------------------------
.. argparse::
:ref: pylorax.api.cmdline.lorax_composer_parser
:prog: lorax-composer
How it Works
------------
The server runs as root, and as ``weldr``. Communication with it is via a unix
domain socket (``/run/weldr/api.socket`` by default). The directory and socket
are owned by ``root:weldr`` so that any user in the ``weldr`` group can use the API
to control ``lorax-composer``.
At startup the server will check for the correct permissions and
ownership of a pre-existing directory, or it will create a new one if it
doesn't exist. The socket path and group owner's name can be changed from the
cmdline by passing it the ``--socket`` and ``--group`` arguments.
It will then drop root privileges for the API thread and run as the ``weldr``
user. The queue and compose thread still runs as root because it needs to be
able to mount/umount files and run Anaconda.
Composing Images
----------------
The `welder-web <https://github.com/weldr/welder-web/>`_ GUI project can be used to construct
blueprints and create composes using a web browser.
Or use the command line with `composer-cli <composer-cli.html>`_.
Blueprints
----------
Blueprints are simple text files in `TOML <https://github.com/toml-lang/toml>`_ format that describe
which packages, and what versions, to install into the image. They can also define a limited set
of customizations to make to the final image.
Example blueprints can be found in the ``lorax-composer`` `test suite
<https://github.com/weldr/lorax/tree/master/tests/pylorax/blueprints/>`_, with a simple one
looking like this::
name = "base"
description = "A base system with bash"
version = "0.0.1"
[[packages]]
name = "bash"
version = "4.4.*"
The ``name`` field is the name of the blueprint. It can contain spaces, but they will be converted to ``-``
when it is written to disk. It should be short and descriptive.
``description`` can be a longer description of the blueprint, it is only used for display purposes.
``version`` is a `semver compatible <https://semver.org/>`_ version number. If
a new blueprint is uploaded with the same ``version`` the server will
automatically bump the PATCH level of the ``version``. If the ``version``
doesn't match it will be used as is. eg. Uploading a blueprint with ``version``
set to ``0.1.0`` when the existing blueprint ``version`` is ``0.0.1`` will
result in the new blueprint being stored as ``version 0.1.0``.
[[packages]] and [[modules]]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
These entries describe the package names and matching version glob to be installed into the image.
The names must match the names exactly, and the versions can be an exact match
or a filesystem-like glob of the version using ``*`` wildcards and ``?``
character matching.
NOTE: Currently there are no differences between ``packages`` and ``modules``
in ``lorax-composer``. Both are treated like an rpm package dependency.
For example, to install ``tmux-2.9a`` and ``openssh-server-8.*``, you would add
this to your blueprint::
[[packages]]
name = "tmux"
version = "2.9a"
[[packages]]
name = "openssh-server"
version = "8.*"
[[groups]]
~~~~~~~~~~
The ``groups`` entries describe a group of packages to be installed into the image. Package groups are
defined in the repository metadata. Each group has a descriptive name used primarily for display
in user interfaces and an ID more commonly used in kickstart files. Here, the ID is the expected
way of listing a group.
Groups have three different ways of categorizing their packages: mandatory, default, and optional.
For purposes of blueprints, mandatory and default packages will be installed. There is no mechanism
for selecting optional packages.
For example, if you want to install the ``anaconda-tools`` group you would add this to your
blueprint::
[[groups]]
name="anaconda-tools"
``groups`` is a TOML list, so each group needs to be listed separately, like ``packages`` but with
no version number.
Customizations
~~~~~~~~~~~~~~
The ``[customizations]`` section can be used to configure the hostname of the final image. eg.::
[customizations]
hostname = "baseimage"
This is optional and may be left out to use the defaults.
[customizations.kernel]
***********************
This allows you to append arguments to the bootloader's kernel commandline. This will not have any
effect on ``tar`` or ``ext4-filesystem`` images since they do not include a bootloader.
For example::
[customizations.kernel]
append = "nosmt=force"
[[customizations.sshkey]]
*************************
Set an existing user's ssh key in the final image::
[[customizations.sshkey]]
user = "root"
key = "PUBLIC SSH KEY"
The key will be added to the user's authorized_keys file.
.. warning::
``key`` expects the entire content of ``~/.ssh/id_rsa.pub``
[[customizations.user]]
***********************
Add a user to the image, and/or set their ssh key.
All fields for this section are optional except for the ``name``, here is a complete example::
[[customizations.user]]
name = "admin"
description = "Administrator account"
password = "$6$CHO2$3rN8eviE2t50lmVyBYihTgVRHcaecmeCk31L..."
key = "PUBLIC SSH KEY"
home = "/srv/widget/"
shell = "/usr/bin/bash"
groups = ["widget", "users", "wheel"]
uid = 1200
gid = 1200
If the password starts with ``$6$``, ``$5$``, or ``$2b$`` it will be stored as
an encrypted password. Otherwise it will be treated as a plain text password.
.. warning::
``key`` expects the entire content of ``~/.ssh/id_rsa.pub``
[[customizations.group]]
************************
Add a group to the image. ``name`` is required and ``gid`` is optional::
[[customizations.group]]
name = "widget"
gid = 1130
[customizations.timezone]
*************************
Customizing the timezone and the NTP servers to use for the system::
[customizations.timezone]
timezone = "US/Eastern"
ntpservers = ["0.north-america.pool.ntp.org", "1.north-america.pool.ntp.org"]
The values supported by ``timezone`` can be listed by running ``timedatectl list-timezones``.
If no timezone is setup the system will default to using `UTC`. The ntp servers are also
optional and will default to using the distribution defaults which are fine for most uses.
In some image types there are already NTP servers setup, eg. Google cloud image, and they
cannot be overridden because they are required to boot in the selected environment. But the
timezone will be updated to the one selected in the blueprint.
[customizations.locale]
***********************
Customize the locale settings for the system::
[customizations.locale]
languages = ["en_US.UTF-8"]
keyboard = "us"
The values supported by ``languages`` can be listed by running ``localectl list-locales`` from
the command line.
The values supported by ``keyboard`` can be listed by running ``localectl list-keymaps`` from
the command line.
Multiple languages can be added. The first one becomes the
primary, and the others are added as secondary. One or the other of ``languages``
or ``keyboard`` must be included (or both) in the section.
[customizations.firewall]
*************************
By default the firewall blocks all access except for services that enable their ports explicitly,
like ``sshd``. This command can be used to open other ports or services. Ports are configured using
the port:protocol format::
[customizations.firewall]
ports = ["22:tcp", "80:tcp", "imap:tcp", "53:tcp", "53:udp"]
Numeric ports, or their names from ``/etc/services`` can be used in the ``ports`` enabled/disabled lists.
The blueprint settings extend any existing settings in the image templates, so if ``sshd`` is
already enabled it will extend the list of ports with the ones listed by the blueprint.
If the distribution uses ``firewalld`` you can specify services listed by ``firewall-cmd --get-services``
in a ``customizations.firewall.services`` section::
[customizations.firewall.services]
enabled = ["ftp", "ntp", "dhcp"]
disabled = ["telnet"]
Remember that the ``firewall.services`` are different from the names in ``/etc/services``.
Both are optional, if they are not used leave them out or set them to an empty list ``[]``. If you
only want the default firewall setup this section can be omitted from the blueprint.
NOTE: The ``Google`` and ``OpenStack`` templates explicitly disable the firewall for their environment.
This cannot be overridden by the blueprint.
[customizations.services]
*************************
This section can be used to control which services are enabled at boot time.
Some image types already have services enabled or disabled in order for the
image to work correctly, and cannot be overridden. eg. ``ami`` requires
``sshd``, ``chronyd``, and ``cloud-init``. Without them the image will not
boot. Blueprint services are added to, not replacing, the list already in the
templates, if any.
The service names are systemd service units. You may specify any systemd unit
file accepted by ``systemctl enable`` eg. ``cockpit.socket``::
[customizations.services]
enabled = ["sshd", "cockpit.socket", "httpd"]
disabled = ["postfix", "telnetd"]
[[repos.git]]
~~~~~~~~~~~~~
The ``[[repos.git]]`` entries are used to add files from a `git repository <https://git-scm.com/>`_
repository to the created image. The repository is cloned, the specified ``ref`` is checked out
and an rpm is created to install the files to a ``destination`` path. The rpm includes a summary
with the details of the repository and reference used to create it. The rpm is also included in the
image build metadata.
To create an rpm named ``server-config-1.0-1.noarch.rpm`` you would add this to your blueprint::
[[repos.git]]
rpmname="server-config"
rpmversion="1.0"
rpmrelease="1"
summary="Setup files for server deployment"
repo="PATH OF GIT REPO TO CLONE"
ref="v1.0"
destination="/opt/server/"
* rpmname: Name of the rpm to create, also used as the prefix name in the tar archive
* rpmversion: Version of the rpm, eg. "1.0.0"
* rpmrelease: Release of the rpm, eg. "1"
* summary: Summary string for the rpm
* repo: URL of the get repo to clone and create the archive from
* ref: Git reference to check out. eg. origin/branch-name, git tag, or git commit hash
* destination: Path to install the / of the git repo at when installing the rpm
An rpm will be created with the contents of the git repository referenced, with the files
being installed under ``/opt/server/`` in this case.
``ref`` can be any valid git reference for use with ``git archive``. eg. to use the head
of a branch set it to ``origin/branch-name``, a tag name, or a commit hash.
Note that the repository is cloned in full each time a build is started, so pointing to a
repository with a large amount of history may take a while to clone and use a significant
amount of disk space. The clone is temporary and is removed once the rpm is created.
Adding Output Types
-------------------
``livemedia-creator`` supports a large number of output types, and only some of
these are currently available via ``lorax-composer``. To add a new output type to
lorax-composer a kickstart file needs to be added to ``./share/composer/``. The
name of the kickstart is what will be used by the ``/compose/types`` route, and the
``compose_type`` field of the POST to start a compose. It also needs to have
code added to the :py:func:`pylorax.api.compose.compose_args` function. The
``_MAP`` entry in this function defines what lorax-composer will pass to
:py:func:`pylorax.installer.novirt_install` when it runs the compose. When the
compose is finished the output files need to be copied out of the build
directory (``/var/lib/lorax/composer/results/<UUID>/compose/``),
:py:func:`pylorax.api.compose.move_compose_results` handles this for each type.
You should move them instead of copying to save space.
If the new output type does not have support in livemedia-creator it should be
added there first. This will make the output available to the widest number of
users.
Example: Add partitioned disk support
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Partitioned disk support is something that livemedia-creator already supports
via the ``--make-disk`` cmdline argument. To add this to lorax-composer it
needs 3 things:
* A ``partitioned-disk.ks`` file in ``./share/composer/``
* A new entry in the _MAP in :py:func:`pylorax.api.compose.compose_args`
* Add a bit of code to :py:func:`pylorax.api.compose.move_compose_results` to move the disk image from
the compose directory to the results directory.
The ``partitioned-disk.ks`` is pretty similar to the example minimal kickstart
in ``./docs/fedora-minimal.ks``. You should remove the ``url`` and ``repo``
commands, they will be added by the compose process. Make sure the bootloader
packages are included in the ``%packages`` section at the end of the kickstart,
and you will want to leave off the ``%end`` so that the compose can append the
list of packages from the blueprint.
The new ``_MAP`` entry should be a copy of one of the existing entries, but with ``make_disk`` set
to ``True``. Make sure that none of the other ``make_*`` options are ``True``. The ``image_name`` is
what the name of the final image will be.
``move_compose_results()`` can be as simple as moving the output file into
the results directory, or it could do some post-processing on it. The end of
the function should always clean up the ``./compose/`` directory, removing any
unneeded extra files. This is especially true for the ``live-iso`` since it produces
the contents of the iso as well as the boot.iso itself.
Package Sources
---------------
By default lorax-composer uses the host's configured repositories. It copies
the ``*.repo`` files from ``/etc/yum.repos.d/`` into
``/var/lib/lorax/composer/repos.d/`` at startup, these are immutable system
repositories and cannot be deleted or changed. If you want to add additional
repos you can put them into ``/var/lib/lorax/composer/repos.d/`` or use the
``/api/v0/projects/source/*`` API routes to create them.
The new source can be added by doing a POST to the ``/api/v0/projects/source/new``
route using JSON (with `Content-Type` header set to `application/json`) or TOML
(with it set to `text/x-toml`). The format of the source looks like this (in
TOML)::
name = "custom-source-1"
url = "https://url/path/to/repository/"
type = "yum-baseurl"
proxy = "https://proxy-url/"
check_ssl = true
check_gpg = true
gpgkey_urls = ["https://url/path/to/gpg-key"]
The ``proxy`` and ``gpgkey_urls`` entries are optional. All of the others are required. The supported
types for the urls are:
* ``yum-baseurl`` is a URL to a yum repository.
* ``yum-mirrorlist`` is a URL for a mirrorlist.
* ``yum-metalink`` is a URL for a metalink.
If ``check_ssl`` is true the https certificates must be valid. If they are self-signed you can either set
this to false, or add your Certificate Authority to the host system.
If ``check_gpg`` is true the GPG key must either be installed on the host system, or ``gpgkey_urls``
should point to it.
You can edit an existing source (other than system sources), by doing a POST to the ``new`` route
with the new version of the source. It will overwrite the previous one.
A list of existing sources is available from ``/api/v0/projects/source/list``, and detailed info
on a source can be retrieved with the ``/api/v0/projects/source/info/<source-name>`` route. By default
it returns JSON but it can also return TOML if ``?format=toml`` is added to the request.
Non-system sources can be deleted by doing a ``DELETE`` request to the
``/api/v0/projects/source/delete/<source-name>`` route.
The documentation for the source API routes can be `found here <pylorax.api.html#api-v0-projects-source-list>`_
The configured sources are used for all blueprint depsolve operations, and for composing images.
When adding additional sources you must make sure that the packages in the source do not
conflict with any other package sources, otherwise depsolving will fail.
DVD ISO Package Source
~~~~~~~~~~~~~~~~~~~~~~
In some situations the system may want to *only* use a DVD iso as the package
source, not the repos from the network. ``lorax-composer`` and ``anaconda``
understand ``file://`` URLs so you can mount an iso on the host, and replace the
system repo files with a configuration file pointing to the DVD.
* Stop the ``lorax-composer.service`` if it is running
* Move the repo files in ``/etc/yum.repos.d/`` someplace safe
* Create a new ``iso.repo`` file in ``/etc/yum.repos.d/``::
[iso]
name=iso
baseurl=file:///mnt/iso/
enabled=1
gpgcheck=1
gpgkey=file:///mnt/iso/RPM-GPG-KEY-redhat-release
* Remove all the cached repo files from ``/var/lib/lorax/composer/repos/``
* Restart the ``lorax-composer.service``
* Check the output of ``composer-cli status show`` for any output specific depsolve errors.
For example, the DVD usually does not include ``grub2-efi-*-cdboot-*`` so the live-iso image
type will not be available.
If you want to *add* the DVD source to the existing sources you can do that by
mounting the iso and creating a source file to point to it as described in the
`Package Sources`_ documentation. In that case there is no need to remove the other
sources from ``/etc/yum.repos.d/`` or clear the cached repos.

View File

@ -0,0 +1,200 @@
Lorax
=====
:Authors:
Brian C. Lane <bcl@redhat.com>
"I am the Lorax. I speak for the trees [and images]."
The `lorax <https://github.com/rhinstaller/lorax>`_ tool is used to create the
`Anaconda <https://github.com/rhinstaller/anaconda>`_ installer boot.iso as
well as the basic release tree, and .treeinfo metadata file. Its dependencies
are fairly light-weight because it needs to be able to run in a mock chroot
environment. It is best to run lorax from the same release as is being targeted
because the templates may have release specific logic in them. eg. Use the
rawhide version to build the boot.iso for rawhide, along with the rawhide
repositories.
lorax cmdline arguments
-----------------------
.. argparse::
:ref: pylorax.cmdline.lorax_parser
:prog: lorax
--macboot : @replace
Make the iso bootable on UEFI based Mac systems
Default: True
--nomacboot : @replace
Do not create a Mac bootable iso
Default: False
Quickstart
----------
Run this as root to create a boot.iso in ``./results/``::
dnf install lorax
setenforce 0
lorax -p Fedora -v 23 -r 23 \
-s http://dl.fedoraproject.org/pub/fedora/linux/releases/23/Everything/x86_64/os/ \
-s http://dl.fedoraproject.org/pub/fedora/linux/updates/23/x86_64/ \
./results/
setenforce 1
You can add your own repos with ``-s`` and packages with higher NVRs will
override the ones in the distribution repositories.
Under ``./results/`` will be the release tree files: .discinfo, .treeinfo, everything that
goes onto the boot.iso, the pxeboot directory, and the boot.iso under ``./images/``.
Branding
--------
By default lorax will search for the first package that provides ``system-release``
that doesn't start with ``generic-`` and will install it. It then selects a
corresponding logo package by using the first part of the system-release package and
appending ``-logos`` to it. eg. fedora-release and fedora-logos.
Variants
~~~~~~~~
If a ``variant`` is passed to lorax it will select a ``system-release`` package that
ends with the variant name. eg. Passing ``--variant workstation`` will select the
``fedora-release-workstation`` package if it exists. It will select a logo package
the same way it does for non-variants. eg. ``fedora-logos``.
If there is no package ending with the variant name it will fall back to using the
first non-generic package providing ``system-release``.
Custom Branding
~~~~~~~~~~~~~~~
If ``--skip-branding`` is passed to lorax it will skip selecting the
``system-release``, and logos packages and leave it up to the user to pass any
branding related packages to lorax using ``--installpkgs``. When using
``skip-branding`` you must make sure that you provide all of the expected files,
otherwise Anaconda may not work as expected. See the contents of ``fedora-release``
and ``fedora-logos`` for examples of what to include.
Note that this does not prevent something else in the dependency tree from
causing these packages to be included. Using ``--excludepkgs`` may help if they
are unexpectedly included.
Running inside of mock
----------------------
As of mock version 2.0 you no longer need to pass ``--old-chroot``. You will,
however, need to pass ``--enable-network`` so that the mock container can download
packages.
Older versions of mock, between 1.3.4 and 2.0, will need to pass ``--old-chroot``
to mock. These versions of mock default to using systemd-nspawn which cannot
create the needed loop device nodes. Passing ``--old-chroot`` will use the old
system where ``/dev/loop*`` is setup for you.
How it works
------------
Lorax uses `dnf <https://github.com/rpm-software-management/dnf>`_ to install
packages into a temporary directory, sets up configuration files, it then
removes unneeded files to save space, and creates a squashfs filesystem of the
files. The iso is then built using a generic initramfs and the kernel from the
selected repositories.
To drive these processes Lorax uses a custom template system, based on `Mako
templates <http://www.makotemplates.org/>`_ with the addition of custom
commands (documented in :class:`pylorax.ltmpl.LoraxTemplateRunner`). Mako
supports ``%if/%endif`` blocks as well as free-form python code inside ``<%
%>`` tags and variable substitution with ``${}``. The default templates are
shipped with lorax in ``/usr/share/lorax/templates.d/99-generic/`` and use the
``.tmpl`` extension.
runtime-install.tmpl
~~~~~~~~~~~~~~~~~~~~
The ``runtime-install.tmpl`` template lists packages to be installed using the
``installpkg`` command. This template is fairly simple, installing common packages and
architecture specific packages. It must end with the ``run_pkg_transaction``
command which tells dnf to download and install the packages.
runtime-postinstall.tmpl
~~~~~~~~~~~~~~~~~~~~~~~~
The ``runtime-postinstall.tmpl`` template is where the system configuration
happens. The installer environment is similar to a normal running system, but
needs some special handling. Configuration files are setup, systemd is told to
start the anaconda.target instead of a default system target, and a number of
unneeded services are disabled, some of which can interfere with the
installation. A number of template commands are used here:
* :func:`append <pylorax.ltmpl.LoraxTemplateRunner.append>` to add text to a file.
* :func:`chmod <pylorax.ltmpl.LoraxTemplateRunner.chmod>` changes the file's mode.
* :func:`install <pylorax.ltmpl.LoraxTemplateRunner.install>` to install a file into the installroot.
* :func:`mkdir <pylorax.ltmpl.LoraxTemplateRunner.mkdir>` makes a new directory.
* :func:`move <pylorax.ltmpl.LoraxTemplateRunner.move>` to move a file into the installroot
* :func:`replace <pylorax.ltmpl.LoraxTemplateRunner.replace>` does text substitution in a file
* :func:`remove <pylorax.ltmpl.LoraxTemplateRunner.remove>` deletes a file
* :func:`runcmd <pylorax.ltmpl.LoraxTemplateRunner.runcmd>` run arbitrary commands.
* :func:`symlink <pylorax.ltmpl.LoraxTemplateRunner.symlink>` creates a symlink
* :func:`systemctl <pylorax.ltmpl.LoraxTemplateRunner.systemctl>` runs systemctl in the installroot
runtime-cleanup.tmpl
~~~~~~~~~~~~~~~~~~~~
The ``runtime-cleanup.tmpl`` template is used to remove files that aren't strictly needed
by the installation environment. In addition to the ``remove`` template command it uses:
* :func:`removepkg <pylorax.ltmpl.LoraxTemplateRunner.removepkg>`
remove all of a specific package's contents. A package may be pulled in as a dependency, but
not really used. eg. sound support.
* :func:`removefrom <pylorax.ltmpl.LoraxTemplateRunner.removefrom>`
Removes some files from a package. A file glob can be used, or the --allbut option to
remove everything except a select few.
* :func:`removekmod <pylorax.ltmpl.LoraxTemplateRunner.removekmod>`
Removes kernel modules
The squashfs filesystem
~~~~~~~~~~~~~~~~~~~~~~~
After ``runtime-*.tmpl`` templates have finished their work lorax creates an
empty ext4 filesystem, copies the remaining files to it, and makes a squashfs
filesystem of it. This file is the / of the boot.iso's installer environment
and is what is in the LiveOS/squashfs.img file on the iso.
iso creation
~~~~~~~~~~~~
The iso creation is handled by another set of templates. The one used depends
on the architecture that the iso is being created for. They are also stored in
``/usr/share/lorax/templates.d/99-generic`` and are named after the arch, like
``x86.tmpl`` and ``aarch64.tmpl``. They handle creation of the tree, copying
configuration template files, configuration variable substitution, treeinfo
metadata (via the :func:`treeinfo <pylorax.ltmpl.LoraxTemplateRunner.treeinfo>`
template command). Kernel and initrd are copied from the installroot to their
final locations and then xorrisofs is run to create the boot.iso
Custom Templates
----------------
The default set of templates and configuration files from the lorax-generic-templates package
are shipped in the ``/usr/share/lorax/templates.d/99-generic/`` directory. You can
make a copy of them and place them into another directory under ``templates.d``
and they will be used instead if their sort order is below all other directories. This
allows multiple packages to ship lorax templates without conflict. You can (and probably
should) select the specific template directory by passing ``--sharedir`` to lorax.

View File

@ -0,0 +1,128 @@
mkksiso
=======
:Authors:
Brian C. Lane <bcl@redhat.com>
``mkksiso`` is a tool for creating kickstart boot isos. In it's simplest form
you can add a kickstart to a boot.iso and the kickstart will be executed when
the iso is booted. If the original iso was created with EFI and Mac support the
kickstart boot.iso will include this support as well.
``mkksiso`` needs to be run as root, it depends on mounting the original iso
and you need to be root to be able to do that.
mkksiso cmdline arguments
-------------------------
Add a kickstart and files to an iso
``usage: mkksiso [-h] [-a ADD_PATHS] [-c CMDLINE] [--debug] ks input_iso output_iso``
Optional arguments
^^^^^^^^^^^^^^^^^^
-h, --help show this help message and exit
-a ADD_PATHS, --add ADD_PATHS
File or directory to add to ISO (may be used multiple
times)
-c CMDLINE, --cmdline CMDLINE
Arguments to add to kernel cmdline
--debug print debugging info
-V VOLID, --volid VOLID
Set the ISO volume id, defaults to input's
Positional arguments
^^^^^^^^^^^^^^^^^^^^
:ks: Kickstart to add to the ISO
:input_iso: ISO to modify
:output_iso: Full pathname of iso to be created
Create a kickstart boot.iso or DVD
----------------------------------
Create a kickstart like you normally would, kickstart documentation can be
`found here <https://pykickstart.readthedocs.io/en/latest/>`_, including the
``url`` and ``repo`` commands. If you are creating a DVD and only need the
content on the DVD you can use the ``cdrom`` command to install without a
network connection. Then run ``mkksiso`` like this::
mkksiso /PATH/TO/KICKSTART /PATH/TO/ISO /PATH/TO/NEW-ISO
This will create a new iso with the kickstart in the root directory, and the
kernel cmdline will have ``inst.ks=...`` added to it so that it will be
executed when the iso is booted (be careful not to boot on a system you don't
want to wipe out! There will be no prompting).
By default the volume id of the iso is preserved. You can set a custom volid
by passing ``-V`` and the string to set. The kernel cmdline will be changes, and the iso will have th custom volume id.
eg.::
mkksiso -V "Test Only" /PATH/TO/KICKSTART /PATH/TO/ISO /PATH/TO/NEW-ISO
Adding package repos to a boot.iso
----------------------------------
You can add repo directories to the iso using ``--add /PATH/TO/REPO/``, make
sure it contains the ``repodata`` directory by running ``createrepo_c`` on it
first. In the kickstart you can refer to the directories (and files) on the iso
using ``file:///run/install/repo/DIRECTORY/``. You can then use these repos in
the kickstart like this::
repo --name=extra-repo --baseurl=file:///run/install/repo/extra-repo/
Run ``mkksiso`` like so::
mkksiso --add /PATH/TO/REPO/ /PATH/TO/KICKSTART /PATH/TO/ISO /PATH/TO/NEW-ISO
Create a liveimg boot.iso
-------------------------
You can use the kickstart `liveimg command
<https://pykickstart.readthedocs.io/en/latest/kickstart-docs.html#liveimg>`_,
to install a pre-generated disk image or tar to the system the iso is booting
on.
Create a disk image or tar with ``lorax-composer`` or ``livemedia-creator``,
make sure the image includes tools expected by ``anaconda``, as well as the
kernel and bootloader support. In ``lorax-composer`` use the ``liveimg-tar``
image type. If you plan to install it to a UEFI machine make sure to include
``grub2-efi`` and ``efibootmgr`` in the blueprint.
Add the ``root.tar.xz`` file to the iso using ``--add /PATH/TO/ROOT.TAR.XZ``,
and in the kickstart reference it with the ``liveimg`` command like this::
liveimg --url=file:///run/install/repo/root.tar.xz
It is also a good idea to use the ``--checksum`` argument to ``liveimg`` to be
sure the file hasn't been corrupted::
mkksiso --add /PATH/TO/root.tar.xz /PATH/TO/KICKSTART /PATH/TO/ISO /PATH/TO/NEW-ISO
When this iso is booted it will execute the kickstart and install the liveimg
contents to the system without any prompting.
How it works
------------
``mkksiso`` first examines the system to make sure the tools it needs are installed,
it will work with ``xorrisofs`` or ``mkisofs`` installed. It mounts the source iso,
and copies the directories that need to be modified to a temporary directory.
It then modifies the boot configuration files to include the ``inst.ks`` command,
and checks to see if the original iso supports EFI. If it does it regenerates the
EFI boot images with the new configuration, and then runs the available iso creation
tool to add the new files and directories to the new iso. If the architecture is
``x86_64`` it will also make sure the iso can be booted as an iso or from a USB
stick (hybridiso).
The last step is to update the iso checksums so that booting with test enabled
will pass.

View File

@ -0,0 +1,9 @@
src
===
.. toctree::
:maxdepth: 4
composer
lifted
pylorax

View File

@ -0,0 +1,27 @@
Product and Updates Images
==========================
Lorax now supports creation of product.img and updates.img as part of the build
process. This is implemented using the installimg template command which will
take the contents of a directory and create a compressed archive from it. The
directory must be created by one of the packages installed by
runtime-install.tmpl or by passing ``--installpkgs <pkgname>`` to lorax at
runtime. The x86, ppc, ppc64le and aarch64 templates all look for
/usr/share/lorax/product/ and /usr/share/lorax/updates/ directories in the
install chroot while creating the final install tree. If there are files in
those directories lorax will create images/product.img and/or
images/updates.img
These archives are just like an anaconda updates image -- their contents are
copied over the top of the filesystem at boot time so that you can drop in
files to add to or replace anything on the filesystem.
Anaconda has several places that it looks for updates, the one for product.img
is in /run/install/product. So for example, to add an installclass to Anaconda
you would put your custom class here:
``/usr/share/lorax/product/run/install/product/pyanaconda/installclasses/custom.py``
If the packages containing the product/updates files are not included as part
of normal dependencies you can add specific packages with the ``--installpkgs``
command or the installpkgs paramater of :class:`pylorax.treebuilder.RuntimeBuilder`

View File

@ -0,0 +1,173 @@
pylorax.api package
===================
Submodules
----------
pylorax.api.bisect module
-------------------------
.. automodule:: pylorax.api.bisect
:members:
:undoc-members:
:show-inheritance:
pylorax.api.checkparams module
------------------------------
.. automodule:: pylorax.api.checkparams
:members:
:undoc-members:
:show-inheritance:
pylorax.api.cmdline module
--------------------------
.. automodule:: pylorax.api.cmdline
:members:
:undoc-members:
:show-inheritance:
pylorax.api.compose module
--------------------------
.. automodule:: pylorax.api.compose
:members:
:undoc-members:
:show-inheritance:
pylorax.api.config module
-------------------------
.. automodule:: pylorax.api.config
:members:
:undoc-members:
:show-inheritance:
pylorax.api.dnfbase module
--------------------------
.. automodule:: pylorax.api.dnfbase
:members:
:undoc-members:
:show-inheritance:
pylorax.api.errors module
-------------------------
.. automodule:: pylorax.api.errors
:members:
:undoc-members:
:show-inheritance:
pylorax.api.flask\_blueprint module
-----------------------------------
.. automodule:: pylorax.api.flask_blueprint
:members:
:undoc-members:
:show-inheritance:
pylorax.api.gitrpm module
-------------------------
.. automodule:: pylorax.api.gitrpm
:members:
:undoc-members:
:show-inheritance:
pylorax.api.projects module
---------------------------
.. automodule:: pylorax.api.projects
:members:
:undoc-members:
:show-inheritance:
pylorax.api.queue module
------------------------
.. automodule:: pylorax.api.queue
:members:
:undoc-members:
:show-inheritance:
pylorax.api.recipes module
--------------------------
.. automodule:: pylorax.api.recipes
:members:
:undoc-members:
:show-inheritance:
pylorax.api.regexes module
--------------------------
.. automodule:: pylorax.api.regexes
:members:
:undoc-members:
:show-inheritance:
pylorax.api.server module
-------------------------
.. automodule:: pylorax.api.server
:members:
:undoc-members:
:show-inheritance:
pylorax.api.timestamp module
----------------------------
.. automodule:: pylorax.api.timestamp
:members:
:undoc-members:
:show-inheritance:
pylorax.api.toml module
-----------------------
.. automodule:: pylorax.api.toml
:members:
:undoc-members:
:show-inheritance:
pylorax.api.utils module
------------------------
.. automodule:: pylorax.api.utils
:members:
:undoc-members:
:show-inheritance:
pylorax.api.v0 module
---------------------
.. automodule:: pylorax.api.v0
:members:
:undoc-members:
:show-inheritance:
pylorax.api.v1 module
---------------------
.. automodule:: pylorax.api.v1
:members:
:undoc-members:
:show-inheritance:
pylorax.api.workspace module
----------------------------
.. automodule:: pylorax.api.workspace
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: pylorax.api
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,165 @@
pylorax package
===============
Subpackages
-----------
.. toctree::
:maxdepth: 4
pylorax.api
Submodules
----------
pylorax.base module
-------------------
.. automodule:: pylorax.base
:members:
:undoc-members:
:show-inheritance:
pylorax.buildstamp module
-------------------------
.. automodule:: pylorax.buildstamp
:members:
:undoc-members:
:show-inheritance:
pylorax.cmdline module
----------------------
.. automodule:: pylorax.cmdline
:members:
:undoc-members:
:show-inheritance:
pylorax.creator module
----------------------
.. automodule:: pylorax.creator
:members:
:undoc-members:
:show-inheritance:
pylorax.decorators module
-------------------------
.. automodule:: pylorax.decorators
:members:
:undoc-members:
:show-inheritance:
pylorax.discinfo module
-----------------------
.. automodule:: pylorax.discinfo
:members:
:undoc-members:
:show-inheritance:
pylorax.dnfbase module
----------------------
.. automodule:: pylorax.dnfbase
:members:
:undoc-members:
:show-inheritance:
pylorax.dnfhelper module
------------------------
.. automodule:: pylorax.dnfhelper
:members:
:undoc-members:
:show-inheritance:
pylorax.executils module
------------------------
.. automodule:: pylorax.executils
:members:
:undoc-members:
:show-inheritance:
pylorax.imgutils module
-----------------------
.. automodule:: pylorax.imgutils
:members:
:undoc-members:
:show-inheritance:
pylorax.installer module
------------------------
.. automodule:: pylorax.installer
:members:
:undoc-members:
:show-inheritance:
pylorax.ltmpl module
--------------------
.. automodule:: pylorax.ltmpl
:members:
:undoc-members:
:show-inheritance:
pylorax.monitor module
----------------------
.. automodule:: pylorax.monitor
:members:
:undoc-members:
:show-inheritance:
pylorax.mount module
--------------------
.. automodule:: pylorax.mount
:members:
:undoc-members:
:show-inheritance:
pylorax.output module
---------------------
.. automodule:: pylorax.output
:members:
:undoc-members:
:show-inheritance:
pylorax.sysutils module
-----------------------
.. automodule:: pylorax.sysutils
:members:
:undoc-members:
:show-inheritance:
pylorax.treebuilder module
--------------------------
.. automodule:: pylorax.treebuilder
:members:
:undoc-members:
:show-inheritance:
pylorax.treeinfo module
-----------------------
.. automodule:: pylorax.treeinfo
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: pylorax
:members:
:undoc-members:
:show-inheritance:

Binary file not shown.

After

Width:  |  Height:  |  Size: 673 B

View File

@ -0,0 +1,855 @@
/*
* basic.css
* ~~~~~~~~~
*
* Sphinx stylesheet -- basic theme.
*
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/* -- main layout ----------------------------------------------------------- */
div.clearer {
clear: both;
}
div.section::after {
display: block;
content: '';
clear: left;
}
/* -- relbar ---------------------------------------------------------------- */
div.related {
width: 100%;
font-size: 90%;
}
div.related h3 {
display: none;
}
div.related ul {
margin: 0;
padding: 0 0 0 10px;
list-style: none;
}
div.related li {
display: inline;
}
div.related li.right {
float: right;
margin-right: 5px;
}
/* -- sidebar --------------------------------------------------------------- */
div.sphinxsidebarwrapper {
padding: 10px 5px 0 10px;
}
div.sphinxsidebar {
float: left;
width: 230px;
margin-left: -100%;
font-size: 90%;
word-wrap: break-word;
overflow-wrap : break-word;
}
div.sphinxsidebar ul {
list-style: none;
}
div.sphinxsidebar ul ul,
div.sphinxsidebar ul.want-points {
margin-left: 20px;
list-style: square;
}
div.sphinxsidebar ul ul {
margin-top: 0;
margin-bottom: 0;
}
div.sphinxsidebar form {
margin-top: 10px;
}
div.sphinxsidebar input {
border: 1px solid #98dbcc;
font-family: sans-serif;
font-size: 1em;
}
div.sphinxsidebar #searchbox form.search {
overflow: hidden;
}
div.sphinxsidebar #searchbox input[type="text"] {
float: left;
width: 80%;
padding: 0.25em;
box-sizing: border-box;
}
div.sphinxsidebar #searchbox input[type="submit"] {
float: left;
width: 20%;
border-left: none;
padding: 0.25em;
box-sizing: border-box;
}
img {
border: 0;
max-width: 100%;
}
/* -- search page ----------------------------------------------------------- */
ul.search {
margin: 10px 0 0 20px;
padding: 0;
}
ul.search li {
padding: 5px 0 5px 20px;
background-image: url(file.png);
background-repeat: no-repeat;
background-position: 0 7px;
}
ul.search li a {
font-weight: bold;
}
ul.search li div.context {
color: #888;
margin: 2px 0 0 30px;
text-align: left;
}
ul.keywordmatches li.goodmatch a {
font-weight: bold;
}
/* -- index page ------------------------------------------------------------ */
table.contentstable {
width: 90%;
margin-left: auto;
margin-right: auto;
}
table.contentstable p.biglink {
line-height: 150%;
}
a.biglink {
font-size: 1.3em;
}
span.linkdescr {
font-style: italic;
padding-top: 5px;
font-size: 90%;
}
/* -- general index --------------------------------------------------------- */
table.indextable {
width: 100%;
}
table.indextable td {
text-align: left;
vertical-align: top;
}
table.indextable ul {
margin-top: 0;
margin-bottom: 0;
list-style-type: none;
}
table.indextable > tbody > tr > td > ul {
padding-left: 0em;
}
table.indextable tr.pcap {
height: 10px;
}
table.indextable tr.cap {
margin-top: 10px;
background-color: #f2f2f2;
}
img.toggler {
margin-right: 3px;
margin-top: 3px;
cursor: pointer;
}
div.modindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
div.genindex-jumpbox {
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
margin: 1em 0 1em 0;
padding: 0.4em;
}
/* -- domain module index --------------------------------------------------- */
table.modindextable td {
padding: 2px;
border-collapse: collapse;
}
/* -- general body styles --------------------------------------------------- */
div.body {
min-width: 450px;
max-width: 800px;
}
div.body p, div.body dd, div.body li, div.body blockquote {
-moz-hyphens: auto;
-ms-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
a.headerlink {
visibility: hidden;
}
a.brackets:before,
span.brackets > a:before{
content: "[";
}
a.brackets:after,
span.brackets > a:after {
content: "]";
}
h1:hover > a.headerlink,
h2:hover > a.headerlink,
h3:hover > a.headerlink,
h4:hover > a.headerlink,
h5:hover > a.headerlink,
h6:hover > a.headerlink,
dt:hover > a.headerlink,
caption:hover > a.headerlink,
p.caption:hover > a.headerlink,
div.code-block-caption:hover > a.headerlink {
visibility: visible;
}
div.body p.caption {
text-align: inherit;
}
div.body td {
text-align: left;
}
.first {
margin-top: 0 !important;
}
p.rubric {
margin-top: 30px;
font-weight: bold;
}
img.align-left, .figure.align-left, object.align-left {
clear: left;
float: left;
margin-right: 1em;
}
img.align-right, .figure.align-right, object.align-right {
clear: right;
float: right;
margin-left: 1em;
}
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
img.align-default, .figure.align-default {
display: block;
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left;
}
.align-center {
text-align: center;
}
.align-default {
text-align: center;
}
.align-right {
text-align: right;
}
/* -- sidebars -------------------------------------------------------------- */
div.sidebar {
margin: 0 0 0.5em 1em;
border: 1px solid #ddb;
padding: 7px;
background-color: #ffe;
width: 40%;
float: right;
clear: right;
overflow-x: auto;
}
p.sidebar-title {
font-weight: bold;
}
div.admonition, div.topic, blockquote {
clear: left;
}
/* -- topics ---------------------------------------------------------------- */
div.topic {
border: 1px solid #ccc;
padding: 7px;
margin: 10px 0 10px 0;
}
p.topic-title {
font-size: 1.1em;
font-weight: bold;
margin-top: 10px;
}
/* -- admonitions ----------------------------------------------------------- */
div.admonition {
margin-top: 10px;
margin-bottom: 10px;
padding: 7px;
}
div.admonition dt {
font-weight: bold;
}
p.admonition-title {
margin: 0px 10px 5px 0px;
font-weight: bold;
}
div.body p.centered {
text-align: center;
margin-top: 25px;
}
/* -- content of sidebars/topics/admonitions -------------------------------- */
div.sidebar > :last-child,
div.topic > :last-child,
div.admonition > :last-child {
margin-bottom: 0;
}
div.sidebar::after,
div.topic::after,
div.admonition::after,
blockquote::after {
display: block;
content: '';
clear: both;
}
/* -- tables ---------------------------------------------------------------- */
table.docutils {
margin-top: 10px;
margin-bottom: 10px;
border: 0;
border-collapse: collapse;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
table.align-default {
margin-left: auto;
margin-right: auto;
}
table caption span.caption-number {
font-style: italic;
}
table caption span.caption-text {
}
table.docutils td, table.docutils th {
padding: 1px 8px 1px 5px;
border-top: 0;
border-left: 0;
border-right: 0;
border-bottom: 1px solid #aaa;
}
table.footnote td, table.footnote th {
border: 0 !important;
}
th {
text-align: left;
padding-right: 5px;
}
table.citation {
border-left: solid 1px gray;
margin-left: 1px;
}
table.citation td {
border-bottom: none;
}
th > :first-child,
td > :first-child {
margin-top: 0px;
}
th > :last-child,
td > :last-child {
margin-bottom: 0px;
}
/* -- figures --------------------------------------------------------------- */
div.figure {
margin: 0.5em;
padding: 0.5em;
}
div.figure p.caption {
padding: 0.3em;
}
div.figure p.caption span.caption-number {
font-style: italic;
}
div.figure p.caption span.caption-text {
}
/* -- field list styles ----------------------------------------------------- */
table.field-list td, table.field-list th {
border: 0 !important;
}
.field-list ul {
margin: 0;
padding-left: 1em;
}
.field-list p {
margin: 0;
}
.field-name {
-moz-hyphens: manual;
-ms-hyphens: manual;
-webkit-hyphens: manual;
hyphens: manual;
}
/* -- hlist styles ---------------------------------------------------------- */
table.hlist {
margin: 1em 0;
}
table.hlist td {
vertical-align: top;
}
/* -- other body styles ----------------------------------------------------- */
ol.arabic {
list-style: decimal;
}
ol.loweralpha {
list-style: lower-alpha;
}
ol.upperalpha {
list-style: upper-alpha;
}
ol.lowerroman {
list-style: lower-roman;
}
ol.upperroman {
list-style: upper-roman;
}
:not(li) > ol > li:first-child > :first-child,
:not(li) > ul > li:first-child > :first-child {
margin-top: 0px;
}
:not(li) > ol > li:last-child > :last-child,
:not(li) > ul > li:last-child > :last-child {
margin-bottom: 0px;
}
ol.simple ol p,
ol.simple ul p,
ul.simple ol p,
ul.simple ul p {
margin-top: 0;
}
ol.simple > li:not(:first-child) > p,
ul.simple > li:not(:first-child) > p {
margin-top: 0;
}
ol.simple p,
ul.simple p {
margin-bottom: 0;
}
dl.footnote > dt,
dl.citation > dt {
float: left;
margin-right: 0.5em;
}
dl.footnote > dd,
dl.citation > dd {
margin-bottom: 0em;
}
dl.footnote > dd:after,
dl.citation > dd:after {
content: "";
clear: both;
}
dl.field-list {
display: grid;
grid-template-columns: fit-content(30%) auto;
}
dl.field-list > dt {
font-weight: bold;
word-break: break-word;
padding-left: 0.5em;
padding-right: 5px;
}
dl.field-list > dt:after {
content: ":";
}
dl.field-list > dd {
padding-left: 0.5em;
margin-top: 0em;
margin-left: 0em;
margin-bottom: 0em;
}
dl {
margin-bottom: 15px;
}
dd > :first-child {
margin-top: 0px;
}
dd ul, dd table {
margin-bottom: 10px;
}
dd {
margin-top: 3px;
margin-bottom: 10px;
margin-left: 30px;
}
dl > dd:last-child,
dl > dd:last-child > :last-child {
margin-bottom: 0;
}
dt:target, span.highlighted {
background-color: #fbe54e;
}
rect.highlighted {
fill: #fbe54e;
}
dl.glossary dt {
font-weight: bold;
font-size: 1.1em;
}
.optional {
font-size: 1.3em;
}
.sig-paren {
font-size: larger;
}
.versionmodified {
font-style: italic;
}
.system-message {
background-color: #fda;
padding: 5px;
border: 3px solid red;
}
.footnote:target {
background-color: #ffa;
}
.line-block {
display: block;
margin-top: 1em;
margin-bottom: 1em;
}
.line-block .line-block {
margin-top: 0;
margin-bottom: 0;
margin-left: 1.5em;
}
.guilabel, .menuselection {
font-family: sans-serif;
}
.accelerator {
text-decoration: underline;
}
.classifier {
font-style: oblique;
}
.classifier:before {
font-style: normal;
margin: 0.5em;
content: ":";
}
abbr, acronym {
border-bottom: dotted 1px;
cursor: help;
}
/* -- code displays --------------------------------------------------------- */
pre {
overflow: auto;
overflow-y: hidden; /* fixes display issues on Chrome browsers */
}
pre, div[class*="highlight-"] {
clear: both;
}
span.pre {
-moz-hyphens: none;
-ms-hyphens: none;
-webkit-hyphens: none;
hyphens: none;
}
div[class*="highlight-"] {
margin: 1em 0;
}
td.linenos pre {
border: 0;
background-color: transparent;
color: #aaa;
}
table.highlighttable {
display: block;
}
table.highlighttable tbody {
display: block;
}
table.highlighttable tr {
display: flex;
}
table.highlighttable td {
margin: 0;
padding: 0;
}
table.highlighttable td.linenos {
padding-right: 0.5em;
}
table.highlighttable td.code {
flex: 1;
overflow: hidden;
}
.highlight .hll {
display: block;
}
div.highlight pre,
table.highlighttable pre {
margin: 0;
}
div.code-block-caption + div {
margin-top: 0;
}
div.code-block-caption {
margin-top: 1em;
padding: 2px 5px;
font-size: small;
}
div.code-block-caption code {
background-color: transparent;
}
table.highlighttable td.linenos,
div.doctest > div.highlight span.gp { /* gp: Generic.Prompt */
user-select: none;
}
div.code-block-caption span.caption-number {
padding: 0.1em 0.3em;
font-style: italic;
}
div.code-block-caption span.caption-text {
}
div.literal-block-wrapper {
margin: 1em 0;
}
code.descname {
background-color: transparent;
font-weight: bold;
font-size: 1.2em;
}
code.descclassname {
background-color: transparent;
}
code.xref, a code {
background-color: transparent;
font-weight: bold;
}
h1 code, h2 code, h3 code, h4 code, h5 code, h6 code {
background-color: transparent;
}
.viewcode-link {
float: right;
}
.viewcode-back {
float: right;
font-family: sans-serif;
}
div.viewcode-block:target {
margin: -1px -10px;
padding: 0 10px;
}
/* -- math display ---------------------------------------------------------- */
img.math {
vertical-align: middle;
}
div.body div.math p {
text-align: center;
}
span.eqno {
float: right;
}
span.eqno a.headerlink {
position: absolute;
z-index: 1;
}
div.math:hover a.headerlink {
visibility: visible;
}
/* -- printout stylesheet --------------------------------------------------- */
@media print {
div.document,
div.documentwrapper,
div.bodywrapper {
margin: 0 !important;
width: 100%;
}
div.sphinxsidebar,
div.related,
div.footer,
#top-link {
display: none;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 829 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 B

View File

@ -0,0 +1 @@
.fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../fonts/fontawesome-webfont.eot");src:url("../fonts/fontawesome-webfont.eot?#iefix") format("embedded-opentype"),url("../fonts/fontawesome-webfont.woff") format("woff"),url("../fonts/fontawesome-webfont.ttf") format("truetype"),url("../fonts/fontawesome-webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,315 @@
/*
* doctools.js
* ~~~~~~~~~~~
*
* Sphinx JavaScript utilities for all documentation.
*
* :copyright: Copyright 2007-2020 by the Sphinx team, see AUTHORS.
* :license: BSD, see LICENSE for details.
*
*/
/**
* select a different prefix for underscore
*/
$u = _.noConflict();
/**
* make the code below compatible with browsers without
* an installed firebug like debugger
if (!window.console || !console.firebug) {
var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
"dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
"profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {};
}
*/
/**
* small helper function to urldecode strings
*/
jQuery.urldecode = function(x) {
return decodeURIComponent(x).replace(/\+/g, ' ');
};
/**
* small helper function to urlencode strings
*/
jQuery.urlencode = encodeURIComponent;
/**
* This function returns the parsed url parameters of the
* current request. Multiple values per key are supported,
* it will always return arrays of strings for the value parts.
*/
jQuery.getQueryParameters = function(s) {
if (typeof s === 'undefined')
s = document.location.search;
var parts = s.substr(s.indexOf('?') + 1).split('&');
var result = {};
for (var i = 0; i < parts.length; i++) {
var tmp = parts[i].split('=', 2);
var key = jQuery.urldecode(tmp[0]);
var value = jQuery.urldecode(tmp[1]);
if (key in result)
result[key].push(value);
else
result[key] = [value];
}
return result;
};
/**
* highlight a given string on a jquery object by wrapping it in
* span elements with the given class name.
*/
jQuery.fn.highlightText = function(text, className) {
function highlight(node, addItems) {
if (node.nodeType === 3) {
var val = node.nodeValue;
var pos = val.toLowerCase().indexOf(text);
if (pos >= 0 &&
!jQuery(node.parentNode).hasClass(className) &&
!jQuery(node.parentNode).hasClass("nohighlight")) {
var span;
var isInSVG = jQuery(node).closest("body, svg, foreignObject").is("svg");
if (isInSVG) {
span = document.createElementNS("http://www.w3.org/2000/svg", "tspan");
} else {
span = document.createElement("span");
span.className = className;
}
span.appendChild(document.createTextNode(val.substr(pos, text.length)));
node.parentNode.insertBefore(span, node.parentNode.insertBefore(
document.createTextNode(val.substr(pos + text.length)),
node.nextSibling));
node.nodeValue = val.substr(0, pos);
if (isInSVG) {
var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
var bbox = node.parentElement.getBBox();
rect.x.baseVal.value = bbox.x;
rect.y.baseVal.value = bbox.y;
rect.width.baseVal.value = bbox.width;
rect.height.baseVal.value = bbox.height;
rect.setAttribute('class', className);
addItems.push({
"parent": node.parentNode,
"target": rect});
}
}
}
else if (!jQuery(node).is("button, select, textarea")) {
jQuery.each(node.childNodes, function() {
highlight(this, addItems);
});
}
}
var addItems = [];
var result = this.each(function() {
highlight(this, addItems);
});
for (var i = 0; i < addItems.length; ++i) {
jQuery(addItems[i].parent).before(addItems[i].target);
}
return result;
};
/*
* backward compatibility for jQuery.browser
* This will be supported until firefox bug is fixed.
*/
if (!jQuery.browser) {
jQuery.uaMatch = function(ua) {
ua = ua.toLowerCase();
var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
/(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
[];
return {
browser: match[ 1 ] || "",
version: match[ 2 ] || "0"
};
};
jQuery.browser = {};
jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
}
/**
* Small JavaScript module for the documentation.
*/
var Documentation = {
init : function() {
this.fixFirefoxAnchorBug();
this.highlightSearchWords();
this.initIndexTable();
if (DOCUMENTATION_OPTIONS.NAVIGATION_WITH_KEYS) {
this.initOnKeyListeners();
}
},
/**
* i18n support
*/
TRANSLATIONS : {},
PLURAL_EXPR : function(n) { return n === 1 ? 0 : 1; },
LOCALE : 'unknown',
// gettext and ngettext don't access this so that the functions
// can safely bound to a different name (_ = Documentation.gettext)
gettext : function(string) {
var translated = Documentation.TRANSLATIONS[string];
if (typeof translated === 'undefined')
return string;
return (typeof translated === 'string') ? translated : translated[0];
},
ngettext : function(singular, plural, n) {
var translated = Documentation.TRANSLATIONS[singular];
if (typeof translated === 'undefined')
return (n == 1) ? singular : plural;
return translated[Documentation.PLURALEXPR(n)];
},
addTranslations : function(catalog) {
for (var key in catalog.messages)
this.TRANSLATIONS[key] = catalog.messages[key];
this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
this.LOCALE = catalog.locale;
},
/**
* add context elements like header anchor links
*/
addContextElements : function() {
$('div[id] > :header:first').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this headline')).
appendTo(this);
});
$('dt[id]').each(function() {
$('<a class="headerlink">\u00B6</a>').
attr('href', '#' + this.id).
attr('title', _('Permalink to this definition')).
appendTo(this);
});
},
/**
* workaround a firefox stupidity
* see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075
*/
fixFirefoxAnchorBug : function() {
if (document.location.hash && $.browser.mozilla)
window.setTimeout(function() {
document.location.href += '';
}, 10);
},
/**
* highlight the search words provided in the url in the text
*/
highlightSearchWords : function() {
var params = $.getQueryParameters();
var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
if (terms.length) {
var body = $('div.body');
if (!body.length) {
body = $('body');
}
window.setTimeout(function() {
$.each(terms, function() {
body.highlightText(this.toLowerCase(), 'highlighted');
});
}, 10);
$('<p class="highlight-link"><a href="javascript:Documentation.' +
'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
.appendTo($('#searchbox'));
}
},
/**
* init the domain index toggle buttons
*/
initIndexTable : function() {
var togglers = $('img.toggler').click(function() {
var src = $(this).attr('src');
var idnum = $(this).attr('id').substr(7);
$('tr.cg-' + idnum).toggle();
if (src.substr(-9) === 'minus.png')
$(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
else
$(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
}).css('display', '');
if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
togglers.click();
}
},
/**
* helper function to hide the search marks again
*/
hideSearchWords : function() {
$('#searchbox .highlight-link').fadeOut(300);
$('span.highlighted').removeClass('highlighted');
},
/**
* make the url absolute
*/
makeURL : function(relativeURL) {
return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
},
/**
* get the current relative url
*/
getCurrentURL : function() {
var path = document.location.pathname;
var parts = path.split(/\//);
$.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
if (this === '..')
parts.pop();
});
var url = parts.join('/');
return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
},
initOnKeyListeners: function() {
$(document).keydown(function(event) {
var activeElementType = document.activeElement.tagName;
// don't navigate when in search box or textarea
if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT'
&& !event.altKey && !event.ctrlKey && !event.metaKey && !event.shiftKey) {
switch (event.keyCode) {
case 37: // left
var prevHref = $('link[rel="prev"]').prop('href');
if (prevHref) {
window.location.href = prevHref;
return false;
}
case 39: // right
var nextHref = $('link[rel="next"]').prop('href');
if (nextHref) {
window.location.href = nextHref;
return false;
}
}
}
});
}
};
// quick alias for translations
_ = Documentation.gettext;
$(document).ready(function() {
Documentation.init();
});

View File

@ -0,0 +1,12 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '33.10',
LANGUAGE: 'None',
COLLAPSE_INDEX: false,
BUILDER: 'html',
FILE_SUFFIX: '.html',
LINK_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt',
NAVIGATION_WITH_KEYS: false
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

BIN
f33-branch/_static/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

BIN
f33-branch/_static/file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More