From 836d350f130eff9e86d7338a7d6fb7e2f14617a9 Mon Sep 17 00:00:00 2001 From: fly Date: Thu, 30 Sep 2021 23:09:46 +0200 Subject: [PATCH] Enable selected database imports Signed-off-by: fly --- worldbuild-worker.py | 54 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/worldbuild-worker.py b/worldbuild-worker.py index 4855a6b..5f2a4cc 100755 --- a/worldbuild-worker.py +++ b/worldbuild-worker.py @@ -30,6 +30,8 @@ api_token = None prefix = "" quiet = False global_db = False +setup_db = False +pbf_path = None argc = len(sys.argv) i = 1 @@ -55,6 +57,11 @@ while i < argc: else: print ("ERROR: Unknown action " + sys.argv[i]) sys.exit(1) + elif sys.argv[i] == "--setup-db": + setup_db = True + elif sys.argv[i] == "--pbf-path": + i += 1 + pbf_path = sys.argv[i] elif sys.argv[i] == "-h" or sys.argv[i] == "--help": print("usage:worldbuild-worker.py [OPTIONS]") print("Retrives jobs from the manager and executes them") @@ -69,6 +76,10 @@ while i < argc: print(" started: Run tiles marked as started. CAUTION, use with care.") print(" rebuild: Build tiles flaged for rebuild") print(" skip: Force building tile that are marked for being skipped") + print(" Set the following options, if the worker should manage the databases") + print(" --setup-db Enables managment of databases") + print(" --pbf-path Path to the dir with the 10x10 degrees .pbf files") + print("") print(" -h, --help Shows this help and exit") sys.exit(0) else: @@ -84,6 +95,10 @@ if api_token == None: print("Error: No API token given") sys.exit(1) +if setup_db and pbf_path == None: + print("Error: Database managment requested but not pbf path given") + sys.exit(1) + def cleanup(name): if name != None: if os.path.isfile("projects/worldbuild-" + name + "/osm2city-exceptions.log"): @@ -91,6 +106,8 @@ def cleanup(name): run("rm -rf projects/worldbuild-" + name, shell=True) name = None + if setup_db: + run("./delete-db " + db_name, shell=True) build = None name = None @@ -102,21 +119,44 @@ try: run("mkdir -p projects/worldbuild-" + name, shell=True) run("cp projects/worldbuild/params.ini projects/worldbuild-" + name + "/", shell=True) - - if global_db: - db_name = prefix + "worldbuild" - else: + + if setup_db: + if not quiet: + print("Cutting .pbf chunk") if get_south(name) >= 80: - db_name = prefix + "n-pole" + source_pbf = pbf_path + "/" + "n-pole.osm.pbf" elif get_south(name) < -80: - db_name = prefix + "s-pole" + source_pbf = pbf_path + "/" + "s-pole.osm.pbf" else: match = re.match(r"[0-9]{1,7}", name) if match == None: print("ERROR: Invalid tile name") sys.exit(1) else: - db_name = prefix + get_area_name(get_south(name), get_west(name), major=True) + source_pbf = pbf_path + "/" + get_area_name(get_south(name), get_west(name), major=True) + ".osm.pbf" + db_name = prefix + name + run("osmium extract " + source_pbf + " --overwrite --bbox " + str(get_west(name)) + "," + str(get_south(name)) + "," + str(get_east(name)) + "," + str(get_north(name)) + " -o projects/worldbuild-" + name + "/tile.osm.pbf", shell=True) + if not quiet: + print("Creating database") + run("./creat-db " + db_name, shell=True) + if not quiet: + print("Loading .pbf into database") + run("./read-pbf " + db_name + " projects/worldbuild-" + name + "/tile.osm.pbf", shell=True) + else: + if global_db: + db_name = prefix + "worldbuild" + else: + if get_south(name) >= 80: + db_name = prefix + "n-pole" + elif get_south(name) < -80: + db_name = prefix + "s-pole" + else: + match = re.match(r"[0-9]{1,7}", name) + if match == None: + print("ERROR: Invalid tile name") + sys.exit(1) + else: + db_name = prefix + get_area_name(get_south(name), get_west(name), major=True) if get_west(name) < 0: bounds = "bounds=*"