Skip to content

Commit

Permalink
utils/mkhtml.py: fix get and set addon manual page source and history…
Browse files Browse the repository at this point in the history
… URL link (#1892)

During g.extension compile (make command) addon, SOURCE_URL (which is addon
URL for downloading) global variable is setted, e.g. for i.sentinel addon is
SOURCE_URL=https://github.com/OSGeo/grass-addons/branches/grass7/src/imagery/
i.sentinel.

mkhtml.py script is runned and handle SOURCE_URL.

Next is find addon (get_addon_path() function) in GRASS GIS GitHub official addon
repository and return addon path e.g. for i.sentinel.coverage is addon path
/src/imagery/i.sentinel/i.sentinel.coverage.

Create final URL e.g. for i.sentinel.coverage  url_source=https://github.com/OSGeo/
grass-addons/branches/grass7/src/imagery/i.sentinel/i.sentinel.coverage.

For addon source code URL e.g. i.sentinel.coverage replace in url_source var, branches
string with tree string https://github.com/OSGeo/grass-addons/tree/grass7/src/imagery/
i.sentinel/i.sentinel.coverage.

For addon source code history URL e.g. i.sentinel.coverage replace in url_source var,
branches string with commits string https://github.com/OSGeo/grass-addons/commits/
grass7/src/imagery/i.sentinel/i.sentinel.coverage.
  • Loading branch information
tmszi committed Dec 26, 2021
1 parent 24258bf commit c35c3a1
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions tools/mkhtml.py
Expand Up @@ -23,6 +23,7 @@
from datetime import datetime
import locale
import json
import pathlib

try:
# Python 2 import
Expand Down Expand Up @@ -266,28 +267,22 @@ def update_toc(data):
return '\n'.join(ret_data)


def get_addon_path(pgm):
"""Check if pgm is in addons list and get addon path
def get_addon_path():
"""Check if pgm is in the addons list and get addon path
:param pgm str: pgm
:return tuple: (True, path) if pgm is addon else (None, None)
return: pgm path if pgm is addon else None
"""
addon_base = os.getenv('GRASS_ADDON_BASE')
if addon_base:
"""'addons_paths.json' is file created during install extension
check get_addons_paths() function in the g.extension.py file
"""
addons_paths = os.path.join(addon_base, 'addons_paths.json')
# addons_paths.json is file created during install extension
# check get_addons_paths() function in the g.extension.py file
addons_paths = os.path.join(addon_base, "addons_paths.json")
if os.path.exists(addons_paths):
with open(addons_paths, 'r') as f:
with open(addons_paths) as f:
addons_paths = json.load(f)
for addon in addons_paths['tree']:
split_path = addon['path'].split('/')
root_dir, module_dir = split_path[0], split_path[-1]
if 'grass7' == root_dir and pgm == module_dir:
return True, addon['path']
return None, None
for addon in addons_paths["tree"]:
if pgm == pathlib.Path(addon["path"]).name:
return addon["path"]


# process header
Expand Down Expand Up @@ -411,40 +406,37 @@ def to_title(name):
# addons
source_url = addons_url
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])
url_source = ''
if os.getenv('SOURCE_URL', ''):
# addons
for prefix in index_names.keys():
cwd = os.getcwd()
idx = cwd.find('{0}{1}.'.format(os.path.sep, prefix))
if idx > -1:
pgmname = cwd[idx+1:]
classname = index_names[prefix]
url_source = urlparse.urljoin('{0}{1}/'.format(
os.environ['SOURCE_URL'], classname),
pgmname
)
break
url_source = ""
if os.getenv("SOURCE_URL", ""):
addon_path = get_addon_path()
if addon_path:
url_source = urlparse.urljoin(
os.environ["SOURCE_URL"].split("src")[0],
addon_path,
)
else:
url_source = urlparse.urljoin(source_url, pgmdir)
if sys.platform == 'win32':
url_source = url_source.replace(os.path.sep, '/')

if index_name:
tree = 'grass/tree'
commits = 'grass/commits'
is_addon, addon_path = get_addon_path(pgm=pgm)
if is_addon:
# Fix gui/wxpython addon url path
url_source = urlparse.urljoin(
os.environ['SOURCE_URL'], addon_path.split('/', 1)[1],
)
tree = 'grass-addons/tree'
commits = 'grass-addons/commits'
branches = "branches"
tree = "tree"
commits = "commits"

if branches in url_source:
url_log = url_source.replace(branches, commits)
url_source = url_source.replace(branches, tree)
else:
url_log = url_source.replace(tree, commits)

sys.stdout.write(sourcecode.substitute(
URL_SOURCE=url_source, PGM=pgm, URL_LOG=url_source.replace(
tree, commits)))
sys.stdout.write(
sourcecode.substitute(
URL_SOURCE=url_source,
PGM=pgm,
URL_LOG=url_log,
)
)
sys.stdout.write(
footer_index.substitute(
INDEXNAME=index_name,
Expand Down

0 comments on commit c35c3a1

Please sign in to comment.