if not os.path.isdir(upload_dir): os.mkdir(upload_dir) if not os.path.isdir(download_dir): os.mkdir(download_dir) except (OSError, IOError) as e: print(e) client.log(iot.LOGERROR, ("Could not create one or more runtime " "directories! Did you run the device manager " "with sufficient priviliges?")) # Setup an OTA Handler ota = ota_handler.OTAHandler() # Set action callbacks, if enabled in iot.cfg action_register_conditional(client, "file_download", file_download, \ config.actions_enabled.file_transfers, \ (runtime_dir, config.wait_for_file_transfer)) action_register_conditional(client, "file_upload", file_upload, \ config.actions_enabled.file_transfers, \ (runtime_dir, config.upload_remove_on_success, config.upload_tar_file, config.wait_for_file_transfer)) action_register_conditional(client, "shutdown_device", device_shutdown, \ config.actions_enabled.shutdown_device) action_register_conditional(client, "reboot_device", device_reboot, \ config.actions_enabled.reboot_device)
# action args params = {} params['ota_timeout'] = 0 params['package'] = args.package_name user_data = [ args.runtime_dir, ] request = iot._core.defs.ActionRequest(request_id='unused', name='offline_updater', params=params) # client object client = iot.Client(app_name, offline=True) client.config.config_file = file_name client.initialize() client.log_level("DEBUG") ota = ota_handler.OTAHandler(offline=True) ota._runtime_dir = args.runtime_dir ota._offline = True ret = ota.update_callback(client, params, user_data, request) print("Status of update: {}".format(ret)) try: os.remove(file_name) except: print("Unable to remove config file") else: print("package_name {} does not exist".format(args.package_name)) else: print("runtime_dir {} does not exist".format(args.runtime_dir))