Skip to content

Instantly share code, notes, and snippets.

@ljesparis
Created March 10, 2015 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ljesparis/5fee44045e820e5d6d5a to your computer and use it in GitHub Desktop.
Save ljesparis/5fee44045e820e5d6d5a to your computer and use it in GitHub Desktop.
upgrade all ur python libs
import subprocess
import argparse
import re
import sys
class BaseUpgrade(object):
def __init__(self, vpip, libs=[], *args, **kwargs):
self.vpip = vpip
self.commands = ['sudo', self.vpip, 'install', '', '--upgrade']
if libs:
self.libraries = libs
else:
self.libraries = list()
self.__pip_results()
self.__libs()
def __pip_results(self):
pip_list = subprocess.check_output([self.vpip, 'list'])
self.ls_results = pip_list.split()
def __libs(self):
for self.ls_result in self.ls_results:
if re.match('[\w\d]', self.ls_result):
self.libraries.append(self.ls_result)
def upgrade(self):
for self.library in self.libraries:
self.commands[3] = self.library
subprocess.call(self.commands)
@classmethod
def start(cls, vpip, libs):
if vpip:
pip = 'pip'
pip += vpip
self = cls(pip, libs)
self.upgrade()
else:
if re.search('^[3|2][.][\d\D\W\w]', sys.version):
subprocess.call(['python'+re.split('[.]',sys.version)[0], __file__, '-h'])
def main():
parser = argparse.ArgumentParser(description='upgrade all your libraries')
parser.add_argument(
'-p',
'--pip',
dest='pip',
help='you can upgrade your python2 or 3 libraries '
)
parser.add_argument(
'-l',
'--libs',
dest='libs',
nargs='*',
help='''
specify at least one library to upgrade, if you dont, it\'ll upgrade all
'''
)
args = parser.parse_args()
BaseUpgrade.start(args.pip, args.libs)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment