Python humanfriendly.parse_size() Examples

The following are 30 code examples of humanfriendly.parse_size(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module humanfriendly , or try the search function .
Example #1
Source File: kubernetes_tools.py    From paasta with Apache License 2.0 6 votes vote down vote up
def parse_container_resources(resources: Mapping[str, str]) -> KubeContainerResources:
    cpu_str = resources.get("cpu")
    if not cpu_str:
        cpus = None
    elif cpu_str[-1] == "m":
        cpus = float(cpu_str[:-1]) / 1000
    else:
        cpus = float(cpu_str)

    mem_str = resources.get("memory")
    if not mem_str:
        mem_mb = None
    else:
        mem_mb = parse_size(mem_str) / 1000000

    disk_str = resources.get("ephemeral-storage")
    if not disk_str:
        disk_mb = None
    else:
        disk_mb = parse_size(disk_str) / 1000000

    return KubeContainerResources(cpus=cpus, mem=mem_mb, disk=disk_mb) 
Example #2
Source File: specs.py    From console with MIT License 6 votes vote down vote up
def render_container_spec(app_name, proc):
    c = ContainerSpec()
    c.Image = proc.image
    c.Env = copy.deepcopy(proc.env)
    c.set_env("TZ", 'Asia/Shanghai')
    c.User = '' if not hasattr(proc, 'user') else proc.user
    c.WorkingDir = '' if not hasattr(proc, 'working_dir') else proc.working_dir
    c.DnsSearch = [] if not hasattr(
        proc, 'dns_search') else copy.deepcopy(proc.dns_search)
    c.Volumes = copy.deepcopy(proc.volumes)
    c.SystemVolumes = copy.deepcopy(
        proc.system_volumes) + get_system_volumes_from_etcd(app_name)
    c.CloudVolumes = render_cloud_volumes(proc.cloud_volumes)
    c.Command = proc.cmd
    c.Entrypoint = proc.entrypoint
    c.CpuLimit = proc.cpu
    c.MemoryLimit = humanfriendly.parse_size(proc.memory)
    c.Expose = 0 if not proc.port else proc.port.keys()[0]
    c.LogConfig = None
    return c 
Example #3
Source File: DockerUtils.py    From ue4-docker with MIT License 6 votes vote down vote up
def maxsize():
		'''
		Determines the configured size limit (in GB) for Windows containers
		'''
		if platform.system() != 'Windows':
			return -1
		
		config = DockerUtils.getConfig()
		if 'storage-opts' in config:
			sizes = [opt.replace('size=', '') for opt in config['storage-opts'] if 'size=' in opt]
			if len(sizes) > 0:
				return humanfriendly.parse_size(sizes[0]) / 1000000000
		
		# The default limit on image size is 20GB
		# (https://docs.microsoft.com/en-us/visualstudio/install/build-tools-container-issues)
		return 20.0 
Example #4
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #5
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #6
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #7
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #8
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #9
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #10
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #11
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #12
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #13
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #14
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #15
Source File: __main__.py    From BIGSI with MIT License 5 votes vote down vote up
def build(
        self,
        bloomfilters: hug.types.multiple = [],
        samples: hug.types.multiple = [],
        from_file: hug.types.text = None,
        config: hug.types.text = None,
    ):
        config = get_config_from_file(config)

        if from_file and bloomfilters:
            raise ValueError(
                "You can only specify blooms via from_file or bloomfilters, but not both"
            )
        elif from_file:
            samples = []
            bloomfilters = []
            with open(from_file, "r") as tsvfile:
                reader = csv.reader(tsvfile, delimiter="\t")
                for row in reader:
                    bloomfilters.append(row[0])
                    samples.append(row[1])
        if samples:
            assert len(samples) == len(bloomfilters)
        else:
            samples = bloomfilters

        if config.get("max_build_mem_bytes"):
            max_memory_bytes = humanfriendly.parse_size(config["max_build_mem_bytes"])
        else:
            max_memory_bytes = None

        return build(
            config=config,
            bloomfilter_filepaths=bloomfilters,
            samples=samples,
            max_memory=max_memory_bytes,
        ) 
Example #16
Source File: config.py    From trains with Apache License 2.0 5 votes vote down vote up
def parse_human_size(value):
    if isinstance(value, six.string_types):
        return humanfriendly.parse_size(value)
    return value 
Example #17
Source File: util.py    From clusterman with Apache License 2.0 5 votes vote down vote up
def mem(resources):
        resources = resources or {}
        return parse_size(resources.get('memory', DEFAULT_KUBERNETES_MEMORY_REQUEST)) / 1000000 
Example #18
Source File: util.py    From clusterman with Apache License 2.0 5 votes vote down vote up
def disk(resources):
        resources = resources or {}
        return parse_size(resources.get('ephemeral-storage', DEFAULT_KUBERNETES_DISK_REQUEST)) / 1000000 
Example #19
Source File: performance.py    From lavatory with Apache License 2.0 5 votes vote down vote up
def _get_human_friendly_used_space(info):
    return parse_size(info['usedSpace'].replace(',', '')) 
Example #20
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #21
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #22
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #23
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #24
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #25
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #26
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #27
Source File: format_wav_scp.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_or_none(value: str):
    if value in ("none", "None", "NONE"):
        return None
    return humanfriendly.parse_size(value) 
Example #28
Source File: types.py    From espnet with Apache License 2.0 5 votes vote down vote up
def humanfriendly_parse_size_or_none(value) -> Optional[float]:
    if value.strip().lower() in ("none", "null", "nil"):
        return None
    return humanfriendly.parse_size(value) 
Example #29
Source File: export_container_base_task.py    From script-languages with MIT License 5 votes vote down vote up
def _export_container(self, container, release_image_name: str, temp_directory: str):
        generator = container.export(chunk_size=humanfriendly.parse_size("10mb"))
        export_file = temp_directory + "/export.tar"
        with open(export_file, "wb") as file:
            still_running_logger = StillRunningLogger(
                self.logger, "Export image %s" % release_image_name)
            for chunk in generator:
                still_running_logger.log()
                file.write(chunk)
        return export_file 
Example #30
Source File: log_mel_fbank.py    From espnet with Apache License 2.0 4 votes vote down vote up
def __init__(
        self,
        fs: Union[int, str] = 16000,
        n_fft: int = 1024,
        win_length: int = None,
        hop_length: int = 256,
        window: Optional[str] = "hann",
        center: bool = True,
        pad_mode: str = "reflect",
        normalized: bool = False,
        onesided: bool = True,
        n_mels: int = 80,
        fmin: Optional[int] = 80,
        fmax: Optional[int] = 7600,
        htk: bool = False,
    ):
        assert check_argument_types()
        super().__init__()
        if isinstance(fs, str):
            fs = humanfriendly.parse_size(fs)

        self.fs = fs
        self.n_mels = n_mels
        self.n_fft = n_fft
        self.hop_length = hop_length
        self.win_length = win_length
        self.window = window
        self.fmin = fmin
        self.fmax = fmax

        self.stft = Stft(
            n_fft=n_fft,
            win_length=win_length,
            hop_length=hop_length,
            window=window,
            center=center,
            pad_mode=pad_mode,
            normalized=normalized,
            onesided=onesided,
        )

        self.logmel = LogMel(
            fs=fs,
            n_fft=n_fft,
            n_mels=n_mels,
            fmin=fmin,
            fmax=fmax,
            htk=htk,
            log_base=10.0,
        )