Skip to content

Commit

Permalink
Version 2.4
Browse files Browse the repository at this point in the history
Bypass self-update if unauthenticated GitHub rate limit is exceeded
  • Loading branch information
Technetium1 committed Dec 12, 2020
1 parent 7abc302 commit 152d605
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode/
.dccache
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
75 changes: 41 additions & 34 deletions ChocolateyUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import certifi
import sys

version = "2.3"
version = "2.4"


def printascii():
Expand Down Expand Up @@ -117,41 +117,48 @@ def selfupdate():
retries=4,
redirect=False)
updateresult = json.loads(r.data.decode("utf-8"))
currentversion = updateresult["tag_name"]
downloadlink = updateresult["assets"][0]["browser_download_url"]
if currentversion > version:
print("\nNewer version found on GitHub!\n")
elif currentversion < version:
print("\nVersion newer than what was found on GitHub!\n")
elif currentversion == version:
print("\nAlready at latest GitHub release!\n")
else:
print("\nSomething went wrong checking for updates! If this continues report to https://github.com/Technetium1/ChocolateyUpdate\n")
system("pause")
raise SystemExit
if updateresult["assets"] and currentversion > version:
print("Downloading new release from: " + downloadlink)
if Path("NewChocolateyUpdate.exe").exists():
remove("NewChocolateyUpdate.exe")
if Path("OldChocolateyUpdate.exe").exists():
remove("OldChocolateyUpdate.exe")
r = http.request(
"GET",
downloadlink,
headers={"User-Agent": "curl"},
timeout=urllib3.Timeout(connect=15.0, read=120.0),
retries=2,
redirect=True)
with open("NewChocolateyUpdate.exe", "wb") as downloadedfile:
downloadedfile.write(r.data)
rename("ChocolateyUpdate.exe", "OldChocolateyUpdate.exe")
system("attrib +h OldChocolateyUpdate.exe")
rename("NewChocolateyUpdate.exe", "ChocolateyUpdate.exe")
print("Update completed! Restart ChocolateyUpdate to complete!")
if updateresult.get("tag_name", None) is None:
print("\nFAILED SELF-UPDATE! GITHUB RATE LIMIT LIKELY EXCEEDED ON YOUR IP!\n")
print("\nCONTINUING WITHOUT SELF-UPDATE!\n")
system("pause")
raise SystemExit
else:
print()
pass
else:
currentversion = updateresult["tag_name"]
downloadlink = updateresult["assets"][0]["browser_download_url"]
if currentversion > version:
print("\nNewer version found on GitHub!\n")
elif currentversion < version:
print("\nVersion newer than what was found on GitHub!\n")
elif currentversion == version:
print("\nAlready at latest GitHub release!\n")
else:
print("\nSomething went wrong checking for updates! If this continues report to https://github.com/Technetium1/ChocolateyUpdate\n")
system("pause")
raise SystemExit
if updateresult["assets"] and currentversion > version:
print("Downloading new release from: " + downloadlink)
if Path("NewChocolateyUpdate.exe").exists():
remove("NewChocolateyUpdate.exe")
if Path("OldChocolateyUpdate.exe").exists():
remove("OldChocolateyUpdate.exe")
r = http.request(
"GET",
downloadlink,
headers={"User-Agent": "curl"},
timeout=urllib3.Timeout(connect=15.0, read=120.0),
retries=2,
redirect=True)
with open("NewChocolateyUpdate.exe", "wb") as downloadedfile:
downloadedfile.write(r.data)
rename("ChocolateyUpdate.exe", "OldChocolateyUpdate.exe")
system("attrib +h OldChocolateyUpdate.exe")
rename("NewChocolateyUpdate.exe", "ChocolateyUpdate.exe")
print("Update completed! Restart ChocolateyUpdate to complete!")
system("pause")
raise SystemExit
else:
pass


admincheck()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
certifi>=2020.11.8
certifi>=2020.12.5
pyinstaller>=4.1
urllib3>=1.26.2

0 comments on commit 152d605

Please sign in to comment.