Python Library FS-Tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.html 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. <!DOCTYPE html>
  2. <html class="writer-html4" lang="en" >
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Welcome to fstools’s documentation! &mdash; fstools documentation</title>
  7. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <!--[if lt IE 9]>
  10. <script src="_static/js/html5shiv.min.js"></script>
  11. <![endif]-->
  12. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  13. <script type="text/javascript" src="_static/jquery.js"></script>
  14. <script type="text/javascript" src="_static/underscore.js"></script>
  15. <script type="text/javascript" src="_static/doctools.js"></script>
  16. <script type="text/javascript" src="_static/language_data.js"></script>
  17. <script type="text/javascript" src="_static/js/theme.js"></script>
  18. <link rel="index" title="Index" href="genindex.html" />
  19. <link rel="search" title="Search" href="search.html" />
  20. </head>
  21. <body class="wy-body-for-nav">
  22. <div class="wy-grid-for-nav">
  23. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  24. <div class="wy-side-scroll">
  25. <div class="wy-side-nav-search" >
  26. <a href="#" class="icon icon-home" alt="Documentation Home"> fstools
  27. </a>
  28. <div role="search">
  29. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  30. <input type="text" name="q" placeholder="Search docs" />
  31. <input type="hidden" name="check_keywords" value="yes" />
  32. <input type="hidden" name="area" value="default" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <!-- Local TOC -->
  38. <div class="local-toc"><ul>
  39. <li><a class="reference internal" href="#">Welcome to fstools’s documentation!</a><ul>
  40. <li><a class="reference internal" href="#fstools-filesystem-tools">fstools (Filesystem Tools)</a></li>
  41. </ul>
  42. </li>
  43. <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
  44. </ul>
  45. </div>
  46. </div>
  47. </div>
  48. </nav>
  49. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  50. <nav class="wy-nav-top" aria-label="top navigation">
  51. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  52. <a href="#">fstools</a>
  53. </nav>
  54. <div class="wy-nav-content">
  55. <div class="rst-content">
  56. <div role="navigation" aria-label="breadcrumbs navigation">
  57. <ul class="wy-breadcrumbs">
  58. <li><a href="#" class="icon icon-home"></a> &raquo;</li>
  59. <li>Welcome to fstools’s documentation!</li>
  60. <li class="wy-breadcrumbs-aside">
  61. <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
  62. </li>
  63. </ul>
  64. <hr/>
  65. </div>
  66. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  67. <div itemprop="articleBody">
  68. <div class="section" id="module-fstools">
  69. <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>
  70. <div class="section" id="fstools-filesystem-tools">
  71. <h2>fstools (Filesystem Tools)<a class="headerlink" href="#fstools-filesystem-tools" title="Permalink to this headline">¶</a></h2>
  72. <p><strong>Author:</strong></p>
  73. <ul class="simple">
  74. <li>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</li>
  75. </ul>
  76. <p><strong>Description:</strong></p>
  77. <blockquote>
  78. <div>This module supports functions and classes to handle files and paths</div></blockquote>
  79. <p><strong>Submodules:</strong></p>
  80. <ul class="simple">
  81. <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>
  82. <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>
  83. <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>
  84. <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>
  85. <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>
  86. <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>
  87. <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>
  88. </ul>
  89. <p><strong>Unittest:</strong></p>
  90. <blockquote>
  91. <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>
  92. <p><strong>Module Documentation:</strong></p>
  93. <dl class="function">
  94. <dt id="fstools.dirlist">
  95. <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>
  96. <dd><p>Function returning a list of directories below a given path.</p>
  97. <table class="docutils field-list" frame="void" rules="none">
  98. <col class="field-name" />
  99. <col class="field-body" />
  100. <tbody valign="top">
  101. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  102. <li><strong>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
  103. <li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
  104. </ul>
  105. </td>
  106. </tr>
  107. <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>
  108. </td>
  109. </tr>
  110. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
  111. </td>
  112. </tr>
  113. </tbody>
  114. </table>
  115. <div class="admonition note">
  116. <p class="first admonition-title">Note</p>
  117. <p class="last">The returned filenames could be relative pathes depending on argument path.</p>
  118. </div>
  119. <p><strong>Example:</strong></p>
  120. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  121. <span class="c1"># -*- coding: UTF-8 -*-</span>
  122. <span class="kn">import</span> <span class="nn">sys</span>
  123. <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">&#39;../..&#39;</span><span class="p">)</span>
  124. <span class="kn">import</span> <span class="nn">fstools</span>
  125. <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">&#39;..&#39;</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
  126. <span class="nb">print</span><span class="p">(</span><span class="n">dirname</span><span class="p">)</span>
  127. </pre></div>
  128. </div>
  129. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">../</span><span class="n">_examples_</span>
  130. <span class="o">../</span><span class="n">__pycache__</span>
  131. <span class="o">../</span><span class="n">_testresults_</span>
  132. <span class="o">../</span><span class="n">_docs_</span>
  133. <span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_static</span>
  134. <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>
  135. <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>
  136. <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>
  137. <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>
  138. <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>
  139. <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>
  140. <span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_sources</span>
  141. <span class="o">../</span><span class="n">_docs_</span><span class="o">/</span><span class="n">_downloads</span>
  142. <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>
  143. </pre></div>
  144. </div>
  145. </dd></dl>
  146. <dl class="function">
  147. <dt id="fstools.filelist">
  148. <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>
  149. <dd><p>Function returning a list of files below a given path.</p>
  150. <table class="docutils field-list" frame="void" rules="none">
  151. <col class="field-name" />
  152. <col class="field-body" />
  153. <tbody valign="top">
  154. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  155. <li><strong>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
  156. <li><strong>expression</strong> (<em>str</em>) – expression to fit including shell-style wildcards.</li>
  157. <li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
  158. </ul>
  159. </td>
  160. </tr>
  161. <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>
  162. </td>
  163. </tr>
  164. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">list</p>
  165. </td>
  166. </tr>
  167. </tbody>
  168. </table>
  169. <div class="admonition note">
  170. <p class="first admonition-title">Note</p>
  171. <p class="last">The returned filenames could be relative pathes depending on argument path.</p>
  172. </div>
  173. <p><strong>Example:</strong></p>
  174. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  175. <span class="c1"># -*- coding: UTF-8 -*-</span>
  176. <span class="kn">import</span> <span class="nn">sys</span>
  177. <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">&#39;../..&#39;</span><span class="p">)</span>
  178. <span class="kn">import</span> <span class="nn">fstools</span>
  179. <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">&#39;..&#39;</span><span class="p">,</span> <span class="n">expression</span><span class="o">=</span><span class="s1">&#39;*.py&#39;</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
  180. <span class="nb">print</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
  181. </pre></div>
  182. </div>
  183. <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>
  184. <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>
  185. <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>
  186. <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>
  187. <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>
  188. <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>
  189. </pre></div>
  190. </div>
  191. </dd></dl>
  192. <dl class="function">
  193. <dt id="fstools.is_writeable">
  194. <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>
  195. <dd><p>Method to get the Information, if a file or folder is writable.</p>
  196. <table class="docutils field-list" frame="void" rules="none">
  197. <col class="field-name" />
  198. <col class="field-body" />
  199. <tbody valign="top">
  200. <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>
  201. </tr>
  202. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">Whether path is writable or not.</td>
  203. </tr>
  204. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  205. </tr>
  206. </tbody>
  207. </table>
  208. <div class="admonition note">
  209. <p class="first admonition-title">Note</p>
  210. <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>
  211. </div>
  212. <p><strong>Example:</strong></p>
  213. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  214. <span class="c1"># -*- coding: UTF-8 -*-</span>
  215. <span class="kn">import</span> <span class="nn">sys</span>
  216. <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">&#39;../..&#39;</span><span class="p">)</span>
  217. <span class="kn">import</span> <span class="nn">fstools</span>
  218. <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">&#39;..&#39;</span><span class="p">))</span>
  219. <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">&#39;../__init__.py&#39;</span><span class="p">))</span>
  220. </pre></div>
  221. </div>
  222. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kc">True</span>
  223. <span class="kc">True</span>
  224. </pre></div>
  225. </div>
  226. </dd></dl>
  227. <dl class="function">
  228. <dt id="fstools.mkdir">
  229. <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>
  230. <dd><p>Method to create a folder.</p>
  231. <div class="admonition note">
  232. <p class="first admonition-title">Note</p>
  233. <p class="last">All needed subfoilders will also be created (rekursive mkdir).</p>
  234. </div>
  235. <table class="docutils field-list" frame="void" rules="none">
  236. <col class="field-name" />
  237. <col class="field-body" />
  238. <tbody valign="top">
  239. <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>
  240. </tr>
  241. <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>
  242. </tr>
  243. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">bool</td>
  244. </tr>
  245. </tbody>
  246. </table>
  247. </dd></dl>
  248. <dl class="function">
  249. <dt id="fstools.open_locked_blocking">
  250. <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>
  251. <dd><p>Method to get exclusive access to a file.</p>
  252. <table class="docutils field-list" frame="void" rules="none">
  253. <col class="field-name" />
  254. <col class="field-body" />
  255. <tbody valign="top">
  256. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  257. <li><strong>args</strong> – Arguments for a standard file open call.</li>
  258. <li><strong>kwargs</strong> – Keyword arguments for a standard file open call.</li>
  259. </ul>
  260. </td>
  261. </tr>
  262. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A file descriptor.</p>
  263. </td>
  264. </tr>
  265. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">file handle</p>
  266. </td>
  267. </tr>
  268. </tbody>
  269. </table>
  270. <div class="admonition note">
  271. <p class="first admonition-title">Note</p>
  272. <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>
  273. </div>
  274. </dd></dl>
  275. <dl class="function">
  276. <dt id="fstools.open_locked_non_blocking">
  277. <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>
  278. <dd><p>Method to get exclusive access to a file.</p>
  279. <table class="docutils field-list" frame="void" rules="none">
  280. <col class="field-name" />
  281. <col class="field-body" />
  282. <tbody valign="top">
  283. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  284. <li><strong>args</strong> – Arguments for a standard file open call.</li>
  285. <li><strong>kwargs</strong> – Keyword arguments for a standard file open call.</li>
  286. </ul>
  287. </td>
  288. </tr>
  289. <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>
  290. </td>
  291. </tr>
  292. <tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">A file descriptor.</p>
  293. </td>
  294. </tr>
  295. <tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">file handle</p>
  296. </td>
  297. </tr>
  298. </tbody>
  299. </table>
  300. <div class="admonition note">
  301. <p class="first admonition-title">Note</p>
  302. <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>
  303. </div>
  304. </dd></dl>
  305. <dl class="function">
  306. <dt id="fstools.uid">
  307. <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>
  308. <dd><p>Function returning a “unique” id for a given file or path.</p>
  309. <table class="docutils field-list" frame="void" rules="none">
  310. <col class="field-name" />
  311. <col class="field-body" />
  312. <tbody valign="top">
  313. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  314. <li><strong>path</strong> (<em>str</em>) – File or folder to generate a uid for.</li>
  315. <li><strong>max_staleness</strong> (<em>int</em>) – If a file or folder is older than that, we may consider
  316. it stale and return a different uid - this is a
  317. dirty trick to work around changes never being
  318. detected. Default is 3600 seconds, use None to
  319. disable this trickery. See below for more details.</li>
  320. </ul>
  321. </td>
  322. </tr>
  323. <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,
  324. None is returned if there were problems accessing the file
  325. or folder.</p>
  326. </td>
  327. </tr>
  328. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
  329. </td>
  330. </tr>
  331. </tbody>
  332. </table>
  333. <div class="admonition warning">
  334. <p class="first admonition-title">Warning</p>
  335. <p class="last">Depending on the operating system capabilities and the way the
  336. file update is done, this function might return the same value
  337. even if the file has changed. It should be better than just
  338. using file’s mtime though.
  339. max_staleness tries to avoid the worst for these cases.</p>
  340. </div>
  341. <div class="admonition note">
  342. <p class="first admonition-title">Note</p>
  343. <p class="last">If this function is used for a path, it will stat all pathes and files rekursively.</p>
  344. </div>
  345. <p><strong>Example:</strong></p>
  346. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  347. <span class="c1"># -*- coding: UTF-8 -*-</span>
  348. <span class="kn">import</span> <span class="nn">sys</span>
  349. <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">&#39;../..&#39;</span><span class="p">)</span>
  350. <span class="kn">import</span> <span class="nn">fstools</span>
  351. <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">&#39;../__init__.py&#39;</span><span class="p">))</span>
  352. </pre></div>
  353. </div>
  354. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">950</span><span class="n">bd674ce9e6ccc93a3f450964b524412961e0d</span>
  355. </pre></div>
  356. </div>
  357. <p>Using just the file’s mtime to determine if the file has changed is
  358. not reliable - if file updates happen faster than the file system’s
  359. mtime granularity, then the modification is not detectable because
  360. the mtime is still the same.</p>
  361. <p>This function tries to improve by using not only the mtime, but also
  362. other metadata values like file size and inode to improve reliability.</p>
  363. <p>For the calculation of this value, we of course only want to use data
  364. that we can get rather fast, thus we use file metadata, not file data
  365. (file content).</p>
  366. </dd></dl>
  367. <dl class="function">
  368. <dt id="fstools.uid_filelist">
  369. <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>
  370. <dd><p>Function returning a unique id for a given file or path.</p>
  371. <table class="docutils field-list" frame="void" rules="none">
  372. <col class="field-name" />
  373. <col class="field-body" />
  374. <tbody valign="top">
  375. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  376. <li><strong>path</strong> (<em>str</em>) – folder which is the basepath for searching files.</li>
  377. <li><strong>expression</strong> (<em>str</em>) – expression to fit including shell-style wildcards.</li>
  378. <li><strong>rekursive</strong> (<em>bool</em>) – search all subfolders if True.</li>
  379. </ul>
  380. </td>
  381. </tr>
  382. <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>
  383. </td>
  384. </tr>
  385. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
  386. </td>
  387. </tr>
  388. </tbody>
  389. </table>
  390. <div class="admonition note">
  391. <p class="first admonition-title">Note</p>
  392. <p class="last">This UID is created out of the file content. Therefore it is more
  393. 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>
  394. </div>
  395. <p><strong>Example:</strong></p>
  396. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
  397. <span class="c1"># -*- coding: UTF-8 -*-</span>
  398. <span class="kn">import</span> <span class="nn">sys</span>
  399. <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">&#39;../..&#39;</span><span class="p">)</span>
  400. <span class="kn">import</span> <span class="nn">fstools</span>
  401. <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">&#39;..&#39;</span><span class="p">,</span> <span class="s1">&#39;*.py&#39;</span><span class="p">,</span> <span class="n">rekursive</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span>
  402. </pre></div>
  403. </div>
  404. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">32</span><span class="n">ca1c130dfa068b79f4e96071c46448</span>
  405. </pre></div>
  406. </div>
  407. </dd></dl>
  408. </div>
  409. <div class="toctree-wrapper compound">
  410. </div>
  411. </div>
  412. <div class="section" id="indices-and-tables">
  413. <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
  414. <ul class="simple">
  415. <li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
  416. <li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
  417. <li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
  418. </ul>
  419. </div>
  420. </div>
  421. </div>
  422. <footer>
  423. <hr/>
  424. <div role="contentinfo">
  425. <p>
  426. &copy; Copyright 2021, Dirk Alders
  427. </p>
  428. </div>
  429. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
  430. <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
  431. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  432. </footer>
  433. </div>
  434. </div>
  435. </section>
  436. </div>
  437. <script type="text/javascript">
  438. jQuery(function () {
  439. SphinxRtdTheme.Navigation.enable(true);
  440. });
  441. </script>
  442. </body>
  443. </html>