Skip to content

Commit

Permalink
Version 1.4.2: Added automatic update
Browse files Browse the repository at this point in the history
  • Loading branch information
k4yt3x committed Aug 28, 2017
1 parent 31de09b commit c20fba1
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions kpm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import socket
import subprocess
import sys
import urllib.request

try:
import avalon_framework as avalon
Expand All @@ -42,7 +43,7 @@
os.system('pip3 install avalon_framework')
else:
print('Installing using method 3')
import urllib.request
# import urllib.request
content = urllib.request.urlopen('https://bootstrap.pypa.io/get-pip.py')
with open('/tmp/get-pip.py', 'w') as getpip:
getpip.write(content.read().decode())
Expand All @@ -64,13 +65,33 @@
else:
print('\033[31m\033[1mInvalid Input!\033[0m')

VERSION = '1.4.1'
VERSION = '1.4.2'

ImportList = []


# -------------------------------- Functions

def check_version():
avalon.subLevelTimeInfo('Checking KPM Version...')
with urllib.request.urlopen('https://raw.githubusercontent.com/K4YT3X/KPM/master/kpm.py') as response:
html = response.read().decode().split('\n')
for line in html:
if 'VERSION = ' in line:
server_version = line.split(' ')[-1].replace('\'', '')
break
avalon.subLevelTimeInfo('Server version: ' + server_version)
if server_version > VERSION:
avalon.info('Here\'s a newer version of KPM!')
if avalon.ask('Update to the newest version?'):
os.system('wget https://raw.githubusercontent.com/K4YT3X/KPM/master/kpm.py -O ' + os.path.abspath(__file__))
else:
avalon.warning('Ignoring update')
else:
avalon.subLevelTimeInfo('KPM is already on the newest version')
return server_version


def icon():
"""
Prints KPM Icon
Expand Down Expand Up @@ -216,6 +237,8 @@ def internet_connected():
avalon.error('Internet not connected! Aborting...')
exit(0)

check_version()

avalon.info('Starting KPM Sequence')
if args.installkpm:
os.system('cp ' + os.path.abspath(__file__) + ' /usr/bin/kpm') # os.rename throws an error when /tmp is in a separate partition
Expand Down

0 comments on commit c20fba1

Please sign in to comment.