From b5a7f793dd15f9849ef62f7eb023fabb28e02bed Mon Sep 17 00:00:00 2001 From: Obijuan Date: Wed, 19 Jun 2024 21:19:15 +0200 Subject: [PATCH] icm lsgit: initial implementation --- .vscode/launch.json | 12 +++++ icm/__main__.py | 8 +++ icm/commands/cmd_list.py | 108 +++++++++++++++++++++++++++++++++++++++ icm/commons/commons.py | 6 ++- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 icm/commands/cmd_list.py diff --git a/.vscode/launch.json b/.vscode/launch.json index a118dbf..0bdef14 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -42,6 +42,18 @@ "internalConsoleOptions": "neverOpen", "preLaunchTask": "Clear terminal", }, + { + "name": "LIST", + "type": "debugpy", + "request": "launch", + "program": "icm-run.py", + "args": ["lsgit"], + //"console": "internalConsole", + "console": "integratedTerminal", + "justMyCode": true, + "internalConsoleOptions": "neverOpen", + "preLaunchTask": "Clear terminal", + }, { "name": "ICM ls", "type": "debugpy", diff --git a/icm/__main__.py b/icm/__main__.py index 16d9ae1..84b9926 100644 --- a/icm/__main__.py +++ b/icm/__main__.py @@ -16,6 +16,7 @@ cmd_install, cmd_ls, cmd_rm, + cmd_list, ) @@ -50,6 +51,7 @@ def info(): @cli.command() +@click.pass_context @click.argument("coltag", nargs=1) @click.option( "-d", "--dev", is_flag=True, help="Install latest development version" @@ -73,3 +75,9 @@ def rm(collection): """Remove colections""" cmd_rm.main(collection) + + +@cli.command() +def lsgit(): + """List available collections in github""" + cmd_list.main() diff --git a/icm/commands/cmd_list.py b/icm/commands/cmd_list.py new file mode 100644 index 0000000..270b477 --- /dev/null +++ b/icm/commands/cmd_list.py @@ -0,0 +1,108 @@ +"""List available collections""" + +from icm.commons import commons + + +# -- AVAILABLE collections +COLLECTION_STORE = { + "stable": [ + "iceK", + "iceWires", + "iceIO", + "iceGates", + "iceMux", + "iceCoders", + "iceFF", + "iceRegs", + "iceSRegs", + ], + "dev": [ + "iceBoards", + "iceComp", + "iceArith", + "iceCounters", + "iceSignals", + "icePLL", + "iceLEDOscope", + "iceLEDs", + "iceHearts", + "iceInputs", + "iceRok", + "iceMachines", + "iceSerial", + "iceMem", + "iceMeassure", + "iceStack", + "iceFlash", + "iceBus", + "iceLCD", + "iceSynth", + "icecrystal", + "icebreaker", + "Collection-stdio", + "LOVE-FPGA-Collection", + "Collection-Jedi", + "CT11-collection", + "collection-generic", + "collection-logic", + "ice-chips-verilog", + "Icestudio-ArithmeticBlocks", + ], +} + + +def list_collections(collection: commons.Collection, typec: str) -> None: + """List all the collections of a given type + * collection: Context information + * typec: Type of collections + 'stable': Estable collections + 'dev' : Development collections + """ + + print(f"{'Name':<15} {'Version':<8} Description") + print(f"{'-'*15:<15} {'-'*8:<8} ----------") + for name in COLLECTION_STORE[typec]: + + # Calculate the url for the collection package.json file + url = collection.package_url(name) + + # -- Download the package.json + package = collection.download_package(url) + + # -- Get the collection information + if package: + version = package["version"] + desc = package["description"] + + print(f"* {name:<15} {version:<8} {desc}") + + # -- There was an error + else: + print(f"* {name:<15} {'xxx':<8} {'xxx'}") + + +def main(): + """ENTRY POINT: List available collections""" + + # -- Get context information + # ctx = commons.Context() + folders = commons.Folders() + collection = commons.Collection(folders) + + print() + + # -- Header + print("-----------------------------------------") + print("AVAILABE COLLECTIONS") + print("-----------------------------------------") + print("STABLE ") + print("--------------------------") + print() + list_collections(collection, "stable") + + print() + print("--------------------------") + print("DEV ") + print("--------------------------") + print() + list_collections(collection, "dev") diff --git a/icm/commons/commons.py b/icm/commons/commons.py index caae190..23fb886 100644 --- a/icm/commons/commons.py +++ b/icm/commons/commons.py @@ -200,7 +200,11 @@ def download_package(self, url: str) -> object: # Or None: or None if there was an error """ # -- Generate an http request - response = requests.get(url, timeout=10) + try: + response = requests.get(url, timeout=10) + except requests.exceptions.ReadTimeout: + print("TIMEOUT!") + return None # -- Check the status. If not ok, exit! if response.status_code != 200: