Tidy up argument parsing

master
Dan Howe 7 years ago
parent ff16ea841c
commit 68fe6c9c9d

@ -31,8 +31,7 @@ def point_to_row(point, layer, dxf_type, dxf_id):
return row return row
def convert(dxf_name, layer_name): def print_layers(dxf_name):
# Read dxf file
dxf = dxfgrabber.readfile(dxf_name) dxf = dxfgrabber.readfile(dxf_name)
# Get data from DTM # Get data from DTM
@ -41,6 +40,11 @@ def convert(dxf_name, layer_name):
for layer in layers: for layer in layers:
print(layer) print(layer)
def convert(dxf_name, layer_name):
# Read dxf file
dxf = dxfgrabber.readfile(dxf_name)
if layer_name: if layer_name:
print("\nExtracting data from layer '{}'".format(layer_name)) print("\nExtracting data from layer '{}'".format(layer_name))
entities = [ entities = [
@ -86,13 +90,26 @@ def convert(dxf_name, layer_name):
def main(): def main():
dxf_name = sys.argv[1] # Set up command line arguments
try: parser = argparse.ArgumentParser()
layer_name = sys.argv[2] parser.add_argument('dxf_name', help='path to dxf file', default=None)
except IndexError: parser.add_argument(
layer_name = None '-n', metavar='LAYER_NAME', help='name of layer', default=None)
parser.add_argument(
convert(dxf_name, layer_name) '-l', action='store_true', help='show list of layers', default=False)
args = parser.parse_args()
# Parse arguments
dxf_name = args.dxf_name
layer_name = args.n
show_layers_only = args.l
if show_layers_only:
# Print list of layers only
print_layers(dxf_name)
else:
# Convert to csv
convert(dxf_name, layer_name)
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save