new get_modem_pin function, which reads from multiple sources
This commit is contained in:
parent
ec4236c58f
commit
000bb0561b
@ -24,6 +24,32 @@ class SIMError(ModemManagerError):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.value)
|
return repr(self.value)
|
||||||
|
|
||||||
|
|
||||||
|
def get_modem_pin():
|
||||||
|
|
||||||
|
def read_modem_pin(path):
|
||||||
|
with open(path, 'r') as mp:
|
||||||
|
return mp.readline().rstrip('\n')
|
||||||
|
|
||||||
|
# Check multiple paths
|
||||||
|
paths = [
|
||||||
|
os.path.join(
|
||||||
|
os.getcwd(),
|
||||||
|
'modem_pin.txt'
|
||||||
|
),
|
||||||
|
os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
|
'modem_pin.txt'
|
||||||
|
),
|
||||||
|
'/etc/modem_pin.txt'
|
||||||
|
]
|
||||||
|
|
||||||
|
for p in paths:
|
||||||
|
if os.path.isfile(p):
|
||||||
|
return read_modem_pin(fpath)
|
||||||
|
|
||||||
|
raise Exception('modem_pin.txt not found in any directory')
|
||||||
|
|
||||||
def get_modem():
|
def get_modem():
|
||||||
# Retry for 5 seconds and give the modems time
|
# Retry for 5 seconds and give the modems time
|
||||||
retries = 0
|
retries = 0
|
||||||
@ -56,17 +82,15 @@ def unlock_sim(modem):
|
|||||||
logger.debug("Modem status: {}".format(props))
|
logger.debug("Modem status: {}".format(props))
|
||||||
if props and props['state'] == 2:
|
if props and props['state'] == 2:
|
||||||
# check if the modem_pin.txt file exists
|
# check if the modem_pin.txt file exists
|
||||||
with open('modem_pin.txt', 'r') as mp:
|
mypin = get_modem_pin()
|
||||||
mypin = mp.readline().rstrip('\n')
|
logger.info("Trying to unlock %s", sim_path)
|
||||||
|
with SystemBus() as bus:
|
||||||
logger.info("Trying to unlock %s", sim_path)
|
sim = bus.get('.ModemManager1', sim_path)
|
||||||
with SystemBus() as bus:
|
try:
|
||||||
sim = bus.get('.ModemManager1', sim_path)
|
sim.SendPin(mypin, timeout=10000)
|
||||||
try:
|
except GLib.Error as exc:
|
||||||
sim.SendPin(mypin, timeout=10000)
|
remaining_attempts = modem.UnlockRetries
|
||||||
except GLib.Error as exc:
|
raise SIMError('Failed to unlock PIN, remaining attempts: {}'.format(remaining_attempts)) from exc
|
||||||
remaining_attempts = modem.UnlockRetries
|
|
||||||
raise SIMError('Failed to unlock PIN, remaining attempts: {}'.format(remaining_attempts)) from exc
|
|
||||||
|
|
||||||
def unlock_and_enable_modem():
|
def unlock_and_enable_modem():
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user