def demonstrate(device_name): """ Mount *and* connect the specified device. The device must not be mounted already. The Controller will attempt connection to the device. Return True if connection succeeds before the time-out period elapses. """ mount_from_settings(device_name) time_accum = 0.0 num_checks = 0 while time_accum < time_out: num_checks += 1 expanding_interval = time_interval * num_checks time_accum += expanding_interval # Don't hammer the Controller or it will crash. # This not a denial-of-service (DOS) attack ;-) time.sleep(expanding_interval) print('connected(' + device_name, sep='', end='): ') if connected(device_name): print(True, 'after %s checks and %s seconds.' % (num_checks, time_accum)) return True else: print(False) continue print('Unconnected after %s checks and %s seconds.' % (num_checks, time_accum)) return False
def main(): print(plain(doc(connected))) device_names = inventory_mounted() if not device_names: print('There are no devices mounted on the Controller.') else: device_name = device_names[0] print('is connected(%s):' % device_name, connected(device_name))
def main(): ''' Document and demonstrate the function until a capable device is found.''' print(plain(doc(capability_discovery))) for device_name in inventory_mounted(): try: if demonstrate(device_name): return os.EX_OK except Exception as e: if connected(device_name): # Unexplained exception. print(e) return os.EX_TEMPFAIL else: # Expect exception when device not connected. print('connected(%s): False' % device_name) return os.EX_TEMPFAIL