svn commit: samba r25490 - in branches/4.0-python: . source/scripting/bin

jelmer at samba.org jelmer at samba.org
Wed Oct 3 19:57:33 GMT 2007


Author: jelmer
Date: 2007-10-03 19:57:32 +0000 (Wed, 03 Oct 2007)
New Revision: 25490

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=25490

Log:
Convert winreg to python.
Modified:
   branches/4.0-python/
   branches/4.0-python/source/scripting/bin/winreg


Changeset:

Property changes on: branches/4.0-python
___________________________________________________________________
Name: bzr:revision-info
...skipped...
Name: bzr:revision-id:v3-trunk0
...skipped...

Modified: branches/4.0-python/source/scripting/bin/winreg
===================================================================
--- branches/4.0-python/source/scripting/bin/winreg	2007-10-03 19:48:00 UTC (rev 25489)
+++ branches/4.0-python/source/scripting/bin/winreg	2007-10-03 19:57:32 UTC (rev 25490)
@@ -1,107 +1,84 @@
-#!/bin/sh
-exec smbscript "$0" ${1+"$@"}
-/*
-  tool to manipulate a remote registry
-  Copyright Andrew Tridgell 2005
-  Released under the GNU GPL v2 or later
-*/	
+#!/usr/bin/python
+#  tool to manipulate a remote registry
+#  Copyright Andrew Tridgell 2005
+#  Copyright Jelmer Vernooij 2007
+#  Released under the GNU GPL v2 or later
+#	
 
-var options = GetOptions(ARGV,
-			 "POPT_AUTOHELP",
-			 "POPT_COMMON_SAMBA",
-			 "POPT_COMMON_CREDENTIALS",
-			 "createkey=s");
-if (options == undefined) {
-	println("Failed to parse options");
-	return -1;
-}
+import getopt
+import optparse
+import sys
 
-libinclude("base.js");
-libinclude("winreg.js");
+sys.path.append("scripting/python")
 
-if (options.ARGV.length < 1) {
-	println("Usage: winreg.js <BINDING> [path]");
-	return -1;
-}
-var binding = options.ARGV[0];
-reg = winregObj();
+import options
+import param
 
-print("Connecting to " + binding + "\n");
-status = reg.connect(binding);
-if (status.is_ok != true) {
-	print("Failed to connect to " + binding + " - " + status.errstr + "\n");
-	return -1;
-}
+parser = optparse.OptionParser("winreg [options] <BINDING>")
+parser.add_option_group(options.SambaOptions(parser))
+parser.add_option_group(options.VersionOptions(parser))
+parser.add_option_group(options.CredentialsOptions(parser))
+parser.add_option("--createkey", help="Create a new key")
 
-function list_values(path) {
-	var list = reg.enum_values(path);
-	var i;
-	if (list == undefined) {
-		return;
-	}
-	for (i=0;i<list.length;i++) {
-		var v = list[i];
-		printf("\ttype=%-30s size=%4d  '%s'\n", reg.typestring(v.type), v.size, v.name);
-		if (v.type == reg.REG_SZ || v.type == reg.REG_EXPAND_SZ) {
-			printf("\t\t'%s'\n", v.value);
-		}
-		if (v.type == reg.REG_MULTI_SZ) {
-			var j;
-			for (j in v.value) {
-				printf("\t\t'%s'\n", v.value[j]);
-			}
-		}
-		if (v.type == reg.REG_DWORD || v.type == reg.REG_DWORD_BIG_ENDIAN) {
-			printf("\t\t0x%08x (%d)\n", v.value, v.value);
-		}
-		if (v.type == reg.REG_QWORD) {
-			printf("\t\t0x%llx (%lld)\n", v.value, v.value);
-		}
-	}
-}
+(opts, args) = parser.parse_args()
 
-function list_path(path) {
-	var count = 0;
-	var list = reg.enum_path(path);
-	if (list == undefined) {
-		println("Unable to list " + path);
-		return 0;
-	}
-	var i;
-	list_values(path);
-	count = count + list.length;
-	for (i=0;i<list.length;i++) {
-		var npath;
-		if (path) {
-			npath = path + "\\" + list[i];
-		} else {
-			npath = list[i];
-		}
-		println(npath);
-		count = count + list_path(npath);
-	}
-	return count;
-}
+if len(args) < 1:
+	parser.print_usage()
+	sys.exit(1)
 
-var root;
+binding = args[1]
+reg = winregObj()
 
-if (options.ARGV.length > 1) {
-	root = options.ARGV[1];
-} else {
-	root = '';
-}
+print("Connecting to " + binding + "\n")
+status = reg.connect(binding)
 
-if (options.createkey) {
-	var ok = reg.create_key("HKLM\\SOFTWARE", options.createkey);
-	if (!ok) {
-		println("Failed to create key");
-	}
-} else {
-	printf("Listing registry tree '%s'\n", root);
-	var count = list_path(root);
-	if (count == 0) {
-		println("No entries found");
-		return 1;
-	}
-}
-return 0;
+def list_values(path):
+	list = reg.enum_values(path)
+	if list is None:
+		return
+	for v in list:
+		print "\ttype=%-30s size=%4d  '%s'\n" % (reg.typestring(v.type), v.size, v.name)
+		if v.type in (reg.REG_SZ, reg.REG_EXPAND_SZ):
+			print "\t\t'%s'\n" % v.value
+
+		if v.type == reg.REG_MULTI_SZ:
+			for j in v.value:
+				print "\t\t'%s'\n" % j
+		if v.type in (reg.REG_DWORD, reg.REG_DWORD_BIG_ENDIAN):
+			print "\t\t0x%08x (%d)\n" % (v.value, v.value)
+		if v.type == reg.REG_QWORD:
+			print "\t\t0x%llx (%lld)\n" % (v.value, v.value)
+
+def list_path(path):
+	count = 0
+	list = reg.enum_path(path)
+	if list is None:
+		print "Unable to list %s" % path
+		return 0
+	list_values(path)
+	count += list.length
+	for v in list:
+		if path:
+			npath += "\\" + v
+		else:
+			npath = v
+		println(npath)
+		count += list_path(npath)
+	return count
+
+if len(args) > 1:
+	root = args[2]
+else:
+	root = ''
+
+if opts.createkey:
+	try:
+		ok = reg.create_key("HKLM\\SOFTWARE", options.createkey)
+	except:
+		print "Failed to create key\n"
+else:
+	print "Listing registry tree '%s'\n" % root
+	count = list_path(root)
+	if count == 0:
+		print "No entries found\n"
+		sys.exit(1)



More information about the samba-cvs mailing list