summaryrefslogtreecommitdiff
path: root/source4/python/samba/printerdata.py
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2003-08-13 01:53:07 +0000
committerAndrew Tridgell <tridge@samba.org>2003-08-13 01:53:07 +0000
commitef2e26c91b80556af033d3335e55f5dfa6fff31d (patch)
treefaa21bfd7e7b5247250b47c7891dc1a5ebee6be9 /source4/python/samba/printerdata.py
downloadsamba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.tar.gz
samba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.tar.bz2
samba-ef2e26c91b80556af033d3335e55f5dfa6fff31d.zip
first public release of samba4 code
(This used to be commit b0510b5428b3461aeb9bbe3cc95f62fc73e2b97f)
Diffstat (limited to 'source4/python/samba/printerdata.py')
-rw-r--r--source4/python/samba/printerdata.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/source4/python/samba/printerdata.py b/source4/python/samba/printerdata.py
new file mode 100644
index 0000000000..33251f6a00
--- /dev/null
+++ b/source4/python/samba/printerdata.py
@@ -0,0 +1,59 @@
+#!/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
+#
+
+#
+# TODO:
+#
+# - Implement __delitem__
+#
+
+from samba import spoolss
+
+class printerdata:
+ def __init__(self, host, creds = {}):
+ self.hnd = spoolss.openprinter(host, creds = creds)
+
+ def keys(self):
+ return self.hnd.enumprinterdata().keys()
+
+ def __getitem__(self, key):
+ return self.hnd.getprinterdata(key)['data']
+
+ def __setitem__(self, key, value):
+ # Store as REG_BINARY for now
+ self.hnd.setprinterdata({"key": "", "value": key, "type": 3,
+ "data": value})
+
+class printerdata_ex:
+ def __init__(self, host):
+ self.host = host
+ self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver",
+ "DsUser"]
+
+ def keys(self):
+ return self.top_level_keys
+
+ def has_key(self, key):
+ for k in self.top_level_keys:
+ if k == key:
+ return 1
+ return 0
+
+ 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)