From c1cf6060d2ed825cd62b71d3c5251ab6f5ccba48 Mon Sep 17 00:00:00 2001 From: xmd5a Date: Fri, 18 Dec 2020 17:19:45 +0300 Subject: [PATCH] Better error handling --- README.md | 2 +- docker_run.sh | 4 +- gui/qgis-xtopo-gui.py | 86 ++++++++++++++++++++++++++++++++++++++--- gui/translations_en.txt | 9 ++++- gui/translations_ru.txt | 9 ++++- init_docker.sh | 6 ++- populate_db.sh | 22 ++++++++--- prepare_data.sh | 75 +++++++++++++++++++---------------- test.py | 5 +++ 9 files changed, 169 insertions(+), 49 deletions(-) create mode 100644 test.py diff --git a/README.md b/README.md index 42456da..39542ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -QGIS-xtopo v0.2.20201213 +QGIS-xtopo v0.2.4 ================ ![GitHub Logo](/docs/splash.png) diff --git a/docker_run.sh b/docker_run.sh index 01355ed..817dc27 100755 --- a/docker_run.sh +++ b/docker_run.sh @@ -130,5 +130,7 @@ if [[ $(docker container ls | grep qgis-xtopo) ]] ; then docker exec -it --user user qgis-xtopo /app/init_docker.sh fi if [[ $RUN_CHAIN == true ]] ; then - . docker_exec_qgis.sh + if [[ ! -f $config_dir/err_prepare_data.flag ]] && [[ ! -f $config_dir/err_populate_db.flag ]] ; then + . docker_exec_qgis.sh + fi fi \ No newline at end of file diff --git a/gui/qgis-xtopo-gui.py b/gui/qgis-xtopo-gui.py index c68500f..2dba9d9 100755 --- a/gui/qgis-xtopo-gui.py +++ b/gui/qgis-xtopo-gui.py @@ -300,8 +300,24 @@ def main(): i = 0 while True: event, values = window.read(timeout=300) + config_dir = values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + populate_db_flag_path = config_dir + slash_str + "err_populate_db.flag" + prepare_data_flag_path = config_dir + slash_str + "err_populate_db.flag" + if os.name == "nt": + if os.path.isfile(populate_db_flag_path): + raise_docker_errors(populate_db_flag_path, '') + try: + os.remove(populate_db_flag_path) + except Exception: + print("Error removing " + populate_db_flag_path) + if os.path.isfile(prepare_data_flag_path): + raise_docker_errors('', prepare_data_flag_path) + try: + os.remove(prepare_data_flag_path) + except Exception: + print("Error removing " + prepare_data_flag_path) if i == 0: - config_dir = values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + if docker_installed: print(translations.get("pulling_image", "Pulling image from DockerHub")) runCommand(cmd="docker pull " + remote_repo_name, window=window) @@ -319,6 +335,11 @@ def main(): update_free_text_color(values) i += 1 if event in (sg.WIN_CLOSED, 'exit'): + try: + os.remove(values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + slash_str + "err_populate_db.flag") + os.remove(values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + slash_str + "err_prepare_data.flag") + except Exception: + pass break if timer_running: @@ -464,6 +485,7 @@ def main(): terminal_command_params_list = get_terminal_command_params_list( 'docker exec -it --user user qgis-xtopo /app/populate_db.sh', '', True) subprocess.Popen(terminal_command_params_list).wait() + raise_docker_errors(populate_db_flag_path, '') else: if os.name == "nt": subprocess.Popen( @@ -477,6 +499,7 @@ def main(): terminal_command_params_list = get_terminal_command_params_list( 'docker exec -it --user user qgis-xtopo /app/prepare_data.sh', '', True) subprocess.Popen(terminal_command_params_list).wait() + raise_docker_errors('', prepare_data_flag_path) else: if os.name == "nt": subprocess.Popen( @@ -681,7 +704,7 @@ def start(values, run_chain): sg.Popup(translations.get('bounding_box_too_large', 'Bounding box is too large. Creating a map will take a ' 'long time'), title=translations.get('warning', 'Warning')) - init_docker(run_chain) + init_docker(run_chain, values) config = values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + slash_str + "config.ini" if values['terrain_src_dir']: for v in range(0, 5): @@ -703,10 +726,12 @@ def start(values, run_chain): file.write(filedata) -def init_docker(run_chain): +def init_docker(run_chain, values): if docker_installed: if "qgis-xtopo" in str( subprocess.check_output(['docker', 'ps'], stdin=subprocess.PIPE, stderr=subprocess.STDOUT)): + populate_db_flag_path = values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + slash_str + "err_populate_db.flag" + prepare_data_flag_path = values["qgis_projects_dir"] + slash_str + "qgisxtopo-config" + slash_str + "err_prepare_data.flag" if os.name == "posix": run_chain_filename = '' if run_chain: @@ -718,8 +743,11 @@ def init_docker(run_chain): f = open(run_chain_filename, "w+") f.write("#!/bin/bash\n") f.write("docker exec --user user qgis-xtopo /app/init_docker.sh\n") + f.write("if [[ ! -f " + populate_db_flag_path + " ]] && [[ ! -f " + prepare_data_flag_path + " ]] ; " + "then\n") f.write("xhost +local:docker\n") f.write("docker exec -it --user user qgis-xtopo /app/exec_qgis.sh\n") + f.write("fi\n") f.close() os.chmod(run_chain_filename, 0o755) terminal_command_params_list = get_terminal_command_params_list( @@ -729,15 +757,63 @@ def init_docker(run_chain): os.remove(run_chain_filename) except OSError: pass + raise_docker_errors(populate_db_flag_path, prepare_data_flag_path) else: if os.name == "nt": subprocess.Popen( ['cmd', '/c start /wait cmd /c docker exec --user user qgis-xtopo /app/init_docker.sh'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT).wait() - if run_chain: + if run_chain and (not os.path.isfile(populate_db_flag_path) and not os.path.isfile(prepare_data_flag_path)): run_qgis() +def raise_docker_errors(populate_db_flag_path, prepare_data_flag_path): + if os.path.isfile(populate_db_flag_path): + f = open(populate_db_flag_path, "r") + populate_db_error_code = f.read(1) + if populate_db_error_code: + if int(populate_db_error_code) == 1: + sg.Popup(translations.get('cropped_extract_is_empty_error', 'Cropped extract is empty. Check that bounding box matches the OSM data area.'), title=translations.get('error', 'Error')) + else: + sg.Popup(translations.get('populating_db_error', 'Error populating Overpass database'), title=translations.get('error', 'Error')) + if os.name == "posix": + try: + os.remove(populate_db_flag_path) + except Exception: + print("Error removing " + populate_db_flag_path) + if os.path.isfile(prepare_data_flag_path): + f = open(prepare_data_flag_path, "r") + prepare_data_error_code = f.read(1) + if prepare_data_error_code: + if int(prepare_data_error_code) == 1: + sg.Popup(translations.get('osmtogeojson_error', 'osmtogeojson error. Try reducing bbox.'), title=translations.get('error', 'Error')) + else: + if int(prepare_data_error_code) == 2: + sg.Popup(translations.get('vector_data_incomplete_error', 'Vector data is incomplete. It looks ' + 'like overpass server has interrupted ' + 'the transmission. Try again or use ' + 'another Overpass instance or Overpass ' + 'server inside docker.'), + title=translations.get('error', 'Error')) + else: + if int(prepare_data_error_code) == 3: + sg.Popup(translations.get('overpass_server_error', + 'Overpass server error. Try again or use another Overpass instance ' + 'or Overpass server inside docker.'), + title=translations.get('error', 'Error')) + if int(prepare_data_error_code) == 4: + sg.Popup(translations.get('terrain_data_not_found_error', + 'Terrain data not found. Check that terrain covered area matches bounding box.'), + title=translations.get('error', 'Error')) + else: + sg.Popup(translations.get('data_preparation_error', 'Data preparation error. Check parameters.'), title=translations.get('error', 'Error')) + if os.name == "posix": + try: + os.remove(prepare_data_flag_path) + except Exception: + print("Error removing " + prepare_data_flag_path) + + def get_terminal_command_params_list(cmd, run_chain_filename, hold): get_terminal_name() terminal_command_params_list = [] @@ -1022,7 +1098,7 @@ def init_config(path, values): params += get_working_repo_name() command = command_to_run + params runCommand(cmd=command, window=window) - init_docker(False) + init_docker(False, values) # start(values, False) diff --git a/gui/translations_en.txt b/gui/translations_en.txt index 1c28a1e..2b70743 100644 --- a/gui/translations_en.txt +++ b/gui/translations_en.txt @@ -85,4 +85,11 @@ or_use_external_overpass_instance=or use external Overpass instance. bounding_box_too_large=Bounding box is too large. Creating a map will take a long time. terrain_input_dir_empty_error=You have selected "Download terrain manually" but terrain directory is empty. Download the data and place it in the following directory. invalid_overpass_endpoint_external_error=Invalid Overpass external endpoint -qgis_projects_dir_not_writable=QGIS projects directory is not writable. Choose another directory. \ No newline at end of file +qgis_projects_dir_not_writable=QGIS projects directory is not writable. Choose another directory. +cropped_extract_is_empty_error=Cropped extract is empty. Check that bounding box matches the OSM data area. +populating_db_error=Error populating Overpass database +osmtogeojson_error=osmtogeojson error. Try reducing bbox. +data_preparation_error=Data preparation error. Check parameters. +vector_data_incomplete_error=Vector data is incomplete. It looks like Overpass server has interrupted the transmission. Try again or use another instance. +overpass_server_error=Overpass server error. Try again or use another instance. +terrain_data_not_found_error=Terrain data not found. Check that terrain covered area matches bounding box. \ No newline at end of file diff --git a/gui/translations_ru.txt b/gui/translations_ru.txt index 8032045..ce6e34e 100644 --- a/gui/translations_ru.txt +++ b/gui/translations_ru.txt @@ -85,4 +85,11 @@ or_use_external_overpass_instance=или используйте внешний O bounding_box_too_large=Границы зоны охвата слишком широки. Создание карты займёт много времени. terrain_input_dir_empty_error=Вы выбрали "Cкачать рельеф вручную" но каталог с рельефом пуст. Скачайте данные и поместите их в следующий каталог. invalid_overpass_endpoint_external_error=Ошибка в адресе внешнего сервера Overpass -qgis_projects_dir_not_writable=Не могу записать в каталог проектов QGIS. Выберите другой каталог. \ No newline at end of file +qgis_projects_dir_not_writable=Не могу записать в каталог проектов QGIS. Выберите другой каталог. +cropped_extract_is_empty_error=Усечённый экстракт пуст. Проверьте что зона охвата находится внутри области, покрываемой данными OSM. +populating_db_error=Ошибка заполнения базы данных Overpass +osmtogeojson_error=Ошибка конвертации OSM в GeoJSON. Попробуйте уменьшить зону охвата. +data_preparation_error=Ошибка подготовки данных. Проверьте параметры. +vector_data_incomplete_error=Векторные данные неполные. Похоже что сервер Overpass прервал передачу. Попробуйте снова или используйте другой сервер. +overpass_server_error=Ошибка сервера Overpass. Попробуйте снова или используйте другой сервер. +terrain_data_not_found_error=Данные рельефа не найдены. Проверьте что область, покрываемая ими, входит в зону охвата. \ No newline at end of file diff --git a/init_docker.sh b/init_docker.sh index bdbdcdc..4c75e61 100755 --- a/init_docker.sh +++ b/init_docker.sh @@ -96,9 +96,13 @@ if [[ ! -f "$project_dir/$project_name.qgz" ]] ; then else echo -e "\033[93mQGIS project '"$project_dir/$project_name.qgz"' already exists. Usually it's ok.\033[0m" fi +rm -f $config_dir/err_populate_db.flag +rm -f $config_dir/err_prepare_data.flag if [[ $RUN_CHAIN == true ]] ; then if [[ $OVERPASS_INSTANCE == docker ]] ; then . /app/populate_db.sh fi - . /app/prepare_data.sh + if [[ ! -f $config_dir/err_populate_db.flag ]] ; then + . /app/prepare_data.sh + fi fi \ No newline at end of file diff --git a/populate_db.sh b/populate_db.sh index 3c50fd5..bf204f8 100755 --- a/populate_db.sh +++ b/populate_db.sh @@ -1,8 +1,18 @@ #!/bin/bash # Populate Overpass DB from local sources in osm_data_dir config_dir=/mnt/qgis_projects/qgisxtopo-config +err_flag_name=err_populate_db.flag +rm -f $config_dir/$err_flag_name + +function make_error_flag { + touch $config_dir/$err_flag_name + if [[ $1 ]] ; then + echo $1 > $config_dir/$err_flag_name + fi +} + if [[ ! -f /.dockerenv ]] ; then - echo -e "\033[91mThis script is not meant to run outside the docker container. Stopping.\033[0m" && exit 1; + echo -e "\033[91mThis script is not meant to run outside the docker container. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ -f $config_dir/config.ini ]] ; then . $config_dir/config.ini @@ -10,7 +20,7 @@ if [[ -f $config_dir/config.ini ]] ; then . $config_dir/set_dirs.ini fi else - echo -e "\033[91mconfig.ini not found. Check project installation integrity. Stopping.\033[0m" && exit 1; + echo -e "\033[91mconfig.ini not found. Check project installation integrity. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ -f $config_dir/config_debug.ini ]] ; then . $config_dir/config_debug.ini @@ -19,7 +29,7 @@ fi overpass_db_dir=$qgis_projects_dir/overpass_db osm_tmp_dir=$osm_data_dir/tmp if [[ ! -d $osm_data_dir ]] ; then - echo -e "\033[91mosm_data_dir in project_dir does not exist. Stopping.\033[0m" && exit 1; + echo -e "\033[91mosm_data_dir in project_dir does not exist. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ ! -d $osm_tmp_dir ]] ; then mkdir $osm_tmp_dir @@ -67,7 +77,7 @@ function merge_populate { echo -e "\e[104mCropping extract by bbox $bbox\033[0m" osmconvert -b=$bbox --complex-ways --complete-ways $osm_tmp_dir/input.pbf --out-osm | lbzip2 > $osm_tmp_dir/input.osm.bz2 if [[ $(wc -c <"$osm_tmp_dir/input.osm.bz2") -le 400 ]] ; then - echo -e "\033[91mError. Cropped extract is empty. Check that bbox parameter matches the OSM data area or turn off 'overpass_endpoint_docker_use_bbox' option.\033[0m" && exit 1; + echo -e "\033[91mError. Cropped extract is empty. Check that bbox parameter matches the OSM data area or turn off 'overpass_endpoint_docker_use_bbox' option.\033[0m" && make_error_flag 1 && exit 1; fi else osmium cat $pbf_str $osm_str $osmbz2_str $o5m_str -o $osm_tmp_dir/input_tmp.pbf -f pbf @@ -86,10 +96,10 @@ function merge_populate { rm -f $osm_data_dir/*.osm rm -f $osm_data_dir/*.osm.bz2 else - echo -e "\033[91mError populating Overpass database\033[0m" && exit 1; + echo -e "\033[91mError populating Overpass database\033[0m" && make_error_flag 2 && exit 1; fi else - echo -e "\033[91mError. No OSM data files found in $osm_data_dir.\033[0m" && exit 1; + echo -e "\033[91mError. No OSM data files found in $osm_data_dir.\033[0m" && make_error_flag && exit 1; fi } diff --git a/prepare_data.sh b/prepare_data.sh index d2e9665..c99b16b 100755 --- a/prepare_data.sh +++ b/prepare_data.sh @@ -39,7 +39,14 @@ else . $qgisxtopo_config_dir/config_debug.ini fi fi - +err_flag_name=err_prepare_data.flag +rm -f $err_flag_name +function make_error_flag { + touch $config_dir/$err_flag_name + if [[ $1 ]] ; then + echo $1 > $config_dir/$err_flag_name + fi +} echo -e "\e[105mProject dir: $project_dir\e[49m" if [[ $running_in_container == true ]] ; then echo -e "\e[100mRunning in docker\e[49m" @@ -48,26 +55,26 @@ echo -e "\e[100mconfig: $qgisxtopo_config_dir/config.ini\e[49m" echo -e "\e[100mterrain dir: $terrain_src_dir\e[49m" if [[ "$project_name" == "" ]] ; then - echo -e "\033[91mproject_name not defined. Please define it in config.ini. Stopping.\033[0m" && exit 1; + echo -e "\033[91mproject_name not defined. Please define it in config.ini. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ ! -d "$project_dir" ]] && [[ $running_in_container == true ]] ; then - echo -e "\033[91mproject_dir $project_dir not found. Please check config.ini (project_name and project_dir variables) and directory itself. Also executing of initialization script (docker_run) can solve this. Stopping.\033[0m" && exit 1; + echo -e "\033[91mproject_dir $project_dir not found. Please check config.ini (project_name and project_dir variables) and directory itself. Also executing of initialization script (docker_run) can solve this. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ ! -d "$project_dir" ]] && [[ $running_in_container == false ]] ; then - echo -e "\033[91mproject_dir $project_dir not found. Please check config.ini (project_name and project_dir variables) and directory itself. Stopping.\033[0m" && exit 1; + echo -e "\033[91mproject_dir $project_dir not found. Please check config.ini (project_name and project_dir variables) and directory itself. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ ! -f "$project_dir/$project_name.qgz" ]] ; then echo -e "\033[93m$project_dir/$project_name.qgz not found. Run docker_run to regenerate it.\033[0m" fi if [[ $get_terrain_tiles == "true" ]] && [[ $download_terrain_tiles == "true" ]] ; then - echo -e "\033[91mget_terrain_tiles and download_terrain_tiles are incompatible with each other. Use only one of them. Check config.ini. Stopping.\033[0m" && exit 1; + echo -e "\033[91mget_terrain_tiles and download_terrain_tiles are incompatible with each other. Use only one of them. Check config.ini. Stopping.\033[0m" && make_error_flag && exit 1; fi case $overpass_instance in "docker") if [[ $running_in_container == true ]] ; then req_path_string="/app/osm-3s/bin/osm3s_query --quiet --db-dir=/mnt/qgis_projects/overpass_db" else - echo -e "\033[91moverpass_instance=docker can't be started outside of container. Please use overpass_instance=external/local/ssh. Stopping.\033[0m" && exit 1; + echo -e "\033[91moverpass_instance=docker can't be started outside of container. Please use overpass_instance=external/local/ssh. Stopping.\033[0m" && make_error_flag && exit 1; fi ;; "local") @@ -76,17 +83,17 @@ case $overpass_instance in if [[ -f "${array_bbox[0]}" ]] ; then req_path_string=$overpass_endpoint_local else - echo -e "\033[91m${array_bbox[0]} not found. Check overpass_endpoint_local. Stopping.\033[0m" && exit 1; + echo -e "\033[91m${array_bbox[0]} not found. Check overpass_endpoint_local. Stopping.\033[0m" && make_error_flag && exit 1; fi else - echo -e "\033[91moverpass_instance=local can't be started inside a container. Please use overpass_instance=external/docker/ssh. Stopping.\033[0m" && exit 1; + echo -e "\033[91moverpass_instance=local can't be started inside a container. Please use overpass_instance=external/docker/ssh. Stopping.\033[0m" && make_error_flag && exit 1; fi ;; "ssh") if [[ $running_in_container == false ]] ; then req_path_string="$overpass_endpoint_ssh --quiet" else - echo -e "\033[91moverpass_instance=ssh can't be started inside a container. Please use overpass_instance=docker/external/local. Stopping.\033[0m" && exit 1; + echo -e "\033[91moverpass_instance=ssh can't be started inside a container. Please use overpass_instance=docker/external/local. Stopping.\033[0m" && make_error_flag && exit 1; fi ;; esac @@ -114,15 +121,15 @@ rm -f $vector_data_dir/*.sqlite_tmp-journal bbox_query=$lat_min,$lon_min,$lat_max,$lon_max bbox_eio_query="$lon_min $lat_min $lon_max $lat_max" -command -v python3 >/dev/null 2>&1 || { echo >&2 -e "\033[91mpython3 is required but not installed.\033[0m" && exit 1;} -command -v osmtogeojson >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmtogeojson is required but not installed. Follow installation instructions at https://github.com/tyrasd/osmtogeojson\033[0m" && exit 1;} -command -v gdalwarp >/dev/null 2>&1 || { echo >&2 -e "\033[91mGDAL is required but not installed. If you are using Ubuntu please install 'gdal-bin' package.\033[0m" && exit 1;} -command -v grass >/dev/null 2>&1 || { echo >&2 -e "\033[91mGRASS > 7.0 is required but not installed.\033[0m" && exit 1;} -command -v osmfilter >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmfilter is required but not installed. If you are using Ubuntu please install 'osmctools' package.\033[0m" && exit 1;} -command -v osmconvert >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmconvert is required but not installed. If you are using Ubuntu please install 'osmctools' package.\033[0m" && exit 1;} -command -v osmium >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmium is required but not installed. If you are using Ubuntu please install 'osmium-tool' package.\033[0m" && exit 1;} -command -v jq >/dev/null 2>&1 || { echo >&2 -e "\033[91mjq is required but not installed. If you are using Ubuntu please install 'jq' package.\033[0m" && exit 1;} -command -v eio >/dev/null 2>&1 || { echo >&2 -e "\033[91meio is required but not installed. Please install python 'elevation' pip (https://github.com/bopen/elevation).\033[0m" && exit 1;} +command -v python3 >/dev/null 2>&1 || { echo >&2 -e "\033[91mpython3 is required but not installed.\033[0m" && make_error_flag && exit 1;} +command -v osmtogeojson >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmtogeojson is required but not installed. Follow installation instructions at https://github.com/tyrasd/osmtogeojson\033[0m" && make_error_flag && exit 1;} +command -v gdalwarp >/dev/null 2>&1 || { echo >&2 -e "\033[91mGDAL is required but not installed. If you are using Ubuntu please install 'gdal-bin' package.\033[0m" && make_error_flag && exit 1;} +command -v grass >/dev/null 2>&1 || { echo >&2 -e "\033[91mGRASS > 7.0 is required but not installed.\033[0m" && make_error_flag && exit 1;} +command -v osmfilter >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmfilter is required but not installed. If you are using Ubuntu please install 'osmctools' package.\033[0m" && make_error_flag && exit 1;} +command -v osmconvert >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmconvert is required but not installed. If you are using Ubuntu please install 'osmctools' package.\033[0m" && make_error_flag && exit 1;} +command -v osmium >/dev/null 2>&1 || { echo >&2 -e "\033[91mosmium is required but not installed. If you are using Ubuntu please install 'osmium-tool' package.\033[0m" && make_error_flag && exit 1;} +command -v jq >/dev/null 2>&1 || { echo >&2 -e "\033[91mjq is required but not installed. If you are using Ubuntu please install 'jq' package.\033[0m" && make_error_flag && exit 1;} +command -v eio >/dev/null 2>&1 || { echo >&2 -e "\033[91meio is required but not installed. Please install python 'elevation' pip (https://github.com/bopen/elevation).\033[0m" && make_error_flag && exit 1;} function run_alg_linestopolygons { case $2 in @@ -147,7 +154,7 @@ function osmtogeojson_wrapper { node --max_old_space_size=$node_mem `which osmtogeojson` $1 > $2 if [[ $? != 0 ]] ; then echo $? - echo -e "\033[91mosmtogeojson error. Try reducing bbox.\033[0m" && exit 1; + echo -e "\033[91mosmtogeojson error. Try reducing bbox.\033[0m" && make_error_flag 1 && exit 1; fi } function convert2spatialite { @@ -188,11 +195,11 @@ if [[ $generate_terrain == "true" ]] ; then echo -e "\e[104m=== Downloading terrain tiles...\e[49m" eio clip -o $terrain_input_dir/srtm.tif --bounds $bbox_eio_query if [[ $? != 0 ]] ; then - echo -e "\033[91mError downloading terrain. Stopping.\033[0m" && exit 1; + echo -e "\033[91mError downloading terrain. Stopping.\033[0m" && make_error_flag && exit 1; elif [[ $(gdalinfo $terrain_input_dir/srtm.tif | grep "Band 1") ]] ; then echo -e "\033[92mTerrain downloaded\033[0m" else - echo -e "\033[91mError downloading terrain. Stopping.\033[0m" && exit 1; + echo -e "\033[91mError downloading terrain. Stopping.\033[0m" && make_error_flag && exit 1; fi eio clean fi @@ -200,13 +207,14 @@ if [[ $generate_terrain == "true" ]] ; then rm -f $terrain_input_dir/*.* echo -e "\e[104m=== Copying DEM tiles from $terrain_src_dir...\e[49m" if [[ $terrain_src_dir == "" ]] ; then - echo -e "\033[91mterrain_src_dir "$terrain_src_dir" not defined in config but get_terrain_tiles=true. Stopping.\033[0m" && exit 1; + echo -e "\033[91mterrain_src_dir "$terrain_src_dir" not defined in config but get_terrain_tiles=true. Stopping.\033[0m" && make_error_flag && exit 1; fi if [[ ! -d $terrain_src_dir ]] ; then echo -e "\033[91mterrain_src_dir "$terrain_src_dir" don't exist but get_terrain_tiles=true. Turn it off or check path. Stopping.\033[0m" if [[ $running_in_container == true ]] ; then echo -e "\033[93mCheck /mnt/terrain docker mount\033[0m" fi + make_error_flag exit 1; fi for tile in "${tiles_list[@]}" @@ -250,7 +258,7 @@ if [[ $generate_terrain == "true" ]] ; then [ -e "$f" ] && gdalwarp -of GTiff $f ${f%.*}.tif && rm $f done for f in "$terrain_input_dir"/*.tif; do - [ ! -e "$f" ] && echo -e "\033[91mNo DEM tiles (GeoTIFF/HGT) found in "$terrain_input_dir". Stopping.\033[0m" && exit 1; + [ ! -e "$f" ] && echo -e "\033[91mNo DEM tiles (GeoTIFF/HGT) found in "$terrain_input_dir". Stopping.\033[0m" && make_error_flag && exit 1; break; done shopt -u nullglob @@ -282,7 +290,7 @@ if [[ $generate_terrain == "true" ]] ; then gdaladdo -ro --config COMPRESS_OVERVIEW LZW "$raster_data_dir/slope_upscaled.tif" 512 256 128 64 32 16 8 4 2 echo -e "\033[92mSlopes generated\033[0m" else - echo -e "\033[91mError. $raster_data_dir/slope_upscaled.tif is empty. Stopping.\033[0m" && exit 1; + echo -e "\033[91mError. $raster_data_dir/slope_upscaled.tif is empty. Stopping.\033[0m" && make_error_flag && exit 1; fi rm -f "$raster_data_dir"/slope.tif rm -f "$raster_data_dir"/slope_cut.tif @@ -345,9 +353,10 @@ if [[ $generate_terrain == "true" ]] ; then fi fi else - echo -e "\033[93mWarning! No DEM data found. Hillshade, slopes and isolines are not generated.\033[0m" + echo -e "\033[93mError. No DEM data found. Hillshade, slopes and isolines are not generated.\033[0m" echo -e "\033[93mCheck download_terrain_tiles=true or get_terrain_tiles=true options in config.ini\033[0m" - exit 1; + make_error_flag 4 + exit 1 fi if [[ $download_terrain_tiles == "true" ]] ; then rm -f $terrain_input_dir/*.* @@ -817,7 +826,7 @@ for t in ${array_queries[@]}; do echo "$req_string" | $req_path_string > $vector_data_dir/$t.osm fi if [[ $? != 0 ]] ; then - echo -e "\033[91mOverpass server error. Stopping.\033[0m" && exit 1; + echo -e "\033[91mOverpass server error. Stopping.\033[0m" && make_error_flag 3 && exit 1; fi if ! grep -q "tag k" "$vector_data_dir/$t.osm" || ( ( [[ $t == "admin_level_2" ]] || [[ $t == "admin_level_4" ]] ) && ! grep -q "way id" "$vector_data_dir/$t.osm" ); then echo -e "\033[93mResult is empty!\033[0m" @@ -827,7 +836,7 @@ for t in ${array_queries[@]}; do if [[ -f "$override_dir/$t.osm" ]] ; then cp $override_dir/$t.osm $vector_data_dir/$t.osm else - echo -e "\033[91m$override_dir/$t.osm not found. Stopping.\033[0m" && exit 1; + echo -e "\033[91m$override_dir/$t.osm not found. Stopping.\033[0m" && make_error_flag && exit 1; fi else ((index++)) @@ -838,7 +847,7 @@ for t in ${array_queries[@]}; do if grep -q \ "$vector_data_dir/$t.osm" ; then echo -e "\033[92mOK\033[0m" else - echo -e "\033[91m$vector_data_dir/$t.osm is incomplete. It looks like overpass server has interrupted the transmission. Try again or use another server (overpass_instance and overpass_endpoint_* variables in config.ini). Stopping.\033[0m" && exit 1; + echo -e "\033[91m$vector_data_dir/$t.osm is incomplete. It looks like Overpass server has interrupted the transmission. Try again or use another server (overpass_instance and overpass_endpoint_* variables in config.ini). Stopping.\033[0m" && make_error_flag 2 && exit 1; fi case $t in @@ -990,7 +999,7 @@ for t in ${array_queries[@]}; do if [[ -f $vector_data_dir/places_main.geojson ]] ; then cp $vector_data_dir/places_main.geojson $temp_dir else - echo -e "\033[91m$vector_data_dir/places_main.geojson not found. Please request places_main before $t. Stopping.\033[0m" && exit 1; + echo -e "\033[91m$vector_data_dir/places_main.geojson not found. Please request places_main before $t. Stopping.\033[0m" && make_error_flag && exit 1; fi run_alg_joinattributesbylocation places_main ${t}_pyfieldcalc 2 "admin_centre_${t: -1}" 0 cp -f $temp_dir/places_main_joinattrsloc.geojson $vector_data_dir/places_main.geojson @@ -1332,7 +1341,7 @@ for t in ${array_queries[@]}; do osmfilter $vector_data_dir/$t.osm --keep-ways-relations="layer<0" -o=$vector_data_dir/${t}_layer_-1.osm osmfilter $vector_data_dir/$t.osm --drop-ways-relations="layer>0 or layer<0" -o=$vector_data_dir/${t}_new.osm && rm -f $vector_data_dir/$t.osm && mv $vector_data_dir/${t}_new.osm $vector_data_dir/$t.osm if [[ $? == 139 ]] ; then - echo -e "\033[91mSegmentation fault\033[0m" && exit 1; + echo -e "\033[91mSegmentation fault\033[0m" && make_error_flag && exit 1; fi osmtogeojson_wrapper $vector_data_dir/$t.osm $vector_data_dir/$t.geojson osmtogeojson_wrapper $vector_data_dir/${t}_layer_1.osm $vector_data_dir/${t}_layer_1.geojson @@ -1362,7 +1371,7 @@ done # Following code is needed to split glacier isolines if [[ $generate_terrain == "true" ]] && [[ $generate_terrain_isolines == "true" ]]; then if [[ ! -f $vector_data_dir/isolines_full.sqlite ]] ; then - echo -e "\033[91m$vector_data_dir/isolines_full.sqlite not found\033[0m" && exit 1; + echo -e "\033[91m$vector_data_dir/isolines_full.sqlite not found\033[0m" && make_error_flag && exit 1; fi rm -f "$vector_data_dir/isolines_glacier.sqlite" # if [[ -f "$vector_data_dir/water.sqlite" ]] && [[ $(stat --printf="%s" "$vector_data_dir/water.sqlite") -ge 70 ]] ; then @@ -1412,7 +1421,7 @@ if [[ -f "$qgis_projects_dir/$project_name/$project_name.qgz" ]] ; then if [[ $(wc -c <${project_name}_tmp.qgz) -ge 8000000 ]] ; then mv -f ${project_name}_tmp.qgz $project_name.qgz else - echo -e "\033[91mError replacing project extent by bbox\033[0m" && exit 1; + echo -e "\033[91mError replacing project extent by bbox\033[0m" && make_error_flag && exit 1; fi fi diff --git a/test.py b/test.py new file mode 100644 index 0000000..0a19ce9 --- /dev/null +++ b/test.py @@ -0,0 +1,5 @@ +import time +starttime = time.time() +while True: + print("tick") + time.sleep( 1 - ((time.time() - starttime) % 1)) \ No newline at end of file