Browse Source

added btree data dump

Pat Beirne 2 years ago
parent
commit
baffd3bf31
2 changed files with 30 additions and 8 deletions
  1. 4 4
      README.md
  2. 26 4
      tf_extend.py

+ 4 - 4
README.md

@@ -122,13 +122,12 @@ In its present form, the module has these limitations:
 * filenames are limited to 255 chars
 * file contents must be text
 	* or have a `\n` at least every 4096 characters
-	* `sed()` requires lines <=2048 characters, and this `sed()` won't match binary chars
+	* `sed()` requires lines <=2048 characters, and this `sed()` will not match binary chars
 * in the simple shell
   * filenames must not have spaces
   * patterns with spaces ***must*** be quoted
-  * the target of `cp` and `mv` *cannot* be a simple a directory-name as in Linux; write the whole filename *w.r.t,* the current directory
-* for the `sed` function and command, the 
-[search](https://docs.micropython.org/en/latest/library/ure.html) pattern can have wildcards like ``\s`, `\w` and `\d`. The replace pattern cannot have *any* of these, and can only have `\0`, `\1`, etc
+  * the target of `cp` and `mv` *cannot* be a simple a directory-name as in Linux; write the whole filename *w.r.t* the current directory
+* for the `sed` function and command, the [search](https://docs.micropython.org/en/latest/library/ure.html) pattern can have wildcards like ``\s`, `\w` and `\d`. The replace pattern cannot have *any* of these, and can only have `\0`, `\1`, etc
   * search patterns involving \ escapes other than those and `\'` probably won't work
 * the complexity of pattern matching is limited. 
   * try to format the grep patterns so they avoid deep stack recursion. For example, `([^#]|\\#)\s*` has a very generous search term as the first half, and can cause deep-stack recursion. The equivalent `(\\#|[^#])\s*` is more likely to succeed.
@@ -230,6 +229,7 @@ exec <python-filename>    # execute a small python file
 free                      # display the heap size: used + free
 wc <filename>             # display the line count, word count and bytes
 less/more [-n] <filename> # similar to cat, but displays 30 lines at a time
+btree <filename>          # display the content of a BTREE database
 ```
 Synonyms: `ip = ifconfig`, `more = less`, `dig = nslookup = host`
 

+ 26 - 4
tf_extend.py

@@ -1,4 +1,4 @@
-import os,sys,network,socket,time,machine,gc,tf
+import os,sys,network,socket,time,machine,gc,tf,btree
 
 # these helper classes let us use the tf.transfer() iterator,
 # by intercepting the .write()
@@ -81,12 +81,33 @@ def cmd(args):
       print("ch: {}\tRSSI: {}\t{}\tSSID: {}".format(i[2],i[3],"open" if i[4]==0 else "",i[0]))
 
   elif cmd=='freq':
-    if len(args)==1 or args[1] in ("160","80"):
+    # identify esp32 or esp8266
+    try:  # is this esp8266
+      machine.TouchPad
+      freqs=("160","80","240")
+    except AttributeError:
+      freqs=("160","80")
+    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))
     else:
-      print("syntax: freq [ 160 | 80 ]")
+      print("syntax: freq [ 160 | 80 | 240 ] ")
+
+  elif cmd=='btree':
+    try:
+      f=open(args[1])
+      b=btree.open(f)
+      print("Key\t\tValue")
+      i=0
+      for w in b:
+        print("{}\t{}".format(w,b[w]))
+        i+=1
+        if i%30==0:
+          r=input("continue? ")
+          if r=='n': break
+    except OSError:
+      print("file not found or is not a btree database")
 
   elif cmd=='exec':
     try:
@@ -99,9 +120,10 @@ def cmd(args):
     print("==Extended commands")
     print("  connect <essid> <password> \tscan")
     print("  ifconfig/ip        \t\thost/dig/nslookup <domain.name>")
-    print("  freq [ 160 | 80 ]  \t\texec <python-filename>")
+    print("  freq [160 | 80 | 240]\texec <python-filename>")
     print("  free        \t\t\twc <filename>")
     print("  less/more [-n] <filename>")
+    print("  bt-list <filename>")
   else: # command not found
     return False
   return True