1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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)
|