Skip to content
Snippets Groups Projects
Commit 1963ecdf authored by Bienchen's avatar Bienchen
Browse files

Updated documentation

parent fee6376a
Branches
Tags
No related merge requests found
...@@ -100,6 +100,41 @@ ...@@ -100,6 +100,41 @@
<span class="n">MsgErrorAndExit</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> file does not exist: </span><span class="si">%s</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span> <span class="n">MsgErrorAndExit</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> file does not exist: </span><span class="si">%s</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">filename</span><span class="p">),</span>
<span class="n">exit_status</span><span class="p">)</span> <span class="n">exit_status</span><span class="p">)</span>
</div> </div>
<div class="viewcode-block" id="FileGzip"><a class="viewcode-back" href="../../../core/helper.html#promod3.core.helper.FileGzip">[docs]</a><span class="k">def</span> <span class="nf">FileGzip</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">exit_status</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">allowed</span><span class="o">=</span><span class="bp">True</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> See if a file is gzipped or not. This is basically done by checking for a</span>
<span class="sd"> &quot;gz&quot; suffix. May also be used to verify that a file is not compressed where</span>
<span class="sd"> it does not apply. That is where *allowed* comes in. If &quot;gz&quot; is not allowed,</span>
<span class="sd"> terminates the script on gzip files.</span>
<span class="sd"> :param prefix: String to put in front of the failure-message where gzip</span>
<span class="sd"> files are not allowed.</span>
<span class="sd"> :type prefix: :class:`str`</span>
<span class="sd"> :param exit_status: Exit code on gzip files to be avoided, ends up in</span>
<span class="sd"> ``$?`` in the shell. ``0`` is traditionally reserved to</span>
<span class="sd"> successful commands.</span>
<span class="sd"> :type exit_status: :class:`int`</span>
<span class="sd"> :param filename: Path including file name to be checked.</span>
<span class="sd"> :type filename: :class:`str`</span>
<span class="sd"> :param allowed: Set to ``False`` if gzipped files are not allowed. Then the</span>
<span class="sd"> script will terminate if a gzip file is found.</span>
<span class="sd"> :type allowed: :class:`bool`</span>
<span class="sd"> :returns: Flag to indicate if file is gzipped (:class:`bool`).</span>
<span class="sd"> &#39;&#39;&#39;</span>
<span class="n">_</span><span class="p">,</span> <span class="n">fileext</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">filename</span><span class="p">)</span>
<span class="n">is_gz</span> <span class="o">=</span> <span class="bp">False</span>
<span class="k">if</span> <span class="n">fileext</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="o">==</span> <span class="s">&#39;.gz&#39;</span><span class="p">:</span>
<span class="n">is_gz</span> <span class="o">=</span> <span class="bp">True</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">allowed</span><span class="p">:</span>
<span class="n">MsgErrorAndExit</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s"> file in Gzip not supported: </span><span class="si">%s</span><span class="s">. &#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">prefix</span><span class="p">,</span>
<span class="n">filename</span><span class="p">),</span>
<span class="n">exit_status</span><span class="p">)</span>
<span class="k">return</span> <span class="n">is_gz</span>
</div>
<div class="viewcode-block" id="FileExtension"><a class="viewcode-back" href="../../../core/helper.html#promod3.core.helper.FileExtension">[docs]</a><span class="k">def</span> <span class="nf">FileExtension</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">exit_status</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">extensions</span><span class="p">,</span> <span class="n">gzip</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> <div class="viewcode-block" id="FileExtension"><a class="viewcode-back" href="../../../core/helper.html#promod3.core.helper.FileExtension">[docs]</a><span class="k">def</span> <span class="nf">FileExtension</span><span class="p">(</span><span class="n">prefix</span><span class="p">,</span> <span class="n">exit_status</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">extensions</span><span class="p">,</span> <span class="n">gzip</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="sd">&#39;&#39;&#39;</span> <span class="sd">&#39;&#39;&#39;</span>
<span class="sd"> Checks a file to carry a known extension given by a list of strings. Since</span> <span class="sd"> Checks a file to carry a known extension given by a list of strings. Since</span>
...@@ -174,6 +209,8 @@ ...@@ -174,6 +209,8 @@
<span class="s">&#39;FileExists&#39;</span><span class="p">,</span> <span class="s">&#39;FileExists&#39;</span><span class="p">,</span>
<span class="s">&#39;FileExtension&#39;</span><span class="p">,</span> <span class="s">&#39;FileExtension&#39;</span><span class="p">,</span>
<span class="p">)</span> <span class="p">)</span>
<span class="c"># LocalWords: gzipped gz param str gzip bool</span>
</pre></div> </pre></div>
</div> </div>
......
...@@ -16,4 +16,8 @@ Changes in Release 0.2 ...@@ -16,4 +16,8 @@ Changes in Release 0.2
* added html documentation to repository * added html documentation to repository
* meld renamed to rawmodel * meld renamed to rawmodel
Changes in Release 0.3 (to be released)
-------------------------------------------------------------------------------
* merged argcheck into the helper module
.. LocalWords: Changelog reStructuredText changelog txt .. LocalWords: Changelog reStructuredText changelog txt
:mod:`~promod3.core.argcheck` - Standard Tests For Command Line Arguments
================================================================================
.. currentmodule:: promod3.core.argcheck
Introduction
--------------------------------------------------------------------------------
For parsing command line arguments -
:py_docs:`optional <howto/argparse.html#introducing-optional-arguments>` and
:py_docs:`positional <howto/argparse.html#introducing-positional-arguments>` -
|project| tools should utilise its own
:mod:`~promod3.core.pm3argparse` module. While this comes with a lot
of functionality to fetch values from the command line comfortably, it has no
means in checking/ verifying input. Some of the most common tests are covered
here. All tests are designed to exit a script on failure.
.. testcode:: argcheck
:hide:
import os
import argparse
import tempfile
from promod3.core import argcheck
(fh, fn) = tempfile.mkstemp(suffix='.pdb')
os.close(fh)
p = argparse.ArgumentParser()
p.add_argument('file', type=str)
opts = p.parse_args([fn])
argcheck.FileExists('Test file', 1, opts.file)
opts.name, opts.ext, opts.gz = argcheck.FileExtension('Test file', 2,
opts.file,
('pdb', 'mmcif'),
gz=True)
os.remove(fn)
.. doctest:: argcheck
import argparse
from promod3.core import argcheck
p = argparse.ArgumentParser()
p.add_argument('file', type=str)
opts = p.parse_args()
argcheck.FileExists('Test file', 1, opts.file)
opts.name, opts.ext, opts.gz = argcheck.FileExtension('Test file', 2,
opts.file,
('pdb', 'mmcif'),
gz=True)
File Tests
--------------------------------------------------------------------------------
.. autofunction:: FileExtension
.. LocalWords: currentmodule py howto argparse testcode argcheck os promod
.. LocalWords: tempfile fh fn ArgumentParser str args FileExists gz pdb
.. LocalWords: FileExtension mmcif doctest autofunction
...@@ -86,3 +86,5 @@ File Tests ...@@ -86,3 +86,5 @@ File Tests
.. autofunction:: FileExists .. autofunction:: FileExists
.. autofunction:: FileExtension .. autofunction:: FileExtension
.. autofunction:: FileGzip
...@@ -73,6 +73,14 @@ ...@@ -73,6 +73,14 @@
</ul> </ul>
</div></blockquote> </div></blockquote>
</div> </div>
<div class="section" id="changes-in-release-0-3-to-be-released">
<h2>Changes in Release 0.3 (to be released)<a class="headerlink" href="#changes-in-release-0-3-to-be-released" title="Permalink to this headline"></a></h2>
<blockquote>
<div><ul class="simple">
<li>merged argcheck into the helper module</li>
</ul>
</div></blockquote>
</div>
</div> </div>
...@@ -86,6 +94,7 @@ ...@@ -86,6 +94,7 @@
<li><a class="reference internal" href="#">Changelog</a><ul> <li><a class="reference internal" href="#">Changelog</a><ul>
<li><a class="reference internal" href="#changes-in-release-0-1">Changes in Release 0.1</a></li> <li><a class="reference internal" href="#changes-in-release-0-1">Changes in Release 0.1</a></li>
<li><a class="reference internal" href="#changes-in-release-0-2">Changes in Release 0.2</a></li> <li><a class="reference internal" href="#changes-in-release-0-2">Changes in Release 0.2</a></li>
<li><a class="reference internal" href="#changes-in-release-0-3-to-be-released">Changes in Release 0.3 (to be released)</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>argcheck - Standard Tests For Command Line Arguments &mdash; ProMod3 0 documentation</title>
<link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="top" title="ProMod3 0 documentation" href="../index.html" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9">
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">ProMod3 0 documentation</a> &raquo;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="argcheck-standard-tests-for-command-line-arguments">
<h1><code class="xref py py-mod docutils literal"><span class="pre">argcheck</span></code> - Standard Tests For Command Line Arguments<a class="headerlink" href="#argcheck-standard-tests-for-command-line-arguments" title="Permalink to this headline"></a></h1>
<div class="section" id="introduction">
<h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline"></a></h2>
<p>For parsing command line arguments -
<a class="reference external" href="https://docs.python.org/2.7/howto/argparse.html#introducing-optional-arguments">optional</a> and
<a class="reference external" href="https://docs.python.org/2.7/howto/argparse.html#introducing-positional-arguments">positional</a> -
ProMod3 tools should utilise its own
<a class="reference internal" href="pm3argparse.html#module-promod3.core.pm3argparse" title="promod3.core.pm3argparse"><code class="xref py py-mod docutils literal"><span class="pre">pm3argparse</span></code></a> module. While this comes with a lot
of functionality to fetch values from the command line comfortably, it has no
means in checking/ verifying input. Some of the most common tests are covered
here. All tests are designed to exit a script on failure.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">from</span> <span class="nn">promod3.core</span> <span class="kn">import</span> <span class="n">argcheck</span>
<span class="n">p</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">p</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;file&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">str</span><span class="p">)</span>
<span class="n">opts</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
<span class="n">argcheck</span><span class="o">.</span><span class="n">FileExists</span><span class="p">(</span><span class="s">&#39;Test file&#39;</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">file</span><span class="p">)</span>
<span class="n">opts</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">ext</span><span class="p">,</span> <span class="n">opts</span><span class="o">.</span><span class="n">gz</span> <span class="o">=</span> <span class="n">argcheck</span><span class="o">.</span><span class="n">FileExtension</span><span class="p">(</span><span class="s">&#39;Test file&#39;</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">file</span><span class="p">,</span>
<span class="p">(</span><span class="s">&#39;pdb&#39;</span><span class="p">,</span> <span class="s">&#39;mmcif&#39;</span><span class="p">),</span>
<span class="n">gz</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
</pre></div>
</div>
</div>
<div class="section" id="file-tests">
<h2>File Tests<a class="headerlink" href="#file-tests" title="Permalink to this headline"></a></h2>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="docutils literal"><span class="pre">argcheck</span></code> - Standard Tests For Command Line Arguments</a><ul>
<li><a class="reference internal" href="#introduction">Introduction</a></li>
<li><a class="reference internal" href="#file-tests">File Tests</a></li>
</ul>
</li>
</ul>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/core/argcheck.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2015, Bienchen.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.3.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.3</a>
|
<a href="../_sources/core/argcheck.txt"
rel="nofollow">Page source</a></li>
</div>
</body>
</html>
\ No newline at end of file
...@@ -178,6 +178,36 @@ without a &#8221;.gz&#8221; (<a class="reference external" href="https://docs.py ...@@ -178,6 +178,36 @@ without a &#8221;.gz&#8221; (<a class="reference external" href="https://docs.py
</table> </table>
</dd></dl> </dd></dl>
<dl class="function">
<dt id="promod3.core.helper.FileGzip">
<code class="descclassname">promod3.core.helper.</code><code class="descname">FileGzip</code><span class="sig-paren">(</span><em>prefix</em>, <em>exit_status</em>, <em>filename</em>, <em>allowed=True</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/promod3/core/helper.html#FileGzip"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#promod3.core.helper.FileGzip" title="Permalink to this definition"></a></dt>
<dd><p>See if a file is gzipped or not. This is basically done by checking for a
&#8220;gz&#8221; suffix. May also be used to verify that a file is not compressed where
it does not apply. That is where <em>allowed</em> comes in. If &#8220;gz&#8221; is not allowed,
terminates the script on gzip files.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>prefix</strong> (<a class="reference external" href="https://docs.python.org/2.7/library/functions.html#str" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a>) &#8211; String to put in front of the failure-message where gzip
files are not allowed.</li>
<li><strong>exit_status</strong> (<a class="reference external" href="https://docs.python.org/2.7/library/functions.html#int" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">int</span></code></a>) &#8211; Exit code on gzip files to be avoided, ends up in
<code class="docutils literal"><span class="pre">$?</span></code> in the shell. <code class="docutils literal"><span class="pre">0</span></code> is traditionally reserved to
successful commands.</li>
<li><strong>filename</strong> (<a class="reference external" href="https://docs.python.org/2.7/library/functions.html#str" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">str</span></code></a>) &#8211; Path including file name to be checked.</li>
<li><strong>allowed</strong> (<a class="reference external" href="https://docs.python.org/2.7/library/functions.html#bool" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">bool</span></code></a>) &#8211; Set to <code class="docutils literal"><span class="pre">False</span></code> if gzipped files are not allowed. Then the
script will terminate if a gzip file is found.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">Flag to indicate if file is gzipped (<a class="reference external" href="https://docs.python.org/2.7/library/functions.html#bool" title="(in Python v2.7)"><code class="xref py py-class docutils literal"><span class="pre">bool</span></code></a>).</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div> </div>
</div> </div>
......
...@@ -160,10 +160,14 @@ ...@@ -160,10 +160,14 @@
<dt><a href="core/helper.html#promod3.core.helper.FileExists">FileExists() (in module promod3.core.helper)</a> <dt><a href="core/helper.html#promod3.core.helper.FileExists">FileExists() (in module promod3.core.helper)</a>
</dt> </dt>
<dt><a href="core/helper.html#promod3.core.helper.FileExtension">FileExtension() (in module promod3.core.helper)</a>
</dt>
</dl></td> </dl></td>
<td style="width: 33%" valign="top"><dl> <td style="width: 33%" valign="top"><dl>
<dt><a href="core/helper.html#promod3.core.helper.FileExtension">FileExtension() (in module promod3.core.helper)</a> <dt><a href="core/helper.html#promod3.core.helper.FileGzip">FileGzip() (in module promod3.core.helper)</a>
</dt> </dt>
</dl></td> </dl></td>
......
...@@ -71,6 +71,7 @@ ...@@ -71,6 +71,7 @@
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a><ul> <li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a><ul>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-release-0-1">Changes in Release 0.1</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-release-0-1">Changes in Release 0.1</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-release-0-2">Changes in Release 0.2</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-release-0-2">Changes in Release 0.2</a></li>
<li class="toctree-l2"><a class="reference internal" href="changelog.html#changes-in-release-0-3-to-be-released">Changes in Release 0.3 (to be released)</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
......
No preview for this file type
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment