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

Competent build script #3324

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
self.is_cli = is_cli
self.settings = g_settings or GSettingsStub
self.utils_conn = ConnectionUtils(
force_offline=self.is_cli or self.settings.get_boolean("force-offline")
force_offline=self.settings.get_boolean("force-offline")
)
self.data_mgr = DataManager()
_offline = True
Expand All @@ -141,7 +141,7 @@ def __init__(
if self.repository_manager.aborted_connections > 0:
self.utils_conn.status = False
_offline = True

times["RepositoryManager"] = time.time()
self.versioning_manager = VersioningManager(self)
times["VersioningManager"] = time.time()
Expand All @@ -153,10 +153,10 @@ def __init__(
self.steam_manager = SteamManager()
times["SteamManager"] = time.time()

if not self.is_cli:
times.update(self.checks(install_latest=False, first_run=True).data)
else:
if self.is_cli is True:
logging.set_silent()

times.update(self.checks(install_latest=False, first_run=True).data)

if "BOOT_TIME" in os.environ:
_temp_times = times.copy()
Expand Down Expand Up @@ -956,6 +956,8 @@ def process_bottle(bottle):
):
self.steam_manager.update_bottles()
self.local_bottles.update(self.steam_manager.list_prefixes())

EventManager.done(Events.BottlesFetching)

# Update parameters in bottle config
def update_config(
Expand Down
2 changes: 2 additions & 0 deletions bottles/backend/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class Events(Enum):
ComponentsFetching = "components.fetching"
DependenciesFetching = "dependencies.fetching"
InstallersFetching = "installers.fetching"
BottlesFetching = "bottles.fetching"
ComponentsOrganizing = "components.organizing"
DependenciesOrganizing = "dependencies.organizing"
InstallersOrganizing = "installers.organizing"
BottlesOrganizing = "bottles.organizing"


class Signals(Enum):
Expand Down
66 changes: 66 additions & 0 deletions bottles/backend/utils/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def is_glibc_min_available():


def sort_by_version(_list: list, extra_check: str = "async"):
"""Sort a list of strings by version."""
def natural_keys(text):
result = [int(re.search(extra_check, text) is None)]
result.extend(
Expand All @@ -112,6 +113,71 @@ def get_mime(path: str):


def random_string(length: int):
"""Generate a random string of given length."""
return "".join(
random.choice(string.ascii_uppercase + string.digits) for _ in range(length)
)

def glob_to_re(pat: str) -> re.Pattern[str]:
"""Convert a glob (UNIX-like) match pattern to a regular expression."""
i, n = 0, len(pat)
res = ''
while i < n:
c = pat[i]
i = i+1
if c == '*':
j = i
if j < n and pat[j] == '*':
res = res + '.*'
i = j+1
else:
res = res + '[^/]*'
elif c == '?':
res = res + '[^/]'
elif c == '[':
j = i
if j < n and pat[j] == '!':
j = j+1
if j < n and pat[j] == ']':
j = j+1
while j < n and pat[j] != ']':
j = j+1
if j >= n:
res = res + '\\['
else:
stuff = pat[i:j]
if '--' not in stuff:
stuff = stuff.replace('\\', r'\\')
else:
chunks = []
k = i+2 if pat[i] == '!' else i+1
while True:
k = pat.find('-', k, j)
if k < 0:
break
chunks.append(pat[i:k])
i = k+1
k = k+3
chunks.append(pat[i:j])
stuff = '-'.join(s.replace('\\', r'\\').replace('-', r'\-')
for s in chunks)
stuff = re.sub(r'([&~|])', r'\\\1', stuff)
i = j+1
if stuff[0] == '!':
stuff = '^/' + stuff[1:]
elif stuff[0] in ('^', '['):
stuff = '\\' + stuff
res = '%s[%s]' % (res, stuff)
else:
res = res + re.escape(c)
return re.compile(r'(?s:%s)\Z' % res)


def glob_filter(objects: list | dict | str, pattern: str) -> list | dict | str | None:
"""Filter objects by a glob (UNIX-like) pattern."""
if isinstance(objects, dict):
return {k: v for k, v in objects.items() if re.match(glob_to_re(pattern), k)}
elif isinstance(objects, list):
return [i for i in objects if re.match(glob_to_re(pattern), i)]
elif isinstance(objects, str):
return objects if re.match(glob_to_re(pattern), objects) else None
Loading