<h1id="module-deluge.common"><ttclass="xref docutils literal"><spanclass="pre">deluge.common</span></tt><aclass="headerlink"href="#module-deluge.common"title="Permalink to this headline">¶</a></h1>
<p>Common functions for various parts of Deluge to use.</p>
<dlclass="function">
<dtid="deluge.common.create_magnet_uri">
<!--[deluge.common.create_magnet_uri]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">create_magnet_uri</tt><big>(</big><em>infohash</em>, <em>name=None</em>, <em>trackers=</em><spanclass="optional">[</span><spanclass="optional">]</span><big>)</big><aclass="headerlink"href="#deluge.common.create_magnet_uri"title="Permalink to this definition">¶</a></dt>
<!--[deluge.common.fdate]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fdate</tt><big>(</big><em>seconds</em><big>)</big><aclass="headerlink"href="#deluge.common.fdate"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats a date string in the form of DD/MM/YY based on the systems timezone</p>
<li><em>seconds</em>– float, time in seconds since the Epoch</li>
</ul>
</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">a string in the form of DD/MM/YY or “” if seconds < 0</p>
<!--[deluge.common.fetch_url]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fetch_url</tt><big>(</big><em>url</em><big>)</big><aclass="headerlink"href="#deluge.common.fetch_url"title="Permalink to this definition">¶</a></dt>
<dd><p>Downloads a torrent file from a given URL and checks the file’s validity</p>
<!--[deluge.common.fpcnt]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fpcnt</tt><big>(</big><em>dec</em><big>)</big><aclass="headerlink"href="#deluge.common.fpcnt"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats a string to display a percentage with two decimal places</p>
<!--[deluge.common.fpeer]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fpeer</tt><big>(</big><em>num_peers</em>, <em>total_peers</em><big>)</big><aclass="headerlink"href="#deluge.common.fpeer"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats a string to show ‘num_peers’ (‘total_peers’)</p>
<li><em>num_peers</em>– int, the number of connected peers</li>
<li><em>total_peers</em>– int, the total number of peers</li>
</ul>
</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">a formatted string: num_peers (total_peers), if total_peers < 0, then it will not be shown</p>
<!--[deluge.common.free_space]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">free_space</tt><big>(</big><em>path</em><big>)</big><aclass="headerlink"href="#deluge.common.free_space"title="Permalink to this definition">¶</a></dt>
<dd><p>Gets the free space available at ‘path’</p>
<!--[deluge.common.fsize]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fsize</tt><big>(</big><em>fsize_b</em><big>)</big><aclass="headerlink"href="#deluge.common.fsize"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats the bytes value into a string with KiB, MiB or GiB units</p>
<!--[deluge.common.fspeed]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">fspeed</tt><big>(</big><em>bps</em><big>)</big><aclass="headerlink"href="#deluge.common.fspeed"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats a string to display a transfer speed utilizing <atitle="deluge.common.fsize"class="reference"href="#deluge.common.fsize"><ttclass="xref docutils literal"><spanclass="pre">fsize()</span></tt></a></p>
<!--[deluge.common.ftime]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">ftime</tt><big>(</big><em>seconds</em><big>)</big><aclass="headerlink"href="#deluge.common.ftime"title="Permalink to this definition">¶</a></dt>
<dd><p>Formats a string to show time in a human readable form</p>
<li><em>seconds</em>– int, the number of seconds</li>
</ul>
</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">a formatted time string, will return ‘unknown’ for values greater than 10 weeks and ‘Infinity’ if seconds == 0</p>
<!--[deluge.common.get_default_config_dir]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_default_config_dir</tt><big>(</big><em>filename=None</em><big>)</big><aclass="headerlink"href="#deluge.common.get_default_config_dir"title="Permalink to this definition">¶</a></dt>
<li><em>filename</em>– if None, only the config path is returned, if provided, a path including the filename will be returned</li>
</ul>
</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">a file path to the config directory and optional filename</p>
<!--[deluge.common.get_default_download_dir]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_default_download_dir</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.get_default_download_dir"title="Permalink to this definition">¶</a></dt>
<!--[deluge.common.get_path_size]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_path_size</tt><big>(</big><em>path</em><big>)</big><aclass="headerlink"href="#deluge.common.get_path_size"title="Permalink to this definition">¶</a></dt>
<dd><p>Gets the size in bytes of ‘path’</p>
<li><em>path</em>– string, the path to check for size</li>
</ul>
</td>
</tr>
<trclass="field"><thclass="field-name">Returns:</th><tdclass="field-body"><pclass="first">the size in bytes of the path or -1 if the path does not exist</p>
<!--[deluge.common.get_pixmap]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_pixmap</tt><big>(</big><em>fname</em><big>)</big><aclass="headerlink"href="#deluge.common.get_pixmap"title="Permalink to this definition">¶</a></dt>
<dd><p>Provides easy access to files in the deluge/data/pixmaps folder within the Deluge egg</p>
<!--[deluge.common.get_revision]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_revision</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.get_revision"title="Permalink to this definition">¶</a></dt>
<dd><p>The svn revision of the build if available</p>
<!--[deluge.common.get_version]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">get_version</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.get_version"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the program version from the egg metadata</p>
<!--[deluge.common.is_ip]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">is_ip</tt><big>(</big><em>ip</em><big>)</big><aclass="headerlink"href="#deluge.common.is_ip"title="Permalink to this definition">¶</a></dt>
<dd><p>A simple test to see if ‘ip’ is valid</p>
<!--[deluge.common.is_magnet]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">is_magnet</tt><big>(</big><em>uri</em><big>)</big><aclass="headerlink"href="#deluge.common.is_magnet"title="Permalink to this definition">¶</a></dt>
<dd><p>A check to determine if a uri is a valid bittorrent magnet uri</p>
<!--[deluge.common.is_url]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">is_url</tt><big>(</big><em>url</em><big>)</big><aclass="headerlink"href="#deluge.common.is_url"title="Permalink to this definition">¶</a></dt>
<dd><p>A simple regex test to check if the URL is valid</p>
<!--[deluge.common.open_file]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">open_file</tt><big>(</big><em>path</em><big>)</big><aclass="headerlink"href="#deluge.common.open_file"title="Permalink to this definition">¶</a></dt>
<dd><p>Opens a file or folder using the system configured program</p>
<trclass="field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><em>path</em>– the path to the file or folder to open</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="function">
<dtid="deluge.common.open_url_in_browser">
<!--[deluge.common.open_url_in_browser]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">open_url_in_browser</tt><big>(</big><em>url</em><big>)</big><aclass="headerlink"href="#deluge.common.open_url_in_browser"title="Permalink to this definition">¶</a></dt>
<dd><p>Opens a url in the desktop’s default browser</p>
<trclass="field"><thclass="field-name">Parameters:</th><tdclass="field-body"><ulclass="first last simple">
<li><em>url</em>– the url to open</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="function">
<dtid="deluge.common.osx_check">
<!--[deluge.common.osx_check]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">osx_check</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.osx_check"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the current platform is Mac OS X</p>
<!--[deluge.common.vista_check]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">vista_check</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.vista_check"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the current platform is Windows Vista</p>
<!--[deluge.common.windows_check]--><ttclass="descclassname">deluge.common.</tt><ttclass="descname">windows_check</tt><big>(</big><big>)</big><aclass="headerlink"href="#deluge.common.windows_check"title="Permalink to this definition">¶</a></dt>
<dd><p>Checks if the current platform is Windows</p>