index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-10-18 21:24:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-18 21:24:46 +0200 |
commit | f32f1e238a0a36b0d1b5220df6f6f053c6c4168c (patch) | |
tree | 78053ae908629bb49725246fcb2e957875d9ec3b /archinstall | |
parent | 3ba6e69e051e4614ebf18f7f08c0d7a18366d9b7 (diff) | |
parent | 06ee896c6c58e877325896b33a2a3dd3eb0a1727 (diff) |
-rw-r--r-- | archinstall/lib/disk.py | 10 | ||||
-rw-r--r-- | archinstall/lib/general.py | 38 | ||||
-rw-r--r-- | archinstall/lib/profiles.py | 3 |
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 7cd8dd0f..b11f2318 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -25,6 +25,16 @@ class BlockDevice(): raise KeyError(f'{self} does not contain information: "{key}"') return self.info[key] + def json(self): + """ + json() has precedence over __dump__, so this is a way + to give less/partial information for user readability. + """ + return { + 'path' : self.path, + 'size' : self.info['size'] if 'size' in self.info else '<unknown>' + } + def __dump__(self): return { 'path' : self.path, diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 393bf69a..ff834241 100644 --- a/archinstall/lib/general.py +++ b/archinstall/lib/general.py @@ -1,5 +1,6 @@ import os, json, hashlib, shlex, sys import time, pty +from datetime import datetime, date from subprocess import Popen, STDOUT, PIPE, check_output from select import epoll, EPOLLIN, EPOLLHUP from .exceptions import * @@ -30,6 +31,43 @@ def locate_binary(name): return os.path.join(root, file) break # Don't recurse +class JSON_Encoder: + def _encode(obj): + if isinstance(obj, dict): + ## We'll need to iterate not just the value that default() usually gets passed + ## But also iterate manually over each key: value pair in order to trap the keys. + + for key, val in list(obj.items()): + if isinstance(val, dict): + val = json.loads(json.dumps(val, cls=JSON)) # This, is a EXTREMELY ugly hack.. + # But it's the only quick way I can think of to + # trigger a encoding of sub-dictionaries. + else: + val = JSON_Encoder._encode(val) + del(obj[key]) + obj[JSON_Encoder._encode(key)] = val + return obj + elif hasattr(obj, 'json'): + return obj.json() + elif hasattr(obj, '__dump__'): + return obj.__dump__() + elif isinstance(obj, (datetime, date)): + return obj.isoformat() + elif isinstance(obj, (list, set, tuple)): + r = [] + for item in obj: + r.append(json.loads(json.dumps(item, cls=JSON))) + return r + else: + return obj + +class JSON(json.JSONEncoder, json.JSONDecoder): + def _encode(self, obj): + return JSON_Encoder._encode(obj) + + def encode(self, obj): + return super(JSON, self).encode(self._encode(obj)) + class sys_command():#Thread): """ Stolen from archinstall_gui diff --git a/archinstall/lib/profiles.py b/archinstall/lib/profiles.py index 47e6dd36..e018f753 100644 --- a/archinstall/lib/profiles.py +++ b/archinstall/lib/profiles.py @@ -61,6 +61,9 @@ class Profile(): self._cache = None self.args = args + def __dump__(self, *args, **kwargs): + return {'path' : self._path} + def __repr__(self, *args, **kwargs): return f'Profile({self._path} <"{self.path}">)' |