Fix compatibility with Python 3: print() is a function

Change-Id: I5dd8e5daf420fc8667c5156bfacc8763d8895993
This commit is contained in:
Vadim Yanitskiy 2020-01-22 23:38:24 +07:00
parent fa1dc34152
commit 6727f0c02c
5 changed files with 51 additions and 51 deletions

View File

@ -101,7 +101,7 @@ sc = SimCardCommands(sl)
sl.wait_for_card()
# Print IMSI
print sc.read_binary(['3f00', '7f20', '6f07'])
print(sc.read_binary(['3f00', '7f20', '6f07']))
# Run A3/A8
print sc.run_gsm('00112233445566778899aabbccddeeff')
print(sc.run_gsm('00112233445566778899aabbccddeeff'))

View File

@ -173,7 +173,7 @@ def parse_options():
if options.type == 'list':
for kls in _cards_classes:
print kls.name
print(kls.name)
sys.exit(0)
if options.probe:
@ -560,7 +560,7 @@ def init_batch(opts):
for k in BATCH_INCOMPATIBLE:
if getattr(opts, k):
print "Incompatible option with batch_state: %s" % (k,)
print("Incompatible option with batch_state: %s" % (k,))
sys.exit(-1)
# Don't load state if there is none ...
@ -568,7 +568,7 @@ def init_batch(opts):
return
if not os.path.isfile(opts.batch_state):
print "No state file yet"
print("No state file yet")
return
# Get stored data
@ -601,12 +601,12 @@ def card_detect(opts, scc):
for kls in _cards_classes:
card = kls.autodetect(scc)
if card:
print "Autodetected card type: %s" % card.name
print("Autodetected card type: %s" % card.name)
card.reset()
break
if card is None:
print "Autodetection failed"
print("Autodetection failed")
return
if opts.type == "auto_once":
@ -631,7 +631,7 @@ def process_card(opts, first, card_handler):
# Get card
card = card_detect(opts, scc)
if card is None:
print "No card detected!"
print("No card detected!")
return -1
# Probe only
@ -640,7 +640,7 @@ def process_card(opts, first, card_handler):
# Erase if requested
if opts.erase:
print "Formatting ..."
print("Formatting ...")
card.erase()
card.reset()
@ -666,16 +666,16 @@ def process_card(opts, first, card_handler):
imsi = opts.imsi
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
if cp is None:
print "Error reading parameters from CSV file!\n"
print("Error reading parameters from CSV file!\n")
return 2
print_parameters(cp)
if opts.dry_run is False:
# Program the card
print "Programming ..."
print("Programming ...")
card.program(cp)
else:
print "Dry Run: NOT PROGRAMMING!"
print("Dry Run: NOT PROGRAMMING!")
# Write parameters permanently
write_parameters(opts, cp)
@ -716,9 +716,9 @@ if __name__ == '__main__':
# If we use a CSV file as data input, check if the CSV file exists.
if opts.source == 'csv':
print "Using CSV file as data input: " + str(opts.read_csv)
print("Using CSV file as data input: " + str(opts.read_csv))
if not os.path.isfile(opts.read_csv):
print "CSV file not found!"
print("CSV file not found!")
sys.exit(1)
# Batch mode init
@ -737,18 +737,18 @@ if __name__ == '__main__':
try:
rc = process_card(opts, first, card_handler)
except (KeyboardInterrupt):
print ""
print "Terminated by user!"
print("")
print("Terminated by user!")
sys.exit(0)
except (SystemExit):
raise
except:
print ""
print "Card programming failed with an execption:"
print "---------------------8<---------------------"
print("")
print("Card programming failed with an execption:")
print("---------------------8<---------------------")
traceback.print_exc()
print "---------------------8<---------------------"
print ""
print("---------------------8<---------------------")
print("")
rc = -1
# Something did not work as well as expected, however, lets

View File

@ -140,7 +140,7 @@ if __name__ == '__main__':
else:
print("PLMNsel: Can't read, response code = %s" % (sw,))
except Exception as e:
print "HPLMNAcT: Can't read file -- " + str(e)
print("HPLMNAcT: Can't read file -- " + str(e))
# EF.PLMNwAcT
try:
@ -150,7 +150,7 @@ if __name__ == '__main__':
else:
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
print "PLMNwAcT: Can't read file -- " + str(e)
print("PLMNwAcT: Can't read file -- " + str(e))
# EF.OPLMNwAcT
try:
@ -160,7 +160,7 @@ if __name__ == '__main__':
else:
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
print "OPLMNwAcT: Can't read file -- " + str(e)
print("OPLMNwAcT: Can't read file -- " + str(e))
# EF.HPLMNAcT
try:
@ -170,7 +170,7 @@ if __name__ == '__main__':
else:
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
except Exception as e:
print "HPLMNAcT: Can't read file -- " + str(e)
print("HPLMNAcT: Can't read file -- " + str(e))
# EF.ACC
(res, sw) = scc.read_binary(['3f00', '7f20', '6f78'])
@ -191,7 +191,7 @@ if __name__ == '__main__':
else:
print("MSISDN: Can't read, response code = %s" % (sw,))
except Exception as e:
print "MSISDN: Can't read file -- " + str(e)
print("MSISDN: Can't read file -- " + str(e))
# EF.AD
(res, sw) = scc.read_binary(['3f00', '7f20', '6fad'])
@ -201,4 +201,4 @@ if __name__ == '__main__':
print("AD: Can't read, response code = %s" % (sw,))
# Done for this card and maybe for everything ?
print "Done !\n"
print("Done !\n")

View File

@ -36,16 +36,16 @@ class card_handler:
self.sl = sl
def get(self, first = False):
print "Ready for Programming: Insert card now (or CTRL-C to cancel)"
print("Ready for Programming: Insert card now (or CTRL-C to cancel)")
self.sl.wait_for_card(newcardonly=not first)
def error(self):
print "Programming failed: Remove card from reader"
print ""
print("Programming failed: Remove card from reader")
print("")
def done(self):
print "Programming successful: Remove card from reader"
print ""
print("Programming successful: Remove card from reader")
print("")
# Automatic card handler: A machine is used to handle the cards.
class card_handler_auto:
@ -55,7 +55,7 @@ class card_handler_auto:
verbose = True
def __init__(self, sl, config_file):
print "Card handler Config-file: " + str(config_file)
print("Card handler Config-file: " + str(config_file))
self.sl = sl
with open(config_file) as cfg:
self.cmds = yaml.load(cfg, Loader=yaml.FullLoader)
@ -63,22 +63,22 @@ class card_handler_auto:
self.verbose = (self.cmds.get('verbose') == True)
def __print_outout(self,out):
print ""
print "Card handler output:"
print "---------------------8<---------------------"
print("")
print("Card handler output:")
print("---------------------8<---------------------")
stdout = out[0].strip()
if len(stdout) > 0:
print "stdout:"
print stdout
print("stdout:")
print(stdout)
stderr = out[1].strip()
if len(stderr) > 0:
print "stderr:"
print stderr
print "---------------------8<---------------------"
print ""
print("stderr:")
print(stderr)
print("---------------------8<---------------------")
print("")
def __exec_cmd(self, command):
print "Card handler Commandline: " + str(command)
print("Card handler Commandline: " + str(command))
proc = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out = proc.communicate()
@ -88,21 +88,21 @@ class card_handler_auto:
self.__print_outout(out)
if rc != 0:
print ""
print "Error: Card handler failure! (rc=" + str(rc) + ")"
print("")
print("Error: Card handler failure! (rc=" + str(rc) + ")")
sys.exit(rc)
def get(self, first = False):
print "Ready for Programming: Transporting card into the reader-bay..."
print("Ready for Programming: Transporting card into the reader-bay...")
self.__exec_cmd(self.cmds['get'])
self.sl.connect()
def error(self):
print "Programming failed: Transporting card to the error-bin..."
print("Programming failed: Transporting card to the error-bin...")
self.__exec_cmd(self.cmds['error'])
print ""
print("")
def done(self):
print "Programming successful: Transporting card into the collector bin..."
print("Programming successful: Transporting card into the collector bin...")
self.__exec_cmd(self.cmds['done'])
print ""
print("")

View File

@ -162,7 +162,7 @@ class SerialSimLink(LinkBase):
def _dbg_print(self, s):
if self._debug:
print s
print(s)
def _tx_byte(self, b):
self._sl.write(b)