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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
|
"""
Created on Aug 28, 2018
@author: mjasnik
"""
# imports
import os
import getpass
from os import geteuid
# timekpr imports
from timekpr.common.constants import constants as cons
from timekpr.common.log import log
from timekpr.client.interface.dbus.administration import timekprAdminConnector
from timekpr.common.utils.config import timekprConfig
from timekpr.common.constants import messages as msg
from timekpr.common.utils.misc import findHourStartEndMinutes as findHourStartEndMinutes
from timekpr.common.utils.misc import splitConfigValueNameParam as splitConfigValueNameParam
class timekprAdminClient(object):
"""Main class for holding all client logic (including dbus)"""
# --------------- initialization / control methods --------------- #
def __init__(self):
"""Initialize admin client"""
# get our connector
self._timekprAdminConnector = timekprAdminConnector()
# main object for GUI
self._adminGUI = None
def startTimekprAdminClient(self, *args):
"""Start up timekpr admin (choose gui or cli and start this up)"""
# check whether we need CLI or GUI
lastParam = args[len(args)-1]
timekprForceCLI = False
# configuration init
_timekprConfig = timekprConfig()
# load config
_timekprConfig.loadMainConfiguration()
# init logging
log.setLogging(_timekprConfig.getTimekprLogLevel(), cons.TK_LOG_TEMP_DIR, (cons.TK_LOG_OWNER_ADMIN_SU if geteuid() == 0 else cons.TK_LOG_OWNER_ADMIN), getpass.getuser())
# check for script
if ("/timekpra" in lastParam or "timekpra.py" in lastParam):
# whether we have X running or wayland?
timekprX11Available = os.getenv("DISPLAY") is not None
timekprWaylandAvailable = os.getenv("WAYLAND_DISPLAY") is not None
timekprMirAvailable = os.getenv("MIR_SOCKET") is not None
# if we are required to run graphical thing
if (timekprX11Available or timekprWaylandAvailable or timekprMirAvailable):
# resource dir
_resourcePathGUI = os.path.join(_timekprConfig.getTimekprSharedDir(), "client/forms")
# use GUI
from timekpr.client.gui.admingui import timekprAdminGUI
# load GUI and process from there
self._adminGUI = timekprAdminGUI(cons.TK_VERSION, _resourcePathGUI, getpass.getuser())
# start GUI
self._adminGUI.startAdminGUI()
# nor X nor wayland are available
else:
# print to console
log.consoleOut("%s\n" % (msg.getTranslation("TK_MSG_CONSOLE_GUI_NOT_AVAILABLE")))
# forced CLI"
timekprForceCLI = True
else:
# CLI
timekprForceCLI = True
# for CLI connections
if timekprForceCLI:
# connect
self._timekprAdminConnector.initTimekprConnection(True)
# connected?
if self._timekprAdminConnector.isConnected()[1]:
# use CLI
# validate possible parameters and their values, when fine - execute them as well
self.checkAndExecuteAdminCommands(*args)
log.flushLogFile()
# --------------- initialization / helper methods --------------- #
def finishTimekpr(self, signal=None, frame=None):
"""Exit timekpr admin GUI gracefully"""
if self._adminGUI is not None:
# finish main thread on GUI`
self._adminGUI.finishTimekpr(signal, frame)
# --------------- parameter validation methods --------------- #
def checkAndExecuteAdminCommands(self, *args):
"""Init connection to timekpr dbus server"""
# initial param len
paramIdx = 0
paramLen = len(args)
adminCmdIncorrect = False
tmpIdx = 0
# determine parameter offset
for rArg in args:
# count offset
tmpIdx += 1
# check for script
if "/timekpra" in rArg or "timekpra.py" in rArg:
paramIdx = tmpIdx
# this gets the command itself (args[0] is the script name)
adminCmd = args[paramIdx] if paramLen > paramIdx else "timekpra"
# now based on params check them out
# this gets saved user list from the server
if adminCmd == "--help":
# fine
pass
# this gets saved user list from the server
elif adminCmd == "--userlist":
# check param len
if paramLen != paramIdx + 1:
# fail
adminCmdIncorrect = True
else:
# get list
result, message, userList = self._timekprAdminConnector.getUserList()
# process
if result == 0:
# process
self.printUserList(userList)
else:
# log error
log.consoleOut(message)
# this gets user configuration from the server
elif adminCmd == "--userinfo":
# check param len
if paramLen != paramIdx + 2:
# fail
adminCmdIncorrect = True
else:
# get user config
result, message, userConfig = self._timekprAdminConnector.getUserConfigurationAndInformation(args[paramIdx+1], cons.TK_CL_INF_FULL)
# process
if result == 0:
# process
self.printUserConfig(args[paramIdx+1], userConfig)
else:
# log error
log.consoleOut(message)
# this sets allowed days for the user
elif adminCmd == "--setalloweddays":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetAllowedDays(args[paramIdx+1], args[paramIdx+2])
# this sets allowed hours per specified day or ALL for every day
elif adminCmd == "--setallowedhours":
# check param len
if paramLen != paramIdx + 4:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetAllowedHours(args[paramIdx+1], args[paramIdx+2], args[paramIdx+3])
# this sets time limits per allowed days
elif adminCmd == "--settimelimits":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetTimeLimits(args[paramIdx+1], args[paramIdx+2])
# this sets time limits per week
elif adminCmd == "--settimelimitweek":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetTimeLimitWeek(args[paramIdx+1], args[paramIdx+2])
# this sets time limits per month
elif adminCmd == "--settimelimitmonth":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetTimeLimitMonth(args[paramIdx+1], args[paramIdx+2])
# this sets whether to track inactive user sessions
elif adminCmd == "--settrackinactive":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetTrackInactive(args[paramIdx+1], args[paramIdx+2])
# this sets whether to show tray icon
elif adminCmd == "--sethidetrayicon":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetHideTrayIcon(args[paramIdx+1], args[paramIdx+2])
# this sets lockout type for the user
elif adminCmd == "--setlockouttype":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetLockoutType(args[paramIdx+1], args[paramIdx+2])
# this sets whether PlayTime is enabled for user
elif adminCmd == "--setplaytimeenabled":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeEnabled(args[paramIdx+1], args[paramIdx+2])
# this sets playtime override for user
elif adminCmd == "--setplaytimelimitoverride":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeLimitOverride(args[paramIdx+1], args[paramIdx+2])
# this sets playtime allowed during unaccounted intervals for user
elif adminCmd == "--setplaytimeunaccountedintervalsflag":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeUnaccountedIntervalsEnabled(args[paramIdx+1], args[paramIdx+2])
# this sets allowed days for PlayTime for the user
elif adminCmd == "--setplaytimealloweddays":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeAllowedDays(args[paramIdx+1], args[paramIdx+2])
# this sets PlayTime limits for allowed days for the user
elif adminCmd == "--setplaytimelimits":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeLimits(args[paramIdx+1], args[paramIdx+2])
# this sets PlayTime activities for the user
elif adminCmd == "--setplaytimeactivities":
# check param len
if paramLen != paramIdx + 3:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeActivities(args[paramIdx+1], args[paramIdx+2])
# this sets time left for the user at current moment
elif adminCmd == "--settimeleft":
# check param len
if paramLen != paramIdx + 4:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetTimeLeft(args[paramIdx+1], args[paramIdx+2], args[paramIdx+3])
# this sets time left for the user at current moment
elif adminCmd == "--setplaytimeleft":
# check param len
if paramLen != paramIdx + 4:
# fail
adminCmdIncorrect = True
else:
# set days
self.processSetPlayTimeLeft(args[paramIdx+1], args[paramIdx+2], args[paramIdx+3])
else:
# out
adminCmdIncorrect = True
# check whether command is supported
if (adminCmd not in cons.TK_USER_ADMIN_COMMANDS and adminCmd not in cons.TK_ADMIN_COMMANDS) or adminCmd == "--help" or adminCmdIncorrect:
# fail
if adminCmdIncorrect:
log.consoleOut(msg.getTranslation("TK_MSG_CONSOLE_COMMAND_INCORRECT"), *args, "\n")
# log notice
log.consoleOut("%s\n*) %s\n*) %s\n*) %s\n" % (
msg.getTranslation("TK_MSG_CONSOLE_USAGE_NOTICE_HEAD"),
msg.getTranslation("TK_MSG_CONSOLE_USAGE_NOTICE_TIME"),
msg.getTranslation("TK_MSG_CONSOLE_USAGE_NOTICE_HOURS"),
msg.getTranslation("TK_MSG_CONSOLE_USAGE_NOTICE_DAYS"))
)
# log usage notes text
log.consoleOut("%s\n" % (msg.getTranslation("TK_MSG_CONSOLE_USAGE_NOTES")))
# initial order
cmds = ["--help", "--userlist", "--userinfo"]
# print initial commands as first
for rCmd in cmds:
log.consoleOut(" ", rCmd, cons.TK_USER_ADMIN_COMMANDS[rCmd], "\n")
# print help
for rCmd, rCmdDesc in cons.TK_USER_ADMIN_COMMANDS.items():
# do not print already known commands
if rCmd not in cmds:
log.consoleOut(" ", rCmd, rCmdDesc, "\n")
# --------------- parameter execution methods --------------- #
def printUserList(self, pUserList):
"""Format and print userlist"""
# print to console
log.consoleOut(msg.getTranslation("TK_MSG_CONSOLE_USERS_TOTAL", len(pUserList)))
# loop and print
for rUser in pUserList:
log.consoleOut(rUser[0])
def printUserConfig(self, pUserName, pPrintUserConfig):
"""Format and print user config"""
# print to console
log.consoleOut("# %s" % (msg.getTranslation("TK_MSG_CONSOLE_CONFIG_FOR") % (pUserName)))
# loop and print the same format as ppl will use to set that
for rUserKey, rUserConfig in pPrintUserConfig.items():
# join the lists
if rUserKey in ("ALLOWED_WEEKDAYS", "LIMITS_PER_WEEKDAYS", "PLAYTIME_ALLOWED_WEEKDAYS", "PLAYTIME_LIMITS_PER_WEEKDAYS"):
# print join
log.consoleOut("%s: %s" % (rUserKey, ";".join(list(map(str, rUserConfig)))))
# join the lists
elif "ALLOWED_HOURS_" in rUserKey:
# hrs
hrs = ""
# print join
if len(rUserConfig) > 0:
# process hours
for rUserHour in sorted(list(map(int, rUserConfig))):
# unaccounted hour
uacc = "!" if rUserConfig[str(rUserHour)][cons.TK_CTRL_UACC] else ""
# get config per hr
hr = "%s" % (rUserHour) if rUserConfig[str(rUserHour)][cons.TK_CTRL_SMIN] <= 0 and rUserConfig[str(rUserHour)][cons.TK_CTRL_EMIN] >= 60 else "%s[%s-%s]" % (rUserHour, rUserConfig[str(rUserHour)][cons.TK_CTRL_SMIN], rUserConfig[str(rUserHour)][cons.TK_CTRL_EMIN])
# empty
hrs = "%s%s" % (uacc, hr) if hrs == "" else "%s;%s%s" % (hrs, uacc, hr)
log.consoleOut("%s: %s" % (rUserKey, hrs))
elif rUserKey in ("TRACK_INACTIVE", "HIDE_TRAY_ICON", "PLAYTIME_ENABLED", "PLAYTIME_LIMIT_OVERRIDE_ENABLED", "PLAYTIME_UNACCOUNTED_INTERVALS_ENABLED"):
log.consoleOut("%s: %s" % (rUserKey, bool(rUserConfig)))
elif rUserKey in ("PLAYTIME_ACTIVITIES"):
# result
result = ""
# loop thorhough activities
for rActArr in rUserConfig:
# activity
act = "%s[%s]" % (rActArr[0], rActArr[1]) if rActArr[1] != "" else "%s" % (rActArr[0])
# gather activities
result = "%s" % (act) if result == "" else "%s;%s" % (result, act)
log.consoleOut("%s: %s" % (rUserKey, result))
else:
log.consoleOut("%s: %s" % (rUserKey, str(rUserConfig)))
def processSetAllowedDays(self, pUserName, pDayList):
"""Process allowed days"""
# defaults
dayMap = []
result = 0
# day map
try:
# try to parse parameters
dayMap = pDayList.split(";")
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setAllowedDays(pUserName, dayMap)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetAllowedHours(self, pUserName, pDayNumber, pHourList):
"""Process allowed hours"""
# this is the dict for hour config
allowedHours = {}
result = 0
# allowed hours
try:
# check hours
for rHour in str(pHourList).split(";"):
# get hours and minutes
hour, sMin, eMin, uacc = findHourStartEndMinutes(rHour)
# raise any error in case we can not get parsing right
if hour is None:
# raise
raise ValueError("this does not compute")
# set hours
allowedHours[str(hour)] = {cons.TK_CTRL_SMIN: sMin, cons.TK_CTRL_EMIN: eMin, cons.TK_CTRL_UACC: uacc}
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setAllowedHours(pUserName, pDayNumber, allowedHours)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetTimeLimits(self, pUserName, pDayLimits):
"""Process time limits for days"""
# defaults
dayLimits = []
result = 0
# day limists
try:
# allow empty limits too
if str(pDayLimits) != "":
# try to parse parameters
dayLimits = list(map(int, pDayLimits.split(";")))
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setTimeLimitForDays(pUserName, dayLimits)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetTimeLimitWeek(self, pUserName, pTimeLimitWeek):
"""Process time limits for week"""
# defaults
weekLimit = 0
result = 0
# week limit
try:
# try to parse parameters
weekLimit = int(pTimeLimitWeek)
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setTimeLimitForWeek(pUserName, weekLimit)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetTimeLimitMonth(self, pUserName, pTimeLimitMonth):
"""Process time limits for month"""
# defaults
monthLimit = 0
result = 0
# week limit
try:
# try to parse parameters
monthLimit = int(pTimeLimitMonth)
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setTimeLimitForMonth(pUserName, monthLimit)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetTrackInactive(self, pUserName, pTrackInactive):
"""Process track inactive"""
# defaults
trackInactive = None
result = 0
# check
if pTrackInactive not in ("true", "True", "TRUE", "false", "False", "FALSE"):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify true or false")
else:
trackInactive = True if pTrackInactive in ("true", "True", "TRUE") else False
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setTrackInactive(pUserName, trackInactive)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetHideTrayIcon(self, pUserName, pHideTrayIcon):
"""Process hide tray icon"""
# defaults
hideTrayIcon = None
result = 0
# check
if pHideTrayIcon not in ("true", "True", "TRUE", "false", "False", "FALSE"):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify true or false")
else:
hideTrayIcon = True if pHideTrayIcon in ("true", "True", "TRUE") else False
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setHideTrayIcon(pUserName, hideTrayIcon)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetLockoutType(self, pUserName, pLockoutType):
"""Process lockout type"""
# defaults
result = 0
# parse lockout
lockout = pLockoutType.split(";")
lockoutType = lockout[0]
lockoutWakeFrom = lockout[1] if len(lockout) == 3 else '0'
lockoutWakeTo = lockout[2] if len(lockout) == 3 else '23'
# check
if lockoutType not in (cons.TK_CTRL_RES_L, cons.TK_CTRL_RES_S, cons.TK_CTRL_RES_W, cons.TK_CTRL_RES_T, cons.TK_CTRL_RES_D):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify one of these: %s, %s, %s, %s, %s" % (cons.TK_CTRL_RES_L, cons.TK_CTRL_RES_S, cons.TK_CTRL_RES_W, cons.TK_CTRL_RES_T, cons.TK_CTRL_RES_D))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setLockoutType(pUserName, lockoutType, lockoutWakeFrom, lockoutWakeTo)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetTimeLeft(self, pUserName, pOperation, pLimit):
"""Process time left"""
# defaults
limit = 0
result = 0
# limit
try:
# try to parse parameters
limit = int(pLimit)
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setTimeLeft(pUserName, pOperation, limit)
# process
if result != 0:
# log error
log.consoleOut(message)
# --------------- parameter execution methods for PlayTime --------------- #
def processSetPlayTimeEnabled(self, pUserName, pPlayTimeEnabled):
"""Process PlayTime enabled flag"""
# defaults
isPlayTimeEnabled = None
result = 0
# check
if pPlayTimeEnabled not in ("true", "True", "TRUE", "false", "False", "FALSE"):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify true or false")
else:
isPlayTimeEnabled = True if pPlayTimeEnabled in ("true", "True", "TRUE") else False
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeEnabled(pUserName, isPlayTimeEnabled)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeLimitOverride(self, pUserName, pPlayTimeLimitOverride):
"""Process PlayTime override flag"""
# defaults
isPlayTimeLimitOverride = None
result = 0
# check
if pPlayTimeLimitOverride not in ("true", "True", "TRUE", "false", "False", "FALSE"):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify true or false")
else:
isPlayTimeLimitOverride = True if pPlayTimeLimitOverride in ("true", "True", "TRUE") else False
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeLimitOverride(pUserName, isPlayTimeLimitOverride)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeUnaccountedIntervalsEnabled(self, pUserName, pPlayTimeUnaccountedIntervalsEnabled):
"""Process PlayTime allowed during unaccounted intervals flag"""
# defaults
isPlayTimeUnaccountedIntervalsEnabled = None
result = 0
# check
if pPlayTimeUnaccountedIntervalsEnabled not in ("true", "True", "TRUE", "false", "False", "FALSE"):
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % ("please specify true or false")
else:
isPlayTimeUnaccountedIntervalsEnabled = True if pPlayTimeUnaccountedIntervalsEnabled in ("true", "True", "TRUE") else False
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeUnaccountedIntervalsEnabled(pUserName, isPlayTimeUnaccountedIntervalsEnabled)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeAllowedDays(self, pUserName, pPlayTimeDayList):
"""Process allowed days for PlayTime"""
# defaults
dayMap = []
result = 0
# day map
try:
# try to parse parameters
dayMap = pPlayTimeDayList.split(";")
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeAllowedDays(pUserName, dayMap)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeLimits(self, pUserName, pPlayTimeDayLimits):
"""Process time limits for allowed days for PlayTime"""
# defaults
dayLimits = []
result = 0
# day limists
try:
# allow empty limits too
if pPlayTimeDayLimits != "":
# try to parse parameters
dayLimits = list(map(int, pPlayTimeDayLimits.split(";")))
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeLimitsForDays(pUserName, dayLimits)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeActivities(self, pUserName, pPlayTimeActivities):
"""Process PlayTime activities"""
# defaults
playTimeActivities = []
result = 0
# day limists
try:
# ## try to parse parameters ##
if pPlayTimeActivities != "":
# split activities
for rAct in pPlayTimeActivities.split(";"):
# try parsing the names
mask, description = splitConfigValueNameParam(rAct)
# raise any error in case we can not get parsing right
if mask is None:
# raise
raise ValueError("this does not compute")
# set up activity list
playTimeActivities.append([mask, description])
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeActivities(pUserName, playTimeActivities)
# process
if result != 0:
# log error
log.consoleOut(message)
def processSetPlayTimeLeft(self, pUserName, pOperation, pLimit):
"""Process time left"""
# defaults
limit = 0
result = 0
# limit
try:
# try to parse parameters
limit = int(pLimit)
except Exception as ex:
# fail
result = -1
message = msg.getTranslation("TK_MSG_PARSE_ERROR") % (str(ex))
# preprocess successful
if result == 0:
# invoke
result, message = self._timekprAdminConnector.setPlayTimeLeft(pUserName, pOperation, limit)
# process
if result != 0:
# log error
log.consoleOut(message)
|