summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source3/python/printerdata.py43
-rw-r--r--source3/python/samba/printerdata.py43
2 files changed, 64 insertions, 22 deletions
diff --git a/source3/python/printerdata.py b/source3/python/printerdata.py
index 3384de4f30..33251f6a00 100644
--- a/source3/python/printerdata.py
+++ b/source3/python/printerdata.py
@@ -1,10 +1,18 @@
+#!/usr/bin/env python
+
#
# A python module that maps printerdata to a dictionary. We define
# two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData
# and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx
#
-import spoolss
+#
+# TODO:
+#
+# - Implement __delitem__
+#
+
+from samba import spoolss
class printerdata:
def __init__(self, host, creds = {}):
@@ -22,17 +30,30 @@ class printerdata:
"data": value})
class printerdata_ex:
- def __init__(self, host, creds = {}):
- self.hnd = spoolss.openprinter(host, creds = creds)
+ def __init__(self, host):
+ self.host = host
+ self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver",
+ "DsUser"]
def keys(self):
- return self.hnd.enumprinterdataex("PrinterDriverData").keys()
+ return self.top_level_keys
- def __getitem__(self, key):
- return self.hnd.getprinterdataex("PrinterDriverData", key)['data']
+ def has_key(self, key):
+ for k in self.top_level_keys:
+ if k == key:
+ return 1
+ return 0
- def __setitem__(self, key, value):
- # Store as REG_BINARY for now
- self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3,
- "data": value})
-
+ class printerdata_ex_subkey:
+ def __init__(self, host, key):
+ self.hnd = spoolss.openprinter(host)
+ self.key = key
+
+ def keys(self):
+ return self.hnd.enumprinterdataex(self.key).keys()
+
+ def __getitem__(self, key):
+ return self.hnd.getprinterdataex(self.key, key)['data']
+
+ def __getitem__(self, key):
+ return self.printerdata_ex_subkey(self.host, key)
diff --git a/source3/python/samba/printerdata.py b/source3/python/samba/printerdata.py
index 3384de4f30..33251f6a00 100644
--- a/source3/python/samba/printerdata.py
+++ b/source3/python/samba/printerdata.py
@@ -1,10 +1,18 @@
+#!/usr/bin/env python
+
#
# A python module that maps printerdata to a dictionary. We define
# two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData
# and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx
#
-import spoolss
+#
+# TODO:
+#
+# - Implement __delitem__
+#
+
+from samba import spoolss
class printerdata:
def __init__(self, host, creds = {}):
@@ -22,17 +30,30 @@ class printerdata:
"data": value})
class printerdata_ex:
- def __init__(self, host, creds = {}):
- self.hnd = spoolss.openprinter(host, creds = creds)
+ def __init__(self, host):
+ self.host = host
+ self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver",
+ "DsUser"]
def keys(self):
- return self.hnd.enumprinterdataex("PrinterDriverData").keys()
+ return self.top_level_keys
- def __getitem__(self, key):
- return self.hnd.getprinterdataex("PrinterDriverData", key)['data']
+ def has_key(self, key):
+ for k in self.top_level_keys:
+ if k == key:
+ return 1
+ return 0
- def __setitem__(self, key, value):
- # Store as REG_BINARY for now
- self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3,
- "data": value})
-
+ class printerdata_ex_subkey:
+ def __init__(self, host, key):
+ self.hnd = spoolss.openprinter(host)
+ self.key = key
+
+ def keys(self):
+ return self.hnd.enumprinterdataex(self.key).keys()
+
+ def __getitem__(self, key):
+ return self.hnd.getprinterdataex(self.key, key)['data']
+
+ def __getitem__(self, key):
+ return self.printerdata_ex_subkey(self.host, key)