View | Details | Raw Unified | Return to bug 33792 | Differences between
and this patch

Collapse All | Expand All

(-)umc/python/printers/__init__.py (-33 / +45 lines)
 Lines 37-42    Link Here 
37
import univention.management.console as umc
37
import univention.management.console as umc
38
import univention.management.console.modules as umcm
38
import univention.management.console.modules as umcm
39
from univention.management.console.modules import UMC_CommandError
39
from univention.management.console.modules import UMC_CommandError
40
from univention.management.console.modules import UMC_Error
40
41
41
import univention.config_registry
42
import univention.config_registry
42
import univention.admin.uldap
43
import univention.admin.uldap
 Lines 105-147    Link Here 
105
		""" lists all quota entries related to this printer. """
106
		""" lists all quota entries related to this printer. """
106
107
107
		result = []
108
		result = []
109
		status = None
108
110
109
		if not os.path.exists('/usr/bin/pkusers'):
111
		try:
110
			raise UMC_CommandError(_('The print quota settings are currently disabled. Please install the package univention-printquota to enable them.'))
112
			from pykota.tool import PyKotaTool
113
			from pykota import reporter
114
			from pykota.storages.pgstorage import PGError
115
		except ImportError as err:
116
			raise UMC_Error(_('The print quota settings are currently disabled. Please install the package univention-printquota to enable them.'))
117
		from lxml import etree
118
		from lxml import html
111
119
112
		(stdout, stderr, status) = self._shell_command(['/usr/bin/pkusers', '--list'], {'LANG':'C'})
120
		try:
113
		users = []
121
			reportTool = PyKotaTool()
114
		expr = re.compile('^\s*(.*?)\s+\-\s\<')
122
			reportTool.deferredInit()
115
		if status == 0:
123
			printers = reportTool.storage.getMatchingPrinters(printer)
116
			for line in stdout.split("\n"):
124
			reportingtool = reporter.openReporter(reportTool, 'html', printers, '*', 0)
117
				match = expr.match(line)
125
			status = reportingtool.generateReport()
118
				if match:
126
		except PGError as err:
119
					users.append(match.group(1))
127
			raise UMC_Error(_('The connection to the print quota postgres database failed: %s' % str(err)))
120
128
121
		result = []
129
		if status:
122
		for user in users:
130
			tree = html.fromstring(status)
123
			if not os.path.exists('/usr/bin/repykota'):
131
			table = tree.find_class('pykotatable')
124
				raise UMC_CommandError(_('The print quota settings are currently disabled. Please install the package univention-printquota to enable them.'))
132
			for i in table:
133
				for a in i.iterchildren(tag='tr'):
134
					data = list()
135
					for b in a.iterchildren(tag='td'):
136
						data.append(b.text_content().strip())
137
					if data and len(data) >= 11:
138
						user = data[0]
139
						limitby = data[1]
140
						overcharge = data[2]
141
						used = data[3]
142
						soft = data[4]
143
						hard = data[5]
144
						balance = data[6]
145
						grace = data[7]
146
						total = data[8]
147
						paid = data[9]
148
						warn = data[10]
149
						result.append(dict(
150
							user=user,
151
							used=used,
152
							soft=soft,
153
							hard=hard,
154
							total=total,
155
						))
125
156
126
			(stdout, stderr, status) = self._shell_command(['/usr/bin/repykota', '-P', printer, user], {'LANG':'C'})
127
			if status == 0:
128
				for line in stdout.split("\n"):
129
					data = line[16:].split()		# ignore possibly truncated user name
130
					if len(data) >= 7:
131
						ok = True
132
						for n in (2, 3,4, len(data)-3):
133
							if not data[n].isdigit():
134
								ok = False
135
						if ok:
136
							MODULE.info("      -> user='%s' used=%s soft=%s hard=%s total=%s" % (user, data[2], data[3], data[4], data[len(data)-3]))
137
							entry = {
138
								'user':		user,
139
								'used':		data[2],
140
								'soft':		data[3],
141
								'hard':		data[4],
142
								'total':	data[len(data)-3]
143
							}
144
							result.append(entry)
145
		return result
157
		return result
146
158
147
	@simple_response
159
	@simple_response

Return to bug 33792