convert strings to f-strings; clean up btree code; wrap network stuff in try-except
This commit is contained in:
23
tf_extend.py
23
tf_extend.py
@@ -46,19 +46,22 @@ def cmd(args):
|
||||
try:
|
||||
tf.transfer(args[1],w)
|
||||
if cmd=='wc':
|
||||
print("lines: {}\twords: {}\tbytes: {}".format(w.lines, w.words, w.bytes_))
|
||||
print(f"lines: {w.lines}\twords: {w.words}\tbytes: {w.bytes_}")
|
||||
except:
|
||||
print("file not found: "+args[1])
|
||||
|
||||
elif cmd in ('ifconfig','ip'):
|
||||
ifc=network.WLAN().ifconfig()
|
||||
print("IP: {}\tmask: {}\tgateway: {}\tDNS: {}".format(*ifc))
|
||||
print(f"IP: {ifc[0]}\tmask: {ifc[1]}\tgateway: {ifc[2]}\tDNS: {ifc[3]}")
|
||||
|
||||
elif cmd in ('host','nslookup','dig'):
|
||||
if len(args)<2:
|
||||
print("syntax: host <domain.name>")
|
||||
else:
|
||||
print("host <{}> is at {}".format(args[1],socket.getaddrinfo(args[1],80)[0][-1][0]))
|
||||
try:
|
||||
print(f"host <{args[1]}> is at {socket.getaddrinfo(args[1],80)[0][-1][0]}")
|
||||
except:
|
||||
print("network/DNS not available")
|
||||
|
||||
elif cmd=='connect':
|
||||
if len(args)<3:
|
||||
@@ -78,7 +81,7 @@ def cmd(args):
|
||||
print("no AP found")
|
||||
return True
|
||||
for i in s:
|
||||
print("ch: {}\tRSSI: {}\t{}\tSSID: {}".format(i[2],i[3],"open" if i[4]==0 else "",i[0]))
|
||||
print(f"ch: {i[2]}\tRSSI: {i[3]}\t{"open" if i[4]==0 else ""}\tSSID: {i[0]}")
|
||||
|
||||
elif cmd=='freq':
|
||||
# identify esp32 or esp8266
|
||||
@@ -90,7 +93,7 @@ def cmd(args):
|
||||
if len(args)==1 or args[1] in freqs:
|
||||
if len(args)>1:
|
||||
machine.freq(int(args[1])*1000000)
|
||||
print("master cpu frequency {}MHz".format(machine.freq()//1000000))
|
||||
print(f"master cpu frequency {machine.freq()//1000000}MHz")
|
||||
else:
|
||||
print("syntax: freq [ 160 | 80 | 240 ] ")
|
||||
|
||||
@@ -100,8 +103,8 @@ def cmd(args):
|
||||
b=btree.open(f)
|
||||
print("Key\t\tValue")
|
||||
i=0
|
||||
for w in b:
|
||||
print("{}\t{}".format(w,b[w]))
|
||||
for k,v in b.items():
|
||||
print(f"{k:10}\t{v}")
|
||||
i+=1
|
||||
if i%30==0:
|
||||
r=input("continue? ")
|
||||
@@ -115,15 +118,15 @@ def cmd(args):
|
||||
except OSError:
|
||||
print("file not found")
|
||||
elif cmd=='free':
|
||||
print("memory used: {}\tmemory free:{}".format(gc.mem_alloc(),gc.mem_free()))
|
||||
print(f"memory used: {gc.mem_alloc()}\tmemory free:{gc.mem_free()}")
|
||||
elif cmd=='help':
|
||||
print("==Extended commands")
|
||||
print(" connect <essid> <password> \tscan")
|
||||
print(" ifconfig/ip \t\thost/dig/nslookup <domain.name>")
|
||||
print(" freq [160 | 80 | 240]\texec <python-filename>")
|
||||
print(" freq [160 | 80 | 240]\t\texec <python-filename>")
|
||||
print(" free \t\t\twc <filename>")
|
||||
print(" less/more [-n] <filename>")
|
||||
print(" bt-list <filename>")
|
||||
print(" btree <filename>")
|
||||
else: # command not found
|
||||
return False
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user