Browse Source

client-barcode: Split Status.commit() up into sub-functions

master
Sebastian Pipping 11 years ago
parent
commit
156a0df88d
  1. 99
      client-barcode/freitagskasse.py

99
client-barcode/freitagskasse.py

@ -267,63 +267,68 @@ class Status: @@ -267,63 +267,68 @@ class Status:
def commit(self):
assert(self.logged_in())
# Compress DepositCommands
dummy, initial_balance = self.transfers[0]
balance_before = initial_balance
compressed_deposit = DepositCommand(Decimal('0'))
others = list()
for (command, dummy) in list(self.transfers):
if isinstance(command, DepositCommand):
compressed_deposit.add(command)
else:
others.append((command, balance_before))
balance_before += command.difference()
if compressed_deposit.difference() != 0:
others.append((compressed_deposit, balance_before))
self.transfers = others
# Compress BuyCommands, use a single bulkbuy
dummy, initial_balance = self.transfers[0]
balance_before = initial_balance
buy_commands = list()
non_buy_commands = list()
total_buy_diff = 0
for command, dummy in self.transfers:
if isinstance(command, BuyCommand):
buy_commands.append(command)
else:
balance_before += command.difference()
non_buy_commands.append((command, balance_before))
def compress_deposit_commands():
dummy, initial_balance = self.transfers[0]
balance_before = initial_balance
compressed_deposit = DepositCommand(Decimal('0'))
others = list()
for (command, dummy) in list(self.transfers):
if isinstance(command, DepositCommand):
compressed_deposit.add(command)
else:
others.append((command, balance_before))
balance_before += command.difference()
if compressed_deposit.difference() != 0:
others.append((compressed_deposit, balance_before))
self.transfers = others
def process_buy_commands_combined():
# Compress BuyCommands, use a single bulkbuy
dummy, initial_balance = self.transfers[0]
balance_before = initial_balance
buy_commands = list()
non_buy_commands = list()
total_buy_diff = 0
try:
net.bulk_buy(buy_commands, self.login_name)
except urllib2.HTTPError as e:
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
else:
self.transfers = non_buy_commands
for command, dummy in self.transfers:
if isinstance(command, BuyCommand):
buy_commands.append(command)
else:
balance_before += command.difference()
non_buy_commands.append((command, balance_before))
# Process remaining command queue
for (command, balance_backup) in list(self.transfers):
try:
command.run(self.login_name)
net.bulk_buy(buy_commands, self.login_name)
except urllib2.HTTPError as e:
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
break
else:
self.transfers.pop(0)
self.transfers = non_buy_commands
if not self.transfers:
# Show final balance for some time
clear()
self.dump()
delay('Logout', 3)
def process_commands():
for (command, balance_backup) in list(self.transfers):
try:
command.run(self.login_name)
except urllib2.HTTPError as e:
myDisplay.display_screen("Server error",'Server Error: %s' % str(e))
error_page('FEHLER bei Kommunikation mit Server "%s"' % str(e))
break
else:
self.transfers.pop(0)
def finish():
if not self.transfers:
# Show final balance for some time
clear()
self.dump()
delay('Logout', 3)
self.logout()
self.logout()
compress_deposit_commands()
process_buy_commands_combined()
process_commands()
finish()
def find(self, barcode):
try:

Loading…
Cancel
Save