Commit ef618bee authored by Zhukov, Alexander P's avatar Zhukov, Alexander P
Browse files

test_read.py is now a standalone test program with simplistic CLI

parent 4318494e
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:14:52 2020
@author: az9
"""
from read_storage import BinaryStorage
file = BinaryStorage('/data/BinStorage/test.bin')
print(file[0:10:2])
file.close()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:11:06 2020
@author: az9
"""
from read_storage import BinaryStorage
file = BinaryStorage('/data/BinStorage/BCMData/Convert/200210_1512_00110000_DCM.bin')
#file = BinaryStorage('/data/BinStorage/BCMData/Convert/200210_1538_00110000_DCM.bin')
# file = BinaryStorage('/data/BinStorage/test.bin')
def show(record):
if 'value' in record:
value = record['value']
record['value'] = value[0]
print(record)
while True:
record = file.read()
if 'EOF' in record:
break
show(record)
print('++++++++++++++++')
show(file[10])
file.close()
......@@ -13,9 +13,7 @@ import os
HEADER_SZ=12
class BinaryStorage:
def __init__(self, path):
self.file = open(path,'rb')
......@@ -45,14 +43,11 @@ class BinaryStorage:
else:
return self.readAt(key)
def __len__(self):
return len(self.rec_table)
def read_size(file, long=True):
if long:
bytes = array('I',file.read(4))
......@@ -203,9 +198,9 @@ def read_epilog(file):
# the last record is EOF, and the very last offset has nothing
raw = array('L', file.read(OFST_SIZE*(num_records-2)))
raw.byteswap()
print('Number of records: ', len(raw))
# print('Number of records: ', len(raw))
# print(raw.itemsize)
print(raw)
# print(raw)
return raw
......
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 27 16:11:06 2020
@author: az9
"""
from read_storage import BinaryStorage
import argparse
from argparse import RawTextHelpFormatter
epilog_text = '''
Examples:
python read_file.py filename
# will read and print out all records from <filename>
python read_file.py -i n1 -i n2 filename
# will read and print out records with indices n1 and n2 from <filename>
'''
parser = argparse.ArgumentParser(epilog=epilog_text, formatter_class=RawTextHelpFormatter)
parser.add_argument('--index','-i', action='append', default=[], type=int,
help='indices of records to read')
parser.add_argument('file', help='file to read')
args=parser.parse_args()
file = BinaryStorage(args.file)
print(args.file,'has',len(file), 'records')
def show(record):
if 'value' in record:
value = record['value']
record['value'] = value[0]
return record
if(not args.index):
while True:
record = file.read()
if 'EOF' in record:
break
print(show(record))
else:
for i in args.index:
print(i,":",show(file[i]))
file.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment