diff --git a/.gitignore b/.gitignore index aa8d55b..52be498 100644 --- a/.gitignore +++ b/.gitignore @@ -88,3 +88,10 @@ ENV/ # Rope project settings .ropeproject .project + +# PyCharm stuff +.idea/workspace.xml +.idea/pipupdate.iml +.idea/modules.xml +.idea/vcs.xml +.idea/misc.xml diff --git a/pipinstall.py b/pipinstall.py index eb6bdf6..6dc4dbf 100644 --- a/pipinstall.py +++ b/pipinstall.py @@ -1,8 +1,8 @@ -# PIPupdate-installPIP 1.0.2 +# PIPupdate-installPIP 1.1.0 # External asset to PIPupdate. -# (c) 2016 o355 under the GNU GPL 3.0 +# (c) 2016-2017 o355 under the GNU GPL 3.0 -print("Welcome to PIPupdate-installPIP (1.0.2)!") +print("Welcome to PIPupdate-installPIP (1.1.0)!") print("Now installing PIP.") try: import sys @@ -32,8 +32,15 @@ sys.exit() print("Now downloading the PIP installer...") -with urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py') as update_response, open('get-pip.py', 'wb') as update_out_file: - shutil.copyfileobj(update_response, update_out_file) +try: + with urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py') as update_response, open('get-pip.py', 'wb') as update_out_file: + shutil.copyfileobj(update_response, update_out_file) +except: + print("The PIP installer could not be fetched, either due to a urllib failure, or you don't have an internet connection.", + "Please attempt to download the installer from this url: 'https://bootstrap.pypa.io/get-pip.py'.", + "Save the file in the pipupdate directory. When this process is complete, press enter to continue. Otherwise, press", + "Control + C to exit.", sep="\n") + input() print("Now running the PIP installer...") print("Please note: get-pip.py is not developed or maintained by myself.") diff --git a/pipupdate-nc.py b/pipupdate-nc.py index 305d18d..969ab20 100644 --- a/pipupdate-nc.py +++ b/pipupdate-nc.py @@ -1,8 +1,8 @@ -# PIPupdate 1.0.2-nocolor +# PIPupdate 1.1.0-nocolor # Specific PIPupdate version to run -# (c) 2016 o355 under the GNU GPL 3.0 +# (c) 2016-2017 o355 under the GNU GPL 3.0 -print("Welcome to PIPupdate-nocolor (v1.0.2)!") +print("Welcome to PIPupdate-nocolor (v1.1.0)!") print("Loading...") updatecountint = 0 @@ -23,15 +23,18 @@ try: import pip except ImportError: - print("Please install PIP to use PIPupdate-nocolor!") - print("You can also use the pipinstall.py script to install PIP.") - sys.exit() - -try: - from subprocess import call -except ImportError: - print("Please install subprocess/subprocess call to use PIPupdate-nocolor!") - sys.exit() + print("Shucks. PIP isn't installed. Would you like me to install PIP for you?") + pipinstall = input("Yes or No: ").lower() + if pipinstall == "yes": + print("Alright. Installing PIP now!") + exec(open("pipinstall.py").read()) + elif pipinstall == "no": + print("Alright. Not installing PIP, exiting PIPupdate.") + sys.exit() + else: + print("I couldn't understand what you inputted.") + print("I'll assume you didn't want to install PIP, exiting now.") + sys.exit() for pkgname in pip.get_installed_distributions(): updatenumber = updatenumber + 1 @@ -42,8 +45,11 @@ print("PIPupdate: Now attempting to update package " + pkgname.project_name + "...") updatecountint = updatecountint + 1 updatecountstr = str(updatecountint) - call("pip install --upgrade " + pkgname.project_name, shell=True) - print("PIPupdate: Updated package " + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") + try: + pip.main(['install', '--upgrade', pkgname.project_name]) + print("PIPupdate: Updated package " + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") + except: + print("PIPupdate: Failed to update package " + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") print("") print("PIPupdate is done, updated " + updatecountstr + " packages!") diff --git a/pipupdate.py b/pipupdate.py index 3edaf56..082e3fe 100644 --- a/pipupdate.py +++ b/pipupdate.py @@ -1,7 +1,7 @@ -# PIPupdate 1.0.2 -# (c) 2016 o355 under the GNU GPL 3.0 +# PIPupdate 1.1.0 +# (c) 2016-2017 o355 under the GNU GPL 3.0 -print("Welcome to PIPupdate (v1.0.2)") +print("Welcome to PIPupdate (v1.1.0)!") print("Loading...") updatecountint = 0 @@ -31,12 +31,7 @@ print("I couldn't understand what you inputted.") print("I'll assume you didn't want to install PIP, exiting now.") sys.exit() - -try: - from subprocess import call -except ImportError: - print("Please install subprocess/subprocess call to use PIPupdate!") - sys.exit() + try: from colorama import init, Fore, Style @@ -82,8 +77,11 @@ print(Fore.GREEN + Style.BRIGHT + "PIPupdate: Now attempting to update package " + pkgname.project_name + "..." + Style.RESET_ALL) updatecountint = updatecountint + 1 updatecountstr = str(updatecountint) - call("pip install --upgrade " + pkgname.project_name, shell=True) - print(Fore.GREEN + Style.BRIGHT + "PIPupdate: Updated package " + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") + try: + pip.main(['install', '--upgrade', pkgname.project_name]) + print(Fore.GREEN + Style.BRIGHT + "PIPupdate: Updated package " + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") + except: + print(Fore.RED + Style.BRIGHT + "PIPupdate: Failed to update package" + pkgname.project_name + ". Progress: " + updatecountstr + "/" + updatenumberstr + " updates") print(Style.RESET_ALL) print("PIPupdate is done, updated " + updatecountstr + " packages!")