parent
bd087c2503
commit
c484011200
@ -0,0 +1,59 @@
|
||||
"""! @file main.py
|
||||
@brief Utility for parsing STL file header
|
||||
@author xlanro00
|
||||
"""
|
||||
|
||||
# Import basic libraries
|
||||
import argparse as ap
|
||||
import sys
|
||||
from os.path import exists
|
||||
|
||||
|
||||
def main():
|
||||
""" Main function
|
||||
Parses stl file header to get info about generated fingerprint.
|
||||
"""
|
||||
# Parse arguments
|
||||
parser = ap.ArgumentParser(description='Command line utility for parsing fingerprint STL file header')
|
||||
parser.add_argument('file', type=str, help='STL file')
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check if file exists
|
||||
if not exists(args.file):
|
||||
sys.stderr.write('Error: File does not exist')
|
||||
sys.exit(1)
|
||||
with open(args.file, "rb") as f:
|
||||
header = f.read(80).decode('UTF-8')
|
||||
#print(header, file=sys.stderr)
|
||||
header = header.split('\n')[0]
|
||||
header_arr = header.split('\\')
|
||||
input_file = header_arr[0]
|
||||
dpi = header_arr[1]
|
||||
|
||||
if exists(header_arr[2]):
|
||||
config = header_arr[2]
|
||||
preset = header_arr[3]
|
||||
else:
|
||||
filters = header_arr[2]
|
||||
|
||||
mode = header_arr[-1]
|
||||
|
||||
if (mode == "P"):
|
||||
height_base = header_arr[-2]
|
||||
height_line = header_arr[-3]
|
||||
print(input_file, dpi, config, preset, mode,
|
||||
height_base, height_line, sep='\n')
|
||||
elif (mode == "C"):
|
||||
curv_rate_y = header_arr[-2]
|
||||
curv_rate_x = header_arr[-3]
|
||||
height_base = header_arr[-4]
|
||||
height_line = header_arr[-5]
|
||||
print(input_file, dpi, config, preset, mode,
|
||||
height_base, height_line, curv_rate_x, curv_rate_y, sep='\n')
|
||||
elif (mode == "M"):
|
||||
pass
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
main()
|
Loading…
Reference in new issue