1# Used by cactus; now a wrapper and not used in Toil.
2# TODO: Remove from cactus and then remove from Toil.
3#   See https://github.com/DataBiosphere/toil/pull/3529#discussion_r611735988
4
5# http://code.activestate.com/recipes/578019-bytes-to-human-human-to-bytes-converter/
6import logging
7from typing import Optional, SupportsInt
8from toil.lib.conversions import bytes2human as b2h, human2bytes as h2b
9
10"""
11Bytes-to-human / human-to-bytes converter.
12Based on: http://goo.gl/kTQMs
13Working with Python 2.x and 3.x.
14
15Author: Giampaolo Rodola' <g.rodola [AT] gmail [DOT] com>
16License: MIT
17"""
18
19logger = logging.getLogger(__name__)
20
21
22def bytes2human(n: SupportsInt, fmt: Optional[str] = None, symbols: Optional[str] = None) -> str:
23    """
24    Convert n bytes into a human readable string based on format.
25    symbols can be either "customary", "customary_ext", "iec" or "iec_ext",
26    see: http://goo.gl/kTQMs
27    """
28    logger.warning('Deprecated toil method.  Please use "toil.lib.conversions.bytes2human()" instead."')
29    return b2h(n)
30
31
32def human2bytes(s):
33    """
34    Attempts to guess the string format based on default symbols
35    set and return the corresponding bytes as an integer.
36
37    When unable to recognize the format ValueError is raised.
38    """
39    logger.warning('Deprecated toil method.  Please use "toil.lib.conversions.human2bytes()" instead."')
40    return h2b(s)
41