From ebffe77c59fb8550fd4b26fd268f3e42717a0828 Mon Sep 17 00:00:00 2001 From: Markus Neteler Date: Sat, 1 Jan 2022 16:53:31 +0100 Subject: [PATCH] g.extension: catch missing modules.xml error (#2058) * g.extension: catch error missing modules.xml Print error message when https://grass.osgeo.org/addons/grass8/modules.xml is missing on server. So far this error appeared: ``` GRASS nc_spm_08_grass7/user1:grass_main > g.extension -l ... Fetching list of extensions from GRASS-Addons SVN repository (be patient)... https://grass.osgeo.org/addons/grass8/ Traceback (most recent call last): File "/home/mneteler/software/grass80/dist.x86_64-pc-linux-gnu/scripts/g.extension", line 682, in list_available_modules tree = etree_fromurl(file_url) File "/home/mneteler/software/grass80/dist.x86_64-pc-linux-gnu/scripts/g.extension", line 384, in etree_fromurl file_ = urlopen(url) ... File "/usr/lib64/python3.10/urllib/request.py", line 643, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 404: Not Found ... ``` With this PR: ``` GRASS nc_spm_08_grass7/user1:grass_main > g.extension -l /home/mneteler/software/grass80/dist.x86_64-pc-linux-gnu/scripts/g.extension:167: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives from distutils.dir_util import copy_tree List of available extensions (modules): ERROR: Download file from , failed. File not on server or check internet connection. ``` --- scripts/g.extension/g.extension.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/g.extension/g.extension.py b/scripts/g.extension/g.extension.py index cf715171e3c..357fc0cd82d 100644 --- a/scripts/g.extension/g.extension.py +++ b/scripts/g.extension/g.extension.py @@ -380,7 +380,18 @@ def etree_fromfile(filename): def etree_fromurl(url): """Create XML element tree from a given URL""" - file_ = urlopen(url) + try: + file_ = urlopen(url) + except URLError: + gscript.fatal( + _( + "Download file from <{url}>," + " failed. File is not on the server or" + " check your internet connection.".format( + url=url, + ), + ), + ) return etree.fromstring(file_.read())