From b60b173a91a842f2f5d024dba98df546452fc10e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 29 Nov 2020 20:52:59 +0000 Subject: Tweaking Profile() to use Script() as a handler for any given path. --- archinstall/lib/profiles.py | 35 +++++++++-------------------------- 1 file changed, 9 insertions(+), 26 deletions(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 0e0d6d59..fc06ec77 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -90,12 +90,13 @@ class Script(): def localize_path(profile_path): if (url := urllib.parse.urlparse(profile_path)).scheme and url.scheme in ('https', 'http'): - temp_file_path = f"/tmp/{self.profile}_{hashlib.md5(os.urandom(12)).hexdigest()}.py" + if not self.converted_path: + self.converted_path = f"/tmp/{self.profile}_{hashlib.md5(os.urandom(12)).hexdigest()}.py" - with open(temp_file_path, "w") as temp_file: - temp_file.write(urllib.request.urlopen(url).read().decode('utf-8')) + with open(self.converted_path, "w") as temp_file: + temp_file.write(urllib.request.urlopen(url).read().decode('utf-8')) - return temp_file_path + return self.converted_path else: return profile_path @@ -130,40 +131,22 @@ class Script(): spec.loader.exec_module(imported_path) sys.modules["tempscript"] = imported_path - class Profile(): def __init__(self, installer, path, args={}): - self._path = path + self._path = Script(path) self.installer = installer self._cache = None self.args = args def __dump__(self, *args, **kwargs): - return {'path' : self._path} + return {'path' : self.path} def __repr__(self, *args, **kwargs): - return f'Profile({self._path} <"{self.path}">)' + return f'Profile({self.path})' @property def path(self, *args, **kwargs): - if os.path.isfile(f'{self._path}'): - return os.path.abspath(f'{self._path}') - - for path in ['./profiles', '/etc/archinstall', '/etc/archinstall/profiles', os.path.abspath(f'{os.path.dirname(__file__)}/../profiles')]: # Step out of /lib - if os.path.isfile(f'{path}/{self._path}.py'): - return os.path.abspath(f'{path}/{self._path}.py') - - try: - if (cache := grab_url_data(f'{storage["UPSTREAM_URL"]}/{self._path}.py')): - self._cache = cache - return f'{storage["UPSTREAM_URL"]}/{self._path}.py' - except urllib.error.HTTPError: - pass - - return None - -# def py_exec_mock(self): -# spec.loader.exec_module(imported) + self._path.path def load_instructions(self, namespace=None): if (absolute_path := self.path): -- cgit v1.2.3-54-g00ecf