diff options
author | Frederick Yin <fkfd@macaw.me> | 2020-06-19 22:46:41 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@macaw.me> | 2020-06-19 22:46:41 +0800 |
commit | 036159de2770b5ca9698474dd15fb63e04a51190 (patch) | |
tree | ad478b88eea833b021c7d65b1c910714837988a5 /git-gmi/git.py | |
parent | 121921ce0fe2403b2545de5fc678f18eaa824d79 (diff) |
Enhance comments
Diffstat (limited to 'git-gmi/git.py')
-rw-r--r-- | git-gmi/git.py | 6 |
1 files changed, 5 insertions, 1 deletions
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") |