Skip to content

Commit 9f92e5a

Browse files
committed
API Refactor
1 parent d8289b0 commit 9f92e5a

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

protonup/api.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def fetch_data(tag) -> dict:
1919
url = PROTONGE_URL + (f'/tags/{tag}' if tag else '/latest')
2020
data = requests.get(url).json()
2121
if 'tag_name' not in data:
22-
return None # invalid tag
22+
return {} # invalid tag
2323

2424
values = {'version': data['tag_name'], 'date': data['published_at'].split('T')[0]}
2525
for asset in data['assets']:
@@ -86,7 +86,7 @@ def installed_versions() -> list:
8686
return versions_found
8787

8888

89-
def get_proton(version=None, yes=True, dl_only=False, output=None) -> None:
89+
def get_proton(version=None, yes=True, dl_only=False, output=None) -> bool:
9090
"""Download and (optionally) install Proton"""
9191
installdir = install_directory()
9292
data = fetch_data(tag=version)
@@ -96,7 +96,7 @@ def get_proton(version=None, yes=True, dl_only=False, output=None) -> None:
9696
print('[ERROR] invalid tag / binary not found')
9797
return False
9898

99-
protondir = installdir + 'Proton-' + data['version']
99+
protondir = installdir + data['version']
100100
checksum_dir = protondir + '/sha512sum'
101101
source_checksum = requests.get(data['checksum']).text if 'checksum' in data else None
102102
local_checksum = open(checksum_dir).read() if os.path.exists(checksum_dir) else None
@@ -106,23 +106,23 @@ def get_proton(version=None, yes=True, dl_only=False, output=None) -> None:
106106
if local_checksum and source_checksum:
107107
if local_checksum in source_checksum:
108108
if not yes:
109-
print(f"[INFO] Proton-{data['version']} already installed")
109+
print(f"[INFO] {data['version']} already installed")
110110
print("[INFO] No hotfix found")
111-
return
111+
return False
112112
elif not yes:
113113
print("[INFO] Hotfix available")
114114
else:
115115
if not yes:
116-
print(f"[INFO] Proton-{data['version']} already installed")
117-
return
116+
print(f"[INFO] {data['version']} already installed")
117+
return False
118118

119119
# Confirmation
120120
if not yes:
121-
print(f"Ready to download Proton-{data['version']}",
121+
print(f"Ready to download {data['version']}",
122122
f"\nSize : {readable_size(data['size'])}",
123123
f"\nPublished : {data['date']}")
124124
if input("Continue? (Y/n): ") not in ['y', 'Y', '']:
125-
return
125+
return False
126126

127127
# Prepare Destination
128128
destination = output if output else (os.getcwd() if dl_only else TEMP_DIR)
@@ -135,14 +135,14 @@ def get_proton(version=None, yes=True, dl_only=False, output=None) -> None:
135135
if not download(url=data['download'], destination=destination, show_progress=not yes):
136136
if not yes:
137137
print("[ERROR] Download failed")
138-
return
138+
return True
139139

140140
download_checksum = sha512sum(destination)
141141
if source_checksum and (download_checksum not in source_checksum):
142142
if not yes:
143143
print("[ERROR] Checksum verification failed")
144144
shutil.rmtree(TEMP_DIR, ignore_errors=True)
145-
return
145+
return True
146146

147147
# Installation
148148
if not dl_only:
@@ -158,12 +158,12 @@ def get_proton(version=None, yes=True, dl_only=False, output=None) -> None:
158158
# Clean up
159159
shutil.rmtree(TEMP_DIR, ignore_errors=True)
160160

161+
return True
162+
161163

162164
def remove_proton(version=None) -> bool:
163165
"""Uninstall existing proton installation"""
164-
if not version.startswith("Proton-"):
165-
version = "Proton-" + version
166-
target = install_directory() + version
166+
target = install_directory() + str(version)
167167
if os.path.exists(target):
168168
shutil.rmtree(target)
169169
return True

0 commit comments

Comments
 (0)