#! /usr/bin/python3 # Copyright (C) 2018 Merspieler, merspieler _at_ airmail.cc # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import sys import os import re from math import ceil import time argc = len(sys.argv) i = 1 first = 1 create_zip = False man_threads = "" project = "" while i < argc: if sys.argv[i] == "-t" or sys.argv[i] == "--threads": i += 1 man_threads = "-t sys.argv[i]" elif sys.argv[i] == "-z" or sys.argv[i] == "--zip": create_zip = True elif sys.argv[i] == "-h" or sys.argv[i] == "--help": print("usage: build [OPTIONS]") print("Builds the tiles with osm2city") print("") print("OPTIONS") print(" -h, --help Shows this help and exit") print(" -t, --threads Number of threads used for building") print(" This will overwrite the value from the general-settings file") print(" -z, --zip Create a ready to distribute zip file on success") sys.exit(0) else: if first == 1: first = 0 project = sys.argv[i] else: print("Unknown option " + sys.argv[i]) sys.exit(1) i += 1 if project == "": print("No project was given. See build -h for details") sys.exit(1) try: settings_file = open("projects/" + project + "/settings") bounds = settings_file.readline() settings_file.close() except: print("Couldn't find the settings file for the given project.") print("Please check if the project exsists and contains the 'settings' file.") print("To create a new project run './create-project'") sys.exit(1) match = re.match("^bounds=\*?(-?[0-9]{1,3}\.[0-9]{0,4})_(-?[0-9]{1,2}\.[0-9]{0,4})_(-?[0-9]{1,3}\.[0-9]{0,4})_(-?[0-9]{1,2}\.[0-9]{0,4})$", bounds) if match: west = float(match.group(1)) south = float(match.group(2)) east = float(match.group(3)) north = float(match.group(4)) else: print("Failed to get bounds") sys.exit(1) width = ceil(east - west) height = ceil(north - south) start_time = time.time() for w in range(0, width): build_w = west + w build_e = build_w + 1 if build_e > east: build_e = east if build_w < 0: build_w = "*" + str(build_w) for s in range(0, height): build_s = south + s build_n = build_s + 1 if build_n > north: build_n = north os.system("./build_tile " + project + " " + man_threads + " -b " + str(build_w) + "_" + str(build_s) + "_" + str(build_e) + "_" + str(build_n)) # Get build time end_time = time.time() elapsed = end_time - start_time seconds = elapsed % 60 elapsed = (elapsed - seconds) / 60 minutes = elapsed % 60 elapsed = (elapsed - minutes) / 60 hours = elapsed % 24 days = (elapsed - hours) / 24 time = str(hours) + " Hours, " + str(minutes) + " Minutes and " + str(seconds) + " Seconds" if days > 0: time = str(days) + " Days, " + time print("Building " + project + "took " + time) if create_zip: print("Creating zip file...") os.system("zip -rq projects/" + project + "/" + project + ".zip projects/" + project + "/scenery/")