A python script to reveal conflicting packages

Sometimes you have a list of packages you want to install with "pkg install -y" or "pkg install -f -y" and you want to make sure there are no conflicting.
Here a script to reveal the conflicting ones,
pip install --user subprocess
Code:
import subprocess

def do_force(my_string:str)-> str:
    print(f"Processing: {my_string}")
    command = ["pkg", "install","-f","-y",my_string]
    process = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
    stdout, stderr = process.communicate(input="optional input string")
    print(f"Output: {stdout}")
    print(f"Errors: {stderr}")
    print(f"Return code: {process.returncode}")
    return stdout

def do_dry(my_string:str)-> str:
    print(f"Processing: {my_string}")
    command = ["pkg", "install","-n",my_string]
    process = subprocess.Popen(command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,text=True)
    stdout, stderr = process.communicate(input="optional input string")
    # print(f"Output: {stdout}")
    # print(f"Errors: {stderr}")
    # print(f"Return code: {process.returncode}")
    return stdout


with open('example.txt', 'r') as file:
    for line in file:
        todo=line.strip()
        print("-------------------------------------------------")
        print(todo)
        stdout=do_dry(todo)
        if "REMOVED" in stdout:
            print(stdout)
            print("DO NOT INSTALL")
        else:
            print("DO INSTALL")
            # do_dry(todo)
 
Back
Top