kopia lustrzana https://github.com/micropython/micropython-lib
upip: Switch to stream mode of operation using uzlib.DecompIO.
So, there's no longer requirement that uncompressed file fit into memory, though for stream mode, max dictionary size of 32K is used so far.pull/106/head
rodzic
b6bfd9963d
commit
6764d27d78
36
upip/upip.py
36
upip/upip.py
|
@ -13,8 +13,8 @@ def upip_import(mod, sub=None):
|
||||||
sys = upip_import("sys")
|
sys = upip_import("sys")
|
||||||
import uos as os
|
import uos as os
|
||||||
import uerrno as errno
|
import uerrno as errno
|
||||||
|
import uzlib
|
||||||
|
|
||||||
gzip = upip_import("gzip")
|
|
||||||
try:
|
try:
|
||||||
tarfile = upip_import("utarfile")
|
tarfile = upip_import("utarfile")
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -28,7 +28,7 @@ except ImportError:
|
||||||
DEFAULT_MICROPYPATH = "~/.micropython/lib:/usr/lib/micropython"
|
DEFAULT_MICROPYPATH = "~/.micropython/lib:/usr/lib/micropython"
|
||||||
|
|
||||||
debug = False
|
debug = False
|
||||||
cleanup_files = [".pkg.tar"]
|
cleanup_files = []
|
||||||
|
|
||||||
class NotFoundError(Exception):
|
class NotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -113,7 +113,7 @@ try:
|
||||||
import ussl
|
import ussl
|
||||||
import usocket
|
import usocket
|
||||||
warn_ussl = True
|
warn_ussl = True
|
||||||
def download(url, local_name):
|
def url_open(url):
|
||||||
global warn_ussl
|
global warn_ussl
|
||||||
proto, _, host, urlpath = url.split('/', 3)
|
proto, _, host, urlpath = url.split('/', 3)
|
||||||
ai = usocket.getaddrinfo(host, 443)
|
ai = usocket.getaddrinfo(host, 443)
|
||||||
|
@ -142,12 +142,8 @@ try:
|
||||||
raise OSError()
|
raise OSError()
|
||||||
if l == b'\r\n':
|
if l == b'\r\n':
|
||||||
break
|
break
|
||||||
with open(local_name, "wb") as f:
|
|
||||||
while 1:
|
return s
|
||||||
l = s.read(1024)
|
|
||||||
if not l:
|
|
||||||
break
|
|
||||||
f.write(l)
|
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
||||||
|
@ -162,9 +158,9 @@ except ImportError:
|
||||||
|
|
||||||
|
|
||||||
def get_pkg_metadata(name):
|
def get_pkg_metadata(name):
|
||||||
download("https://pypi.python.org/pypi/%s/json" % name, ".pkg.json")
|
f = url_open("https://pypi.python.org/pypi/%s/json" % name)
|
||||||
with open(".pkg.json") as f:
|
s = f.read()
|
||||||
s = f.read()
|
f.close()
|
||||||
return json.loads(s)
|
return json.loads(s)
|
||||||
|
|
||||||
|
|
||||||
|
@ -192,16 +188,12 @@ def install_pkg(pkg_spec, install_path):
|
||||||
package_url = packages[0]["url"]
|
package_url = packages[0]["url"]
|
||||||
print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
|
print("Installing %s %s from %s" % (pkg_spec, latest_ver, package_url))
|
||||||
package_fname = op_basename(package_url)
|
package_fname = op_basename(package_url)
|
||||||
download(package_url, package_fname)
|
f1 = url_open(package_url)
|
||||||
|
f2 = uzlib.DecompIO(f1, 16 + 15)
|
||||||
data = gzdecompress(package_fname)
|
f3 = tarfile.TarFile(fileobj=f2)
|
||||||
|
meta = install_tar(f3, install_path)
|
||||||
f = open(".pkg.tar", "wb")
|
f1.close()
|
||||||
f.write(data)
|
return meta
|
||||||
f.close()
|
|
||||||
|
|
||||||
f = tarfile.TarFile(".pkg.tar")
|
|
||||||
return install_tar(f, install_path)
|
|
||||||
|
|
||||||
def cleanup():
|
def cleanup():
|
||||||
for fname in cleanup_files:
|
for fname in cleanup_files:
|
||||||
|
|
Ładowanie…
Reference in New Issue