kopia lustrzana https://github.com/peterhinch/micropython-samples
Make more PEP8 compliant.
rodzic
7516fceedf
commit
40389dbbfc
|
@ -116,14 +116,11 @@ def url_open(url):
|
||||||
try:
|
try:
|
||||||
ai = usocket.getaddrinfo(host, 443)
|
ai = usocket.getaddrinfo(host, 443)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
fatal("Unable to resolve %s (no Internet?)" % host, e)
|
print("Unable to resolve %s (no Internet?)" % host)
|
||||||
# print("Address infos:", ai)
|
raise
|
||||||
addr = ai[0][4]
|
addr = ai[0][4]
|
||||||
|
|
||||||
s = usocket.socket(ai[0][0])
|
s = usocket.socket(ai[0][0])
|
||||||
try:
|
try:
|
||||||
# print("Connect address:", addr)
|
|
||||||
|
|
||||||
if proto == "https:":
|
if proto == "https:":
|
||||||
s = ussl.wrap_socket(s)
|
s = ussl.wrap_socket(s)
|
||||||
if warn_ussl:
|
if warn_ussl:
|
||||||
|
@ -159,10 +156,8 @@ def get_pkg_metadata(name):
|
||||||
finally:
|
finally:
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def fatal(msg, exc=None):
|
def fatal(msg):
|
||||||
print("Error:", msg)
|
print("Error:", msg)
|
||||||
if exc and debug:
|
|
||||||
raise exc
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def install_pkg(pkg_spec, install_path):
|
def install_pkg(pkg_spec, install_path):
|
||||||
|
@ -173,7 +168,6 @@ def install_pkg(pkg_spec, install_path):
|
||||||
assert len(packages) == 1
|
assert len(packages) == 1
|
||||||
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 = os.path.basename(package_url)
|
|
||||||
f1 = url_open(package_url)
|
f1 = url_open(package_url)
|
||||||
s = read_lines(f1)
|
s = read_lines(f1)
|
||||||
try:
|
try:
|
||||||
|
@ -213,10 +207,9 @@ def install(to_install):
|
||||||
to_install.extend(deps)
|
to_install.extend(deps)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error installing '{}': {}, packages may be partially installed".format(
|
print("Error installing '{}': {}, packages may be partially installed".format(
|
||||||
pkg_spec, e),
|
pkg_spec, e), file=sys.stderr)
|
||||||
file=sys.stderr)
|
|
||||||
|
|
||||||
def help():
|
def help_msg():
|
||||||
print("""\
|
print("""\
|
||||||
micropip - Simple PyPI package manager for MicroPython
|
micropip - Simple PyPI package manager for MicroPython
|
||||||
Runs on a PC under Python 3.2 or above, and installs to a PC directory for
|
Runs on a PC under Python 3.2 or above, and installs to a PC directory for
|
||||||
|
@ -237,7 +230,7 @@ def main():
|
||||||
global g_install_path
|
global g_install_path
|
||||||
|
|
||||||
if len(sys.argv) < 2 or sys.argv[1] == "-h" or sys.argv[1] == "--help":
|
if len(sys.argv) < 2 or sys.argv[1] == "-h" or sys.argv[1] == "--help":
|
||||||
help()
|
help_msg()
|
||||||
return
|
return
|
||||||
|
|
||||||
if sys.argv[1] != "install":
|
if sys.argv[1] != "install":
|
||||||
|
@ -250,7 +243,7 @@ def main():
|
||||||
opt = sys.argv[i]
|
opt = sys.argv[i]
|
||||||
i += 1
|
i += 1
|
||||||
if opt == "-h" or opt == "--help":
|
if opt == "-h" or opt == "--help":
|
||||||
help()
|
help_msg()
|
||||||
return
|
return
|
||||||
elif opt == "-p":
|
elif opt == "-p":
|
||||||
g_install_path = sys.argv[i]
|
g_install_path = sys.argv[i]
|
||||||
|
@ -273,12 +266,11 @@ def main():
|
||||||
|
|
||||||
to_install.extend(sys.argv[i:])
|
to_install.extend(sys.argv[i:])
|
||||||
if not to_install:
|
if not to_install:
|
||||||
help()
|
help_msg()
|
||||||
return
|
return
|
||||||
|
|
||||||
g_install_path = os.path.expanduser(g_install_path)
|
g_install_path = os.path.expanduser(g_install_path)
|
||||||
g_install_path = os.path.abspath(g_install_path)
|
g_install_path = os.path.abspath(g_install_path)
|
||||||
print('g_install_path', g_install_path)
|
|
||||||
install(to_install)
|
install(to_install)
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue