How to use the pingparsing.cli.TimestampFormat.EPOCH function in pingparsing

To help you get started, we’ve selected a few pingparsing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pingparsing / pingparsing / cli.py View on Github external
const=QUIET_LOG_LEVEL,
        default=logbook.INFO,
        help="suppress execution log messages.",
    )

    group = parser.add_argument_group("Ping Options")
    group.add_argument(
        "--timestamp",
        choices=TimestampFormat.LIST,
        default=TimestampFormat.NONE,
        help="""[Only for LINUX]
        {}: no timestamps.
        {}: add timestamps with UNIX epoch time format.
        {}: add timestamps with ISO time format.
        """.format(
            TimestampFormat.NONE, TimestampFormat.EPOCH, TimestampFormat.DATETIME
        ),
    )
    group.add_argument(
        "-c",
        "--count",
        type=int,
        help="""Stop after sending the count.
        see also ping(8) [-c count] option description.
        """,
    )
    group.add_argument(
        "-w",
        "--deadline",
        type=str,
        help="""Timeout before ping exits.
        valid time units are: {units}. if no unit string found, considered seconds as
github thombashi / pingparsing / pingparsing / cli.py View on Github external
raise TypeError("not supported type to convert: {}".format(type(obj)))


def _serialize_datetime(obj):
    if isinstance(obj, datetime):
        return obj.isoformat()

    if isinstance(obj, TIMESTAMP_TYPES):
        return obj

    raise TypeError("not supported type to convert: {}".format(type(obj)))


timestamp_serialize_map = {
    TimestampFormat.NONE: None,
    TimestampFormat.EPOCH: _serialize_epoch,
    TimestampFormat.DATETIME: _serialize_datetime,
}


def dumps_dict(obj, timestamp_format, indent=0):
    serialize_func = timestamp_serialize_map[timestamp_format]

    if indent <= 0:
        return json.dumps(obj, default=serialize_func)

    return json.dumps(obj, indent=indent, default=serialize_func)


def main():
    options = parse_option()