Run 2to3 to start moving to python3
This commit is contained in:
parent
f155d21ae0
commit
ce56649c7c
2
conf.py
2
conf.py
|
@ -1,4 +1,4 @@
|
|||
db_url = 'postgres://CVi@127.0.0.1/pvv_vv'
|
||||
db_url = 'postgres://robertem@127.0.0.1/pvvvv'
|
||||
quit_allowed = True
|
||||
stop_allowed = False
|
||||
show_tracebacks = True
|
||||
|
|
10
helpers.py
10
helpers.py
|
@ -104,13 +104,13 @@ def argmax(d, all=False, value=None):
|
|||
if value != None:
|
||||
dd = d
|
||||
d = {}
|
||||
for key in dd.keys():
|
||||
for key in list(dd.keys()):
|
||||
d[key] = value(dd[key])
|
||||
for key in d.keys():
|
||||
for key in list(d.keys()):
|
||||
if maxarg == None or d[key] > d[maxarg]:
|
||||
maxarg = key
|
||||
if all:
|
||||
return filter(lambda k: d[k] == d[maxarg], d.keys())
|
||||
return [k for k in list(d.keys()) if d[k] == d[maxarg]]
|
||||
return maxarg
|
||||
|
||||
def safe_str(obj):
|
||||
|
@ -122,10 +122,10 @@ def safe_str(obj):
|
|||
'''
|
||||
if isinstance(obj, str):
|
||||
return obj
|
||||
if isinstance(obj, unicode):
|
||||
if isinstance(obj, str):
|
||||
return obj.encode('utf8')
|
||||
else:
|
||||
return safe_str(unicode(obj))
|
||||
return safe_str(str(obj))
|
||||
|
||||
def less(string):
|
||||
'''
|
||||
|
|
|
@ -6,4 +6,4 @@ session=Session()
|
|||
slabbedasker=session.query(User).filter(User.credit<0).all()
|
||||
|
||||
for slubbert in slabbedasker:
|
||||
print "%s, %s" % (slubbert.name, slubbert.credit)
|
||||
print("%s, %s" % (slubbert.name, slubbert.credit))
|
||||
|
|
|
@ -7,29 +7,29 @@ import matplotlib.dates as mdates
|
|||
def getInputType():
|
||||
inp = 0
|
||||
while not (inp == '1' or inp == '2' or inp == '3' or inp == '4'):
|
||||
print 'type 1 for user-statistics'
|
||||
print 'type 2 for product-statistics'
|
||||
print 'type 3 for global-statistics'
|
||||
print 'type 4 to enter loop-mode'
|
||||
inp = raw_input('')
|
||||
print('type 1 for user-statistics')
|
||||
print('type 2 for product-statistics')
|
||||
print('type 3 for global-statistics')
|
||||
print('type 4 to enter loop-mode')
|
||||
inp = input('')
|
||||
return int(inp)
|
||||
|
||||
def getDateFile(date, n):
|
||||
try:
|
||||
if n==0:
|
||||
inp = raw_input('start date? (yyyy-mm-dd) ')
|
||||
inp = input('start date? (yyyy-mm-dd) ')
|
||||
elif n==-1:
|
||||
inp = raw_input('end date? (yyyy-mm-dd) ')
|
||||
inp = input('end date? (yyyy-mm-dd) ')
|
||||
year = inp.partition('-')
|
||||
month = year[2].partition('-')
|
||||
return datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
except:
|
||||
print 'invalid date, setting start start date'
|
||||
print('invalid date, setting start start date')
|
||||
if n==0:
|
||||
print 'to date found on first line'
|
||||
print('to date found on first line')
|
||||
elif n==-1:
|
||||
print 'to date found on last line'
|
||||
print date
|
||||
print('to date found on last line')
|
||||
print(date)
|
||||
return datetime.date(int(date.partition('-')[0]), int(date.partition('-')[2].partition('-')[0]), int(date.partition('-')[2].partition('-')[2]))
|
||||
|
||||
def dateToDateNumFile(date, startDate):
|
||||
|
@ -72,8 +72,8 @@ def dayPlot(array, days):
|
|||
if (not array == []):
|
||||
for i in range(7):
|
||||
array[i]=array[i]*7.0/days
|
||||
plt.bar(range(7), array)
|
||||
plt.xticks(range(7),[' mon',' tue',' wed',' thu',' fri',' sat',' sun'])
|
||||
plt.bar(list(range(7)), array)
|
||||
plt.xticks(list(range(7)),[' mon',' tue',' wed',' thu',' fri',' sat',' sun'])
|
||||
|
||||
def graphPlot(array, dateLine):
|
||||
if (not array == []):
|
||||
|
@ -135,22 +135,22 @@ def plotGlobal(database, dateLine, n):
|
|||
def alt4menu(database, dateLine, useDatabase):
|
||||
n=10
|
||||
while 1:
|
||||
print '\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit'
|
||||
print('\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit')
|
||||
try:
|
||||
inp = raw_input('')
|
||||
inp = input('')
|
||||
except:
|
||||
continue
|
||||
if inp == 'q':
|
||||
break
|
||||
elif inp == '1':
|
||||
if i=='0':
|
||||
user = raw_input('input full username: ')
|
||||
user = input('input full username: ')
|
||||
else:
|
||||
user = getUser()
|
||||
plotUser(database, dateLine, user, n)
|
||||
elif inp == '2':
|
||||
if i=='0':
|
||||
product = raw_input('input full product name: ')
|
||||
product = input('input full product name: ')
|
||||
else:
|
||||
product = getProduct()
|
||||
plotProduct(database, dateLine, product, n)
|
||||
|
@ -158,21 +158,21 @@ def alt4menu(database, dateLine, useDatabase):
|
|||
plotGlobal(database, dateLine, n)
|
||||
elif inp == 'n':
|
||||
try:
|
||||
n=int(raw_input('set number to show '));
|
||||
n=int(input('set number to show '));
|
||||
except:
|
||||
pass
|
||||
#---------------------------------------MAIN-------------------------------------
|
||||
inputType=getInputType()
|
||||
i = raw_input('0:fil, 1:database \n? ')
|
||||
i = input('0:fil, 1:database \n? ')
|
||||
if (inputType == 1):
|
||||
if i=='0':
|
||||
user = raw_input('input full username: ')
|
||||
user = input('input full username: ')
|
||||
else:
|
||||
user = getUser()
|
||||
product = ''
|
||||
elif (inputType == 2):
|
||||
if i=='0':
|
||||
product = raw_input('input full product name: ')
|
||||
product = input('input full product name: ')
|
||||
else:
|
||||
product = getProduct()
|
||||
user = ''
|
||||
|
@ -180,7 +180,7 @@ else :
|
|||
product = ''
|
||||
user = ''
|
||||
if i=='0':
|
||||
inputFile=raw_input('logfil? ')
|
||||
inputFile=input('logfil? ')
|
||||
if inputFile=='':
|
||||
inputFile='default.dibblerlog'
|
||||
database, dateLine = buildDatabaseFromFile(inputFile, inputType, product, user)
|
||||
|
|
|
@ -9,7 +9,7 @@ import db
|
|||
|
||||
def getUser():
|
||||
while 1:
|
||||
string = raw_input('user? ')
|
||||
string = input('user? ')
|
||||
session = Session()
|
||||
user = search_user(string, session)
|
||||
session.close()
|
||||
|
@ -17,25 +17,25 @@ def getUser():
|
|||
return user.name
|
||||
i=0
|
||||
if len(user)==0:
|
||||
print 'no matching string'
|
||||
print('no matching string')
|
||||
if len(user)==1:
|
||||
print 'antar: ', user[0].name, '\n'
|
||||
print('antar: ', user[0].name, '\n')
|
||||
return user[0].name
|
||||
if len(user)>10:
|
||||
continue
|
||||
for u in user:
|
||||
print i, u.name
|
||||
print(i, u.name)
|
||||
i += 1
|
||||
try:
|
||||
n = int(raw_input ('enter number:'))
|
||||
n = int(input ('enter number:'))
|
||||
except:
|
||||
print 'invalid input, restarting'
|
||||
print('invalid input, restarting')
|
||||
continue
|
||||
if (n>-1) and (n<i):
|
||||
return user[n].name
|
||||
def getProduct():
|
||||
while 1:
|
||||
string = raw_input('product? ')
|
||||
string = input('product? ')
|
||||
session = Session()
|
||||
product = search_product(string, session)
|
||||
session.close()
|
||||
|
@ -43,19 +43,19 @@ def getProduct():
|
|||
return product.name
|
||||
i=0
|
||||
if len(product)==0:
|
||||
print 'no matching string'
|
||||
print('no matching string')
|
||||
if len(product)==1:
|
||||
print 'antar: ', product[0].name, '\n'
|
||||
print('antar: ', product[0].name, '\n')
|
||||
return product[0].name
|
||||
if len(product)>10:
|
||||
continue
|
||||
for u in product:
|
||||
print i, u.name
|
||||
print(i, u.name)
|
||||
i += 1
|
||||
try:
|
||||
n = int(raw_input ('enter number:'))
|
||||
n = int(input ('enter number:'))
|
||||
except:
|
||||
print 'invalid input, restarting'
|
||||
print('invalid input, restarting')
|
||||
continue
|
||||
if (n>-1) and (n<i):
|
||||
return product[n].name
|
||||
|
@ -94,8 +94,8 @@ def getDateDb(date, inp):
|
|||
month = year[2].partition('-')
|
||||
return datetime.datetime(int(year[0]), int(month[0]), int(month[2]))
|
||||
except:
|
||||
print 'invalid date, setting date to date found in db'
|
||||
print date
|
||||
print('invalid date, setting date to date found in db')
|
||||
print(date)
|
||||
return date
|
||||
|
||||
def dateToDateNumDb(date, startDate):
|
||||
|
@ -105,11 +105,11 @@ def dateToDateNumDb(date, startDate):
|
|||
def getInputType():
|
||||
inp = 0
|
||||
while not (inp == '1' or inp == '2' or inp == '3' or inp == '4'):
|
||||
print 'type 1 for user-statistics'
|
||||
print 'type 2 for product-statistics'
|
||||
print 'type 3 for global-statistics'
|
||||
print 'type 4 to enter loop-mode'
|
||||
inp = raw_input('')
|
||||
print('type 1 for user-statistics')
|
||||
print('type 2 for product-statistics')
|
||||
print('type 3 for global-statistics')
|
||||
print('type 4 to enter loop-mode')
|
||||
inp = input('')
|
||||
return int(inp)
|
||||
|
||||
def getProducts(products):
|
||||
|
@ -127,8 +127,8 @@ def getDateFile(date, inp):
|
|||
month = year[2].partition('-')
|
||||
return datetime.date(int(year[0]), int(month[0]), int(month[2]))
|
||||
except:
|
||||
print 'invalid date, setting date to date found on file file'
|
||||
print date
|
||||
print('invalid date, setting date to date found on file file')
|
||||
print(date)
|
||||
return datetime.date(int(date.partition('-')[0]), int(date.partition('-')[2].partition('-')[0]), int(date.partition('-')[2].partition('-')[2]))
|
||||
|
||||
def dateToDateNumFile(date, startDate):
|
||||
|
@ -199,9 +199,9 @@ def addLineToDatabase(database, inputLine):
|
|||
return database
|
||||
|
||||
def buildDatabaseFromDb(inputType, inputProduct, inputUser):
|
||||
sdate = raw_input('enter start date (yyyy-mm-dd)? ')
|
||||
edate = raw_input('enter end date (yyyy-mm-dd)? ')
|
||||
print 'building database...'
|
||||
sdate = input('enter start date (yyyy-mm-dd)? ')
|
||||
edate = input('enter end date (yyyy-mm-dd)? ')
|
||||
print('building database...')
|
||||
session = Session()
|
||||
transaction_list = session.query(Transaction).all()
|
||||
inputLine = InputLine(inputUser, inputProduct, inputType)
|
||||
|
@ -216,10 +216,10 @@ def buildDatabaseFromDb(inputType, inputProduct, inputUser):
|
|||
database.globalDatoForbruk = [0]*(inputLine.numberOfDays+1)
|
||||
database.globalUkedagForbruk = [0]*7
|
||||
database.pengebeholdning = [0]*(inputLine.numberOfDays+1)
|
||||
print 'wait for it.... '
|
||||
print('wait for it.... ')
|
||||
for transaction in transaction_list:
|
||||
if transaction.purchase:
|
||||
products = map(lambda ent: ent.product.name, transaction.purchase.entries)
|
||||
products = [ent.product.name for ent in transaction.purchase.entries]
|
||||
else:
|
||||
products = []
|
||||
products.append('')
|
||||
|
@ -232,13 +232,13 @@ def buildDatabaseFromDb(inputType, inputProduct, inputUser):
|
|||
database=addLineToDatabase(database, inputLine )
|
||||
inputLine.price = 0;
|
||||
|
||||
print 'saving as default.dibblerlog...',
|
||||
print('saving as default.dibblerlog...', end=' ')
|
||||
f=open('default.dibblerlog','w')
|
||||
line_format = '%s|%s|%s|%s|%s|%s\n'
|
||||
transaction_list = session.query(Transaction).all()
|
||||
for transaction in transaction_list:
|
||||
if transaction.purchase:
|
||||
products = u'¤'.join(map(lambda ent: ent.product.name, transaction.purchase.entries))
|
||||
products = '¤'.join([ent.product.name for ent in transaction.purchase.entries])
|
||||
description = ''
|
||||
else:
|
||||
products = ''
|
||||
|
@ -258,12 +258,12 @@ def buildDatabaseFromDb(inputType, inputProduct, inputUser):
|
|||
dateLine.append(startDate)
|
||||
for n in range(inputLine.numberOfDays):
|
||||
dateLine.append(startDate+n*day)
|
||||
print 'done'
|
||||
print('done')
|
||||
return database, dateLine
|
||||
|
||||
def buildDatabaseFromFile(inputFile, inputType, inputProduct, inputUser):
|
||||
sdate = raw_input('enter start date (yyyy-mm-dd)? ')
|
||||
edate = raw_input('enter end date (yyyy-mm-dd)? ')
|
||||
sdate = input('enter start date (yyyy-mm-dd)? ')
|
||||
edate = input('enter end date (yyyy-mm-dd)? ')
|
||||
|
||||
f=open(inputFile)
|
||||
try:
|
||||
|
@ -315,18 +315,18 @@ def buildDatabaseFromFile(inputFile, inputType, inputProduct, inputUser):
|
|||
def printTopDict(dictionary, n, k):
|
||||
i=0
|
||||
for key in sorted(dictionary, key=dictionary.get, reverse=k):
|
||||
print key, ': ',dictionary[key]
|
||||
print(key, ': ',dictionary[key])
|
||||
if i<n:
|
||||
i += 1
|
||||
else:
|
||||
break
|
||||
|
||||
def printTopDict2(dictionary, dictionary2, n):
|
||||
print ''
|
||||
print 'product : price[kr] ( number )'
|
||||
print('')
|
||||
print('product : price[kr] ( number )')
|
||||
i=0
|
||||
for key in sorted(dictionary, key=dictionary.get, reverse=True):
|
||||
print key, ': ',dictionary[key], ' (', dictionary2[key], ') '
|
||||
print(key, ': ',dictionary[key], ' (', dictionary2[key], ') ')
|
||||
if i<n:
|
||||
i += 1
|
||||
else:
|
||||
|
@ -335,80 +335,80 @@ def printTopDict2(dictionary, dictionary2, n):
|
|||
def printWeekdays(week, days):
|
||||
if week==[] or days==0:
|
||||
return
|
||||
print 'mon: ', '%.2f'%(week[0]*7.0/days), ' tue: ', '%.2f'%(week[1]*7.0/days), ' wen: ', '%.2f'%(week[2]*7.0/days), ' thu: ', '%.2f'%(week[3]*7.0/days), ' fri: ', '%.2f'%(week[4]*7.0/days), ' sat: ','%.2f'%( week[5]*7.0/days), ' sun: ', '%.2f'%(week[6]*7.0/days)
|
||||
print 'forbruk per dag (snitt): ', '%.2f'%(sum(week)*1.0/days)
|
||||
print ''
|
||||
print('mon: ', '%.2f'%(week[0]*7.0/days), ' tue: ', '%.2f'%(week[1]*7.0/days), ' wen: ', '%.2f'%(week[2]*7.0/days), ' thu: ', '%.2f'%(week[3]*7.0/days), ' fri: ', '%.2f'%(week[4]*7.0/days), ' sat: ','%.2f'%( week[5]*7.0/days), ' sun: ', '%.2f'%(week[6]*7.0/days))
|
||||
print('forbruk per dag (snitt): ', '%.2f'%(sum(week)*1.0/days))
|
||||
print('')
|
||||
|
||||
def printBalance(database, user):
|
||||
forbruk = 0
|
||||
if (user in database.personVareVerdi):
|
||||
forbruk = sum([i for i in database.personVareVerdi[user].values()])
|
||||
print 'totalt kjøpt for: ', forbruk,
|
||||
forbruk = sum([i for i in list(database.personVareVerdi[user].values())])
|
||||
print('totalt kjøpt for: ', forbruk, end=' ')
|
||||
if (user in database.personNegTransactions):
|
||||
print 'kr, totalt lagt til: ', -database.personNegTransactions[user],
|
||||
print('kr, totalt lagt til: ', -database.personNegTransactions[user], end=' ')
|
||||
forbruk=-database.personNegTransactions[user]-forbruk
|
||||
if (user in database.personPosTransactions):
|
||||
print 'kr, totalt tatt fra boks: ', database.personPosTransactions[user],
|
||||
print('kr, totalt tatt fra boks: ', database.personPosTransactions[user], end=' ')
|
||||
forbruk=forbruk-database.personPosTransactions[user]
|
||||
print 'balanse: ', forbruk, 'kr',
|
||||
print ''
|
||||
print('balanse: ', forbruk, 'kr', end=' ')
|
||||
print('')
|
||||
|
||||
def printUser(database, dateLine, user, n):
|
||||
printTopDict2(database.personVareVerdi[user], database.personVareAntall[user], n)
|
||||
print '\nforbruk per ukedag [kr/dag],',
|
||||
print('\nforbruk per ukedag [kr/dag],', end=' ')
|
||||
printWeekdays(database.personUkedagVerdi[user], len(dateLine))
|
||||
printBalance(database, user)
|
||||
|
||||
def printProduct(database, dateLine, product, n):
|
||||
printTopDict(database.varePersonAntall[product], n, 1)
|
||||
print '\nforbruk per ukedag [antall/dag],',
|
||||
print('\nforbruk per ukedag [antall/dag],', end=' ')
|
||||
printWeekdays(database.vareUkedagAntall[product], len(dateLine))
|
||||
print 'Det er solgt: ', database.globalVareAntall[product], product, 'til en verdi av: ', database.globalVareVerdi[product], 'kr'
|
||||
print('Det er solgt: ', database.globalVareAntall[product], product, 'til en verdi av: ', database.globalVareVerdi[product], 'kr')
|
||||
|
||||
def printGlobal(database, dateLine, n):
|
||||
print '\nmest lagt til: '
|
||||
print('\nmest lagt til: ')
|
||||
printTopDict(database.personNegTransactions, n, 0)
|
||||
print '\nmest tatt fra:'
|
||||
print('\nmest tatt fra:')
|
||||
printTopDict(database.personPosTransactions, n, 1)
|
||||
print '\nstørst forbruk:'
|
||||
print('\nstørst forbruk:')
|
||||
printTopDict(database.globalPersonForbruk, n, 1)
|
||||
printTopDict2(database.globalVareVerdi, database.globalVareAntall, n)
|
||||
print '\nforbruk per ukedag [kr/dag],',
|
||||
print('\nforbruk per ukedag [kr/dag],', end=' ')
|
||||
printWeekdays(database.globalUkedagForbruk, len(dateLine))
|
||||
print 'Det er solgt varer til en verdi av: ', sum(database.globalDatoForbruk), 'kr, det er lagt til', -sum([i for i in database.personNegTransactions.values()]), 'og tatt fra', sum([i for i in database.personPosTransactions.values()]),
|
||||
print 'balansen blir:', database.pengebeholdning[len(dateLine)-1], 'der negative verdier representerer at brukere har kreditt tilgjengelig'
|
||||
print('Det er solgt varer til en verdi av: ', sum(database.globalDatoForbruk), 'kr, det er lagt til', -sum([i for i in list(database.personNegTransactions.values())]), 'og tatt fra', sum([i for i in list(database.personPosTransactions.values())]), end=' ')
|
||||
print('balansen blir:', database.pengebeholdning[len(dateLine)-1], 'der negative verdier representerer at brukere har kreditt tilgjengelig')
|
||||
|
||||
def alt4menuTextOnly(database, dateLine):
|
||||
n=10
|
||||
while 1:
|
||||
print '\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit'
|
||||
inp = raw_input('')
|
||||
print('\n1: user-statistics, 2: product-statistics, 3:global-statistics, n: adjust amount of data shown q:quit')
|
||||
inp = input('')
|
||||
if inp == 'q':
|
||||
break
|
||||
elif inp == '1':
|
||||
try:
|
||||
printUser(database, dateLine, getUser(), n)
|
||||
except:
|
||||
print '\n\nSomething is not right, (last date prior to first date?)'
|
||||
print('\n\nSomething is not right, (last date prior to first date?)')
|
||||
elif inp == '2':
|
||||
try:
|
||||
printProduct(database, dateLine, getProduct(), n)
|
||||
except:
|
||||
print '\n\nSomething is not right, (last date prior to first date?)'
|
||||
print('\n\nSomething is not right, (last date prior to first date?)')
|
||||
elif inp == '3':
|
||||
try:
|
||||
printGlobal(database, dateLine, n)
|
||||
except:
|
||||
print '\n\nSomething is not right, (last date prior to first date?)'
|
||||
print('\n\nSomething is not right, (last date prior to first date?)')
|
||||
elif inp == 'n':
|
||||
n=int(raw_input('set number to show '));
|
||||
n=int(input('set number to show '));
|
||||
|
||||
def statisticsTextOnly():
|
||||
inputType = 4
|
||||
product = ''
|
||||
user = ''
|
||||
print '\n0: from file, 1: from database, q:quit'
|
||||
inp = raw_input('')
|
||||
print('\n0: from file, 1: from database, q:quit')
|
||||
inp = input('')
|
||||
if inp == '1':
|
||||
database, dateLine = buildDatabaseFromDb(inputType, product, user)
|
||||
elif inp=='0' or inp == '':
|
||||
|
|
|
@ -60,13 +60,13 @@ if __name__ == '__main__':
|
|||
try:
|
||||
main.execute()
|
||||
except KeyboardInterrupt:
|
||||
print ''
|
||||
print 'Interrupted.'
|
||||
print('')
|
||||
print('Interrupted.')
|
||||
except:
|
||||
print 'Something went wrong.'
|
||||
print '%s: %s' % (sys.exc_info()[0], sys.exc_info()[1])
|
||||
print('Something went wrong.')
|
||||
print('%s: %s' % (sys.exc_info()[0], sys.exc_info()[1]))
|
||||
if conf.show_tracebacks:
|
||||
traceback.print_tb(sys.exc_info()[2])
|
||||
else:
|
||||
break
|
||||
print 'Restarting main menu.'
|
||||
print('Restarting main menu.')
|
||||
|
|
|
@ -66,36 +66,36 @@ much money you're due in credits for the purchase when prompted.\n'''
|
|||
return bool(self.users) and len(self.products) and self.price
|
||||
|
||||
def print_info(self):
|
||||
print (6 + Product.name_length) * '-'
|
||||
print((6 + Product.name_length) * '-')
|
||||
if self.price:
|
||||
print "Amount to be credited: {{0:>{0}d}}".format(Product.name_length-17).format(self.price)
|
||||
print("Amount to be credited: {{0:>{0}d}}".format(Product.name_length-17).format(self.price))
|
||||
if self.users:
|
||||
print "Users to credit:"
|
||||
print("Users to credit:")
|
||||
for user in self.users:
|
||||
print " %s" % str(user.name)
|
||||
print u"\n{{0:s}}{{1:>{0}s}}".format(Product.name_length-1).format("Product", "Amount")
|
||||
print (6 + Product.name_length) * '-'
|
||||
print(" %s" % str(user.name))
|
||||
print("\n{{0:s}}{{1:>{0}s}}".format(Product.name_length-1).format("Product", "Amount"))
|
||||
print((6 + Product.name_length) * '-')
|
||||
if len(self.products):
|
||||
for product in self.products.keys():
|
||||
print u'{{0:<{0}}}{{1:>6d}}'.format(Product.name_length).format(product.name, self.products[product][0])
|
||||
print (6 + Product.name_length) * '-'
|
||||
for product in list(self.products.keys()):
|
||||
print('{{0:<{0}}}{{1:>6d}}'.format(Product.name_length).format(product.name, self.products[product][0]))
|
||||
print((6 + Product.name_length) * '-')
|
||||
|
||||
def add_thing_to_pending(self, thing, amount, price):
|
||||
if isinstance(thing, User):
|
||||
self.users.append(thing)
|
||||
elif thing in self.products.keys():
|
||||
print 'Already added this product, adding amounts'
|
||||
elif thing in list(self.products.keys()):
|
||||
print('Already added this product, adding amounts')
|
||||
self.products[thing][0] += amount
|
||||
self.products[thing][1] += price
|
||||
else:
|
||||
self.products[thing] = [amount, price]
|
||||
|
||||
def perform_transaction(self):
|
||||
print 'Did you pay a different price?'
|
||||
print('Did you pay a different price?')
|
||||
if self.confirm('>', default=False):
|
||||
price = self.input_int('How much did you pay?', default=self.price)
|
||||
if price > self.price:
|
||||
print 'Illegal action, total can not be higher than your total.'
|
||||
print('Illegal action, total can not be higher than your total.')
|
||||
else:
|
||||
self.price = price
|
||||
|
||||
|
@ -109,9 +109,9 @@ much money you're due in credits for the purchase when prompted.\n'''
|
|||
product.price = int(ceil(float(value) / (max(product.stock, 0) + self.products[product][0])))
|
||||
product.stock = max(self.products[product][0], product.stock + self.products[product][0])
|
||||
product.hidden = False
|
||||
print "New stock for %s: %d" % (product.name, product.stock), \
|
||||
print("New stock for %s: %d" % (product.name, product.stock), \
|
||||
("- New price: " + str(product.price) if old_price != product.price else ""), \
|
||||
("- Removed hidden status" if old_hidden != product.hidden else "")
|
||||
("- Removed hidden status" if old_hidden != product.hidden else ""))
|
||||
|
||||
purchase = Purchase()
|
||||
for user in self.users:
|
||||
|
@ -124,9 +124,9 @@ much money you're due in credits for the purchase when prompted.\n'''
|
|||
|
||||
try:
|
||||
self.session.commit()
|
||||
print "Success! Transaction performed:"
|
||||
print("Success! Transaction performed:")
|
||||
# self.print_info()
|
||||
for user in self.users:
|
||||
print "User %s's credit is now %i" % (user.name, user.credit)
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not perform transaction: %s' % e
|
||||
print("User %s's credit is now %i" % (user.name, user.credit))
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not perform transaction: %s' % e)
|
||||
|
|
|
@ -34,29 +34,29 @@ When finished, write an empty line to confirm the purchase.\n'''
|
|||
def low_credit_warning(self, user, timeout=False):
|
||||
assert isinstance(user, User)
|
||||
|
||||
print "***********************************************************************"
|
||||
print "***********************************************************************"
|
||||
print ""
|
||||
print "$$\ $$\ $$$$$$\ $$$$$$$\ $$\ $$\ $$$$$$\ $$\ $$\ $$$$$$\\"
|
||||
print "$$ | $\ $$ |$$ __$$\ $$ __$$\ $$$\ $$ |\_$$ _|$$$\ $$ |$$ __$$\\"
|
||||
print "$$ |$$$\ $$ |$$ / $$ |$$ | $$ |$$$$\ $$ | $$ | $$$$\ $$ |$$ / \__|"
|
||||
print "$$ $$ $$\$$ |$$$$$$$$ |$$$$$$$ |$$ $$\$$ | $$ | $$ $$\$$ |$$ |$$$$\\"
|
||||
print "$$$$ _$$$$ |$$ __$$ |$$ __$$< $$ \$$$$ | $$ | $$ \$$$$ |$$ |\_$$ |"
|
||||
print "$$$ / \$$$ |$$ | $$ |$$ | $$ |$$ |\$$$ | $$ | $$ |\$$$ |$$ | $$ |"
|
||||
print "$$ / \$$ |$$ | $$ |$$ | $$ |$$ | \$$ |$$$$$$\ $$ | \$$ |\$$$$$$ |"
|
||||
print "\__/ \__|\__| \__|\__| \__|\__| \__|\______|\__| \__| \______/"
|
||||
print ""
|
||||
print "***********************************************************************"
|
||||
print "***********************************************************************"
|
||||
print ""
|
||||
print "USER %s HAS LOWER CREDIT THAN %d." % (user.name, conf.low_credit_warning_limit)
|
||||
print "THIS PURCHASE WILL CHARGE YOUR CREDIT TWICE AS MUCH."
|
||||
print "CONSIDER PUTTING MONEY IN THE BOX TO AVOID THIS."
|
||||
print ""
|
||||
print "Do you want to continue with this purchase?"
|
||||
print("***********************************************************************")
|
||||
print("***********************************************************************")
|
||||
print("")
|
||||
print("$$\ $$\ $$$$$$\ $$$$$$$\ $$\ $$\ $$$$$$\ $$\ $$\ $$$$$$\\")
|
||||
print("$$ | $\ $$ |$$ __$$\ $$ __$$\ $$$\ $$ |\_$$ _|$$$\ $$ |$$ __$$\\")
|
||||
print("$$ |$$$\ $$ |$$ / $$ |$$ | $$ |$$$$\ $$ | $$ | $$$$\ $$ |$$ / \__|")
|
||||
print("$$ $$ $$\$$ |$$$$$$$$ |$$$$$$$ |$$ $$\$$ | $$ | $$ $$\$$ |$$ |$$$$\\")
|
||||
print("$$$$ _$$$$ |$$ __$$ |$$ __$$< $$ \$$$$ | $$ | $$ \$$$$ |$$ |\_$$ |")
|
||||
print("$$$ / \$$$ |$$ | $$ |$$ | $$ |$$ |\$$$ | $$ | $$ |\$$$ |$$ | $$ |")
|
||||
print("$$ / \$$ |$$ | $$ |$$ | $$ |$$ | \$$ |$$$$$$\ $$ | \$$ |\$$$$$$ |")
|
||||
print("\__/ \__|\__| \__|\__| \__|\__| \__|\______|\__| \__| \______/")
|
||||
print("")
|
||||
print("***********************************************************************")
|
||||
print("***********************************************************************")
|
||||
print("")
|
||||
print("USER %s HAS LOWER CREDIT THAN %d." % (user.name, conf.low_credit_warning_limit))
|
||||
print("THIS PURCHASE WILL CHARGE YOUR CREDIT TWICE AS MUCH.")
|
||||
print("CONSIDER PUTTING MONEY IN THE BOX TO AVOID THIS.")
|
||||
print("")
|
||||
print("Do you want to continue with this purchase?")
|
||||
|
||||
if timeout:
|
||||
print"THIS PURCHASE WILL AUTOMATICALLY BE PERFORMED IN 3 MINUTES!"
|
||||
print("THIS PURCHASE WILL AUTOMATICALLY BE PERFORMED IN 3 MINUTES!")
|
||||
return self.confirm(prompt=">", default=True, timeout=180)
|
||||
else:
|
||||
return self.confirm(prompt=">", default=True)
|
||||
|
@ -64,10 +64,10 @@ When finished, write an empty line to confirm the purchase.\n'''
|
|||
def add_thing_to_purchase(self, thing, amount=1):
|
||||
if isinstance(thing, User):
|
||||
if thing.is_anonymous():
|
||||
print '---------------------------------------------'
|
||||
print '| You are now purchasing as the user anonym.|'
|
||||
print '| You have to put money in the anonym-jar. |'
|
||||
print '---------------------------------------------'
|
||||
print('---------------------------------------------')
|
||||
print('| You are now purchasing as the user anonym.|')
|
||||
print('| You have to put money in the anonym-jar. |')
|
||||
print('---------------------------------------------')
|
||||
|
||||
if not self.credit_check(thing):
|
||||
if self.low_credit_warning(user=thing, timeout=self.superfast_mode):
|
||||
|
@ -100,11 +100,11 @@ When finished, write an empty line to confirm the purchase.\n'''
|
|||
|
||||
if len(initial_contents) > 0 and all(map(is_product, initial_contents)):
|
||||
self.superfast_mode = True
|
||||
print '***********************************************'
|
||||
print '****** Buy menu is in SUPERFASTmode[tm]! ******'
|
||||
print '*** The purchase will be stored immediately ***'
|
||||
print '*** when you enter a user. ***'
|
||||
print '***********************************************'
|
||||
print('***********************************************')
|
||||
print('****** Buy menu is in SUPERFASTmode[tm]! ******')
|
||||
print('*** The purchase will be stored immediately ***')
|
||||
print('*** when you enter a user. ***')
|
||||
print('***********************************************')
|
||||
|
||||
while True:
|
||||
self.print_purchase()
|
||||
|
@ -148,17 +148,17 @@ When finished, write an empty line to confirm the purchase.\n'''
|
|||
self.session.add(self.purchase)
|
||||
try:
|
||||
self.session.commit()
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store purchase: %s' % e
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store purchase: %s' % e)
|
||||
else:
|
||||
print 'Purchase stored.'
|
||||
print('Purchase stored.')
|
||||
self.print_purchase()
|
||||
for t in self.purchase.transactions:
|
||||
if not t.user.is_anonymous():
|
||||
print 'User %s\'s credit is now %d kr' % (t.user.name, t.user.credit)
|
||||
print('User %s\'s credit is now %d kr' % (t.user.name, t.user.credit))
|
||||
if t.user.credit < conf.low_credit_warning_limit:
|
||||
print 'USER %s HAS LOWER CREDIT THAN %d, AND SHOULD CONSIDER PUTTING SOME MONEY IN THE BOX.' \
|
||||
% (t.user.name, conf.low_credit_warning_limit)
|
||||
print('USER %s HAS LOWER CREDIT THAN %d, AND SHOULD CONSIDER PUTTING SOME MONEY IN THE BOX.' \
|
||||
% (t.user.name, conf.low_credit_warning_limit))
|
||||
|
||||
return True
|
||||
|
||||
|
@ -177,15 +177,13 @@ When finished, write an empty line to confirm the purchase.\n'''
|
|||
string += '(empty)'
|
||||
else:
|
||||
string += ', '.join(
|
||||
map(lambda t: t.user.name + ("*" if not self.credit_check(t.user) else ""),
|
||||
transactions))
|
||||
[t.user.name + ("*" if not self.credit_check(t.user) else "") for t in transactions])
|
||||
string += '\n products: '
|
||||
if len(entries) == 0:
|
||||
string += '(empty)'
|
||||
else:
|
||||
string += "\n "
|
||||
string += '\n '.join(map(lambda e: '%dx %s (%d kr)' % (e.amount, e.product.name, e.product.price),
|
||||
entries))
|
||||
string += '\n '.join(['%dx %s (%d kr)' % (e.amount, e.product.name, e.product.price) for e in entries])
|
||||
if len(transactions) > 1:
|
||||
string += '\n price per person: %d kr' % self.purchase.price_per_transaction()
|
||||
if any(t.penalty > 1 for t in transactions):
|
||||
|
|
|
@ -19,9 +19,9 @@ class AddUserMenu(Menu):
|
|||
self.session.add(user)
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'User %s stored' % username
|
||||
except sqlalchemy.exc.IntegrityError, e:
|
||||
print 'Could not store user %s: %s' % (username, e)
|
||||
print('User %s stored' % username)
|
||||
except sqlalchemy.exc.IntegrityError as e:
|
||||
print('Could not store user %s: %s' % (username, e))
|
||||
self.pause()
|
||||
|
||||
|
||||
|
@ -56,9 +56,9 @@ user, then rfid (write an empty line to remove the card number or rfid).
|
|||
empty_string_is_none=True)
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'User %s stored' % user.name
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store user %s: %s' % (user.name, e)
|
||||
print('User %s stored' % user.name)
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store user %s: %s' % (user.name, e))
|
||||
self.pause()
|
||||
|
||||
|
||||
|
@ -75,9 +75,9 @@ class AddProductMenu(Menu):
|
|||
self.session.add(product)
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'Product %s stored' % name
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store product %s: %s' % (name, e)
|
||||
print('Product %s stored' % name)
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store product %s: %s' % (name, e))
|
||||
self.pause()
|
||||
|
||||
|
||||
|
@ -108,16 +108,16 @@ class EditProductMenu(Menu):
|
|||
elif what == 'store':
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'Product %s stored' % product.name
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store product %s: %s' % (product.name, e)
|
||||
print('Product %s stored' % product.name)
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store product %s: %s' % (product.name, e))
|
||||
self.pause()
|
||||
return
|
||||
elif what is None:
|
||||
print 'Edit aborted'
|
||||
print('Edit aborted')
|
||||
return
|
||||
else:
|
||||
print 'What what?'
|
||||
print('What what?')
|
||||
|
||||
|
||||
class AdjustStockMenu(Menu):
|
||||
|
@ -128,25 +128,25 @@ class AdjustStockMenu(Menu):
|
|||
self.print_header()
|
||||
product = self.input_product('Product> ')
|
||||
|
||||
print 'The stock of this product is: %d ' % product.stock
|
||||
print 'Write the number of products you have added to the stock'
|
||||
print 'Alternatively, correct the stock for any mistakes'
|
||||
print('The stock of this product is: %d ' % product.stock)
|
||||
print('Write the number of products you have added to the stock')
|
||||
print('Alternatively, correct the stock for any mistakes')
|
||||
add_stock = self.input_int('Added stock> ', (-1000, 1000))
|
||||
print 'You added %d to the stock of %s' % (add_stock, product)
|
||||
print('You added %d to the stock of %s' % (add_stock, product))
|
||||
|
||||
product.stock += add_stock
|
||||
|
||||
print 'The stock is now %d' % product.stock
|
||||
print('The stock is now %d' % product.stock)
|
||||
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'Stock is now stored'
|
||||
print('Stock is now stored')
|
||||
self.pause()
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store stock: %s' % e
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store stock: %s' % e)
|
||||
self.pause()
|
||||
return
|
||||
print 'The stock is now %d' % product.stock
|
||||
print('The stock is now %d' % product.stock)
|
||||
|
||||
|
||||
class CleanupStockMenu(Menu):
|
||||
|
@ -158,10 +158,10 @@ class CleanupStockMenu(Menu):
|
|||
|
||||
products = self.session.query(Product).filter(Product.stock != 0).all()
|
||||
|
||||
print "Every product in stock will be printed."
|
||||
print "Entering no value will keep current stock or set it to 0 if it is negative."
|
||||
print "Entering a value will set current stock to that value."
|
||||
print "Press enter to begin."
|
||||
print("Every product in stock will be printed.")
|
||||
print("Entering no value will keep current stock or set it to 0 if it is negative.")
|
||||
print("Entering a value will set current stock to that value.")
|
||||
print("Press enter to begin.")
|
||||
|
||||
self.pause()
|
||||
|
||||
|
@ -176,12 +176,12 @@ class CleanupStockMenu(Menu):
|
|||
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'New stocks are now stored.'
|
||||
print('New stocks are now stored.')
|
||||
self.pause()
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store stock: %s' % e
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store stock: %s' % e)
|
||||
self.pause()
|
||||
return
|
||||
|
||||
for p in changed_products:
|
||||
print p[0].name, ".", p[1], "->", p[0].stock
|
||||
print(p[0].name, ".", p[1], "->", p[0].stock)
|
||||
|
|
|
@ -46,7 +46,7 @@ class FAQMenu(Menu):
|
|||
MessageMenu('Where are the easter eggs? I tried saying "moo", but nothing happened.',
|
||||
'Don\'t say "moo".'),
|
||||
MessageMenu('Why does the program speak English when all the users are Norwegians?',
|
||||
u'Godt spørsmål. Det virket sikkert som en god idé der og da.'),
|
||||
'Godt spørsmål. Det virket sikkert som en god idé der og da.'),
|
||||
MessageMenu('I found a bug; is there a reward?',
|
||||
'''
|
||||
No.
|
||||
|
|
|
@ -38,7 +38,7 @@ class Menu(object):
|
|||
|
||||
def exit_menu(self):
|
||||
if self.exit_disallowed_msg is not None:
|
||||
print self.exit_disallowed_msg
|
||||
print(self.exit_disallowed_msg)
|
||||
return
|
||||
if self.exit_confirm_msg is not None:
|
||||
if not self.confirm(self.exit_confirm_msg, default=True):
|
||||
|
@ -47,27 +47,27 @@ class Menu(object):
|
|||
|
||||
def at_exit(self):
|
||||
if self.exit_msg:
|
||||
print self.exit_msg
|
||||
print(self.exit_msg)
|
||||
|
||||
def set_context(self, string, display=True):
|
||||
self.context = string
|
||||
if self.context is not None and display:
|
||||
print self.context
|
||||
print(self.context)
|
||||
|
||||
def add_to_context(self, string):
|
||||
self.context += string
|
||||
|
||||
def printc(self, string):
|
||||
print string
|
||||
print(string)
|
||||
if self.context is None:
|
||||
self.context = string
|
||||
else:
|
||||
self.context += '\n' + string
|
||||
|
||||
def show_context(self):
|
||||
print self.header_format % self.name
|
||||
print(self.header_format % self.name)
|
||||
if self.context is not None:
|
||||
print self.context
|
||||
print(self.context)
|
||||
|
||||
def item_is_submenu(self, i):
|
||||
return isinstance(self.items[i], Menu)
|
||||
|
@ -98,7 +98,7 @@ class Menu(object):
|
|||
if result is None or re.match(regex + '$', result):
|
||||
return result
|
||||
else:
|
||||
print 'Value must match regular expression "%s"' % regex
|
||||
print('Value must match regular expression "%s"' % regex)
|
||||
if length_range != (None, None):
|
||||
while True:
|
||||
result = self.input_str(prompt, empty_string_is_none=empty_string_is_none)
|
||||
|
@ -109,11 +109,11 @@ class Menu(object):
|
|||
if ((length_range[0] and length < length_range[0]) or
|
||||
(length_range[1] and length > length_range[1])):
|
||||
if length_range[0] and length_range[1]:
|
||||
print 'Value must have length in range [%d,%d]' % length_range
|
||||
print('Value must have length in range [%d,%d]' % length_range)
|
||||
elif length_range[0]:
|
||||
print 'Value must have length at least %d' % length_range[0]
|
||||
print('Value must have length at least %d' % length_range[0])
|
||||
else:
|
||||
print 'Value must have length at most %d' % length_range[1]
|
||||
print('Value must have length at most %d' % length_range[1])
|
||||
else:
|
||||
return result
|
||||
while True:
|
||||
|
@ -129,11 +129,11 @@ class Menu(object):
|
|||
# timeout occurred, simulate empty line
|
||||
result = ''
|
||||
else:
|
||||
result = unicode(raw_input(), conf.input_encoding).strip()
|
||||
result = str(input(), conf.input_encoding).strip()
|
||||
else:
|
||||
result = unicode(raw_input(safe_str(prompt)), conf.input_encoding).strip()
|
||||
result = str(input(safe_str(prompt)), conf.input_encoding).strip()
|
||||
except EOFError:
|
||||
print 'quit'
|
||||
print('quit')
|
||||
self.exit_menu()
|
||||
continue
|
||||
if result in exit_commands:
|
||||
|
@ -180,7 +180,7 @@ class Menu(object):
|
|||
while True:
|
||||
result = self.input_str(prompt)
|
||||
if result == '':
|
||||
print 'Please enter something'
|
||||
print('Please enter something')
|
||||
# 'c' in main menu to change colours
|
||||
elif result == 'c':
|
||||
os.system('echo -e "\033[' + str(random.randint(40, 49)) + ';' + str(random.randint(30, 37)) + ';5m"')
|
||||
|
@ -204,7 +204,7 @@ class Menu(object):
|
|||
self.invalid_menu_choice(result)
|
||||
|
||||
def invalid_menu_choice(self, in_str):
|
||||
print 'Please enter a valid choice.'
|
||||
print('Please enter a valid choice.')
|
||||
|
||||
def input_int(self, prompt=None, allowed_range=(None, None), null_allowed=False, default=None):
|
||||
if prompt is None:
|
||||
|
@ -223,15 +223,15 @@ class Menu(object):
|
|||
if ((allowed_range[0] and value < allowed_range[0]) or
|
||||
(allowed_range[1] and value > allowed_range[1])):
|
||||
if allowed_range[0] and allowed_range[1]:
|
||||
print 'Value must be in range [%d,%d]' % allowed_range
|
||||
print('Value must be in range [%d,%d]' % allowed_range)
|
||||
elif allowed_range[0]:
|
||||
print 'Value must be at least %d' % allowed_range[0]
|
||||
print('Value must be at least %d' % allowed_range[0])
|
||||
else:
|
||||
print 'Value must be at most %d' % allowed_range[1]
|
||||
print('Value must be at most %d' % allowed_range[1])
|
||||
else:
|
||||
return value
|
||||
except ValueError:
|
||||
print "Please enter an integer"
|
||||
print("Please enter an integer")
|
||||
|
||||
def input_user(self, prompt=None):
|
||||
user = None
|
||||
|
@ -275,7 +275,7 @@ class Menu(object):
|
|||
num = 1
|
||||
|
||||
if (result is None) and (len(search_lst) > 1):
|
||||
print 'Interpreting input as "<number> <product>"'
|
||||
print('Interpreting input as "<number> <product>"')
|
||||
try:
|
||||
num = int(search_lst[0])
|
||||
result = self.search_for_thing(" ".join(search_lst[1:]), permitted_things, add_nonexisting,
|
||||
|
@ -321,7 +321,7 @@ class Menu(object):
|
|||
def search_add(self, string):
|
||||
type_guess = guess_data_type(string)
|
||||
if type_guess == 'username':
|
||||
print '"%s" looks like a username, but no such user exists.' % string
|
||||
print('"%s" looks like a username, but no such user exists.' % string)
|
||||
if self.confirm('Create user %s?' % string):
|
||||
user = User(string, None)
|
||||
self.session.add(user)
|
||||
|
@ -342,11 +342,11 @@ class Menu(object):
|
|||
user = self.input_user('User to set card number for> ')
|
||||
old_card = user.card
|
||||
user.card = string
|
||||
print 'Card number of %s set to %s (was %s)' % (user.name, string, old_card)
|
||||
print('Card number of %s set to %s (was %s)' % (user.name, string, old_card))
|
||||
return user
|
||||
return None
|
||||
if type_guess == 'bar_code':
|
||||
print '"%s" looks like the bar code for a product, but no such product exists.' % string
|
||||
print('"%s" looks like the bar code for a product, but no such product exists.' % string)
|
||||
return None
|
||||
|
||||
def search_ui(self, search_fun, search_str, thing):
|
||||
|
@ -357,11 +357,11 @@ class Menu(object):
|
|||
if not isinstance(result, list):
|
||||
return result
|
||||
if len(result) == 0:
|
||||
print 'No %ss matching "%s"' % (thing, search_str)
|
||||
print('No %ss matching "%s"' % (thing, search_str))
|
||||
return None
|
||||
if len(result) == 1:
|
||||
msg = 'One %s matching "%s": %s. Use this?' % \
|
||||
(thing, search_str, unicode(result[0]))
|
||||
(thing, search_str, str(result[0]))
|
||||
if self.confirm(msg, default=True):
|
||||
return result[0]
|
||||
return None
|
||||
|
@ -383,15 +383,15 @@ class Menu(object):
|
|||
return ConfirmMenu(prompt, default, timeout).execute()
|
||||
|
||||
def print_header(self):
|
||||
print ""
|
||||
print self.header_format % self.name
|
||||
print("")
|
||||
print(self.header_format % self.name)
|
||||
|
||||
def pause(self):
|
||||
self.input_str('.')
|
||||
|
||||
@staticmethod
|
||||
def general_help():
|
||||
print '''
|
||||
print('''
|
||||
DIBBLER HELP
|
||||
|
||||
The following commands are recognized (almost) everywhere:
|
||||
|
@ -412,15 +412,15 @@ class Menu(object):
|
|||
of money PVVVV owes the user. This value decreases with the
|
||||
appropriate amount when you register a purchase, and you may increase
|
||||
it by putting money in the box and using the "Adjust credit" menu.
|
||||
'''
|
||||
''')
|
||||
|
||||
def local_help(self):
|
||||
if self.help_text is None:
|
||||
print 'no help here'
|
||||
print('no help here')
|
||||
else:
|
||||
print ''
|
||||
print 'Help for %s:' % (self.header_format % self.name)
|
||||
print self.help_text
|
||||
print('')
|
||||
print('Help for %s:' % (self.header_format % self.name))
|
||||
print(self.help_text)
|
||||
|
||||
def execute(self, **kwargs):
|
||||
self.set_context(None)
|
||||
|
@ -462,8 +462,8 @@ class MessageMenu(Menu):
|
|||
|
||||
def _execute(self):
|
||||
self.print_header()
|
||||
print ''
|
||||
print self.message
|
||||
print('')
|
||||
print(self.message)
|
||||
if self.pause_after_message:
|
||||
self.pause()
|
||||
|
||||
|
@ -487,7 +487,7 @@ class ConfirmMenu(Menu):
|
|||
elif self.default is not None and result == '':
|
||||
return self.default
|
||||
else:
|
||||
print 'Please answer yes or no'
|
||||
print('Please answer yes or no')
|
||||
|
||||
|
||||
class Selector(Menu):
|
||||
|
@ -499,13 +499,13 @@ class Selector(Menu):
|
|||
self.header_format = '%s'
|
||||
|
||||
def print_header(self):
|
||||
print self.header_format % self.name
|
||||
print(self.header_format % self.name)
|
||||
|
||||
def local_help(self):
|
||||
if self.help_text is None:
|
||||
print 'This is a selection menu. Enter one of the listed numbers, or'
|
||||
print '\'exit\' to go out and do something else.'
|
||||
print('This is a selection menu. Enter one of the listed numbers, or')
|
||||
print('\'exit\' to go out and do something else.')
|
||||
else:
|
||||
print ''
|
||||
print 'Help for selector (%s):' % self.name
|
||||
print self.help_text
|
||||
print('')
|
||||
print('Help for selector (%s):' % self.name)
|
||||
print(self.help_text)
|
||||
|
|
|
@ -46,4 +46,4 @@ class MainMenu(Menu):
|
|||
return False
|
||||
|
||||
def invalid_menu_choice(self, in_str):
|
||||
print self.show_context()
|
||||
print(self.show_context())
|
||||
|
|
|
@ -31,12 +31,12 @@ class TransferMenu(Menu):
|
|||
self.session.add(t2)
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'Transfered %d kr from %s to %s' % (amount, user1, user2)
|
||||
print 'User %s\'s credit is now %d kr' % (user1, user1.credit)
|
||||
print 'User %s\'s credit is now %d kr' % (user2, user2.credit)
|
||||
print 'Comment: %s' % comment
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not perform transfer: %s' % e
|
||||
print('Transfered %d kr from %s to %s' % (amount, user1, user2))
|
||||
print('User %s\'s credit is now %d kr' % (user1, user1.credit))
|
||||
print('User %s\'s credit is now %d kr' % (user2, user2.credit))
|
||||
print('Comment: %s' % comment)
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not perform transfer: %s' % e)
|
||||
# self.pause()
|
||||
|
||||
|
||||
|
@ -47,10 +47,10 @@ class ShowUserMenu(Menu):
|
|||
def _execute(self):
|
||||
self.print_header()
|
||||
user = self.input_user('User name, card number or RFID> ')
|
||||
print 'User name: %s' % user.name
|
||||
print 'Card number: %s' % user.card
|
||||
print 'RFID: %s' % user.rfid
|
||||
print 'Credit: %s kr' % user.credit
|
||||
print('User name: %s' % user.name)
|
||||
print('Card number: %s' % user.card)
|
||||
print('RFID: %s' % user.rfid)
|
||||
print('Credit: %s kr' % user.credit)
|
||||
selector = Selector('What do you want to know about %s?' % user.name,
|
||||
items=[('transactions', 'Recent transactions (List of last ' + str(
|
||||
conf.user_recent_transaction_limit) + ')'),
|
||||
|
@ -64,7 +64,7 @@ class ShowUserMenu(Menu):
|
|||
elif what == 'transactions-all':
|
||||
self.print_all_transactions(user)
|
||||
else:
|
||||
print 'What what?'
|
||||
print('What what?')
|
||||
|
||||
@staticmethod
|
||||
def print_all_transactions(user):
|
||||
|
@ -77,8 +77,7 @@ class ShowUserMenu(Menu):
|
|||
abs(t.amount))
|
||||
if t.purchase:
|
||||
string += 'purchase ('
|
||||
string += ', '.join(map(lambda e: e.product.name,
|
||||
t.purchase.entries))
|
||||
string += ', '.join([e.product.name for e in t.purchase.entries])
|
||||
string += ')'
|
||||
if t.penalty > 1:
|
||||
string += ' * %dx penalty applied' % t.penalty
|
||||
|
@ -101,8 +100,7 @@ class ShowUserMenu(Menu):
|
|||
abs(t.amount))
|
||||
if t.purchase:
|
||||
string += 'purchase ('
|
||||
string += ', '.join(map(lambda e: e.product.name,
|
||||
t.purchase.entries))
|
||||
string += ', '.join([e.product.name for e in t.purchase.entries])
|
||||
string += ')'
|
||||
if t.penalty > 1:
|
||||
string += ' * %dx penalty applied' % t.penalty
|
||||
|
@ -121,12 +119,12 @@ class ShowUserMenu(Menu):
|
|||
products.append((product, count))
|
||||
num_products = len(products)
|
||||
if num_products == 0:
|
||||
print 'No products purchased yet'
|
||||
print('No products purchased yet')
|
||||
else:
|
||||
text = ''
|
||||
text += 'Products purchased:\n'
|
||||
for product, count in products:
|
||||
text += u'{0:<47} {1:>3}\n'.format(product.name, count)
|
||||
text += '{0:<47} {1:>3}\n'.format(product.name, count)
|
||||
less(text)
|
||||
|
||||
|
||||
|
@ -158,15 +156,15 @@ class AdjustCreditMenu(Menu): # reimplements ChargeMenu; these should be combin
|
|||
def _execute(self):
|
||||
self.print_header()
|
||||
user = self.input_user('User> ')
|
||||
print 'User %s\'s credit is %d kr' % (user.name, user.credit)
|
||||
print('User %s\'s credit is %d kr' % (user.name, user.credit))
|
||||
|