Implement refs() to list all branches and tags - stahg-gopher - Static Mercurial page generator for gopher HTML hg clone https://bitbucket.org/iamleot/stahg-gopher DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR changeset 1614c33a9710f589494b5916d530a0388afb2144 DIR parent 12d7dd66c5a3153b8ed11b3af5f7df8f0ce140eb HTML Author: Leonardo Taccari <iamleot@gmail.com> Date: Mon, 13 May 2019 17:50:22 Implement refs() to list all branches and tags Diffstat: TODO | 1 - stahg-gopher.py | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) --- diff -r 12d7dd66c5a3 -r 1614c33a9710 TODO --- a/TODO Mon May 13 15:35:55 2019 +0200 +++ b/TODO Mon May 13 17:50:22 2019 +0200 @@ -4,7 +4,6 @@ Missing features/bugs --------------------- - - Implement refs(), to list all branches and tags - Write a stahg-gopher-index - Write documentation and man page(s) diff -r 12d7dd66c5a3 -r 1614c33a9710 stahg-gopher.py --- a/stahg-gopher.py Mon May 13 15:35:55 2019 +0200 +++ b/stahg-gopher.py Mon May 13 17:50:22 2019 +0200 @@ -150,7 +150,8 @@ bp = gph_escape_entry(self.base_prefix) m = '[1|Log|' + bp + '/log.gph|server|port]\n' + \ - '[1|Files|' + bp + '/files.gph|server|port]' + '[1|Files|' + bp + '/files.gph|server|port]\n' + \ + '[1|Refs|' + bp + '/refs.gph|server|port]' if self.readme: m += '\n[1|README|' + bp + '/file/{file}.gph|server|port]'.format( @@ -221,7 +222,35 @@ def refs(self): """Generate refs.gph listing all branches and tags""" - pass # TODO + bp = gph_escape_entry(self.base_prefix) + fname = 'refs.gph' + + with open(fname, 'w') as f: + print(self.title('Files'), file=f) + print(self.menu(), file=f) + print('---', file=f) + + print('Branches', file=f) + print(' {:32} {:16} {:26}'.format('Name', 'Last commit date', 'Author'), file=f) + for name, _, changeset in self.client.branches(): + print( + gph_escape_text(' {name:32} {date:16} {author:26}'.format( + name=shorten(name.decode(), 32), + date=self.client[changeset].date().strftime('%Y-%m-%d %H:%M'), + author=author_name(self.client[changeset].author().decode()))), + file=f) + + print(file=f) + + print('Tags', file=f) + print(' {:32} {:16} {:26}'.format('Name', 'Last commit date', 'Author'), file=f) + for name, _, changeset, _ in self.client.tags(): + print( + gph_escape_text(' {name:32} {date:16} {author:26}'.format( + name=shorten(name.decode(), 32), + date=self.client[changeset].date().strftime('%Y-%m-%d %H:%M'), + author=author_name(self.client[changeset].author().decode()))), + file=f) def commit(self, changeset):