Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-11-29 20:50:22 +0000
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-11-29 20:50:22 +0000
commit817465b8fb7a2958c059887a1633574aac678910 (patch)
tree7be44b6d8c73b20c9a342c6b1755f3e49b66aab6 /archinstall/lib
parent4d153c5bd1803657e9d1fb6189c36676736f8c68 (diff)
Merging in find_installation_script() into Script() for a more unified handler of any given script type or location. Which should correct #62.
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/profiles.py63
1 files changed, 34 insertions, 29 deletions
diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py
index 1e2c1206..0e0d6d59 100644
--- a/archinstall/lib/profiles.py
+++ b/archinstall/lib/profiles.py
@@ -65,28 +65,6 @@ def list_profiles(filter_irrelevant_macs=True):
return cache
-def find_installation_script(profile):
- parsed_url = urllib.parse.urlparse(profile)
- if not parsed_url.scheme:
- examples = list_profiles()
- if f"{profile}.py" in examples:
- with open(examples[f"{profile}.py"]) as file:
- return Script(file.read(), filename=os.path.basename(profile)+".py")
- try:
- with open(profile, 'r') as file:
- return Script(file.read(), filename=os.path.basename(profile))
- except FileNotFoundError:
- # We need to traverse backwards one step with /../ because
- # We're living in src/lib/ and we're not executing from src/ anymore.
- cwd = os.path.abspath(f'{os.path.dirname(__file__)}/../')
- examples = f"{cwd}/examples"
- raise ProfileNotFound(f"File {profile} does not exist in {examples}")
- elif parsed_url.scheme in ('https', 'http'):
- return Script(urllib.request.urlopen(profile).read().decode('utf-8'), filename=os.path.basename(profile))
- else:
- raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
-
-
class Imported():
def __init__(self, spec, imported):
self.spec = spec
@@ -103,18 +81,45 @@ class Imported():
class Script():
- def __init__(self, content, filename=''):
- self.content = content
- self.filename = filename
+ def __init__(self, profile):
+ # profile: https://hvornum.se/something.py
+ # profile: desktop
+ # profile: /path/to/profile.py
+ self.profile = profile
+ self.converted_path = None
+
+ 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"
+
+ with open(temp_file_path, "w") as temp_file:
+ temp_file.write(urllib.request.urlopen(url).read().decode('utf-8'))
+
+ return temp_file_path
+ else:
+ return profile_path
@property
def path(self):
- temp_file_path = f"/tmp/{self.filename}_{hashlib.md5(os.urandom(12)).hexdigest()}.py"
+ parsed_url = urllib.parse.urlparse(self.profile)
+
+ # The Profile was not a direct match on a remote URL
+ if not parsed_url.scheme:
+ # Try to locate all local or known URL's
+ examples = list_profiles()
+
+ if f"{self.profile}.py" in examples:
+ return self.localize_path(examples[f"{self.profile}.py"]['path'])
- with open(temp_file_path, "w") as temp_file:
- temp_file.write(self.content)
+ # Path was not found in any known examples, check if it's an abolute path
+ if os.path.isfile(self.profile):
+ return os.path.basename(self.profile)
- return temp_file_path
+ raise ProfileNotFound(f"File {self.profile} does not exist in {examples}")
+ elif parsed_url.scheme in ('https', 'http'):
+ return self.localize_path(self.profile)
+ else:
+ raise ProfileNotFound(f"Cannot handle scheme {parsed_url.scheme}")
def execute(self):
spec = importlib.util.spec_from_file_location(