aboutsummaryrefslogtreecommitdiff
path: root/contrib/linearize/linearize-data.py
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/linearize/linearize-data.py')
-rwxr-xr-xcontrib/linearize/linearize-data.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/contrib/linearize/linearize-data.py b/contrib/linearize/linearize-data.py
index 7510204bb1..b72c7b0d08 100755
--- a/contrib/linearize/linearize-data.py
+++ b/contrib/linearize/linearize-data.py
@@ -34,12 +34,12 @@ def get_blk_dt(blk_hdr):
# When getting the list of block hashes, undo any byte reversals.
def get_block_hashes(settings):
blkindex = []
- f = open(settings['hashlist'], "r", encoding="utf8")
- for line in f:
- line = line.rstrip()
- if settings['rev_hash_bytes'] == 'true':
- line = bytes.fromhex(line)[::-1].hex()
- blkindex.append(line)
+ with open(settings['hashlist'], "r", encoding="utf8") as f:
+ for line in f:
+ line = line.rstrip()
+ if settings['rev_hash_bytes'] == 'true':
+ line = bytes.fromhex(line)[::-1].hex()
+ blkindex.append(line)
print("Read " + str(len(blkindex)) + " hashes")
@@ -249,19 +249,18 @@ if __name__ == '__main__':
print("Usage: linearize-data.py CONFIG-FILE")
sys.exit(1)
- f = open(sys.argv[1], encoding="utf8")
- for line in f:
- # skip comment lines
- m = re.search(r'^\s*#', line)
- if m:
- continue
-
- # parse key=value lines
- m = re.search(r'^(\w+)\s*=\s*(\S.*)$', line)
- if m is None:
- continue
- settings[m.group(1)] = m.group(2)
- f.close()
+ with open(sys.argv[1], encoding="utf8") as f:
+ for line in f:
+ # skip comment lines
+ m = re.search(r'^\s*#', line)
+ if m:
+ continue
+
+ # parse key=value lines
+ m = re.search(r'^(\w+)\s*=\s*(\S.*)$', line)
+ if m is None:
+ continue
+ settings[m.group(1)] = m.group(2)
# Force hash byte format setting to be lowercase to make comparisons easier.
# Also place upfront in case any settings need to know about it.