mirror of https://gerrit.osmocom.org/pysim
Fix compatibility with Python 3: print() is a function
Change-Id: I5dd8e5daf420fc8667c5156bfacc8763d8895993
This commit is contained in:
parent
fa1dc34152
commit
6727f0c02c
|
@ -101,7 +101,7 @@ sc = SimCardCommands(sl)
|
||||||
sl.wait_for_card()
|
sl.wait_for_card()
|
||||||
|
|
||||||
# Print IMSI
|
# Print IMSI
|
||||||
print sc.read_binary(['3f00', '7f20', '6f07'])
|
print(sc.read_binary(['3f00', '7f20', '6f07']))
|
||||||
|
|
||||||
# Run A3/A8
|
# Run A3/A8
|
||||||
print sc.run_gsm('00112233445566778899aabbccddeeff')
|
print(sc.run_gsm('00112233445566778899aabbccddeeff'))
|
||||||
|
|
|
@ -173,7 +173,7 @@ def parse_options():
|
||||||
|
|
||||||
if options.type == 'list':
|
if options.type == 'list':
|
||||||
for kls in _cards_classes:
|
for kls in _cards_classes:
|
||||||
print kls.name
|
print(kls.name)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if options.probe:
|
if options.probe:
|
||||||
|
@ -560,7 +560,7 @@ def init_batch(opts):
|
||||||
|
|
||||||
for k in BATCH_INCOMPATIBLE:
|
for k in BATCH_INCOMPATIBLE:
|
||||||
if getattr(opts, k):
|
if getattr(opts, k):
|
||||||
print "Incompatible option with batch_state: %s" % (k,)
|
print("Incompatible option with batch_state: %s" % (k,))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Don't load state if there is none ...
|
# Don't load state if there is none ...
|
||||||
|
@ -568,7 +568,7 @@ def init_batch(opts):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not os.path.isfile(opts.batch_state):
|
if not os.path.isfile(opts.batch_state):
|
||||||
print "No state file yet"
|
print("No state file yet")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get stored data
|
# Get stored data
|
||||||
|
@ -601,12 +601,12 @@ def card_detect(opts, scc):
|
||||||
for kls in _cards_classes:
|
for kls in _cards_classes:
|
||||||
card = kls.autodetect(scc)
|
card = kls.autodetect(scc)
|
||||||
if card:
|
if card:
|
||||||
print "Autodetected card type: %s" % card.name
|
print("Autodetected card type: %s" % card.name)
|
||||||
card.reset()
|
card.reset()
|
||||||
break
|
break
|
||||||
|
|
||||||
if card is None:
|
if card is None:
|
||||||
print "Autodetection failed"
|
print("Autodetection failed")
|
||||||
return
|
return
|
||||||
|
|
||||||
if opts.type == "auto_once":
|
if opts.type == "auto_once":
|
||||||
|
@ -631,7 +631,7 @@ def process_card(opts, first, card_handler):
|
||||||
# Get card
|
# Get card
|
||||||
card = card_detect(opts, scc)
|
card = card_detect(opts, scc)
|
||||||
if card is None:
|
if card is None:
|
||||||
print "No card detected!"
|
print("No card detected!")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
# Probe only
|
# Probe only
|
||||||
|
@ -640,7 +640,7 @@ def process_card(opts, first, card_handler):
|
||||||
|
|
||||||
# Erase if requested
|
# Erase if requested
|
||||||
if opts.erase:
|
if opts.erase:
|
||||||
print "Formatting ..."
|
print("Formatting ...")
|
||||||
card.erase()
|
card.erase()
|
||||||
card.reset()
|
card.reset()
|
||||||
|
|
||||||
|
@ -666,16 +666,16 @@ def process_card(opts, first, card_handler):
|
||||||
imsi = opts.imsi
|
imsi = opts.imsi
|
||||||
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
|
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
|
||||||
if cp is None:
|
if cp is None:
|
||||||
print "Error reading parameters from CSV file!\n"
|
print("Error reading parameters from CSV file!\n")
|
||||||
return 2
|
return 2
|
||||||
print_parameters(cp)
|
print_parameters(cp)
|
||||||
|
|
||||||
if opts.dry_run is False:
|
if opts.dry_run is False:
|
||||||
# Program the card
|
# Program the card
|
||||||
print "Programming ..."
|
print("Programming ...")
|
||||||
card.program(cp)
|
card.program(cp)
|
||||||
else:
|
else:
|
||||||
print "Dry Run: NOT PROGRAMMING!"
|
print("Dry Run: NOT PROGRAMMING!")
|
||||||
|
|
||||||
# Write parameters permanently
|
# Write parameters permanently
|
||||||
write_parameters(opts, cp)
|
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 we use a CSV file as data input, check if the CSV file exists.
|
||||||
if opts.source == 'csv':
|
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):
|
if not os.path.isfile(opts.read_csv):
|
||||||
print "CSV file not found!"
|
print("CSV file not found!")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Batch mode init
|
# Batch mode init
|
||||||
|
@ -737,18 +737,18 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
rc = process_card(opts, first, card_handler)
|
rc = process_card(opts, first, card_handler)
|
||||||
except (KeyboardInterrupt):
|
except (KeyboardInterrupt):
|
||||||
print ""
|
print("")
|
||||||
print "Terminated by user!"
|
print("Terminated by user!")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except (SystemExit):
|
except (SystemExit):
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
print ""
|
print("")
|
||||||
print "Card programming failed with an execption:"
|
print("Card programming failed with an execption:")
|
||||||
print "---------------------8<---------------------"
|
print("---------------------8<---------------------")
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print "---------------------8<---------------------"
|
print("---------------------8<---------------------")
|
||||||
print ""
|
print("")
|
||||||
rc = -1
|
rc = -1
|
||||||
|
|
||||||
# Something did not work as well as expected, however, lets
|
# Something did not work as well as expected, however, lets
|
||||||
|
|
|
@ -140,7 +140,7 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print("PLMNsel: Can't read, response code = %s" % (sw,))
|
print("PLMNsel: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "HPLMNAcT: Can't read file -- " + str(e)
|
print("HPLMNAcT: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# EF.PLMNwAcT
|
# EF.PLMNwAcT
|
||||||
try:
|
try:
|
||||||
|
@ -150,7 +150,7 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
|
print("PLMNwAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "PLMNwAcT: Can't read file -- " + str(e)
|
print("PLMNwAcT: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# EF.OPLMNwAcT
|
# EF.OPLMNwAcT
|
||||||
try:
|
try:
|
||||||
|
@ -160,7 +160,7 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
|
print("OPLMNwAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "OPLMNwAcT: Can't read file -- " + str(e)
|
print("OPLMNwAcT: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# EF.HPLMNAcT
|
# EF.HPLMNAcT
|
||||||
try:
|
try:
|
||||||
|
@ -170,7 +170,7 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
|
print("HPLMNAcT: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "HPLMNAcT: Can't read file -- " + str(e)
|
print("HPLMNAcT: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# EF.ACC
|
# EF.ACC
|
||||||
(res, sw) = scc.read_binary(['3f00', '7f20', '6f78'])
|
(res, sw) = scc.read_binary(['3f00', '7f20', '6f78'])
|
||||||
|
@ -191,7 +191,7 @@ if __name__ == '__main__':
|
||||||
else:
|
else:
|
||||||
print("MSISDN: Can't read, response code = %s" % (sw,))
|
print("MSISDN: Can't read, response code = %s" % (sw,))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "MSISDN: Can't read file -- " + str(e)
|
print("MSISDN: Can't read file -- " + str(e))
|
||||||
|
|
||||||
# EF.AD
|
# EF.AD
|
||||||
(res, sw) = scc.read_binary(['3f00', '7f20', '6fad'])
|
(res, sw) = scc.read_binary(['3f00', '7f20', '6fad'])
|
||||||
|
@ -201,4 +201,4 @@ if __name__ == '__main__':
|
||||||
print("AD: Can't read, response code = %s" % (sw,))
|
print("AD: Can't read, response code = %s" % (sw,))
|
||||||
|
|
||||||
# Done for this card and maybe for everything ?
|
# Done for this card and maybe for everything ?
|
||||||
print "Done !\n"
|
print("Done !\n")
|
||||||
|
|
|
@ -36,16 +36,16 @@ class card_handler:
|
||||||
self.sl = sl
|
self.sl = sl
|
||||||
|
|
||||||
def get(self, first = False):
|
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)
|
self.sl.wait_for_card(newcardonly=not first)
|
||||||
|
|
||||||
def error(self):
|
def error(self):
|
||||||
print "Programming failed: Remove card from reader"
|
print("Programming failed: Remove card from reader")
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
def done(self):
|
def done(self):
|
||||||
print "Programming successful: Remove card from reader"
|
print("Programming successful: Remove card from reader")
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
# Automatic card handler: A machine is used to handle the cards.
|
# Automatic card handler: A machine is used to handle the cards.
|
||||||
class card_handler_auto:
|
class card_handler_auto:
|
||||||
|
@ -55,7 +55,7 @@ class card_handler_auto:
|
||||||
verbose = True
|
verbose = True
|
||||||
|
|
||||||
def __init__(self, sl, config_file):
|
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
|
self.sl = sl
|
||||||
with open(config_file) as cfg:
|
with open(config_file) as cfg:
|
||||||
self.cmds = yaml.load(cfg, Loader=yaml.FullLoader)
|
self.cmds = yaml.load(cfg, Loader=yaml.FullLoader)
|
||||||
|
@ -63,22 +63,22 @@ class card_handler_auto:
|
||||||
self.verbose = (self.cmds.get('verbose') == True)
|
self.verbose = (self.cmds.get('verbose') == True)
|
||||||
|
|
||||||
def __print_outout(self,out):
|
def __print_outout(self,out):
|
||||||
print ""
|
print("")
|
||||||
print "Card handler output:"
|
print("Card handler output:")
|
||||||
print "---------------------8<---------------------"
|
print("---------------------8<---------------------")
|
||||||
stdout = out[0].strip()
|
stdout = out[0].strip()
|
||||||
if len(stdout) > 0:
|
if len(stdout) > 0:
|
||||||
print "stdout:"
|
print("stdout:")
|
||||||
print stdout
|
print(stdout)
|
||||||
stderr = out[1].strip()
|
stderr = out[1].strip()
|
||||||
if len(stderr) > 0:
|
if len(stderr) > 0:
|
||||||
print "stderr:"
|
print("stderr:")
|
||||||
print stderr
|
print(stderr)
|
||||||
print "---------------------8<---------------------"
|
print("---------------------8<---------------------")
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
def __exec_cmd(self, command):
|
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)
|
proc = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||||
out = proc.communicate()
|
out = proc.communicate()
|
||||||
|
@ -88,21 +88,21 @@ class card_handler_auto:
|
||||||
self.__print_outout(out)
|
self.__print_outout(out)
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
print ""
|
print("")
|
||||||
print "Error: Card handler failure! (rc=" + str(rc) + ")"
|
print("Error: Card handler failure! (rc=" + str(rc) + ")")
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
|
|
||||||
def get(self, first = False):
|
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.__exec_cmd(self.cmds['get'])
|
||||||
self.sl.connect()
|
self.sl.connect()
|
||||||
|
|
||||||
def error(self):
|
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'])
|
self.__exec_cmd(self.cmds['error'])
|
||||||
print ""
|
print("")
|
||||||
|
|
||||||
def done(self):
|
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'])
|
self.__exec_cmd(self.cmds['done'])
|
||||||
print ""
|
print("")
|
||||||
|
|
|
@ -162,7 +162,7 @@ class SerialSimLink(LinkBase):
|
||||||
|
|
||||||
def _dbg_print(self, s):
|
def _dbg_print(self, s):
|
||||||
if self._debug:
|
if self._debug:
|
||||||
print s
|
print(s)
|
||||||
|
|
||||||
def _tx_byte(self, b):
|
def _tx_byte(self, b):
|
||||||
self._sl.write(b)
|
self._sl.write(b)
|
||||||
|
|
Loading…
Reference in New Issue