Skip to content

Commit 01732b1

Browse files
backend: General performance improvements and code cleanup
This commit is the first of many to avoid the back-end rewrite. * document Result object * document Diff class * remove layered env code * remove Notifications since deprecated * fix method name (PEP8) * add convenient method to force kill wineserver when stalled * use force_f_stalled in runner * use Result obj in Downloader.download * handle the Result obj in ComponentManager.download * code cleanup * remove old RunnerName type * remove old note repositories can now instruct this changes * code cleanup * code cleanup * code cleanup * code cleanup * new trailing newline * extend __validate_template method with essential paths * code cleanup * improve offline check the old method was too slow, the new one just checks the headers with curl, which is much faster * remove deprecations and old migrations * fixes #2345 * fix typo Co-authored-by: Kinsteen <[email protected]> * fix exception string * remove cabextract binary check since it's already done in health.py * remove reportMissingImports useless now since the main package moved from src to bottles * add PycURL * replace urllib with pycurl in crucial points Co-authored-by: Kinsteen <[email protected]>
1 parent a63684b commit 01732b1

File tree

121 files changed

+370
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+370
-885
lines changed

Diff for: bottles/backend/cabextract.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import subprocess
2222
from gettext import gettext as _
2323

24-
from bottles.backend.logger import Logger # pyright: reportMissingImports=false
24+
from bottles.backend.logger import Logger
2525

2626
logging = Logger()
2727

@@ -61,15 +61,6 @@ def __checks(self):
6161
logging.error(f"Cab file {self.path} not found")
6262
return False
6363

64-
if not self.cabextract_bin:
65-
logging.critical("cabextract utility not found, please install to use "
66-
"dependencies which need this feature")
67-
logging.write_log(
68-
"cabextract utility not found, please install to use "
69-
"dependencies which need this feature"
70-
)
71-
return False
72-
7364
return True
7465

7566
def __extract(self) -> bool:
@@ -81,7 +72,7 @@ def __extract(self) -> bool:
8172
for file in self.files:
8273
'''
8374
if file already exists as a symlink, remove it
84-
preventing broken symlinks when using layers
75+
preventing broken symlinks
8576
'''
8677
if os.path.exists(os.path.join(self.destination, file)):
8778
if os.path.islink(os.path.join(self.destination, file)):
@@ -111,10 +102,7 @@ def __extract(self) -> bool:
111102
f"-q {self.path}"
112103
]
113104
command = " ".join(command)
114-
subprocess.Popen(
115-
command,
116-
shell=True
117-
).communicate()
105+
subprocess.Popen(command, shell=True).communicate()
118106

119107
logging.info(f"Cabinet {self.name} extracted successfully")
120108
return True

Diff for: bottles/backend/diff.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44

55
class Diff:
6+
'''
7+
This class is no more used by the application, it's just a
8+
reference for future implementations.
9+
'''
610
__ignored = [
711
"dosdevices",
812
"users",
913
"bottle.yml",
10-
"layer.yml",
1114
"storage"
1215
]
1316

Diff for: bottles/backend/dlls/dll.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from typing import NewType
2121
from abc import abstractmethod
2222

23-
from bottles.backend.logger import Logger # pyright: reportMissingImports=false
23+
from bottles.backend.logger import Logger
2424
from bottles.backend.utils.manager import ManagerUtils
2525
from bottles.backend.wine.reg import Reg
2626
from bottles.backend.wine.wineboot import WineBoot

Diff for: bottles/backend/dlls/dxvk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
#
1717

18-
from bottles.backend.dlls.dll import DLLComponent # pyright: reportMissingImports=false
18+
from bottles.backend.dlls.dll import DLLComponent
1919
from bottles.backend.utils.manager import ManagerUtils
2020

2121

Diff for: bottles/backend/dlls/latencyflex.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
#
1717

18-
from bottles.backend.dlls.dll import DLLComponent # pyright: reportMissingImports=false
18+
from bottles.backend.dlls.dll import DLLComponent
1919
from bottles.backend.utils.manager import ManagerUtils
2020

2121

Diff for: bottles/backend/dlls/nvapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
#
1717

18-
from bottles.backend.dlls.dll import DLLComponent # pyright: reportMissingImports=false
18+
from bottles.backend.dlls.dll import DLLComponent
1919
from bottles.backend.utils.manager import ManagerUtils
2020

2121

Diff for: bottles/backend/dlls/vkd3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
#
1717

18-
from bottles.backend.dlls.dll import DLLComponent # pyright: reportMissingImports=false
18+
from bottles.backend.dlls.dll import DLLComponent
1919
from bottles.backend.utils.manager import ManagerUtils
2020

2121

Diff for: bottles/backend/downloader.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
import requests
2020
from gi.repository import GLib
2121

22-
from bottles.backend.logger import Logger # pyright: reportMissingImports=false
22+
from bottles.backend.logger import Logger
2323
from bottles.backend.utils.file import FileUtils
24+
from bottles.backend.models.result import Result
2425

2526
logging = Logger()
2627

@@ -39,12 +40,12 @@ def __init__(self, url: str, file: str, func: callable = None, task_id: int = No
3940
self.func = func
4041
self.task_id = task_id
4142

42-
def download(self):
43+
def download(self) -> Result:
4344
"""Start the download."""
4445
try:
4546
with open(self.file, "wb") as file:
4647
self.start_time = time.time()
47-
headers = {"User-Agent": "curl/7.79.1"}
48+
headers = {"User-Agent": "curl/7.79.1"} # we fake the user-agent to avoid 403 errors on some servers
4849
response = requests.get(self.url, stream=True, headers=headers)
4950
total_size = int(response.headers.get("content-length", 0))
5051
block_size = 1024
@@ -78,12 +79,12 @@ def download(self):
7879
self.__progress(1, 1, 1)
7980
except requests.exceptions.SSLError:
8081
logging.error("Download failed due to a SSL error. Your system may have a wrong date/time or wrong certificates.")
81-
return False
82+
return Result(False, message="Download failed due to a SSL error.")
8283
except (requests.exceptions.RequestException, OSError):
8384
logging.error("Download failed! Check your internet connection.")
84-
return False
85+
return Result(False, message="Download failed! Check your internet connection.")
8586

86-
return True
87+
return Result(True)
8788

8889
def __progress(self, count, block_size, total_size):
8990
"""Update the progress bar."""

Diff for: bottles/backend/globals.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@
2121
from pathlib import Path
2222
from functools import lru_cache
2323

24-
from bottles.backend.logger import Logger # pyright: reportMissingImports=false
24+
from bottles.backend.logger import Logger
2525
from bottles.backend.utils.display import DisplayUtils
2626
from bottles.backend.managers.data import DataManager
2727

2828
logging = Logger()
2929

3030

31-
class API:
32-
notifications = "https://raw.githubusercontent.com/bottlesdevs/data/main/notifications.yml"
33-
34-
3531
# xdg data path
3632
xdg_data_home = GLib.get_user_data_dir()
3733

@@ -45,7 +41,7 @@ def get_apps_dir():
4541
_dir = f"{Path.home()}/.local/share/applications"
4642
return _dir
4743

48-
def VkBasaltPath():
44+
def is_vkbasalt_available():
4945
vkbasalt_paths = [
5046
"/usr/lib/extensions/vulkan/vkBasalt/etc/vkBasalt",
5147
"/usr/local",
@@ -76,7 +72,6 @@ class Paths:
7672
runners = f"{base}/runners"
7773
bottles = f"{base}/bottles"
7874
steam = f"{base}/steam"
79-
layers = f"{base}/layers"
8075
dxvk = f"{base}/dxvk"
8176
vkd3d = f"{base}/vkd3d"
8277
nvapi = f"{base}/nvapi"
@@ -105,7 +100,7 @@ class TrdyPaths:
105100
# Check if some tools are available
106101
gamemode_available = shutil.which("gamemoderun") or False
107102
gamescope_available = shutil.which("gamescope") or False
108-
vkbasalt_available = VkBasaltPath()
103+
vkbasalt_available = is_vkbasalt_available()
109104
mangohud_available = shutil.which("mangohud") or False
110105
obs_vkc_available = shutil.which("obs-vkcapture") or False
111106
vmtouch_available = shutil.which("vmtouch") or False

Diff for: bottles/backend/health.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import contextlib
2323
import subprocess
2424

25-
from bottles.backend.logger import Logger # pyright: reportMissingImports=false
25+
from bottles.backend.logger import Logger
2626
from bottles.backend.utils.display import DisplayUtils
2727
from bottles.backend.utils.gpu import GPUUtils
2828
from bottles.backend.utils.generic import is_glibc_min_available
@@ -70,6 +70,7 @@ def __init__(self):
7070
"MemAvailable": "n/a"
7171
}
7272
self.get_ram_data()
73+
7374
if not "FLATPAK_ID" in os.environ:
7475
self.cabextract = self.check_cabextract()
7576
self.p7zip = self.check_p7zip()
@@ -231,7 +232,6 @@ def __get_distro():
231232
@staticmethod
232233
def get_bottles_envs():
233234
look = [
234-
"LAYERS",
235235
"TESTING_REPOS",
236236
"LOCAL_INSTALLERS",
237237
"LOCAL_COMPONENTS",
@@ -269,6 +269,7 @@ def get_ram_data(self):
269269

270270
def get_results(self, plain: bool = False):
271271
results = {
272+
"Official Package": "FLATPAK_ID" in os.environ,
272273
"Version": VERSION,
273274
"Display": {
274275
"X.org": self.x11,

0 commit comments

Comments
 (0)