|
@@ -23,6 +23,7 @@ import re
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
import locale
|
|
import locale
|
|
import json
|
|
import json
|
|
|
|
+import pathlib
|
|
|
|
|
|
try:
|
|
try:
|
|
# Python 2 import
|
|
# Python 2 import
|
|
@@ -288,28 +289,22 @@ def update_toc(data):
|
|
return "\n".join(ret_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")
|
|
addon_base = os.getenv("GRASS_ADDON_BASE")
|
|
if 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.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 = os.path.join(addon_base, "addons_paths.json")
|
|
if os.path.exists(addons_paths):
|
|
if os.path.exists(addons_paths):
|
|
- with open(addons_paths, "r") as f:
|
|
|
|
|
|
+ with open(addons_paths) as f:
|
|
addons_paths = json.load(f)
|
|
addons_paths = json.load(f)
|
|
for addon in addons_paths["tree"]:
|
|
for addon in addons_paths["tree"]:
|
|
- split_path = addon["path"].split("/")
|
|
|
|
- root_dir, module_dir = split_path[0], split_path[-1]
|
|
|
|
- if "grass8" == root_dir and pgm == module_dir:
|
|
|
|
- return True, addon["path"]
|
|
|
|
- return None, None
|
|
|
|
|
|
+ if pgm == pathlib.Path(addon["path"]).name:
|
|
|
|
+ return addon["path"]
|
|
|
|
|
|
|
|
|
|
# process header
|
|
# process header
|
|
@@ -437,38 +432,33 @@ else:
|
|
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])
|
|
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])
|
|
url_source = ""
|
|
url_source = ""
|
|
if os.getenv("SOURCE_URL", ""):
|
|
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
|
|
|
|
|
|
+ addon_path = get_addon_path()
|
|
|
|
+ if addon_path:
|
|
|
|
+ url_source = urlparse.urljoin(
|
|
|
|
+ os.environ["SOURCE_URL"].split("src")[0],
|
|
|
|
+ addon_path,
|
|
|
|
+ )
|
|
else:
|
|
else:
|
|
url_source = urlparse.urljoin(source_url, pgmdir)
|
|
url_source = urlparse.urljoin(source_url, pgmdir)
|
|
if sys.platform == "win32":
|
|
if sys.platform == "win32":
|
|
url_source = url_source.replace(os.path.sep, "/")
|
|
url_source = url_source.replace(os.path.sep, "/")
|
|
|
|
|
|
if index_name:
|
|
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(
|
|
sys.stdout.write(
|
|
sourcecode.substitute(
|
|
sourcecode.substitute(
|
|
- URL_SOURCE=url_source, PGM=pgm, URL_LOG=url_source.replace(tree, commits)
|
|
|
|
|
|
+ URL_SOURCE=url_source,
|
|
|
|
+ PGM=pgm,
|
|
|
|
+ URL_LOG=url_log,
|
|
)
|
|
)
|
|
)
|
|
)
|
|
sys.stdout.write(
|
|
sys.stdout.write(
|