|
Lines 31-65
Link Here
|
| 31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# /usr/share/common-licenses/AGPL-3; if not, see |
| 32 |
# <http://www.gnu.org/licenses/>. |
32 |
# <http://www.gnu.org/licenses/>. |
| 33 |
|
33 |
|
| 34 |
import pprint |
34 |
import re |
| 35 |
import subprocess |
35 |
import subprocess |
| 36 |
import os |
36 |
import lxml.html |
| 37 |
import univention.management.console as umc |
|
|
| 38 |
import univention.management.console.modules as umcm |
| 39 |
from univention.management.console.modules import UMC_CommandError |
| 40 |
from univention.management.console.modules import UMC_Error |
| 41 |
|
37 |
|
| 42 |
import univention.config_registry |
38 |
from univention.lib.i18n import Translation |
| 43 |
import univention.admin.uldap |
|
|
| 44 |
|
39 |
|
| 45 |
import re |
40 |
import univention.admin.uldap |
| 46 |
import lxml.html |
|
|
| 47 |
|
41 |
|
|
|
42 |
from univention.management.console.base import Base |
| 48 |
from univention.management.console.log import MODULE |
43 |
from univention.management.console.log import MODULE |
| 49 |
from univention.management.console.protocol.definitions import * |
44 |
from univention.management.console.config import ucr |
|
|
45 |
from univention.management.console.modules import UMC_Error |
| 50 |
from univention.management.console.modules.decorators import simple_response, log, sanitize |
46 |
from univention.management.console.modules.decorators import simple_response, log, sanitize |
| 51 |
from univention.management.console.modules.sanitizers import PatternSanitizer, ChoicesSanitizer |
47 |
from univention.management.console.modules.sanitizers import PatternSanitizer, ChoicesSanitizer |
| 52 |
|
48 |
|
| 53 |
_ = umc.Translation('univention-management-console-module-printers').translate |
49 |
_ = Translation('univention-management-console-module-printers').translate |
| 54 |
|
50 |
|
| 55 |
class Instance(umcm.Base): |
51 |
class Instance(Base): |
| 56 |
|
52 |
|
| 57 |
def init(self): |
53 |
def init(self): |
| 58 |
|
54 |
self._hostname = ucr.get('hostname') |
| 59 |
self.ucr = univention.config_registry.ConfigRegistry() |
|
|
| 60 |
self.ucr.load() |
| 61 |
|
| 62 |
self._hostname = self.ucr.get('hostname') |
| 63 |
|
55 |
|
| 64 |
@sanitize(pattern=PatternSanitizer(default='.*'), key=ChoicesSanitizer(choices=['printer', 'description', 'location'], required=True)) |
56 |
@sanitize(pattern=PatternSanitizer(default='.*'), key=ChoicesSanitizer(choices=['printer', 'description', 'location'], required=True)) |
| 65 |
@simple_response |
57 |
@simple_response |
|
Lines 113-119
def list_quota(self, printer=''):
Link Here
|
| 113 |
from pykota.tool import PyKotaTool |
105 |
from pykota.tool import PyKotaTool |
| 114 |
from pykota import reporter |
106 |
from pykota import reporter |
| 115 |
from pykota.storages.pgstorage import PGError |
107 |
from pykota.storages.pgstorage import PGError |
| 116 |
except ImportError as err: |
108 |
except ImportError: |
| 117 |
raise UMC_Error(_('The print quota settings are currently disabled. Please install the package univention-printquota to enable them.')) |
109 |
raise UMC_Error(_('The print quota settings are currently disabled. Please install the package univention-printquota to enable them.')) |
| 118 |
|
110 |
|
| 119 |
try: |
111 |
try: |
|
Lines 122-129
def list_quota(self, printer=''):
Link Here
|
| 122 |
printers = reportTool.storage.getMatchingPrinters(printer) |
114 |
printers = reportTool.storage.getMatchingPrinters(printer) |
| 123 |
reportingtool = reporter.openReporter(reportTool, 'html', printers, '*', 0) |
115 |
reportingtool = reporter.openReporter(reportTool, 'html', printers, '*', 0) |
| 124 |
status = reportingtool.generateReport() |
116 |
status = reportingtool.generateReport() |
| 125 |
except PGError as err: |
117 |
except PGError as exc: |
| 126 |
raise UMC_Error(_('The connection to the print quota postgres database failed: %s') % str(err)) |
118 |
MODULE.error('Cannot connect to postgres: %s' % (exc,)) |
|
|
119 |
raise UMC_Error(_('The connection to the print quota postgres database failed. Please make sure the postgres service is running and reachable.')) |
| 127 |
|
120 |
|
| 128 |
if status: |
121 |
if status: |
| 129 |
tree = lxml.html.fromstring(status) |
122 |
tree = lxml.html.fromstring(status) |
|
Lines 135-150
def list_quota(self, printer=''):
Link Here
|
| 135 |
data.append(b.text_content().strip()) |
128 |
data.append(b.text_content().strip()) |
| 136 |
if data and len(data) >= 11: |
129 |
if data and len(data) >= 11: |
| 137 |
user = data[0] |
130 |
user = data[0] |
| 138 |
limitby = data[1] |
131 |
# limitby = data[1] |
| 139 |
overcharge = data[2] |
132 |
# overcharge = data[2] |
| 140 |
used = data[3] |
133 |
used = data[3] |
| 141 |
soft = data[4] |
134 |
soft = data[4] |
| 142 |
hard = data[5] |
135 |
hard = data[5] |
| 143 |
balance = data[6] |
136 |
# balance = data[6] |
| 144 |
grace = data[7] |
137 |
# grace = data[7] |
| 145 |
total = data[8] |
138 |
total = data[8] |
| 146 |
paid = data[9] |
139 |
# paid = data[9] |
| 147 |
warn = data[10] |
140 |
# warn = data[10] |
| 148 |
result.append(dict( |
141 |
result.append(dict( |
| 149 |
user=user, |
142 |
user=user, |
| 150 |
used=used, |
143 |
used=used, |
|
Lines 190-196
def cancel_jobs(self, jobs, printer=''):
Link Here
|
| 190 |
|
183 |
|
| 191 |
return self._cancel_jobs(printer, jobs) |
184 |
return self._cancel_jobs(printer, jobs) |
| 192 |
|
185 |
|
| 193 |
|
|
|
| 194 |
@simple_response |
186 |
@simple_response |
| 195 |
@log |
187 |
@log |
| 196 |
def set_quota(self, printer='', user='', soft=0, hard=0): |
188 |
def set_quota(self, printer='', user='', soft=0, hard=0): |
|
Lines 335-341
def _reset_quota(self, printer, users):
Link Here
|
| 335 |
cmd.append(user) |
327 |
cmd.append(user) |
| 336 |
(stdout, stderr, status) = self._shell_command(cmd, {'LANG':'C'}) |
328 |
(stdout, stderr, status) = self._shell_command(cmd, {'LANG':'C'}) |
| 337 |
|
329 |
|
| 338 |
if status or len(stderr): |
330 |
if status or stderr: |
| 339 |
return stderr |
331 |
return stderr |
| 340 |
|
332 |
|
| 341 |
return '' |
333 |
return '' |
|
Lines 361-369
def _quota_enabled(self, printer=None):
Link Here
|
| 361 |
return result |
353 |
return result |
| 362 |
|
354 |
|
| 363 |
# Printer specified: return its quota value or False if not found. |
355 |
# Printer specified: return its quota value or False if not found. |
| 364 |
if printer in result: |
356 |
return result.get(printer, False) |
| 365 |
return result[printer] |
|
|
| 366 |
return False |
| 367 |
|
357 |
|
| 368 |
def _cancel_jobs(self, printer, jobs): |
358 |
def _cancel_jobs(self, printer, jobs): |
| 369 |
""" internal function that cancels a list of jobs. |
359 |
""" internal function that cancels a list of jobs. |
|
Lines 386-389
def _shell_command(self, args, env=None):
Link Here
|
| 386 |
outputs = proc.communicate() |
376 |
outputs = proc.communicate() |
| 387 |
|
377 |
|
| 388 |
return (outputs[0], outputs[1], proc.returncode) |
378 |
return (outputs[0], outputs[1], proc.returncode) |
| 389 |
|
|
|