list command done
This commit is contained in:
34
src/list.py
Normal file
34
src/list.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
from rich import print
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
|
|
||||||
|
def list_cmd(args):
|
||||||
|
ground_libs_folder = os.getenv("GROUND_LIBS") or "/usr/lib/ground/"
|
||||||
|
folders = os.listdir(ground_libs_folder)
|
||||||
|
|
||||||
|
table = Table("Name", "Version", "Description", title="Installed")
|
||||||
|
config_parser = configparser.ConfigParser()
|
||||||
|
|
||||||
|
for folder in folders:
|
||||||
|
full_path = os.path.join(ground_libs_folder, folder)
|
||||||
|
|
||||||
|
# skip anything that isnt a folder
|
||||||
|
if not os.path.isdir(full_path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# read the mineral.ini file to figure out the version and description
|
||||||
|
ini_path = os.path.join(full_path, "mineral.ini")
|
||||||
|
if not os.path.isfile(ini_path):
|
||||||
|
continue
|
||||||
|
|
||||||
|
config_parser.read(ini_path)
|
||||||
|
|
||||||
|
table.add_row(
|
||||||
|
f"[b]{folder}",
|
||||||
|
f"[blue]{config_parser.get('package', 'version')}",
|
||||||
|
config_parser.get("package", "description"),
|
||||||
|
)
|
||||||
|
|
||||||
|
print(table)
|
||||||
@@ -4,6 +4,7 @@ import os, sys
|
|||||||
from install import install
|
from install import install
|
||||||
from publish import publish
|
from publish import publish
|
||||||
from remove import remove
|
from remove import remove
|
||||||
|
from list import list_cmd
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments():
|
def parse_arguments():
|
||||||
@@ -63,6 +64,8 @@ def parse_arguments():
|
|||||||
publish(args)
|
publish(args)
|
||||||
elif args.command == "remove":
|
elif args.command == "remove":
|
||||||
remove(args)
|
remove(args)
|
||||||
|
elif args.command == "list":
|
||||||
|
list_cmd(args)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parse_arguments()
|
parse_arguments()
|
||||||
|
|||||||
Reference in New Issue
Block a user