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()}\"")
|
print_error_message(f"Failed to download \"{name}\": \"{result.stderr.decode()}\"")
|
||||||
sys.exit(1)
|
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}[/]...")
|
status.update(f"Installing [b]{name}[/]...")
|
||||||
rock_file = os.path.join(temp_dir, "rock.json")
|
rock_file = os.path.join(temp_dir, "rock.json")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from .install import install
|
from .install import install
|
||||||
|
from .pull import pull
|
||||||
|
|
||||||
__VERSION__ = "1.0.0"
|
__VERSION__ = "1.0.0"
|
||||||
|
|
||||||
@@ -21,6 +22,9 @@ def main() -> int:
|
|||||||
install_cmd.add_argument("names", help="name of the rocks to install", nargs="+")
|
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)
|
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()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
# do different things based on args
|
# do different things based on args
|
||||||
@@ -31,6 +35,8 @@ def main() -> int:
|
|||||||
match args.cmd:
|
match args.cmd:
|
||||||
case "install":
|
case "install":
|
||||||
install(args)
|
install(args)
|
||||||
|
case "pull":
|
||||||
|
pull(args)
|
||||||
|
|
||||||
# really feeling like a C programmer lmao
|
# really feeling like a C programmer lmao
|
||||||
return 0
|
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,22 +46,30 @@ def get_needed_headers() -> bool:
|
|||||||
console.print("[d][:white_check_mark:] Installed headers.[/]")
|
console.print("[d][:white_check_mark:] Installed headers.[/]")
|
||||||
console.print("[b][green]Comet headers are installed![/green] [:white_check_mark:][/b]\n")
|
console.print("[b][green]Comet headers are installed![/green] [:white_check_mark:][/b]\n")
|
||||||
|
|
||||||
def get_package_index() -> dict:
|
def update_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:
|
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")
|
package_data = requests.get("https://chookspace.com/Comet/Nebula/raw/branch/main/package_index.json")
|
||||||
if not package_data.ok:
|
if not package_data.ok:
|
||||||
print_error_message(f"Failed to download package index: {package_data.reason}")
|
print_error_message(f"Failed to download package index: {package_data.reason}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
console.print("[d][:white_check_mark:] Downloaded package index.[/]")
|
||||||
|
|
||||||
status.update("Saving package index...")
|
status.update("Saving package index...")
|
||||||
data = package_data.json()
|
data = package_data.json()
|
||||||
|
|
||||||
with open(os.path.join(comet_dir(), "package_index.json"), "w") as f:
|
with open(os.path.join(comet_dir(), "package_index.json"), "w") as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
|
|
||||||
|
console.print("[b][:white_check_mark:] [green]Done pulling package index![/green][/b]")
|
||||||
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def get_package_index() -> dict:
|
||||||
|
if not os.path.isfile(os.path.join(comet_dir(), "package_index.json")):
|
||||||
|
return update_package_index()
|
||||||
|
|
||||||
with open(os.path.join(comet_dir(), "package_index.json"), "r") as f:
|
with open(os.path.join(comet_dir(), "package_index.json"), "r") as f:
|
||||||
package_data = json.load(f)
|
package_data = json.load(f)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user