Skip to content

Commit

Permalink
scripts/g.extension: fix link generation in multi-addon man page for …
Browse files Browse the repository at this point in the history
…addons (#2097)

When multi-addon contains addons which install only html manual page
and manual page contains link to these addon, link source URI is wrong
pointed to GISBASE directory e.g. i.sentinel.mask has "Overview of
i.sentinel toolset" link to the i.sentinel.html with wrong URI
"file:///usr/lib64/grass81/docs/html/i.sentinel.html". The correct URI link
path for the r.sentinel multi-addon html page should be "i.sentinel.html".

* Keep the GRASS GIS logo URI in the multi-addon manual page if it is a 
remote URL
  • Loading branch information
tmszi committed Jan 19, 2022
1 parent 33d95f7 commit 04e3de8
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions scripts/g.extension/g.extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,23 +1273,13 @@ def install_extension_xml(edict):
return None


def filter_multi_addon_addons(mlist):
"""Filter out list of multi-addon addons which contains
and installs only *.html manual page, without source/binary
excutable module and doesn't need to check metadata.
def get_multi_addon_addons_which_install_only_html_man_page():
"""Get multi-addon addons which install only manual html page
e.g. the i.sentinel multi-addon consists of several full i.sentinel.*
addons along with a i.sentinel.html overview file.
:param list mlist: list of multi-addons (groups of addons
with respective addon overview HTML pages)
:return list mlist: list of individual multi-addons without respective
addon overview HTML pages
:return list addons: list of multi-addon addons which install
only manual html page
"""
# Make a list of unique addons
mlist = list(set(mlist))
addons = []
all_addon_dirs = []
addon_dirs_with_source_module = [] # *.py, *.c file
addon_pattern = re.compile(r".*{}".format(options["extension"]))
Expand All @@ -1315,12 +1305,31 @@ def filter_multi_addon_addons(mlist):
# Add all addon dirs
all_addon_dirs.append(addon["path"])

for addon in set(all_addon_dirs) ^ set(addon_dirs_with_source_module):
addons.append(os.path.basename(addon))
return addons


def filter_multi_addon_addons(mlist):
"""Filter out list of multi-addon addons which contains
and installs only *.html manual page, without source/binary
excutable module and doesn't need to check metadata.
e.g. the i.sentinel multi-addon consists of several full i.sentinel.*
addons along with a i.sentinel.html overview file.
:param list mlist: list of multi-addons (groups of addons
with respective addon overview HTML pages)
:return list mlist: list of individual multi-addons without respective
addon overview HTML pages
"""
# Filters out add-ons that only contain the *.html man page,
# e.g. multi-addon i.sentinel (root directory) contains only
# the *.html manual page for installation, it does not need
# to check if metadata is available if there is no executable module.
for subaddon in set(all_addon_dirs) ^ set(addon_dirs_with_source_module):
addon = os.path.basename(subaddon)
for addon in get_multi_addon_addons_which_install_only_html_man_page():
if addon in mlist:
mlist.pop(mlist.index(addon))
return mlist
Expand All @@ -1342,7 +1351,9 @@ def install_module_xml(mlist):

# Filter multi-addon addons
if len(mlist) > 1:
mlist = filter_multi_addon_addons(mlist)
mlist = filter_multi_addon_addons(
mlist.copy()
) # mlist.copy() keep the original list of add-ons

# update tree
for name in mlist:
Expand Down Expand Up @@ -1786,7 +1797,8 @@ def install_extension_std_platforms(name, source, url, branch):
try:
modulename = line.split("=")[1].strip()
if modulename:
module_list.append(modulename)
if modulename not in module_list:
module_list.append(modulename)
else:
grass.fatal(pgm_not_found_message)
except IndexError:
Expand Down Expand Up @@ -2204,11 +2216,19 @@ def update_manual_page(module):
# fix logo URL
pattern = r'''<a href="([^"]+)"><img src="grass_logo.png"'''
for match in re.finditer(pattern, shtml):
if match.group(1)[:4] == "http":
continue
pos.append(match.start(1))

# find URIs
pattern = r"""<a href="([^"]+)">([^>]+)</a>"""
addons = get_installed_extensions(force=True)
# Multi-addon
if len(addons) > 1:
for a in get_multi_addon_addons_which_install_only_html_man_page():
# Add multi-addon addons which install only manual html page
addons.append(a)

for match in re.finditer(pattern, shtml):
if match.group(1)[:4] == "http":
continue
Expand Down

0 comments on commit 04e3de8

Please sign in to comment.