diff --git a/scripts/g.extension/g.extension.py b/scripts/g.extension/g.extension.py index d72d6a6075b..8e1be707c9b 100644 --- a/scripts/g.extension/g.extension.py +++ b/scripts/g.extension/g.extension.py @@ -144,7 +144,6 @@ # TODO: solve addon-extension(-module) confusion import fileinput -import http import os import codecs import sys @@ -188,7 +187,6 @@ HEADERS = { "User-Agent": "Mozilla/5.0", } -HTTP_STATUS_CODES = list(http.HTTPStatus) GIT_URL = "https://github.com/OSGeo/grass-addons/" # MAKE command @@ -258,7 +256,7 @@ def _get_version(self): git_version, stderr = git_version.communicate() if stderr: gs.fatal( - _("Failed to get Git version.\n{error}").format( + _("Failed to get Git version.\n{}").format( gs.decode(stderr), ) ) @@ -504,23 +502,27 @@ def get_version_branch(major_version): if not, take branch for the previous version For the official repo we assume that at least one version branch is present""" version_branch = f"grass{major_version}" - branch = gs.Popen( - ["git", "ls-remote", "--heads", GIT_URL, f"refs/heads/{version_branch}"], - stdout=PIPE, - stderr=PIPE, - ) - branch, stderr = branch.communicate() - if stderr: - gs.fatal( - _( - "Failed to get branch from the Git repository <{repo_path}>.\n" - "{error}" - ).format( - repo_path=GIT_URL, - error=gs.decode(stderr), - ) + if sys.platform == "win32": + return version_branch + else: + branch = gs.Popen( + ["git", "ls-remote", "--heads", GIT_URL, f"refs/heads/{version_branch}"], + stdout=PIPE, + stderr=PIPE, ) - if version_branch not in gs.decode(branch): + branch, stderr = branch.communicate() + if stderr: + gs.fatal( + _( + "Failed to get branch from the Git repository <{repo_path}>.\n" + "{error}" + ).format( + repo_path=GIT_URL, + error=gs.decode(stderr), + ) + ) + branch = gs.decode(branch) + if version_branch not in branch: version_branch = "grass{}".format(int(major_version) - 1) return version_branch @@ -1147,7 +1149,7 @@ def write_xml_toolboxes(name, tree=None): file_.close() -def install_extension(source, url, xmlurl, branch): +def install_extension(source=None, url=None, xmlurl=None, branch=None): """Install extension (e.g. one module) or a toolbox (list of modules)""" gisbase = os.getenv("GISBASE") if not gisbase: @@ -1514,11 +1516,12 @@ def install_module_xml(mlist): # read XML file tree = etree_fromfile(xml_file) - # Filter multi-addon addons - if len(mlist) > 1: - mlist = filter_multi_addon_addons( - mlist.copy() - ) # mlist.copy() keep the original list of add-ons + if sys.platform != "win32": + # Filter multi-addon addons + if len(mlist) > 1: + mlist = filter_multi_addon_addons( + mlist.copy() + ) # mlist.copy() keep the original list of add-ons # update tree for name in mlist: @@ -2412,11 +2415,12 @@ def update_manual_page(module): # find URIs pattern = r"""([^>]+)""" 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) + if sys.platform != "win32": + # 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": @@ -2825,17 +2829,23 @@ def main(): if options["operation"] == "add": check_dirs() - if original_url == "" or flags["o"]: - """ - Query GitHub API only if extension will be downloaded - from official GRASS GIS addon repository - """ - get_addons_paths(gg_addons_base_dir=options["prefix"]) - source, url = resolve_source_code( - name=options["extension"], url=original_url, branch=branch, fork=flags["o"] - ) - xmlurl = resolve_xmlurl_prefix(original_url, source=source) - install_extension(source=source, url=url, xmlurl=xmlurl, branch=branch) + if sys.platform == "win32": + install_extension() + else: + if original_url == "" or flags["o"]: + """ + Query GitHub API only if extension will be downloaded + from official GRASS GIS addon repository + """ + get_addons_paths(gg_addons_base_dir=options["prefix"]) + source, url = resolve_source_code( + name=options["extension"], + url=original_url, + branch=branch, + fork=flags["o"], + ) + xmlurl = resolve_xmlurl_prefix(original_url, source=source) + install_extension(source=source, url=url, xmlurl=xmlurl, branch=branch) else: # remove remove_extension(force=flags["f"])