kopia lustrzana https://github.com/micropython/micropython-lib
pkg_resources: Support "frozen" resources (in R.py module).
rodzic
e1f75100cf
commit
8a2958ee36
|
@ -1,9 +1,27 @@
|
||||||
import os
|
import uio
|
||||||
import os.path
|
|
||||||
|
c = {}
|
||||||
|
|
||||||
def resource_stream(package, resource):
|
def resource_stream(package, resource):
|
||||||
|
if package not in c:
|
||||||
|
try:
|
||||||
|
if package:
|
||||||
|
p = __import__(package + ".R", None, None, True)
|
||||||
|
else:
|
||||||
|
p = __import__("R")
|
||||||
|
c[package] = p.R
|
||||||
|
except ImportError:
|
||||||
|
if package:
|
||||||
p = __import__(package)
|
p = __import__(package)
|
||||||
d = os.path.dirname(p.__file__)
|
d = p.__path__
|
||||||
|
else:
|
||||||
|
d = "."
|
||||||
if d[0] != "/":
|
if d[0] != "/":
|
||||||
d = os.getcwd() + "/" + d
|
import uos
|
||||||
return open(d + "/" + resource, "rb")
|
d = uos.getcwd() + "/" + d
|
||||||
|
c[package] = d + "/"
|
||||||
|
|
||||||
|
p = c[package]
|
||||||
|
if isinstance(p, dict):
|
||||||
|
return uio.BytesIO(p[resource])
|
||||||
|
return open(p + resource, "rb")
|
||||||
|
|
Ładowanie…
Reference in New Issue