From 2ebe80c27c8cd39a0f40ef6de3a9f805cb7d6bed Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 14 Jan 2008 19:51:08 +0100 Subject: python: Convert winreg.py completely to rpc, use new RPC Python bindings. (This used to be commit 9c21773737ea941b623105352b4625dcb8437706) --- source4/scripting/bin/winreg.py | 133 ++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 72 deletions(-) mode change 100644 => 100755 source4/scripting/bin/winreg.py (limited to 'source4/scripting') diff --git a/source4/scripting/bin/winreg.py b/source4/scripting/bin/winreg.py old mode 100644 new mode 100755 index 6cdc3a5898..f68f2d12f2 --- a/source4/scripting/bin/winreg.py +++ b/source4/scripting/bin/winreg.py @@ -7,87 +7,76 @@ # import sys +import winreg +import optparse +import samba.getopt as options -options = GetOptions(ARGV, - "POPT_AUTOHELP", - "POPT_COMMON_SAMBA", - "POPT_COMMON_CREDENTIALS", - "createkey=s") -if (options == undefined) { - print "Failed to parse options" - sys.exit(-1) +parser = optparse.OptionParser("%s [path]" % sys.argv[0]) +parser.add_option_group(options.SambaOptions(parser)) +parser.add_option("--createkey", type="string", metavar="KEYNAME", + help="create a key") -if len(sys.argv < 2: - print "Usage: %s [path]" % sys.argv[0] - sys.exit(-1) +opts, args = parser.parse_args() -binding = options.ARGV[0] -reg = winregObj() +if len(args) < 1: + parser.print_usage() + sys.exit(-1) + +binding = args[0] print "Connecting to " + binding -status = reg.connect(binding) -if (status.is_ok != true) { - print("Failed to connect to " + binding + " - " + status.errstr + "\n") - return -1 -} +conn = winreg.winreg(binding, opts.configfile) -def list_values(path): - list = reg.enum_values(path) - if (list == undefined) { - return - } - for (i=0;i 2: - root = sys.argv[2] +if len(args) > 1: + root = args[1] else: - root = '' + root = "HKLM" -if options.createkey: - try: - reg.create_key("HKLM\\SOFTWARE", options.createkey) - except: - print "Failed to create key" +if opts.createkey: + reg.create_key("HKLM\\SOFTWARE", opt.createkey) else: - printf("Listing registry tree '%s'\n", root) - count = list_path(root) + print "Listing registry tree '%s'" % root + try: + root_key = getattr(conn, "Open%s" % root)(None, winreg.KEY_QUERY_VALUE | winreg.KEY_ENUMERATE_SUB_KEYS) + except AttributeError: + print "Unknown root key name %s" % root + sys.exit(1) + count = list_path(root_key, root) if count == 0: - println("No entries found") - sys.exit(1) + print "No entries found" + sys.exit(1) -- cgit