|
import os |
|
import subprocess |
|
|
|
|
|
def get_shim_list(): |
|
result = subprocess.run( |
|
["pwsh", "-Command", "scoop shim list"], |
|
capture_output=True, |
|
text=True, |
|
encoding="utf-8", |
|
errors="replace", |
|
) |
|
return result.stdout.strip() |
|
|
|
|
|
def parse_shim_list(output): |
|
lines = output.strip().split("\n")[3:] # Skip header lines |
|
shims = {} |
|
for line in lines: |
|
parts = line.split()[:-2] |
|
if len(parts) < 3: |
|
continue |
|
name = parts[0] |
|
source = parts[1] |
|
alternatives = parts[2:] |
|
print(f"{name}\t from {source}\t have alternatives: {", ".join(alternatives)}") |
|
shims[name] = {"source": source, "alternatives": alternatives} |
|
return shims |
|
|
|
|
|
def modify_shim_priority(name, source, alternatives): |
|
if len(alternatives) > 1 and alternatives[0] == source: |
|
for alternative in alternatives: |
|
choice = ( |
|
input(f"Do you want to use '{name}' from '{alternative}'? (Y/n): ") |
|
.strip() |
|
.lower() |
|
or "y" |
|
) |
|
if choice in ["y", "yes"]: |
|
cur_shim_path = os.path.join( |
|
os.environ["SCOOP"], "shims", f"{name}.shim" |
|
) |
|
bak_shim_path = os.path.join( |
|
os.environ["SCOOP"], "shims", f"{name}.shim.{source}" |
|
) |
|
new_shim_path = os.path.join( |
|
os.environ["SCOOP"], "shims", f"{name}.shim.{alternative}" |
|
) |
|
|
|
os.rename(cur_shim_path, bak_shim_path) |
|
os.rename(new_shim_path, cur_shim_path) |
|
print(f"Modified shim priority for '{name}' to use '{alternative}'.") |
|
break |
|
else: |
|
print("No changes made.") |
|
else: |
|
print(f"No modification needed for '{name}'.") |
|
|
|
|
|
def main(): |
|
print("Scanning for shims, it may take a while...") |
|
print("-" * 80) |
|
output = get_shim_list() |
|
shims = parse_shim_list(output) |
|
print("-" * 80) |
|
for name, details in shims.items(): |
|
choice = ( |
|
input( |
|
f"Do you want to modify shim priority for '{name}'? (Currently using '{details['source']}') (y/N): " |
|
) |
|
.strip() |
|
.lower() |
|
or "n" |
|
) |
|
if choice in ["y", "yes"]: |
|
modify_shim_priority(name, details["source"], details["alternatives"]) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |