summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoritsme <itsme@xs4all.nl>2021-07-13 21:19:25 +0200
committeritsme <itsme@xs4all.nl>2021-07-13 21:19:25 +0200
commit40b8b1b16a50360f6a6cbd7a65198f0414ce98bf (patch)
treeb99abf6be8915acfd6c34a8388d511dbb1573acb
parentf004854d5f2a0bc246a2524ddb843e369b21de99 (diff)
example showing how to use db.enumerate
-rw-r--r--dumpdbfields.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/dumpdbfields.py b/dumpdbfields.py
new file mode 100644
index 0000000..131cfa3
--- /dev/null
+++ b/dumpdbfields.py
@@ -0,0 +1,33 @@
1from crodump import Database
2import os
3import os.path
4from hexdump import asasc
5
6class Cls: pass
7
8def main():
9 import sys
10 dbpath = sys.argv[1] if len(sys.argv)>1 else os.path.join(os.getenv("HOME"), "prj/cronos")
11 args = Cls()
12 args.verbose = False
13
14 for path, _, files in os.walk(dbpath):
15 if any(_ for _ in files if _.lower()=="crostru.dat"):
16 print(path)
17
18 db = Database(path)
19 for tab in db.enumerate_tables():
20 tab.dump(args)
21 print("nr=%d" % db.nrofrecords())
22 i = 0
23 for rec in db.enumerate_records(tab):
24 # beware to skip tab.fields[0], which is the 'sysnum'
25 for field, fielddef in zip(rec, tab.fields[1:]):
26 print(">> %s -- %s" % (fielddef, asasc(field)))
27 i += 1
28 if i>100: break
29
30
31if __name__=="__main__":
32 main()
33