brmbar-qt4: Add ALERT_SCRIPT support to call external hook on low balance

This commit is contained in:
Petr Baudis 2015-06-04 23:06:57 +02:00
parent 1c0e51a246
commit 6cc95ab680

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3
import sys
import subprocess
from PySide import QtCore, QtGui, QtDeclarative
@ -10,6 +11,12 @@ import brmbar
# User credit balance limit; sale will fail when balance is below this limit.
LIMIT_BALANCE = -200
# When below this credit balance, an alert hook script (see below) is run.
ALERT_BALANCE = 0
# This script is executed when a user is buying things and their balance is
# below LIMIT_BALANCE (with argument "limit") or below ALERT_BALANCE
# (with argument "alert").
ALERT_SCRIPT = "./alert.sh"
class ShopAdapter(QtCore.QObject):
@ -76,7 +83,14 @@ class ShopAdapter(QtCore.QObject):
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
def canSellItem(self, itemid, userid):
user = brmbar.Account.load(db, id = userid)
return -user.balance() > LIMIT_BALANCE
if -user.balance() > ALERT_BALANCE:
return True
elif -user.balance() > LIMIT_BALANCE:
subprocess.call(["sh", ALERT_SCRIPT, "alert"])
return True
else:
subprocess.call(["sh", ALERT_SCRIPT, "limit"])
return False
@QtCore.Slot('QVariant', 'QVariant', result='QVariant')
def sellItem(self, itemid, userid):