summaryrefslogtreecommitdiff
path: root/source3/python/gtdbtool
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-05-27 07:47:58 +0000
committerTim Potter <tpot@samba.org>2002-05-27 07:47:58 +0000
commitd26bcfaf955027d0a61e2b3557f3062e47c25ccd (patch)
treebd06f247688aa57bebba06afbb71abae314e0070 /source3/python/gtdbtool
parent0f1de232c254bdcc3d2b381f0724697750a907dd (diff)
downloadsamba-d26bcfaf955027d0a61e2b3557f3062e47c25ccd.tar.gz
samba-d26bcfaf955027d0a61e2b3557f3062e47c25ccd.tar.bz2
samba-d26bcfaf955027d0a61e2b3557f3062e47c25ccd.zip
Use a fixed size font for displaying tdb values.
Added a (regexp, function) pair to register display functions for keys matching regular expressions. Expand the size of the value scrolling window. Added hex dump function and some regexps to display DRIVERS, SECDESC and PRINTERS keys in hex instead of ascii. (This used to be commit 7d10dc5f7bd12e25ea3e64b380a029c89929156f)
Diffstat (limited to 'source3/python/gtdbtool')
-rwxr-xr-xsource3/python/gtdbtool115
1 files changed, 111 insertions, 4 deletions
diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool
index cb88792acc..670fca9973 100755
--- a/source3/python/gtdbtool
+++ b/source3/python/gtdbtool
@@ -20,6 +20,8 @@ class gtdbtool:
def __init__(self, dict):
self.dict = dict
+ self.value_display_fns = []
+ self.filter_regex = ""
# Create and configure user interface widgets. A string argument is
# used to set the window title.
@@ -70,7 +72,7 @@ class gtdbtool:
scrolled_win = GtkScrolledWindow()
scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
hpaned.add2(scrolled_win)
- scrolled_win.set_usize(350,400)
+ scrolled_win.set_usize(500,400)
scrolled_win.show()
self.text = GtkText()
@@ -83,7 +85,7 @@ class gtdbtool:
self.menu = GtkMenu()
self.menu.show()
- self.filter_regex = ""
+ self.font = load_font("fixed")
self.update_keylist()
@@ -107,14 +109,30 @@ class gtdbtool:
def set_value_text(self, text):
self.text.delete_text(0, self.text.get_length())
- self.text.insert_defaults(text)
+
+ # The text widget has trouble inserting text containing NULL
+ # characters.
+
+ text = string.replace(text, "\x00", ".")
+
+ self.text.insert(self.font, None, None, text)
# This function is called when a key is selected in the left hand side
# of the user interface.
def key_selected(self, list, list_item):
key = list_item.children()[0].get()
- self.set_value_text(t[list_item.get_data("raw_key")])
+
+ # Look for a match in the value display function list
+
+ text = t[list_item.get_data("raw_key")]
+
+ for entry in self.value_display_fns:
+ if re.match(entry[0], key):
+ text = entry[1](text)
+ break
+
+ self.set_value_text(text)
# Refresh the key list by removing all items and re-inserting them.
# Items are only inserted if they pass through the filter regexp.
@@ -143,8 +161,90 @@ class gtdbtool:
def set_display_key_fn(self, fn):
self.display_key = fn
+ # Register a value display function for a key. The first argument is a
+ # regex that matches key values, and the second argument is a function
+ # to call to convert the raw value data to a string to display in the
+ # right hand side of the UI.
+
+ def register_display_value_fn(self, key_regexp, fn):
+ self.value_display_fns.append((key_regexp, fn))
+
+ def display_value_hex(self, value):
+ return "foo"
+
+def convert_to_hex(data):
+ """Return a hex dump of a string as a string.
+
+ The output produced is in the standard 16 characters per line hex +
+ ascii format:
+
+ 00000000: 40 00 00 00 00 00 00 00 40 00 00 00 01 00 04 80 @....... @.......
+ 00000010: 01 01 00 00 00 00 00 01 00 00 00 00 ........ ....
+ """
+
+ pos = 0 # Position in data
+ line = 0 # Line of data
+
+ hex = "" # Hex display
+ ascii = "" # ASCII display
+
+ result = ""
+
+ while pos < len(data):
+
+ # Start with header
+
+ if pos % 16 == 0:
+ hex = "%08x: " % (line * 16)
+ ascii = ""
+
+ # Add character
+
+ hex = hex + "%02x " % (ord(data[pos]))
+
+ if ord(data[pos]) < 32 or ord(data[pos]) > 176:
+ ascii = ascii + '.'
+ else:
+ ascii = ascii + data[pos]
+
+ pos = pos + 1
+
+ # Add separator if half way
+
+ if pos % 16 == 8:
+ hex = hex + " "
+ ascii = ascii + " "
+
+ # End of line
+
+ if pos % 16 == 0:
+ result = result + "%s %s\n" % (hex, ascii)
+ line = line + 1
+
+ # Leftover bits
+
+ if pos % 16 != 0:
+
+ # Pad hex string
+
+ for i in range(0, (16 - (pos % 16))):
+ hex = hex + " "
+
+ # Half way separator
+
+ if (pos % 16) < 8:
+ hex = hex + " "
+
+ result = result + "%s %s\n" % (hex, ascii)
+
+ return result
+
# Open handle on tdb
+if len(sys.argv) != 2:
+ print "Usage: gdbtool <tdbfile>"
+ sys.exit(1)
+
t = tdb.open(sys.argv[1])
# Create user interface
@@ -159,6 +259,13 @@ def display_key_x00(key):
w.set_display_key_fn(display_key_x00)
+def display_value_hex(value):
+ return value;
+
+w.register_display_value_fn("DRIVERS/", convert_to_hex)
+w.register_display_value_fn("SECDESC/", convert_to_hex)
+w.register_display_value_fn("PRINTERS/", convert_to_hex)
+
# Show user interface
w.build_ui("gtdbtool: %s" % sys.argv[1])