618 lines
80 KiB
HTML
618 lines
80 KiB
HTML
|
|
|
|
<!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 — Lorax 29.20 documentation</title>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<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" />
|
|
|
|
|
|
<script src="../../_static/js/modernizr.min.js"></script>
|
|
|
|
</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">
|
|
29.20
|
|
</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> »</li>
|
|
|
|
<li><a href="../index.html">Module code</a> »</li>
|
|
|
|
<li><a href="../pylorax.html">pylorax</a> »</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 <http://www.gnu.org/licenses/>.</span>
|
|
<span class="c1">#</span>
|
|
<span class="c1"># Author(s): Will Woods <wwoods@redhat.com></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">"pylorax.treebuilder"</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="k">import</span> <span class="n">basename</span>
|
|
<span class="kn">from</span> <span class="nn">shutil</span> <span class="k">import</span> <span class="n">copytree</span><span class="p">,</span> <span class="n">copy2</span>
|
|
<span class="kn">from</span> <span class="nn">pathlib</span> <span class="k">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="k">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="k">import</span> <span class="n">DataHolder</span>
|
|
<span class="kn">from</span> <span class="nn">pylorax.ltmpl</span> <span class="k">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="k">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">'i386'</span><span class="p">:</span> <span class="s1">'x86.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'x86_64'</span><span class="p">:</span> <span class="s1">'x86.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'ppc'</span><span class="p">:</span> <span class="s1">'ppc.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'ppc64'</span><span class="p">:</span> <span class="s1">'ppc.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'ppc64le'</span><span class="p">:</span> <span class="s1">'ppc64le.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'s390'</span><span class="p">:</span> <span class="s1">'s390.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'s390x'</span><span class="p">:</span> <span class="s1">'s390.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'aarch64'</span><span class="p">:</span> <span class="s1">'aarch64.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'arm'</span><span class="p">:</span> <span class="s1">'arm.tmpl'</span><span class="p">,</span>
|
|
<span class="s1">'armhfp'</span><span class="p">:</span> <span class="s1">'arm.tmpl'</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">"modinfo"</span><span class="p">,</span> <span class="s2">"-F"</span><span class="p">,</span> <span class="s2">"description"</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">".ko"</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">'scsi'</span><span class="p">:</span><span class="n">read_module_set</span><span class="p">(</span><span class="s2">"modules.block"</span><span class="p">),</span>
|
|
<span class="s1">'eth'</span><span class="p">:</span><span class="n">read_module_set</span><span class="p">(</span><span class="s2">"modules.networking"</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 -> (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">"</span><span class="si">%s</span><span class="s2"> driver"</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">"module-info"</span><span class="p">),</span> <span class="s2">"w"</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">"Version 0</span><span class="se">\n</span><span class="s2">"</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">'name'</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">'</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">"</span><span class="si">{desc:.65}</span><span class="s1">"</span><span class="se">\n</span><span class="s1">'</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">'''Builds the anaconda runtime image.'''</span>
|
|
<span class="k">def</span> <span class="nf">__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">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="k">def</span> <span class="nf">_install_branding</span><span class="p">(</span><span class="bp">self</span><span class="p">):</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="k">for</span> <span class="n">pkg</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">'system-release'</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">"Found release package </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">pkg</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">pkg</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="s1">'generic'</span><span class="p">):</span>
|
|
<span class="k">continue</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="n">release</span> <span class="o">=</span> <span class="n">pkg</span><span class="o">.</span><span class="n">name</span>
|
|
<span class="k">break</span>
|
|
|
|
<span class="k">if</span> <span class="ow">not</span> <span class="n">release</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">'could not get the release'</span><span class="p">)</span>
|
|
<span class="k">return</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">'got release: </span><span class="si">%s</span><span class="s1">'</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">'-'</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">'</span><span class="si">%s</span><span class="s1">-logos'</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">'''Install packages and do initial setup with runtime-install.tmpl'''</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">></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">></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">"runtime-install.tmpl"</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">'''debugging data: write out lists of package contents'''</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">"w"</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">"</span><span class="si">{0}</span><span class="se">\n</span><span class="s2">"</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">'''Do some post-install setup work with runtime-postinstall.tmpl'''</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">"config_files"</span><span class="p">)</span>
|
|
<span class="n">configdir_path</span> <span class="o">=</span> <span class="s2">"tmp/config_files"</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">"runtime-postinstall.tmpl"</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">'''Remove unneeded packages and files with runtime-cleanup.tmpl'''</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">"runtime-cleanup.tmpl"</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">'''Ensure that contents of the installroot can run'''</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">'</span><span class="se">\x7f</span><span class="s1">ELF'</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'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">'/usr/bin'</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">'/usr/sbin'</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">"rb"</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">'#!'</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'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">"rt"</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"latin-1"</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">'</span><span class="si">%s</span><span class="s1">, needed by </span><span class="si">%s</span><span class="s1">, does not exist'</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't logged a million times.</span>
|
|
<span class="c1"># At least one thing in the list isn'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">''</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">'ldd'</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">'</span><span class="se">\n</span><span class="s1">'</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">'not found'</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">'</span><span class="si">%s</span><span class="s1">, needed by </span><span class="si">%s</span><span class="s1">, not found'</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">'''debugging data: write a big list of pkg sizes'''</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">"w"</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">"</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">"</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">"lib/modules/"</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">"boot/System.map-</span><span class="si">%s</span><span class="s2">"</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">"doing depmod and module-info for </span><span class="si">%s</span><span class="s2">"</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">"depmod"</span><span class="p">,</span> <span class="s2">"-a"</span><span class="p">,</span> <span class="s2">"-F"</span><span class="p">,</span> <span class="n">ksyms</span><span class="p">,</span> <span class="s2">"-b"</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">"module-info"</span><span class="p">)</span></div>
|
|
|
|
<div class="viewcode-block" id="RuntimeBuilder.create_runtime"><a class="viewcode-back" href="../../pylorax.html#pylorax.treebuilder.RuntimeBuilder.create_runtime">[docs]</a> <span class="k">def</span> <span class="nf">create_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">"/var/tmp/squashfs.img"</span><span class="p">,</span> <span class="n">compression</span><span class="o">=</span><span class="s2">"xz"</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="c1"># make live rootfs image - must be named "LiveOS/rootfs.img" 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">"runtime-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="n">joinpaths</span><span class="p">(</span><span class="n">workdir</span><span class="p">,</span> <span class="s2">"LiveOS"</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">"LiveOS/rootfs.img"</span><span class="p">),</span>
|
|
<span class="s2">"Anaconda"</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="c1"># squash the live rootfs and clean up workdir</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></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">""" Done using RuntimeBuilder</span>
|
|
|
|
<span class="sd"> Close the dnf base object</span>
|
|
<span class="sd"> """</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">'''Builds the arch-specific boot images.</span>
|
|
<span class="sd"> inroot should be the installtree root (the newly-built runtime dir)'''</span>
|
|
<span class="k">def</span> <span class="nf">__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="c1"># NOTE: if you pass an arg named "runtime" to a mako template it'll</span>
|
|
<span class="c1"># clobber some mako internal variables - hence "runtime_img".</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="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">""</span><span class="p">,</span> <span class="n">prefix</span><span class="o">=</span><span class="s2">""</span><span class="p">):</span>
|
|
<span class="sd">'''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 "${prefix}-${kernel.version}.img"</span>
|
|
|
|
<span class="sd"> If the initrd doesn't exist its name will be created based on the</span>
|
|
<span class="sd"> name of the kernel.</span>
|
|
<span class="sd"> '''</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">"dracut"</span><span class="p">,</span> <span class="s2">"--nomdadmconf"</span><span class="p">,</span> <span class="s2">"--nolvmconf"</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">"--force"</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">"No kernels found, cannot rebuild_initrds"</span><span class="p">)</span>
|
|
|
|
<span class="c1"># Hush some dracut warnings. TODO: bind-mount proc in place?</span>
|
|
<span class="nb">open</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">inroot</span><span class="p">,</span><span class="s2">"/proc/modules"</span><span class="p">),</span><span class="s2">"w"</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">'-'</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">'.img'</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">"initrd"</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">"vmlinuz-"</span><span class="p">,</span> <span class="s2">"initrd-"</span><span class="p">)</span> <span class="o">+</span> <span class="s2">".img"</span>
|
|
<span class="n">logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s2">"rebuilding </span><span class="si">%s</span><span class="s2">"</span><span class="p">,</span> <span class="n">outfile</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>
|
|
|
|
<span class="c1"># ppc64 cannot boot images > 32MiB, check size and warn</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">arch</span><span class="o">.</span><span class="n">basearch</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">"ppc64"</span><span class="p">,</span> <span class="s2">"ppc64le"</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">exists</span><span class="p">(</span><span class="n">outfile</span><span class="p">):</span>
|
|
<span class="n">st</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">outfile</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="n">st</span><span class="o">.</span><span class="n">st_size</span> <span class="o">></span> <span class="mi">32</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">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s2">"ppc64 initrd </span><span class="si">%s</span><span class="s2"> is > 32MiB"</span><span class="p">,</span> <span class="n">outfile</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="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">"/proc/modules"</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">'boot.iso'</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">'boot.iso'</span><span class="p">])</span>
|
|
<span class="n">runcmd</span><span class="p">([</span><span class="s2">"implantisomd5"</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">""" 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"> """</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">"dracut_hooks"</span><span class="p">)</span>
|
|
<span class="k">else</span><span class="p">:</span>
|
|
<span class="k">return</span> <span class="s2">"/usr/share/lorax/dracut_hooks"</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">""" Copy the hook scripts in hooks into the installroot'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. [("99anaconda-copy-ks.sh", "/lib/dracut/hooks/pre-pivot")])</span>
|
|
<span class="sd"> """</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">"Missing lorax dracut hook script </span><span class="si">%s</span><span class="s2">"</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">"/tmp/"</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">"--include"</span><span class="p">,</span> <span class="n">joinpaths</span><span class="p">(</span><span class="s2">"/tmp/"</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">"/"</span><span class="p">,</span> <span class="n">kdir</span><span class="o">=</span><span class="s2">"boot"</span><span class="p">):</span>
|
|
<span class="c1"># To find possible flavors, awk '/BuildKernel/ { print $4 }' kernel.spec</span>
|
|
<span class="n">flavors</span> <span class="o">=</span> <span class="p">(</span><span class="s1">'debug'</span><span class="p">,</span> <span class="s1">'PAE'</span><span class="p">,</span> <span class="s1">'PAEdebug'</span><span class="p">,</span> <span class="s1">'smp'</span><span class="p">,</span> <span class="s1">'xen'</span><span class="p">,</span> <span class="s1">'lpae'</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">"vmlinuz-(?P<version>.+?\.(?P<arch>[a-z0-9_]+)"</span>
|
|
<span class="sa">r</span><span class="s2">"(.(?P<flavor></span><span class="si">{0}</span><span class="s2">))?)$"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">"|"</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">'-'</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">'.img'</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">'-'</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">'initramfs'</span><span class="p">:</span>
|
|
<span class="n">imgtype</span> <span class="o">=</span> <span class="s1">'initrd'</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">"kernels=</span><span class="si">%s</span><span class="s2">"</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: 'a-zA-Z0-9#+.:=@_-' (see is_whitelisted in libudev-util.c)</span>
|
|
<span class="n">udev_blacklist</span><span class="o">=</span><span class="s1">' !"$%&</span><span class="se">\'</span><span class="s1">()*,/;<>?[</span><span class="se">\\</span><span class="s1">]^`{|}~'</span> <span class="c1"># ASCII printable, minus whitelist</span>
|
|
<span class="n">udev_blacklist</span> <span class="o">+=</span> <span class="s1">''</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">''</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">'</span><span class="se">\\</span><span class="s1">x</span><span class="si">%02x</span><span class="s1">'</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">""" 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"> """</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>
|
|
© 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">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT:'../../',
|
|
VERSION:'29.20',
|
|
LANGUAGE:'None',
|
|
COLLAPSE_INDEX:false,
|
|
FILE_SUFFIX:'.html',
|
|
HAS_SOURCE: true,
|
|
SOURCELINK_SUFFIX: '.txt'
|
|
};
|
|
</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/js/theme.js"></script>
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(true);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html> |