Пример #1
0
def main():
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    """ Main

    Args: None.  (Use sys.argv[] to get args)

    Returns: N/A

    Raises: None

    """
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    # Initialize.
    err = None
    ret = 0
    debug = are_keys = force_req_print = False

    # Parse commandline into options and args.
    try:
        (opt_pairs, other_args) = getopt.getopt(sys.argv[1:], "dhkr?")
    except getopt.GetoptError as err:
        print("ManifestRead: " + str(err), file=sys.stderr)
    except IndexError as err:
        print("ManifestRead: Insufficient arguments", file=sys.stderr)
    if (err is not None):
        usage(sys.stderr)
        sys.exit(errno.EINVAL)

    # Set option flags.
    for (opt, optarg) in opt_pairs:
        del optarg
        if (opt == "-d"):
            debug = True
        elif ((opt == "-h") or (opt == "-?")):
            usage(sys.stdout)
            sys.exit(0)
        elif (opt == "-k"):
            are_keys = True
        elif (opt == "-r"):
            force_req_print = True

    # Must have at least socket specified as first arg.
    if (not other_args):
        usage(sys.stderr)
        sys.exit(errno.EINVAL)

    # Do the work.
    try:
        mrobj = ManifestRead(other_args[0])
        mrobj.set_debug(debug)
        print_values(mrobj, other_args[1:], are_keys, force_req_print)
    except (SystemExit, KeyboardInterrupt):
        pass
    except Exception as err:
        print("Error running Manifest Reader", file=sys.stderr)
    if (err):
        ret = err.args[0]
    sys.exit(ret)
Пример #2
0
            usage(sys.stdout)
            sys.exit(0)
        elif (opt == "-k"):
            are_keys = True
        elif (opt == "-r"):
            force_req_print = True

    # Must have at least socket specified as first arg.
    if (not other_args):
        usage(sys.stderr)
        sys.exit(errno.EINVAL)

    # Do the work.
    try:
        mrobj = ManifestRead(other_args[0])
        mrobj.set_debug(debug)
        print_values(mrobj, other_args[1:], are_keys, force_req_print)
    except (SystemExit, KeyboardInterrupt):
        pass
    except Exception, err:
        print >> sys.stderr, "Error running Manifest Reader"
    if (err):
        ret = err.args[0]
    sys.exit(ret)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Main
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if __name__ == "__main__":
    main()