Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/profiles.py
diff options
context:
space:
mode:
Diffstat (limited to 'archinstall/lib/profiles.py')
-rw-r--r--archinstall/lib/profiles.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index 21ec5f6f..06237c1c 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -1,10 +1,10 @@
import os, urllib.request, urllib.parse, ssl, json, re
-import importlib.util, sys, glob, hashlib
+import importlib.util, sys, glob, hashlib, logging
from collections import OrderedDict
from .general import multisplit, sys_command
from .exceptions import *
from .networking import *
-from .output import log, LOG_LEVELS
+from .output import log
from .storage import storage
def grab_url_data(path):
@@ -15,7 +15,7 @@ def grab_url_data(path):
response = urllib.request.urlopen(safe_path, context=ssl_context)
return response.read()
-def list_profiles(filter_irrelevant_macs=True, subpath=''):
+def list_profiles(filter_irrelevant_macs=True, subpath='', filter_top_level_profiles=False):
# TODO: Grab from github page as well, not just local static files
if filter_irrelevant_macs:
local_macs = list_interfaces()
@@ -63,6 +63,11 @@ def list_profiles(filter_irrelevant_macs=True, subpath=''):
cache[profile[:-3]] = {'path' : os.path.join(storage["UPSTREAM_URL"]+subpath, profile), 'description' : profile_list[profile], 'tailored' : tailored}
+ if filter_top_level_profiles:
+ for profile in list(cache.keys()):
+ if Profile(None, profile).is_top_level_profile() is False:
+ del(cache[profile])
+
return cache
class Script():
@@ -77,7 +82,6 @@ class Script():
self.examples = None
self.namespace = os.path.splitext(os.path.basename(self.path))[0]
self.original_namespace = self.namespace
- log(f"Script {self} has been loaded with namespace '{self.namespace}'", level=LOG_LEVELS.Debug)
def __enter__(self, *args, **kwargs):
self.execute()
@@ -88,6 +92,9 @@ class Script():
if len(args) >= 2 and args[1]:
raise args[1]
+ if self.original_namespace:
+ self.namespace = self.original_namespace
+
def localize_path(self, profile_path):
if (url := urllib.parse.urlparse(profile_path)).scheme and url.scheme in ('https', 'http'):
if not self.converted_path:
@@ -177,7 +184,7 @@ class Profile(Script):
if hasattr(imported, '_prep_function'):
return True
return False
- """
+
def has_post_install(self):
with open(self.path, 'r') as source:
source_data = source.read()
@@ -193,14 +200,19 @@ class Profile(Script):
with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
if hasattr(imported, '_post_install'):
return True
- """
def is_top_level_profile(self):
with open(self.path, 'r') as source:
source_data = source.read()
- # TODO: I imagine that there is probably a better way to write this.
- return 'top_level_profile = True' in source_data
+ if '__name__' in source_data and 'is_top_level_profile' in source_data:
+ with self.load_instructions(namespace=f"{self.namespace}.py") as imported:
+ if hasattr(imported, 'is_top_level_profile'):
+ return imported.is_top_level_profile
+
+ # Default to True if nothing is specified,
+ # since developers like less code - omitting it should assume they want to present it.
+ return True
@property
def packages(self) -> list:
@@ -222,7 +234,6 @@ class Profile(Script):
if hasattr(imported, '__packages__'):
return imported.__packages__
return None
-
class Application(Profile):
def __repr__(self, *args, **kwargs):