Feb-17-2019, 08:15 PM
I want to automate updating python packages through pip. I think I have most of it. I just don't know how to evaluate the output from
results = os.system('pip list --outdated'). I thought putting 0 for none would be sufficient but it doesn't work. It gives me a list of outdated packages but says they are all up to date. It never runs lines 12-21.
def pkg_update():
options = ['Check for updates?', '1 Yes', '2 Exit']
for option in options:
print(option)
choice = input('> ')
if choice == '1':
print('Checking for updates.')
results = os.system('pip list --outdated')
if results == 0: # What do I put here?
print('All packages are up to date.\n')
pkg_update()
else:
print(results)
while True:
update_list = list(results)
current = update_list.pop(0)
print(f'Updating {current}.')
os.system(f'''pip install --upgrade
{current}''')
print('Done')
pkg_update()
elif choice == '2':
raise SystemExit
else:
pkg_update()
if __name__ == "__main__":
pkg_update(
