index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds@gmail.com> | 2021-05-12 14:45:04 +0200 |
---|---|---|
committer | Anton Hvornum <anton.feeds@gmail.com> | 2021-05-12 14:45:04 +0200 |
commit | 12dc55650d78dc41bbc0ab7013baa7b3ce61ec7c (patch) | |
tree | 945dd48af6c32e03f10aa14186149e92f2a120a1 /archinstall/lib/profiles.py | |
parent | 1708f1850d5d620e7a44ab4da4a9c5c028f5008b (diff) | |
parent | df6c4e77f721da2b03a510548d281992b25987b2 (diff) |
-rw-r--r-- | archinstall/lib/profiles.py | 58 |
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index ad5d3bac..1feba1cd 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -1,3 +1,4 @@ +from typing import Optional import os, urllib.request, urllib.parse, ssl, json, re import importlib.util, sys, glob, hashlib, logging from collections import OrderedDict @@ -49,7 +50,7 @@ def list_profiles(filter_irrelevant_macs=True, subpath='', filter_top_level_prof except urllib.error.HTTPError as err: print(f'Error: Listing profiles on URL "{profiles_url}" resulted in:', err) return cache - except: + except json.decoder.JSONDecodeError as err: print(f'Error: Could not decode "{profiles_url}" result as JSON:', err) return cache @@ -92,6 +93,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: @@ -202,54 +206,17 @@ class Profile(Script): 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 - - @property - def packages(self) -> list: - """ - Returns a list of packages baked into the profile definition. - If no package definition has been done, .packages() will return None. - """ - with open(self.path, 'r') as source: - source_data = source.read() - - # Some crude safety checks, make sure the imported profile has - # a __name__ check before importing. - # - # If the requirements are met, import with .py in the namespace to not - # trigger a traditional: - # if __name__ == 'moduleName' - if '__name__' in source_data and '__packages__' 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, '__packages__'): - return imported.__packages__ - return None - + if hasattr(imported, 'is_top_level_profile'): + return imported.is_top_level_profile - def has_post_install(self): - with open(self.path, 'r') as source: - source_data = source.read() - - # Some crude safety checks, make sure the imported profile has - # a __name__ check and if so, check if it's got a _prep_function() - # we can call to ask for more user input. - # - # If the requirements are met, import with .py in the namespace to not - # trigger a traditional: - # if __name__ == 'moduleName' - if '__name__' in source_data and '_post_install' in source_data: - 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() - return 'top_level_profile = True' in source_data + # 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: + def packages(self) -> Optional[list]: """ Returns a list of packages baked into the profile definition. If no package definition has been done, .packages() will return None. @@ -268,7 +235,6 @@ class Profile(Script): if hasattr(imported, '__packages__'): return imported.__packages__ return None - class Application(Profile): def __repr__(self, *args, **kwargs): |