583 行
28 KiB
HTML
583 行
28 KiB
HTML
|
|
|
|
<!DOCTYPE html>
|
|
<html class="writer-html4" lang="en" >
|
|
<head>
|
|
<meta charset="utf-8">
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<title>Welcome to fstools’s documentation! — fstools documentation</title>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
|
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!--[if lt IE 9]>
|
|
<script src="_static/js/html5shiv.min.js"></script>
|
|
<![endif]-->
|
|
|
|
|
|
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
|
<script type="text/javascript" src="_static/jquery.js"></script>
|
|
<script type="text/javascript" src="_static/underscore.js"></script>
|
|
<script type="text/javascript" src="_static/doctools.js"></script>
|
|
<script type="text/javascript" src="_static/language_data.js"></script>
|
|
|
|
<script type="text/javascript" src="_static/js/theme.js"></script>
|
|
|
|
|
|
<link rel="index" title="Index" href="genindex.html" />
|
|
<link rel="search" title="Search" href="search.html" />
|
|
</head>
|
|
|
|
<body class="wy-body-for-nav">
|
|
|
|
|
|
<div class="wy-grid-for-nav">
|
|
|
|
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
|
<div class="wy-side-scroll">
|
|
<div class="wy-side-nav-search" >
|
|
|
|
|
|
|
|
<a href="#" class="icon icon-home" alt="Documentation Home"> fstools
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<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">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Local TOC -->
|
|
<div class="local-toc"><ul>
|
|
<li><a class="reference internal" href="#">Welcome to fstools’s documentation!</a><ul>
|
|
<li><a class="reference internal" href="#fstools-filesystem-tools">fstools (Filesystem Tools)</a></li>
|
|
</ul>
|
|
</li>
|
|
<li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
</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="#">fstools</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="#" class="icon icon-home"></a> »</li>
|
|
|
|
<li>Welcome to fstools’s documentation!</li>
|
|
|
|
|
|
<li class="wy-breadcrumbs-aside">
|
|
|
|
|
|
<a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
|
|
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
|
<hr/>
|
|
</div>
|
|
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
|
<div itemprop="articleBody">
|
|
|
|
<div class="section" id="module-fstools">
|
|
<span id="welcome-to-fstools-s-documentation"></span><h1>Welcome to fstools’s documentation!<a class="headerlink" href="#module-fstools" title="Permalink to this headline">¶</a></h1>
|
|
<div class="section" id="fstools-filesystem-tools">
|
|
<h2>fstools (Filesystem Tools)<a class="headerlink" href="#fstools-filesystem-tools" title="Permalink to this headline">¶</a></h2>
|
|
<p><strong>Author:</strong></p>
|
|
<ul class="simple">
|
|
<li>Dirk Alders <<a class="reference external" href="mailto:sudo-dirk%40mount-mockery.de">sudo-dirk<span>@</span>mount-mockery<span>.</span>de</a>></li>
|
|
</ul>
|
|
<p><strong>Description:</strong></p>
|
|
<blockquote>
|
|
<div>This module supports functions and classes to handle files and paths</div></blockquote>
|
|
<p><strong>Submodules:</strong></p>
|
|
<ul class="simple">
|
|
<li><a class="reference internal" href="#fstools.dirlist" title="fstools.dirlist"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.dirlist()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.filelist" title="fstools.filelist"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.filelist()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.is_writeable" title="fstools.is_writeable"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.is_writeable()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.mkdir" title="fstools.mkdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.mkdir()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.open_locked_blocking" title="fstools.open_locked_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.open_locked_blocking()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.open_locked_non_blocking" title="fstools.open_locked_non_blocking"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.open_locked_non_blocking()</span></code></a></li>
|
|
<li><a class="reference internal" href="#fstools.uid" title="fstools.uid"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.uid()</span></code></a></li>
|
|
</ul>
|
|
<p><strong>Unittest:</strong></p>
|
|
<blockquote>
|
|
<div>See also the <a class="reference download internal" download="" href="_downloads/7bf10188aa659556c284b4a8298dba8d/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
|
|
<p><strong>Module Documentation:</strong></p>
|
|
<dl class="function">
|
|
<dt id="fstools.dirlist">
|
|
<code class="descclassname">fstools.</code><code class="descname">dirlist</code><span class="sig-paren">(</span><em>path='.'</em>, <em>rekursive=True</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.dirlist" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Function returning a list of directories below a given path.</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>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
|
|
<li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">list of filenames including the pathe</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">The returned filenames could be relative pathes depending on argument path.</p>
|
|
</div>
|
|
<p><strong>Example:</strong></p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">fstools</span>
|
|
|
|
|
|
<span class="k">for</span> <span class="n">dirname</span> <span class="ow">in</span> <span class="n">fstools</span><span class="o">.</span><span class="n">dirlist</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="s1">'..'</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">dirname</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">../</span><span class="n">_examples_</span>
|
|
<span class="o">../</span><span class="n">__pycache__</span>
|
|
<span class="o">../</span><span class="n">_testresults_</span>
|
|
<span class="o">../</span><span class="n">_docs_</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">fonts</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">fonts</span><span class="o">/</span><span class="n">Lato</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">fonts</span><span class="o">/</span><span class="n">RobotoSlab</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">js</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">css</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span><span class="o">/</span><span class="n">css</span><span class="o">/</span><span class="n">fonts</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_sources</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_downloads</span>
|
|
<span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_downloads</span><span class="o">/</span><span class="mi">7</span><span class="n">bf10188aa659556c284b4a8298dba8d</span>
|
|
</pre></div>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.filelist">
|
|
<code class="descclassname">fstools.</code><code class="descname">filelist</code><span class="sig-paren">(</span><em>path='.'</em>, <em>expression='*'</em>, <em>rekursive=True</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.filelist" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Function returning a list of files below a given path.</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>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
|
|
<li><strong>expression</strong> (<em>str</em>) – expression to fit including shell-style wildcards.</li>
|
|
<li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">list of filenames including the pathe</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">The returned filenames could be relative pathes depending on argument path.</p>
|
|
</div>
|
|
<p><strong>Example:</strong></p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">fstools</span>
|
|
|
|
|
|
<span class="k">for</span> <span class="n">filename</span> <span class="ow">in</span> <span class="n">fstools</span><span class="o">.</span><span class="n">filelist</span><span class="p">(</span><span class="n">path</span><span class="o">=</span><span class="s1">'..'</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="s1">'*.py'</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">../</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
|
|
<span class="o">../</span><span class="n">_examples_</span><span class="o">/</span><span class="n">uid</span><span class="o">.</span><span class="n">py</span>
|
|
<span class="o">../</span><span class="n">_examples_</span><span class="o">/</span><span class="n">is_writeable</span><span class="o">.</span><span class="n">py</span>
|
|
<span class="o">../</span><span class="n">_examples_</span><span class="o">/</span><span class="n">uid_filelist</span><span class="o">.</span><span class="n">py</span>
|
|
<span class="o">../</span><span class="n">_examples_</span><span class="o">/</span><span class="n">dirlist</span><span class="o">.</span><span class="n">py</span>
|
|
<span class="o">../</span><span class="n">_examples_</span><span class="o">/</span><span class="n">filelist</span><span class="o">.</span><span class="n">py</span>
|
|
</pre></div>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.is_writeable">
|
|
<code class="descclassname">fstools.</code><code class="descname">is_writeable</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.is_writeable" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Method to get the Information, if a file or folder is writable.</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"><strong>path</strong> (<em>str</em>) – file or folder to check.</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Whether path is writable or not.</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">If path does not exist, the return Value is <code class="xref py py-const docutils literal notranslate"><span class="pre">False</span></code>.</p>
|
|
</div>
|
|
<p><strong>Example:</strong></p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">fstools</span>
|
|
|
|
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">fstools</span><span class="o">.</span><span class="n">is_writeable</span><span class="p">(</span><span class="s1">'..'</span><span class="p">))</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">fstools</span><span class="o">.</span><span class="n">is_writeable</span><span class="p">(</span><span class="s1">'../__init__.py'</span><span class="p">))</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kc">True</span>
|
|
<span class="kc">True</span>
|
|
</pre></div>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.mkdir">
|
|
<code class="descclassname">fstools.</code><code class="descname">mkdir</code><span class="sig-paren">(</span><em>path</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.mkdir" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Method to create a folder.</p>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">All needed subfoilders will also be created (rekursive mkdir).</p>
|
|
</div>
|
|
<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"><strong>path</strong> (<em>str</em>) – folder to be created.</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">True, if folder exists after creation commands, otherwise False.</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.open_locked_blocking">
|
|
<code class="descclassname">fstools.</code><code class="descname">open_locked_blocking</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.open_locked_blocking" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Method to get exclusive access to a file.</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>args</strong> – Arguments for a standard file open call.</li>
|
|
<li><strong>kwargs</strong> – Keyword arguments for a standard file open call.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A file descriptor.</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">file handle</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">The call blocks until file is able to be used. This can cause a deadlock, if the file release es done after trying to open the file!</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.open_locked_non_blocking">
|
|
<code class="descclassname">fstools.</code><code class="descname">open_locked_non_blocking</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.open_locked_non_blocking" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Method to get exclusive access to a file.</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>args</strong> – Arguments for a standard file open call.</li>
|
|
<li><strong>kwargs</strong> – Keyword arguments for a standard file open call.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><p class="first">OSError, if the file is already blocked.</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A file descriptor.</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">file handle</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">The call blocks until file is able to be used. This can cause a deadlock, if the file release es done after trying to open the file!</p>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.uid">
|
|
<code class="descclassname">fstools.</code><code class="descname">uid</code><span class="sig-paren">(</span><em>path</em>, <em>max_staleness=3600</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.uid" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Function returning a “unique” id for a given file or path.</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>path</strong> (<em>str</em>) – File or folder to generate a uid for.</li>
|
|
<li><strong>max_staleness</strong> (<em>int</em>) – If a file or folder is older than that, we may consider
|
|
it stale and return a different uid - this is a
|
|
dirty trick to work around changes never being
|
|
detected. Default is 3600 seconds, use None to
|
|
disable this trickery. See below for more details.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An object that changes value if the file changed,
|
|
None is returned if there were problems accessing the file
|
|
or folder.</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition warning">
|
|
<p class="first admonition-title">Warning</p>
|
|
<p class="last">Depending on the operating system capabilities and the way the
|
|
file update is done, this function might return the same value
|
|
even if the file has changed. It should be better than just
|
|
using file’s mtime though.
|
|
max_staleness tries to avoid the worst for these cases.</p>
|
|
</div>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">If this function is used for a path, it will stat all pathes and files rekursively.</p>
|
|
</div>
|
|
<p><strong>Example:</strong></p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">fstools</span>
|
|
|
|
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">fstools</span><span class="o">.</span><span class="n">uid</span><span class="p">(</span><span class="s1">'../__init__.py'</span><span class="p">))</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">950</span><span class="n">bd674ce9e6ccc93a3f450964b524412961e0d</span>
|
|
</pre></div>
|
|
</div>
|
|
<p>Using just the file’s mtime to determine if the file has changed is
|
|
not reliable - if file updates happen faster than the file system’s
|
|
mtime granularity, then the modification is not detectable because
|
|
the mtime is still the same.</p>
|
|
<p>This function tries to improve by using not only the mtime, but also
|
|
other metadata values like file size and inode to improve reliability.</p>
|
|
<p>For the calculation of this value, we of course only want to use data
|
|
that we can get rather fast, thus we use file metadata, not file data
|
|
(file content).</p>
|
|
</dd></dl>
|
|
|
|
<dl class="function">
|
|
<dt id="fstools.uid_filelist">
|
|
<code class="descclassname">fstools.</code><code class="descname">uid_filelist</code><span class="sig-paren">(</span><em>path='.'</em>, <em>expression='*'</em>, <em>rekursive=True</em><span class="sig-paren">)</span><a class="headerlink" href="#fstools.uid_filelist" title="Permalink to this definition">¶</a></dt>
|
|
<dd><p>Function returning a unique id for a given file or path.</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>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
|
|
<li><strong>expression</strong> (<em>str</em>) – expression to fit including shell-style wildcards.</li>
|
|
<li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">An object that changes value if one of the files change.</p>
|
|
</td>
|
|
</tr>
|
|
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<div class="admonition note">
|
|
<p class="first admonition-title">Note</p>
|
|
<p class="last">This UID is created out of the file content. Therefore it is more
|
|
reliable then <a class="reference internal" href="#fstools.uid" title="fstools.uid"><code class="xref py py-func docutils literal notranslate"><span class="pre">fstools.uid()</span></code></a>, but also much slower.</p>
|
|
</div>
|
|
<p><strong>Example:</strong></p>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
|
|
<span class="c1"># -*- coding: UTF-8 -*-</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">sys</span>
|
|
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">'../..'</span><span class="p">)</span>
|
|
|
|
<span class="kn">import</span> <span class="nn">fstools</span>
|
|
|
|
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">fstools</span><span class="o">.</span><span class="n">uid_filelist</span><span class="p">(</span><span class="s1">'..'</span><span class="p">,</span> <span class="s1">'*.py'</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
|
|
</pre></div>
|
|
</div>
|
|
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">32</span><span class="n">ca1c130dfa068b79f4e96071c46448</span>
|
|
</pre></div>
|
|
</div>
|
|
</dd></dl>
|
|
|
|
</div>
|
|
<div class="toctree-wrapper compound">
|
|
</div>
|
|
</div>
|
|
<div class="section" id="indices-and-tables">
|
|
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
|
|
<ul class="simple">
|
|
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
|
|
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
|
|
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
<footer>
|
|
|
|
|
|
<hr/>
|
|
|
|
<div role="contentinfo">
|
|
<p>
|
|
|
|
© Copyright 2021, Dirk Alders
|
|
|
|
</p>
|
|
</div>
|
|
|
|
|
|
|
|
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
|
|
|
|
<a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
|
|
|
|
provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript">
|
|
jQuery(function () {
|
|
SphinxRtdTheme.Navigation.enable(true);
|
|
});
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
</html> |