def get_database_elements(): lens_element = camera_element = None distortion_element = tca_element = vignetting_element = real_focal_length_element = fov_element = None files_found = False def crawl_directory(dirpath): nonlocal lens_element, camera_element, distortion_element, tca_element, vignetting_element, real_focal_length_element, \ fov_element, files_found for root, __, filenames in os.walk(dirpath): for filename in filenames: if filename.endswith(".xml"): files_found = True tree = ElementTree.parse(os.path.join(root, filename)).getroot() for element in tree: if camera_element is None and \ element.tag == "camera" and element.find("model").text == camera_model_name: camera_element = element elif element.tag == "lens" and element.find( "model").text == lens_model_name: if lens_element is not None: print( "This program cannot handle lens model names that occur multiple times in the\n" "read XML files. Please use another lens." ) sys.exit(1) lens_element = element if element.find("calibration") is not None: for calibration_element in element.find( "calibration"): if calibration_element.tag == "distortion" and \ float(calibration_element.attrib["focal"]) == focal_length: distortion_element = calibration_element elif calibration_element.tag == "tca" and \ float(calibration_element.attrib["focal"]) == focal_length: tca_element = calibration_element elif calibration_element.tag == "vignetting" and \ float(calibration_element.attrib["focal"]) == focal_length and \ float(calibration_element.attrib["aperture"]) == aperture and \ float(calibration_element.attrib["distance"]) == distance: vignetting_element = calibration_element elif calibration_element.tag == "field_of_view" and \ float(calibration_element.attrib["focal"]) == focal_length: fov_element = calibration_element paths_search_list = [ args.db_path ] if args.db_path else lensfun.get_database_directories() for path in paths_search_list: crawl_directory(path) if not files_found: print("No XML files found.") sys.exit(1) if lens_element is None: print("Lens model name not found.") sys.exit(1) if camera_element is None: print("Camera model name not found.") sys.exit(1) return lens_element, camera_element, distortion_element, tca_element, vignetting_element, real_focal_length_element, fov_element
def get_database_elements(): lens_element = camera_element = None distortion_element = tca_element = vignetting_element = real_focal_length_element = fov_element = None files_found = False def crawl_directory(dirpath): nonlocal lens_element, camera_element, distortion_element, tca_element, vignetting_element, real_focal_length_element, \ fov_element, files_found for root, __, filenames in os.walk(dirpath): for filename in filenames: if filename.endswith(".xml"): files_found = True tree = ElementTree.parse(os.path.join(root, filename)).getroot() for element in tree: if camera_element is None and \ element.tag == "camera" and element.find("model").text == camera_model_name: camera_element = element elif element.tag == "lens" and element.find("model").text == lens_model_name: if lens_element is not None: print("This program cannot handle lens model names that occur multiple times in the\n" "read XML files. Please use another lens.") sys.exit(1) lens_element = element if element.find("calibration") is not None: for calibration_element in element.find("calibration"): if calibration_element.tag == "distortion" and \ float(calibration_element.attrib["focal"]) == focal_length: distortion_element = calibration_element elif calibration_element.tag == "tca" and \ float(calibration_element.attrib["focal"]) == focal_length: tca_element = calibration_element elif calibration_element.tag == "vignetting" and \ float(calibration_element.attrib["focal"]) == focal_length and \ float(calibration_element.attrib["aperture"]) == aperture and \ float(calibration_element.attrib["distance"]) == distance: vignetting_element = calibration_element elif calibration_element.tag == "field_of_view" and \ float(calibration_element.attrib["focal"]) == focal_length: fov_element = calibration_element paths_search_list = [args.db_path] if args.db_path else lensfun.get_database_directories() for path in paths_search_list: crawl_directory(path) if not files_found: print("No XML files found.") sys.exit(1) if lens_element is None: print("Lens model name not found.") sys.exit(1) if camera_element is None: print("Camera model name not found.") sys.exit(1) return lens_element, camera_element, distortion_element, tca_element, vignetting_element, real_focal_length_element, fov_element