import io p = 'app/api/v1/plugins.py' s = io.open(p, encoding='utf-8', newline='').read() a = '".vst2" if instrument_type.upper() == "VST2" else' b = '(".dll", ".so") if instrument_type.upper() == "VST2" else' assert s.count(a) == 1, s.count(a) s = s.replace(a, b) a2 = 'if fn.lower().endswith(ext) and \\' b2 = 'if (fn.lower().endswith(ext) if isinstance(ext, tuple) else fn.lower().endswith(ext)) and \\' assert s.count(a2) == 1, s.count(a2) s = s.replace(a2, b2) a3 = 'if os.path.isdir(sp) and sub.lower().endswith(ext) and \\' b3 = 'if os.path.isdir(sp) and (sub.lower().endswith(ext) if isinstance(ext, tuple) else sub.lower().endswith(ext)) and \\' assert s.count(a3) == 1, s.count(a3) s = s.replace(a3, b3) io.open(p, 'w', encoding='utf-8', newline='').write(s) print('ok')