From a8106995fa315a239d6901e16cf440904f4e8529 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 28 Feb 2023 10:04:41 +0100 Subject: [PATCH] init --- clone_for_markdown.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 clone_for_markdown.py diff --git a/clone_for_markdown.py b/clone_for_markdown.py new file mode 100644 index 0000000..2d11d03 --- /dev/null +++ b/clone_for_markdown.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +""" +Python script to parse, clone and return a repo for gitea +in order for asciidoctor to be able to access included files + +Doesn't overwrite folder if it already exists, will still return that folder name in that case. + +Parameters : +in : a relative path as given by GITEA_PREFIX_SRC (https://docs.gitea.io/en-us/config-cheat-sheet/#markup-markup) +return : The name of the folder containing the cloned repo +""" + +#PATH_PREFIX = "/var/lib/gitea/git/repositories" +PATH_PREFIX = ".." + +import sys +import subprocess +import os + +if(len(sys.argv) != 2): + sys.exit("wrong number of args") # wrong number of args + +repo_path = sys.argv[1].split('/',3) +if(len(repo_path)<2): + sys.exit("Wrong path format passed") + +repo_name = repo_path[2] +repo_path = "/".join(repo_path[:3]) +repo_path = PATH_PREFIX + repo_path + +if not os.path.isdir(repo_name): + subprocess.run(["git", "clone", repo_path, repo_name], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + +print(repo_name) \ No newline at end of file