index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-10-18 20:17:45 +0200 |
---|---|---|
committer | Anton Hvornum <anton.feeds+github@gmail.com> | 2020-10-18 20:17:45 +0200 |
commit | d5effa744f23472d328f71d7bda9ebd46540c265 (patch) | |
tree | 04767dd653712f5bd3795473b086be7d563b9148 | |
parent | 23365d2d8e33a3967e13ae6aa579e52a4d8ac349 (diff) |
-rw-r--r-- | archinstall/lib/general.py | 41 | ||||
-rw-r--r-- | examples/guided.py | 2 |
diff --git a/archinstall/lib/general.py b/archinstall/lib/general.py index 393bf69a..10d22c31 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 from subprocess import Popen, STDOUT, PIPE, check_output from select import epoll, EPOLLIN, EPOLLHUP from .exceptions import * @@ -30,6 +31,46 @@ def locate_binary(name): return os.path.join(root, file) break # Don't recurse +def to_json(dictionary): + return json.dumps(dictionary, cls=) + +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/examples/guided.py b/examples/guided.py index 8233a205..00d2565c 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -137,7 +137,7 @@ while 1: except archinstall.RequirementError as e: print(e) -print(json.dumps(archinstall.storage['_guided'], indent=4, sort_keys=True)) +print(json.dumps(archinstall.storage['_guided'], indent=4, sort_keys=True, cls=archinstall.JSON)) """ Issue a final warning before we continue with something un-revertable. |