~dricottone/filters

ref: bf44d42c110c86e88d84348332b4f6b0f40ce5f2 filters/rng/internals.py -rw-r--r-- 1.3 KiB
bf44d42cDominic Ricottone Toolchain updates 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3

import sys
from typing import *

VERSION = (1,0,1,)

def _try_get_float(
    mapping: Dict,
    key: str,
    *,
    default: Optional[float] = None,
) -> Optional[float]:
    if key in mapping:
        return float(mapping[key])
    else:
        return default

def _try_get_int(
    mapping: Dict,
    key: str,
    *,
    default: Optional[float] = None,
) -> Optional[float]:
    if key in mapping:
        return int(mapping[key])
    else:
        return default

def _print_help() -> None:
    _msg = "Usage: rng DISTRIBUTION [OPTIONS]\n"
    sys.stdout.write(_msg)

def _print_version() -> None:
    _msg = "rng {0}\n".format(".".join(str(v) for v in VERSION))
    sys.stdout.write(_msg)

def _print_distributions(*dist: str) -> None:
    _msg = "Valid distributions: {0}\n".format(", ".join(dist))
    sys.stdout.write(_msg)

def _print_usage() -> None:
    _msg = (
        "Usage: rng DISTRIBUTION [OPTIONS]",
        "Try `rng --list-distributions` and `rng DISTRIBUTION --help`",
    )
    sys.stderr.write("\n".join(_msg) + "\n")

def _print_invalid_distribution(dist: str) -> None:
    _msg = (
        "{0}: Invalid distribution '{1}'".format(sys.argv[0], dist),
        "Try `rng --list-distributions`",
    )
    sys.stderr.write("\n".join(_msg) + "\n")