chainlib

Generic blockchain access library and tooling
Log | Files | Refs | README | LICENSE

commit 3013edc3ff10c64c98529637159ce7a2c031a29b
parent c8357c1fd8f9d27b9eef67f7160e431b4dce5590
Author: lash <dev@holbrook.no>
Date:   Wed,  9 Aug 2023 21:08:43 +0100

Add no newline flag

Diffstat:
Mscripts/chainlib-flags.py | 20++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/scripts/chainlib-flags.py b/scripts/chainlib-flags.py @@ -12,9 +12,10 @@ def value_int(v): def value_hex(v): sz = math.log(v, 2) + print("sz v {} {}".format(sz, v)) if v == 0: return "00" - sz = math.ceil(sz) + sz = math.floor(sz) sz = (sz / 8) + 1 return '0x' + v.to_bytes(int(sz), byteorder='big').hex() @@ -23,6 +24,7 @@ argflag = ArgFlag() argparser = argparse.ArgumentParser() argparser.add_argument('-l', '--list', action='store_true', help='List all flag names and values') argparser.add_argument('-x', '--hex', action='store_true', help='Output all values in hex') +argparser.add_argument('-0', dest='nonl', action='store_true', help='Omit newline in single flag output') argparser.add_argument('flag', type=str, nargs='*', help='One or more flag name to calculate flag value for') args = argparser.parse_args(sys.argv[1:]) @@ -42,10 +44,12 @@ if args.list: sys.exit(0) if len(args.flag) == 0: - print(m(argflag.all)) - sys.exit(0) - -r = 0 -for k in args.flag: - r += argflag.val(k) -print(m(r)) + sys.stdout.write(m(argflag.all)) +else: + r = 0 + for k in args.flag: + r += argflag.val(k) + sys.stdout.write(m(r)) + +if not args.nonl: + sys.stdout.write("\n")