Skip to content
This repository was archived by the owner on Jun 23, 2024. It is now read-only.

Commit c1993a6

Browse files
committed
Show versions table of modules
1 parent d4cf5b1 commit c1993a6

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

Diff for: sync/cli/Main.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,19 @@ def index(cls) -> int:
266266
config = Config(root_folder)
267267

268268
index = Index(root_folder=root_folder, config=config)
269-
index(version=cls._args.index_version, to_file=not cls._args.json)
270269

271-
if cls._args.json:
272-
print_json(index.modules_json)
270+
if cls._args.table:
271+
markdown_text = index.get_version_table()
272+
print(markdown_text)
273273

274-
elif cls._args.push:
275-
index.push_by_git(cls._args.git_branch)
274+
else:
275+
index(version=cls._args.index_version, to_file=not cls._args.json)
276+
277+
if cls._args.json:
278+
print_json(index.modules_json)
279+
280+
elif cls._args.push:
281+
index.push_by_git(cls._args.git_branch)
276282

277283
return cls.CODE_SUCCESS
278284

Diff for: sync/cli/Parameters.py

+5
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ def configure_parser_index(cls, sub_parsers):
326326
action="store_true",
327327
help="Show modules.json (JSON format)."
328328
)
329+
p.add_argument(
330+
"--table",
331+
action="store_true",
332+
help="Show versions table of modules (GitHub flavored Markdown)."
333+
)
329334

330335
cls.add_parser_git(p, add_set_size=False)
331336
cls.add_parser_env(p)

Diff for: sync/core/Index.py

+29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from datetime import datetime
22

3+
from tabulate import tabulate
4+
35
from .Config import Config
46
from .Sync import Sync
57
from ..error import Result
@@ -125,3 +127,30 @@ def __call__(self, version, to_file):
125127
def push_by_git(self, branch):
126128
func = getattr(Sync, "push_by_git")
127129
return func(self, branch)
130+
131+
def get_version_table(self, module_list=None):
132+
headers = ["id", "name", "version"]
133+
modules = []
134+
135+
if module_list is None:
136+
for track in self._tracks.get_tracks():
137+
module_folder = self._modules_folder.joinpath(track.id)
138+
update_json_file = module_folder.joinpath(UpdateJson.filename())
139+
140+
if not update_json_file.exists():
141+
continue
142+
143+
update_json = UpdateJson.load(update_json_file)
144+
if len(update_json.versions) == 0:
145+
continue
146+
147+
latest = update_json.versions[-1]
148+
zipfile = module_folder.joinpath(latest.zipfile_name)
149+
online_module = LocalModule.load(zipfile).to(OnlineModule)
150+
modules.append(online_module)
151+
else:
152+
modules = module_list
153+
154+
table = [[module.id, module.name, module.version_display] for module in modules]
155+
markdown_text = tabulate(table, headers, tablefmt="github")
156+
return markdown_text

Diff for: sync/core/Index.pyi

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ class Index:
4848
version: int
4949
): ...
5050
def get_online_module(self, module_id: str, zip_file: Path) -> Optional[OnlineModule]: ...
51-
def push_by_git(self, branch: str): ...
51+
def push_by_git(self, branch: str): ...
52+
def get_version_table(self, module_list: Optional[List[OnlineModule]] = ...) -> str: ...

0 commit comments

Comments
 (0)