Commit 3dcfe388 authored by Rick Gruber-Riemer's avatar Rick Gruber-Riemer

Take arguments parsing out of process() methods to prepare for parallel processing.

parent 4063089d
......@@ -381,48 +381,21 @@ def _write_xml(path: str, file_name: str, the_buildings: List[building_lib.Build
xml.close()
def process():
def process(uninstall: bool=False, create_atlas: bool=False) -> None:
random.seed(42)
# -- Parse arguments. Command line overrides config file.
parser = argparse.ArgumentParser(description="buildings.py reads OSM data and creates buildings for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="e", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-c", dest="c", action="store_true",
help="do not check for overlapping with static objects", required=False)
parser.add_argument("-a", "--create-atlas", action="store_true",
help="create texture atlas", required=False)
parser.add_argument("-u", dest="uninstall", action="store_true",
help="uninstall ours from .stg", required=False)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
if args.filename is not None:
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.e:
parameters.NO_ELEV = True
if args.c:
parameters.OVERLAP_CHECK = False
if args.uninstall:
files_to_remove = list()
if uninstall:
logging.info("Uninstalling.")
files_to_remove = []
parameters.NO_ELEV = True
parameters.OVERLAP_CHECK = False
parameters.show()
# -- prepare transformation to local coordinates
center = parameters.get_center_global()
coords_transform = coordinates.Transformation(center, hdg=0)
tools.init(coords_transform)
prepare_textures.init(args.create_atlas)
prepare_textures.init(create_atlas)
if parameters.BOUNDARY_CLIPPING:
clipping_border = shgm.Polygon(parameters.get_clipping_extent())
......@@ -565,7 +538,7 @@ def process():
stg_manager.add_object_static('lightmap-switch.xml', center_global, cluster_elev, 0, once=True)
if args.uninstall:
if uninstall:
files_to_remove.append(path_to_stg + file_name + ".ac")
files_to_remove.append(path_to_stg + file_name + ".xml")
else:
......@@ -578,7 +551,7 @@ def process():
handled_index += 1
logging.debug("Total number of buildings written to a cluster *.ac files: %d", total_buildings_written)
if args.uninstall:
if uninstall:
for f in files_to_remove:
try:
os.remove(f)
......@@ -597,4 +570,32 @@ def process():
sys.exit(0)
if __name__ == "__main__":
process()
# -- Parse arguments. Command line overrides config file.
parser = argparse.ArgumentParser(
description="buildings.py reads OSM data and creates buildings for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="skip_elev", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-c", dest="skip_overlap_check", action="store_true",
help="do not check for overlapping with static objects", required=False)
parser.add_argument("-a", "--create-atlas", dest="create_atlas", action="store_true",
help="create texture atlas", required=False)
parser.add_argument("-u", dest="uninstall", action="store_true",
help="uninstall ours from .stg", required=False)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.skip_elev:
parameters.NO_ELEV = True
parameters.show()
if args.skip_elev:
parameters.NO_ELEV = True
if args.skip_overlap_check:
parameters.OVERLAP_CHECK = False
process(args.uninstall, args.create_atlas)
......@@ -372,7 +372,33 @@ def show_default():
print(line, end='')
def set_loglevel(args_loglevel=None):
def set_boundary(boundary_west: float, boundary_south: float,
boundary_east: float, boundary_north: float) -> None:
"""Overrides the geographical boundary values (either default values or read from file).
In most situations should be called after method read_from_file().
"""
boundary_ok = True
if boundary_west >= boundary_east:
boundary_ok = False
logging.error("Boundary West {} must be smaller than East {} -> aborting!".format(boundary_west,
boundary_east))
if boundary_south >= boundary_north:
boundary_ok = False
logging.error("Boundary -south {} must be smaller than North {} -> aborting!".format(boundary_south,
boundary_north))
if not boundary_ok:
sys.exit(1)
global BOUNDARY_WEST
BOUNDARY_WEST = boundary_west
global BOUNDARY_SOUTH
BOUNDARY_SOUTH = boundary_south
global BOUNDARY_EAST
BOUNDARY_EAST = boundary_east
global BOUNDARY_NORTH
BOUNDARY_NORTH = boundary_north
def set_loglevel(args_loglevel=None) -> None:
"""Set loglevel from parameters or command line."""
global LOGLEVEL
if args_loglevel is not None:
......
......@@ -7,6 +7,7 @@ Created on Sun Sep 29 10:42:12 2013
@author: Portree Kid
"""
import argparse
import logging
import math
import os
......@@ -305,24 +306,7 @@ def _write_pier_line(pier, obj, offset):
obj.face(sideface, mat=0)
def process():
logging.basicConfig(level=logging.INFO)
import argparse
parser = argparse.ArgumentParser(description="piers.py reads OSM data and creates Pier models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
if args.filename is not None:
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
def process() -> None:
# -- prepare transformation to local coordinates
cmin, cmax = parameters.get_extent_global()
center_global = parameters.get_center_global()
......@@ -374,4 +358,15 @@ def process():
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="piers.py reads OSM data and creates Pier models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-l", "--loglevel", dest="loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
process()
......@@ -10,7 +10,7 @@ import argparse
import logging
import numpy as np
import os
from typing import List
from typing import List, Optional
import shapely.geometry as shg
......@@ -198,21 +198,7 @@ def _write_line(platform, fg_elev: FGElev, obj, offset):
obj.face(sideface, mat=0)
def process():
parser = argparse.ArgumentParser(description="platforms.py reads OSM data and creates platform models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
if args.filename is not None:
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
def process() -> None:
# -- prepare transformation to local coordinates
cmin, cmax = parameters.get_extent_global()
center_global = parameters.get_center_global()
......@@ -261,4 +247,15 @@ def process():
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="platforms.py reads OSM data and creates platform models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-l", "--loglevel", dest="loglevel",
help="set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL",
required=False)
args = parser.parse_args()
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
parameters.show()
process()
......@@ -1442,32 +1442,12 @@ def fetch_osm_file_data() -> Tuple[Dict[int, osmparser.Node], Dict[int, osmparse
return handler.nodes_dict, handler.ways_dict
def process():
# Handling arguments and parameters
parser = argparse.ArgumentParser(
description="pylons.py reads OSM data and creates pylons, powerlines and aerialways for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="e", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-u", dest="uninstall", action="store_true",
help="uninstall ours from .stg", required=False)
parser.add_argument("-l", "--loglevel",
help="Set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL", required=False)
args = parser.parse_args()
if args.filename is not None:
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.e:
parameters.NO_ELEV = True
def process(uninstall: bool=False) -> None:
files_to_remove = list()
if args.uninstall:
if uninstall:
logging.info("Uninstalling.")
parameters.NO_ELEV = True
parameters.show()
# Initializing tools for global/local coordinate transformations
center_global = parameters.get_center_global()
......@@ -1594,7 +1574,24 @@ def process():
if __name__ == "__main__":
process()
parser = argparse.ArgumentParser(
description="pylons.py reads OSM data and creates pylons, powerlines and aerialways for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="skip_elev", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-u", dest="uninstall", action="store_true",
help="uninstall ours from .stg", required=False)
parser.add_argument("-l", "--loglevel", dest="loglevel",
help="Set loglevel. Valid levels are VERBOSE, DEBUG, INFO, WARNING, ERROR, CRITICAL", required=False)
args = parser.parse_args()
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.skip_elev:
parameters.NO_ELEV = True
parameters.show()
process(args.uninstall)
# ================ UNITTESTS =======================
......
......@@ -1130,27 +1130,6 @@ def debug_create_eps(roads, clusters, elev, plot_cluster_borders=0):
def process():
random.seed(42)
parser = argparse.ArgumentParser(description="roads.py reads OSM data and creates road, railway and bridge models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="e", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-b", "--bridges-only", action="store_true",
help="create only bridges and embankments", required=False)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are DEBUG, INFO, WARNING, ERROR, CRITICAL", required=False)
args = parser.parse_args()
# -- command line args override parameters
if args.filename is not None:
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel)
if args.e:
parameters.NO_ELEV = True
if args.bridges_only:
parameters.CREATE_BRIDGES_ONLY = True
parameters.show()
center_global = parameters.get_center_global()
coords_transform = coordinates.Transformation(center_global, hdg=0)
......@@ -1206,4 +1185,22 @@ def process():
logging.debug("final " + str(roads))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="roads.py reads OSM data and creates road, railway and bridge models for use with FlightGear")
parser.add_argument("-f", "--file", dest="filename",
help="read parameters from FILE (e.g. params.ini)", metavar="FILE", required=True)
parser.add_argument("-e", dest="skip_elev", action="store_true",
help="skip elevation interpolation", required=False)
parser.add_argument("-b", "--bridges-only", dest="bridges_only", action="store_true",
help="create only bridges and embankments", required=False)
parser.add_argument("-l", "--loglevel",
help="set loglevel. Valid levels are DEBUG, INFO, WARNING, ERROR, CRITICAL", required=False)
args = parser.parse_args()
parameters.read_from_file(args.filename)
parameters.set_loglevel(args.loglevel) # -- must go after reading params file
if args.skip_elev:
parameters.NO_ELEV = True
if args.bridges_only:
parameters.CREATE_BRIDGES_ONLY = True
parameters.show()
process()
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