kopia lustrzana https://github.com/micropython/micropython
Merge 4ecbf11936
into 01c31ea804
commit
72c92c33d3
|
@ -90,16 +90,29 @@ def _download_file(transport, url, dest):
|
||||||
|
|
||||||
|
|
||||||
def _install_json(transport, package_json_url, index, target, version, mpy):
|
def _install_json(transport, package_json_url, index, target, version, mpy):
|
||||||
try:
|
if (
|
||||||
with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response:
|
package_json_url.startswith("http://")
|
||||||
package_json = json.load(response)
|
or package_json_url.startswith("https://")
|
||||||
except urllib.error.HTTPError as e:
|
or package_json_url.startswith("github:")
|
||||||
if e.status == 404:
|
):
|
||||||
raise CommandError(f"Package not found: {package_json_url}")
|
try:
|
||||||
else:
|
with urllib.request.urlopen(_rewrite_url(package_json_url, version)) as response:
|
||||||
raise CommandError(f"Error {e.status} requesting {package_json_url}")
|
package_json = json.load(response)
|
||||||
except urllib.error.URLError as e:
|
except urllib.error.HTTPError as e:
|
||||||
raise CommandError(f"{e.reason} requesting {package_json_url}")
|
if e.status == 404:
|
||||||
|
raise CommandError(f"Package not found: {package_json_url}")
|
||||||
|
else:
|
||||||
|
raise CommandError(f"Error {e.status} requesting {package_json_url}")
|
||||||
|
except urllib.error.URLError as e:
|
||||||
|
raise CommandError(f"{e.reason} requesting {package_json_url}")
|
||||||
|
elif package_json_url.endswith(".json"):
|
||||||
|
try:
|
||||||
|
with open(package_json_url, "r") as f:
|
||||||
|
package_json = json.load(f)
|
||||||
|
except OSError:
|
||||||
|
raise CommandError(f"Error opening {package_json_url}")
|
||||||
|
else:
|
||||||
|
raise CommandError(f"Invalid url for package: {package_json_url}")
|
||||||
for target_path, short_hash in package_json.get("hashes", ()):
|
for target_path, short_hash in package_json.get("hashes", ()):
|
||||||
fs_target_path = target + "/" + target_path
|
fs_target_path = target + "/" + target_path
|
||||||
file_url = f"{index}/file/{short_hash[:2]}/{short_hash}"
|
file_url = f"{index}/file/{short_hash[:2]}/{short_hash}"
|
||||||
|
@ -129,6 +142,8 @@ def _install_package(transport, package, index, target, version, mpy):
|
||||||
package += "/"
|
package += "/"
|
||||||
package += "package.json"
|
package += "package.json"
|
||||||
print(f"Installing {package} to {target}")
|
print(f"Installing {package} to {target}")
|
||||||
|
elif package.endswith(".json"):
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
if not version:
|
if not version:
|
||||||
version = "latest"
|
version = "latest"
|
||||||
|
|
Ładowanie…
Reference in New Issue