Skip to content

Commit

Permalink
Allow update check to fail silently (close #50)
Browse files Browse the repository at this point in the history
  • Loading branch information
AcidWeb committed Mar 20, 2020
1 parent bb279b4 commit 1ab88af
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import string
import random

__version__ = '3.1.7'
__version__ = '3.1.8'
__license__ = 'GPLv3'
__copyright__ = '2019-2020, Paweł Jastrzębski <[email protected]>'
__docformat__ = 'restructuredtext en'
Expand Down
53 changes: 27 additions & 26 deletions CurseBreaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,33 @@ def auto_update(self):
pass
payload = requests.get('https://api.github.com/repos/AcidWeb/CurseBreaker/releases/latest',
headers=HEADERS).json()
remoteversion = payload['name']
changelog = payload['body']
url = None
for binary in payload['assets']:
if (self.os == 'Windows' and '.exe' in binary['name'])\
or (self.os == 'Darwin' and '.zip' in binary['name'])\
or (self.os == 'Linux' and '.gz' in binary['name']):
url = binary['browser_download_url']
break
if url and StrictVersion(remoteversion[1:]) > StrictVersion(__version__):
printft(HTML('<ansigreen>Updating CurseBreaker...</ansigreen>'))
shutil.move(sys.executable, sys.executable + '.old')
payload = requests.get(url, headers=HEADERS)
if self.os == 'Darwin':
zipfile.ZipFile(io.BytesIO(payload.content)).extractall()
else:
with open(sys.executable, 'wb') as f:
if self.os == 'Windows':
f.write(payload.content)
elif self.os == 'Linux':
f.write(gzip.decompress(payload.content))
os.chmod(sys.executable, 0o775)
printft(HTML(f'<ansibrightgreen>Update complete! Please restart the application.</ansibrightgreen'
f'>\n\n<ansigreen>Changelog:</ansigreen>\n{changelog}\n'))
pause()
sys.exit(0)
if 'name' in payload and 'body' in payload and 'assets' in payload:
remoteversion = payload['name']
changelog = payload['body']
url = None
for binary in payload['assets']:
if (self.os == 'Windows' and '.exe' in binary['name'])\
or (self.os == 'Darwin' and '.zip' in binary['name'])\
or (self.os == 'Linux' and '.gz' in binary['name']):
url = binary['browser_download_url']
break
if url and StrictVersion(remoteversion[1:]) > StrictVersion(__version__):
printft(HTML('<ansigreen>Updating CurseBreaker...</ansigreen>'))
shutil.move(sys.executable, sys.executable + '.old')
payload = requests.get(url, headers=HEADERS)
if self.os == 'Darwin':
zipfile.ZipFile(io.BytesIO(payload.content)).extractall()
else:
with open(sys.executable, 'wb') as f:
if self.os == 'Windows':
f.write(payload.content)
elif self.os == 'Linux':
f.write(gzip.decompress(payload.content))
os.chmod(sys.executable, 0o775)
printft(HTML(f'<ansibrightgreen>Update complete! Please restart the application.</ansibrightgre'
f'en>\n\n<ansigreen>Changelog:</ansigreen>\n{changelog}\n'))
pause()
sys.exit(0)
except Exception as e:
printft(HTML(f'<ansibrightred>Update failed!\n\nReason: {str(e)}</ansibrightred>\n'))
pause()
Expand Down

0 comments on commit 1ab88af

Please sign in to comment.