### Navigation

- index
- modules |
- next |
- previous |
- deluge v1.1.0 documentation »

# `deluge.common`

Common functions for various parts of Deluge to use.

`deluge.common.``create_magnet_uri`(infohash, name=None, trackers=[])

  Creates a magnet uri

  Parameters: | infohash – string, the info-hash of the torrent name – string, the name of the torrent (optional) trackers – list of strings, the trackers to announce to (optional)
  Returns: | a magnet uri string
  Return type: | string

`deluge.common.``fdate`(seconds)

  Formats a date string in the form of DD/MM/YY based on the systems timezone

  Parameters: | seconds – float, time in seconds since the Epoch
  Returns: | a string in the form of DD/MM/YY or “” if seconds < 0
  Return type: | string

`deluge.common.``fetch_url`(url)

  Downloads a torrent file from a given URL and checks the file’s validity

  Parameters: | url – string, the url of the .torrent file to fetch
  Returns: | the filepath to the downloaded file
  Return type: | string

`deluge.common.``fpcnt`(dec)

  Formats a string to display a percentage with two decimal places

  Parameters: | dec – float, the ratio in the range [0.0, 1.0]
  Returns: | a formatted string representing a percentage
  Return type: | string

  Usage

      >>> fpcnt(0.9311)
      '93.11%'

`deluge.common.``fpeer`(num_peers, total_peers)

  Formats a string to show ‘num_peers’ (‘total_peers’)

  Parameters: | num_peers – int, the number of connected peers total_peers – int, the total number of peers
  Returns: | a formatted string: num_peers (total_peers), if total_peers < 0, then it will not be shown
  Return type: | string

  Usage

      >>> fpeer(10, 20)
      '10 (20)'
      >>> fpeer(10, -1)
      '10'

`deluge.common.``free_space`(path)

  Gets the free space available at ‘path’

  Parameters: | path – string, the path to check
  Returns: | the free space at path in bytes
  Return type: | int

`deluge.common.``fsize`(fsize_b)

  Formats the bytes value into a string with KiB, MiB or GiB units

  Parameters: | fsize_b – int, the filesize in bytes
  Returns: | formatted string in KiB, MiB or GiB units
  Return type: | string

  Usage

      >>> fsize(112245)
      '109.6 KiB'

`deluge.common.``fspeed`(bps)

  Formats a string to display a transfer speed utilizing `fsize()`

  Parameters: | bps – int, bytes per second
  Returns: | a formatted string representing transfer speed
  Return type: | string

  Usage

      >>> fspeed(43134)
      '42.1 KiB/s'

`deluge.common.``ftime`(seconds)

  Formats a string to show time in a human readable form

  Parameters: | seconds – int, the number of seconds
  Returns: | a formatted time string, will return ‘unknown’ for values greater than 10 weeks and ‘Infinity’ if seconds == 0
  Return type: | string

  Usage

      >>> ftime(23011)
      '6h 23m'

`deluge.common.``get_default_config_dir`(filename=None)

  Parameters: | filename – if None, only the config path is returned, if provided, a path including the filename will be returned
  Returns: | a file path to the config directory and optional filename
  Return type: | string

`deluge.common.``get_default_download_dir`()

  Returns: | the default download directory
  Return type: | string

`deluge.common.``get_path_size`(path)

  Gets the size in bytes of ‘path’

  Parameters: | path – string, the path to check for size
  Returns: | the size in bytes of the path or -1 if the path does not exist
  Return type: | int

`deluge.common.``get_pixmap`(fname)

  Provides easy access to files in the deluge/data/pixmaps folder within the Deluge egg

  Parameters: | fname – the filename to look for
  Returns: | a path to a pixmap file included with Deluge
  Return type: | string

`deluge.common.``get_revision`()

  The svn revision of the build if available

  Returns: | the svn revision, or “”
  Return type: | string

`deluge.common.``get_version`()

  Returns the program version from the egg metadata

  Returns: | the version of Deluge
  Return type: | string

`deluge.common.``is_ip`(ip)

  A simple test to see if ‘ip’ is valid

  Parameters: | ip – string, the ip to check
  Returns: | True or False
  Return type: | bool

  ** Usage **

      >>> is_ip("127.0.0.1")
      True

`deluge.common.``is_magnet`(uri)

  A check to determine if a uri is a valid bittorrent magnet uri

  Parameters: | uri – string, the uri to check
  Returns: | True or False
  Return type: | bool

  Usage

      >>> is_magnet("magnet:?xt=urn:btih:SU5225URMTUEQLDXQWRB2EQWN6KLTYKN")
      True

`deluge.common.``is_url`(url)

  A simple regex test to check if the URL is valid

  Parameters: | url – string, the url to test
  Returns: | True or False
  Return type: | bool

  Usage

      >>> is_url("http://deluge-torrent.org")
      True

`deluge.common.``open_file`(path)

  Opens a file or folder using the system configured program

  Parameters: | path – the path to the file or folder to open

`deluge.common.``open_url_in_browser`(url)

  Opens a url in the desktop’s default browser

  Parameters: | url – the url to open

`deluge.common.``osx_check`()

  Checks if the current platform is Mac OS X

  Returns: | True or False
  Return type: | bool

`deluge.common.``vista_check`()

  Checks if the current platform is Windows Vista

  Returns: | True or False
  Return type: | bool

`deluge.common.``windows_check`()

  Checks if the current platform is Windows

  Returns: | True or False
  Return type: | bool

### Navigation

- index
- modules |
- next |
- previous |
- deluge v1.1.0 documentation »