From 960a263356328dcd459e5031063fbff3b2cb793a Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 16 Aug 2014 18:34:24 +0200 Subject: [PATCH] Use getopt for option parsing --- mt2obj.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mt2obj.py b/mt2obj.py index c3e42cc..4281272 100755 --- a/mt2obj.py +++ b/mt2obj.py @@ -3,6 +3,7 @@ import zlib import struct import sys import time +import getopt # mt2obj - MTS schematic to OBJ converter # Copyright (C) 2014 sfan5 @@ -313,18 +314,22 @@ colors = { "farming:cotton_8": (228, 226, 225), } -if len(sys.argv) <= 1: - print("Usage: %s " % sys.argv[0]) +optargs, args = getopt.getopt(sys.argv[1:], '') + +if len(args) <= 1: + print("Usage: %s <.mts schematic>" % sys.argv[0]) + print("Converts .mts schematics to Wavefront .obj geometry files") print("") - print("Output files are written into the current directory.") + print("Output files are written into directory where the source file lays.") exit(1) else: sch = open(sys.argv[1], "rb") if sch.read(4) != b"MTSM": print("This file does not look like an MTS schematic..") exit(1) - if struct.unpack("!H", sch.read(2))[0] != 3: - print("Sorry. This MTS file is too old or too new") + v = struct.unpack("!H", sch.read(2))[0] + if v != 3: + print("Wrong file version: got %d, expected %d" % (v, 3)) exit(1) width, height, depth = struct.unpack("!HHH", sch.read(6)) sch.seek(height, 1)