add ability to pull package index
This commit is contained in:
@@ -42,7 +42,7 @@ def install(args):
|
||||
print_error_message(f"Failed to download \"{name}\": \"{result.stderr.decode()}\"")
|
||||
sys.exit(1)
|
||||
|
||||
console.print("[b][:white_check_mark:] Downloaded.[/]")
|
||||
console.print(f"[b][:white_check_mark:] Downloaded [green]{name}[/green].[/]")
|
||||
|
||||
status.update(f"Installing [b]{name}[/]...")
|
||||
rock_file = os.path.join(temp_dir, "rock.json")
|
||||
|
||||
@@ -3,6 +3,7 @@ import sys
|
||||
import os
|
||||
|
||||
from .install import install
|
||||
from .pull import pull
|
||||
|
||||
__VERSION__ = "1.0.0"
|
||||
|
||||
@@ -20,6 +21,9 @@ def main() -> int:
|
||||
install_cmd = sub_parsers.add_parser(name="install", description="install a rock (package)")
|
||||
install_cmd.add_argument("names", help="name of the rocks to install", nargs="+")
|
||||
install_cmd.add_argument("--max-retries", help="max number of download retries before giving up", type=int, default=3)
|
||||
|
||||
# pull command
|
||||
pull_cmd = sub_parsers.add_parser(name="pull", description="pull rock index")
|
||||
|
||||
args = arg_parser.parse_args()
|
||||
|
||||
@@ -31,6 +35,8 @@ def main() -> int:
|
||||
match args.cmd:
|
||||
case "install":
|
||||
install(args)
|
||||
case "pull":
|
||||
pull(args)
|
||||
|
||||
# really feeling like a C programmer lmao
|
||||
return 0
|
||||
|
||||
4
neb/src/pull.py
Normal file
4
neb/src/pull.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .util import update_package_index
|
||||
|
||||
def pull(args):
|
||||
update_package_index()
|
||||
@@ -46,21 +46,29 @@ def get_needed_headers() -> bool:
|
||||
console.print("[d][:white_check_mark:] Installed headers.[/]")
|
||||
console.print("[b][green]Comet headers are installed![/green] [:white_check_mark:][/b]\n")
|
||||
|
||||
def update_package_index() -> dict:
|
||||
with console.status("Downloading package index...", spinner="moon") as status:
|
||||
package_data = requests.get("https://chookspace.com/Comet/Nebula/raw/branch/main/package_index.json")
|
||||
if not package_data.ok:
|
||||
print_error_message(f"Failed to download package index: {package_data.reason}")
|
||||
sys.exit(1)
|
||||
|
||||
console.print("[d][:white_check_mark:] Downloaded package index.[/]")
|
||||
|
||||
status.update("Saving package index...")
|
||||
data = package_data.json()
|
||||
|
||||
with open(os.path.join(comet_dir(), "package_index.json"), "w") as f:
|
||||
json.dump(data, f)
|
||||
|
||||
console.print("[b][:white_check_mark:] [green]Done pulling package index![/green][/b]")
|
||||
|
||||
|
||||
return data
|
||||
|
||||
def get_package_index() -> dict:
|
||||
if not os.path.isfile(os.path.join(comet_dir(), "package_index.json")):
|
||||
with console.status("Downloading package index...", spinner="moon") as status:
|
||||
package_data = requests.get("https://chookspace.com/Comet/Nebula/raw/branch/main/package_index.json")
|
||||
if not package_data.ok:
|
||||
print_error_message(f"Failed to download package index: {package_data.reason}")
|
||||
sys.exit(1)
|
||||
|
||||
status.update("Saving package index...")
|
||||
data = package_data.json()
|
||||
|
||||
with open(os.path.join(comet_dir(), "package_index.json"), "w") as f:
|
||||
json.dump(data, f)
|
||||
|
||||
return data
|
||||
return update_package_index()
|
||||
|
||||
with open(os.path.join(comet_dir(), "package_index.json"), "r") as f:
|
||||
package_data = json.load(f)
|
||||
|
||||
Reference in New Issue
Block a user