Skip to content

universal update script for linux/unix/osx #3965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pip/update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python
import os

update_list = []
p = os.popen('sudo -H pip freeze --local',"r")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a personal script, this is fine but you should probably use subprocess.Popen for production scripts.

while 1:
line = p.readline()
if not line: break
Copy link
Member

@pfmoore pfmoore Sep 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify these 3 lines to

for line in p:

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do some work on making this universal for Windows also, I'm sure I could do OS checks and just split the nix and nt code as functions.

I just added this in the fork to get some feedback as I wrote this a couple years back and decided hey why not actually introduce it to the community.

I'll do some work on it and report back here and see what everyone thinks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't worry too much, as it's unlikely we'd accept this PR as a standalone utility script in the pip source tree anyway (and there are a few discussions about a "proper" subcommand, such as #3744 and #3194 - none have yet been accepted because there are some hard issues to be resolved).

update_list.append(line.rstrip('\n').split('=')[0])
counter = 0
while counter < len(update_list):
os.system('sudo -H pip install -U "' + update_list[counter] + '"')
counter += 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't use counter here, so

for entry in update_list:
    subprocess.check_call(['sudo', '-H', 'pip', 'install', '-U', entry])

is probably simpler (and more secure, as you're not relying on shell quoting, and hence exposing yourself to security issues from weird package names).