diff options
Diffstat (limited to 'git-gmi')
-rw-r--r-- | git-gmi/gateway.py | 6 | ||||
-rw-r--r-- | git-gmi/git.py | 6 |
2 files changed, 10 insertions, 2 deletions
diff --git a/git-gmi/gateway.py b/git-gmi/gateway.py index f8c4601..bb7f2e0 100644 --- a/git-gmi/gateway.py +++ b/git-gmi/gateway.py @@ -9,7 +9,8 @@ from os import environ, listdir def handle_cgi_request(path: str, query: str): # intended to work with Jetforce. - # url: gemini://git.gemini.site/cgi-bin/cgi.py/repo/src/static/css/[index.css] + # hypothetical example: + # url: gemini://git.gemini.site/git/cgi/repo/src/static/css/[index.css] # path: /repo/src/static/css/[index.css] # path_trace = ['repo', 'src', 'static', 'css', 'index.css'] path_trace = path[1:].split("/") @@ -29,6 +30,7 @@ def handle_cgi_request(path: str, query: str): if len(path_trace) > 1: view = path_trace[1] # e.g. summary, tree, log else: + # gemini://git.gemini.site/git/cgi/<repo>/ print("31 summary") return @@ -42,10 +44,12 @@ def handle_cgi_request(path: str, query: str): elif view == "tree": if len(path_trace) == 2: + # gemini://git.gemini.site/git/cgi/<repo>/tree/ print(f"31 {MAIN_BRANCH}/") return if len(path_trace) > 2: + # gemini://git.gemini.site/git/cgi/<repo>/tree/<branch>/ branch = path_trace[2] location = path_trace[3:] diff --git a/git-gmi/git.py b/git-gmi/git.py index 79a59c4..52764d2 100644 --- a/git-gmi/git.py +++ b/git-gmi/git.py @@ -10,6 +10,7 @@ mimetypes.add_type("text/gemini", ".gemini") def convert_filesize(bytes: int) -> str: + # convert filesize in bytes to a human-friendly format return size(bytes, system=alternative) @@ -23,6 +24,7 @@ class GitGmiRepo: raise FileNotFoundError(f"Error: no such repo: {name}") def generate_header(self): + # global "header" to display above all views (except raw files) header = ( f"# {self.name}\n" f"=> {CGI_PATH} {GIT_GMI_SITE_TITLE}\n" @@ -62,7 +64,7 @@ class GitGmiRepo: return response def get_commit_log(self) -> list: - # returns the commit log in a human-readable way. + # returns useful info from commit log. repo = self.repo commits = list(repo.walk(repo[repo.head.target].id, GIT_SORT_TIME)) log = [ @@ -82,6 +84,7 @@ class GitGmiRepo: response = f"{STATUS_SUCCESS} {META_GEMINI}\n" + self.generate_header() log = self.get_commit_log() for cmt in log: + # looks like "2020-06-06 04:51:21 UTC" time = str(datetime.utcfromtimestamp(cmt["time"])) + " UTC" response += ( f"## {cmt['short_id']} - {cmt['author']} - {time}\n" @@ -199,6 +202,7 @@ class GitGmiRepo: def view_raw_blob(self, branch: str, location=[]) -> str: blob = self.get_blob(branch, location) + # if mimetypes can't make out the type, set it to plaintext guessed_mimetype = mimetypes.guess_type(blob.name)[0] or "text/plain" response = f"{STATUS_SUCCESS} {guessed_mimetype}\n" response += blob.data.decode("utf-8") |