Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete sandbox and runtime, and clean up directory structure #3615

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
.mypy_cache/
.pytest_cache/
/.project
Expand Down
21 changes: 0 additions & 21 deletions .vscode/launch.json

This file was deleted.

18 changes: 0 additions & 18 deletions .vscode/settings.json

This file was deleted.

27 changes: 0 additions & 27 deletions .vscode/tasks.json

This file was deleted.

2 changes: 1 addition & 1 deletion CODING_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pytest .
Regenerate PYPI dependency manifest when requirements.txt changed

```bash
python ./utils/flatpak-pip-generator.py --runtime org.gnome.Sdk -r requirements.txt -o com.usebottles.bottles.pypi-deps --yaml
python ./build-aux/flatpak-pip-generator.py --runtime org.gnome.Sdk -r requirements.txt -o com.usebottles.bottles.pypi-deps --yaml
```

## I18n files
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ There are two methods to build Bottles. The first and longer method is using `or
Since Bottles is primarily and officially distributed as a Flatpak, we only provide instructions to directly build it inside a Flatpak environment:

1. Download and install the latest build of Bottles: [bottles-x86_64.zip](https://nightly.link/bottlesdevs/Bottles/workflows/build_flatpak/main/bottles-x86_64.zip). Unzip it, and run `flatpak install bottles.flatpak` (use `--user` if necessary)
2. Run `flatpak run -d --filesystem=$PWD --command=bash com.usebottles.bottles.Devel` from the root of the repository, followed by `./utils/install.sh`. This will build Bottles and install it under the `build/` directory.
2. Run `flatpak run -d --filesystem=$PWD --command=bash com.usebottles.bottles.Devel` from the root of the repository, followed by `./build-aux/install.sh`. This will build Bottles and install it under the `build/` directory.
3. Run `./build/bin/bottles` to launch Bottles

Due to GNOME Builder limitations, Builder cannot build Bottles for the time being; see [GNOME/gnome-builder#2061](https://gitlab.gnome.org/GNOME/gnome-builder/-/issues/2061) for more context. This is the best workaround we can provide.
Expand Down
147 changes: 3 additions & 144 deletions bottles/backend/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import os
from bottles.backend.utils import yaml
import shutil
import contextlib

from bottles.backend.logger import Logger
Expand Down Expand Up @@ -56,42 +55,16 @@ def __init__(self):
self.file_utils = FileUtils()
self.x11 = self.check_x11()
self.wayland = self.check_wayland()
self.xwayland = self.check_xwayland()
self.xwayland = self.x11 and self.wayland
self.desktop = self.check_desktop()
self.gpus = self.check_gpus()
self.gpus = GPUUtils().get_gpu()
self.glibc_min = is_glibc_min_available()
self.bottles_envs = self.get_bottles_envs()
self.check_system_info()
self.disk = self.get_disk_data()
self.ram = {"MemTotal": "n/a", "MemAvailable": "n/a"}
self.get_ram_data()

if "FLATPAK_ID" not in os.environ:
self.cabextract = self.check_cabextract()
self.p7zip = self.check_p7zip()
self.patool = self.check_patool()
self.icoextract = self.check_icoextract()
self.pefile = self.check_pefile()
self.orjson = self.check_orjson()
self.markdown = self.check_markdown()
self.xdpyinfo = self.check_xdpyinfo()
self.ImageMagick = self.check_ImageMagick()
self.FVS = self.check_FVS()
else:
self.cabextract = True
self.p7zip = True
self.patool = True
self.icoextract = True
self.pefile = True
self.orjson = True
self.markdown = True
self.ImageMagick = True
self.FVS = True

@staticmethod
def check_gpus():
return GPUUtils().get_gpu()

def check_x11(self):
port = DisplayUtils.get_x_display()
if port:
Expand All @@ -101,98 +74,11 @@ def check_x11(self):

@staticmethod
def check_wayland():
if "WAYLAND_DISPLAY" in os.environ or "WAYLAND_SOCKET" in os.environ:
return True
return False

def check_xwayland(self):
if self.x11 and self.wayland:
return True
return False
return "WAYLAND_DISPLAY" in os.environ or "WAYLAND_SOCKET" in os.environ

def check_desktop(self):
return os.environ.get("DESKTOP_SESSION")

@staticmethod
def check_cabextract():
res = shutil.which("cabextract")
if res is None:
return False
return True

@staticmethod
def check_p7zip():
res = shutil.which("7z")
if res is None:
return False
return True

@staticmethod
def check_patool():
res = shutil.which("patool")
if res is None:
return False
return True

@staticmethod
def check_icoextract():
try:
import icoextract

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_pefile():
try:
import pefile

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_markdown():
try:
import markdown

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_orjson():
try:
import orjson

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_xdpyinfo():
res = shutil.which("xdpyinfo")
if res is None:
return False
return True

@staticmethod
def check_ImageMagick():
res = shutil.which("identify")
if res is None:
return False
return True

@staticmethod
def check_FVS():
try:
from fvs.repo import FVSRepo

return True
except ModuleNotFoundError:
return False

@staticmethod
def get_bottles_envs():
look = [
Expand Down Expand Up @@ -246,36 +132,9 @@ def get_results(self, plain: bool = False):
"Bottles_envs": self.bottles_envs,
}

if "FLATPAK_ID" not in os.environ:
results["Tools and Libraries"] = {
"cabextract": self.cabextract,
"p7zip": self.p7zip,
"patool": self.patool,
"glibc_min": self.glibc_min,
"icoextract": self.icoextract,
"pefile": self.pefile,
"orjson": self.orjson,
"markdown": self.markdown,
"ImageMagick": self.ImageMagick,
"FVS": self.FVS,
"xdpyinfo": self.xdpyinfo,
}

if plain:
_yaml = yaml.dump(results, sort_keys=False, indent=4)
_yaml = _yaml.replace("&id", "&id")
return _yaml

return results

def has_core_deps(self):
result = True

for k, v in self.get_results()["Tools and Libraries"].items():
if v is False:
logging.error(
f"Core dependency {k} not found, Bottles can't be started."
)
result = False

return result
72 changes: 32 additions & 40 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,50 +1312,42 @@ def components_check():
wineboot.init()
log_update(_("Wine config updated!"))

if "FLATPAK_ID" in os.environ or sandbox:
"""
If running as Flatpak, or sandbox flag is set to True, unlink home
directories and make them as folders.
"""
if "FLATPAK_ID":
log_update(_("Running as Flatpak, sandboxing userdir…"))
if sandbox:
log_update(_("Sandboxing userdir…"))

userdir = f"{bottle_complete_path}/drive_c/users"
if os.path.exists(userdir):
# userdir may not exists when unpacking a template, safely
# ignore as it will be created on first winebot.
links = []
for user in os.listdir(userdir):
_user_dir = os.path.join(userdir, user)

if os.path.isdir(_user_dir):
for _dir in os.listdir(_user_dir):
_dir_path = os.path.join(_user_dir, _dir)
log_update(_("Sandboxing user directory…"))

userdir = f"{bottle_complete_path}/drive_c/users"
if os.path.exists(userdir):
# userdir may not exists when unpacking a template, safely
# ignore as it will be created on first winebot.
links = []
for user in os.listdir(userdir):
_user_dir = os.path.join(userdir, user)

if os.path.isdir(_user_dir):
for _dir in os.listdir(_user_dir):
_dir_path = os.path.join(_user_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_documents_dir = os.path.join(_user_dir, "Documents")
if os.path.isdir(_documents_dir):
for _dir in os.listdir(_documents_dir):
_dir_path = os.path.join(_documents_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_documents_dir = os.path.join(_user_dir, "Documents")
if os.path.isdir(_documents_dir):
for _dir in os.listdir(_documents_dir):
_dir_path = os.path.join(_documents_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)
_win_dir = os.path.join(
_user_dir, "AppData", "Roaming", "Microsoft", "Windows"
)
if os.path.isdir(_win_dir):
for _dir in os.listdir(_win_dir):
_dir_path = os.path.join(_win_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_win_dir = os.path.join(
_user_dir, "AppData", "Roaming", "Microsoft", "Windows"
)
if os.path.isdir(_win_dir):
for _dir in os.listdir(_win_dir):
_dir_path = os.path.join(_win_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

for link in links:
with contextlib.suppress(IOError, OSError):
os.unlink(link)
os.makedirs(link)
for link in links:
with contextlib.suppress(IOError, OSError):
os.unlink(link)
os.makedirs(link)

# wait for registry files to be created
FileUtils.wait_for_files(reg_files)
Expand Down
Loading
Loading