Refactor install location checking - fixes #69

This commit is contained in:
kramo
2023-04-14 14:12:27 +02:00
parent 8a7d716db6
commit 43e8317c46
8 changed files with 143 additions and 99 deletions

View File

@@ -22,28 +22,30 @@ from time import time
import yaml
from .check_install import check_install
def bottles_importer(parent_widget):
schema = parent_widget.schema
bottles_dir = Path(schema.get_string("bottles-location")).expanduser()
location_key = "bottles-location"
bottles_dir = Path(schema.get_string(location_key)).expanduser()
check = "library.yml"
if not (bottles_dir / "library.yml").is_file():
if (
Path("~/.var/app/com.usebottles.bottles/data/bottles/")
.expanduser()
.exists()
):
schema.set_string(
"bottles-location", "~/.var/app/com.usebottles.bottles/data/bottles/"
)
elif (parent_widget.data_dir / "bottles").exists():
schema.set_string(
"bottles-location", str(parent_widget.data_dir / "bottles")
)
else:
if not (bottles_dir / check).is_file():
locations = (
Path.home()
/ ".var"
/ "app"
/ "com.usebottles.bottles"
/ "data"
/ "bottles",
parent_widget.data_dir / "bottles",
)
bottles_dir = check_install(check, locations, (schema, location_key))
if not bottles_dir:
return
bottles_dir = Path(schema.get_string("bottles-location")).expanduser()
current_time = int(time())
data = (bottles_dir / "library.yml").read_text("utf-8")