Skip to content

Commit

Permalink
refactor(upay): use upay.common and upay.client packages
Browse files Browse the repository at this point in the history
  • Loading branch information
schneider42 committed Nov 30, 2014
1 parent b7e9bbc commit 5024e1d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions scripts/fnordload
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import logging
import logging.config
import logging.handlers
import max7301
import upay
import upay.common
import upay.client
import sys

from decimal import Decimal
Expand Down Expand Up @@ -245,7 +246,7 @@ class Fnordload(object):
time.sleep(2)

def _upay_show_balance(self):
token_reader = upay.USBTokenReader()
token_reader = upay.common.USBTokenReader()
t0 = time.time()

self._lcd.write("Fnordload UPAY", "", "Please insert your", "USB drive")
Expand All @@ -257,7 +258,7 @@ class Fnordload(object):
found_medium_callback =
lambda x: self._lcd.write("Fnordload UPAY", "", "Reading USB drive", ""))
break
except upay.NoTokensAvailableError:
except upay.common.NoTokensAvailableError:
time.sleep(1)

if not tokens:
Expand All @@ -266,7 +267,7 @@ class Fnordload(object):
return

self._lcd.write("Fnordload UPAY", "", "Validating tokens", "")
token_client = upay.TokenClient()
token_client = upay.client.TokenClient()
tokens = token_client.validate_tokens(tokens)
value = sum([token.value for token in tokens])

Expand All @@ -276,8 +277,8 @@ class Fnordload(object):
def _upay_get_tokens(self):
self._logger.info("Entered get tokens menu")
self._lcd.write("Fnordload UPAY", "", "Reading internal", "purse...")
local_tokens = upay.read_tokens_from_file('local-purse', max_tokens = 100, max_size = 300 * 1024)
token_client = upay.TokenClient()
local_tokens = upay.common.read_tokens_from_file('local-purse', max_tokens = 100, max_size = 300 * 1024)
token_client = upay.client.TokenClient()

self._lcd.write("Fnordload UPAY", "", "Validating internal", "purse...")
local_tokens = token_client.validate_tokens(local_tokens)
Expand All @@ -299,15 +300,15 @@ class Fnordload(object):
self._lcd.write("Fnordload UPAY", "", "Reading USB drive", "")
local.purse_path = path

token_reader = upay.USBTokenReader()
token_reader = upay.common.USBTokenReader()
t0 = time.time()
self._lcd.write("Fnordload UPAY", "", "Please insert your", "USB drive")

tokens = []
while time.time() < t0 + 30:
try:
tokens = token_reader.read_tokens(found_medium_callback = found_usb_drive)
except upay.NoTokensAvailableError:
except upay.common.NoTokensAvailableError:
time.sleep(1)

if local.purse_path:
Expand Down

0 comments on commit 5024e1d

Please sign in to comment.