Run 2to3 to start moving to python3
This commit is contained in:
@@ -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))
|
||||
self.set_context('Adjusting credit for user %s' % user.name, display=False)
|
||||
print '(Note on sign convention: Enter a positive amount here if you have'
|
||||
print 'added money to the PVVVV money box, a negative amount if you have'
|
||||
print 'taken money from it)'
|
||||
print('(Note on sign convention: Enter a positive amount here if you have')
|
||||
print('added money to the PVVVV money box, a negative amount if you have')
|
||||
print('taken money from it)')
|
||||
amount = self.input_int('Add amount> ', (-100000, 100000))
|
||||
print '(The "log message" will show up in the transaction history in the'
|
||||
print '"Show user" menu. It is not necessary to enter a message, but it'
|
||||
print 'might be useful to help you remember why you adjusted the credit)'
|
||||
print('(The "log message" will show up in the transaction history in the')
|
||||
print('"Show user" menu. It is not necessary to enter a message, but it')
|
||||
print('might be useful to help you remember why you adjusted the credit)')
|
||||
description = self.input_str('Log message> ', length_range=(0, 50))
|
||||
if description == '':
|
||||
description = 'manually adjusted credit'
|
||||
@@ -175,9 +173,9 @@ class AdjustCreditMenu(Menu): # reimplements ChargeMenu; these should be combin
|
||||
self.session.add(transaction)
|
||||
try:
|
||||
self.session.commit()
|
||||
print 'User %s\'s credit is now %d kr' % (user.name, user.credit)
|
||||
except sqlalchemy.exc.SQLAlchemyError, e:
|
||||
print 'Could not store transaction: %s' % e
|
||||
print('User %s\'s credit is now %d kr' % (user.name, user.credit))
|
||||
except sqlalchemy.exc.SQLAlchemyError as e:
|
||||
print('Could not store transaction: %s' % e)
|
||||
# self.pause()
|
||||
|
||||
|
||||
@@ -210,7 +208,7 @@ class ProductSearchMenu(Menu):
|
||||
self.print_header()
|
||||
self.set_context('Enter (part of) product name or bar code')
|
||||
product = self.input_product()
|
||||
print 'Result: %s, price: %d kr, bar code: %s, stock: %d, hidden: %s' % (product.name, product.price,
|
||||
print('Result: %s, price: %d kr, bar code: %s, stock: %d, hidden: %s' % (product.name, product.price,
|
||||
product.bar_code, product.stock,
|
||||
("Y" if product.hidden else "N"))
|
||||
("Y" if product.hidden else "N")))
|
||||
# self.pause()
|
||||
|
@@ -27,7 +27,7 @@ class ProductPopularityMenu(Menu):
|
||||
.order_by(desc(sub.c.purchase_count)) \
|
||||
.filter(sub.c.purchase_count is not None) \
|
||||
.all()
|
||||
line_format = u'{0:10s} | {1:>45s}\n'
|
||||
line_format = '{0:10s} | {1:>45s}\n'
|
||||
text += line_format.format('items sold', 'product')
|
||||
text += '-' * (31 + Product.name_length) + '\n'
|
||||
for product, number in product_list:
|
||||
@@ -55,7 +55,7 @@ class ProductRevenueMenu(Menu):
|
||||
.order_by(desc(sub.c.purchase_count * Product.price)) \
|
||||
.filter(sub.c.purchase_count is not None) \
|
||||
.all()
|
||||
line_format = u'{0:7s} | {1:10s} | {2:6s} | {3:>45s}\n'
|
||||
line_format = '{0:7s} | {1:10s} | {2:6s} | {3:>45s}\n'
|
||||
text += line_format.format('revenue', 'items sold', 'price', 'product')
|
||||
text += '-' * (31 + Product.name_length) + '\n'
|
||||
for product, number in product_list:
|
||||
|
Reference in New Issue
Block a user