mmgen-wallet/scripts/compute-file-chksum.py
The MMGen Project c7adb56e38
Config API, Part I
This patch eliminates the global configuration variables `opt` and `g`, making
all functions and class instances locally configurable.  Configuration data is
passed to functions and constructors via the `cfg` parameter and made available
to methods in `self.cfg`.

Local configuration free from dependence on the command line will enable the
creation of multiple, independently configured instances of MMGen’s data
objects within a single process.

Potential applications include testing (tracking wallets configured to interact
with spawned processes, for example) and the use of MMGen as a library for
other projects.

This patch completes most of the work required to enable the API.  The full
implementation will appear in a forthcoming commit.
2023-03-28 18:14:37 +00:00

29 lines
805 B
Python
Executable file

#!/usr/bin/env python3
import sys,os
repo_root = os.path.split(os.path.abspath(os.path.dirname(sys.argv[0])))[0]
sys.path = [repo_root] + sys.path
from mmgen.common import *
opts_data = {
'text': {
'desc': 'Compute checksum for a MMGen data file',
'usage':'[opts] infile',
'options': """
-h, --help Print this help message.
-i, --include-first-line Include the first line of the file (you probably don't want this)
"""
}
}
cfg = opts.init(opts_data)
from mmgen.fileutil import get_lines_from_file
lines = get_lines_from_file( cfg, cfg._args[0] )
start = (1,0)[bool(cfg.include_first_line)]
a = make_chksum_6(' '.join(lines[start:]).encode())
if start == 1:
b = lines[0]
msg(("Checksum in file ({}) doesn't match computed value!".format(b),'Checksum in file OK')[a==b])
Msg(a)