Skip to content

Commit

Permalink
icm lsgit: initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Obijuan committed Jun 19, 2024
1 parent 1f1e304 commit b5a7f79
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
12 changes: 12 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions icm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
cmd_install,
cmd_ls,
cmd_rm,
cmd_list,
)


Expand Down Expand Up @@ -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"
Expand All @@ -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()
108 changes: 108 additions & 0 deletions icm/commands/cmd_list.py
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 5 additions & 1 deletion icm/commons/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b5a7f79

Please sign in to comment.