+def match_asterisk(pattern, data):
+ """Match data against a pattern
+
+ The difference to fnmatch is that this function only accepts patterns with a single
+ asterisk and that it returns a "closeness" number, which is larger the better the match.
+ Zero indicates no match at all.
+ """
+ if "*" not in pattern:
+ return 1 if pattern == data else 0
+ parts = pattern.split("*")
+ if len(parts) > 2:
+ raise ValueError("Only patterns with a single asterisk are supported, %s is invalid" % pattern)
+ if not data.startswith(parts[0]):
+ return 0
+ if not data.endswith(parts[1]):
+ return 0
+ matched = len(pattern)
+ total = len(data) + 1
+ return matched * 1. / total
+
+
+def update_profiles_edid(profiles, config):
+ fp_map = {}
+ for c in config:
+ if config[c].fingerprint is not None:
+ fp_map[config[c].fingerprint] = c
+
+ for p in profiles:
+ profile_config = profiles[p]["config"]
+
+ for fingerprint in fp_map:
+ for c in list(profile_config.keys()):
+ if profile_config[c].fingerprint != fingerprint or c == fp_map[fingerprint]:
+ continue
+
+ print("%s: renaming display %s to %s" % (p, c, fp_map[fingerprint]), file=sys.stderr)
+
+ tmp_disp = profile_config[c]
+
+ if fp_map[fingerprint] in profile_config:
+ # Swap the two entries
+ profile_config[c] = profile_config[fp_map[fingerprint]]
+ profile_config[c].output = c
+ else:
+ # Object is reassigned to another key, drop this one
+ del profile_config[c]
+
+ profile_config[fp_map[fingerprint]] = tmp_disp
+ profile_config[fp_map[fingerprint]].output = fp_map[fingerprint]
+
+