def __init__(self, *layers: Path, default_factory=OrderedDict): model = None for layer in layers: if layer is not None and layer.is_file(): if model is None: model = jloadfile(layer) else: jlayer_update(model, jloadfile(layer)) if model is None: model = default_factory() JsonObject.__init__(self, model) self._check_model()
def available_packages(self) -> list: if not self.is_fetched: raise LeafException("Remote is not fetched") out = [] for json in JsonObject(self.content).jsonget( JsonConstants.REMOTE_PACKAGES, []): ap = AvailablePackage(json, remote=self) out.append(ap) return out
def from_json(identifier: str, json: dict): jo = JsonObject(json) key = jo.jsonget(JsonConstants.SETTING_KEY, mandatory=True) description = jo.jsonget(JsonConstants.SETTING_DESCRIPTION) scopes = [] if jo.has(JsonConstants.SETTING_SCOPES): for scope_str in jo.jsonget(JsonConstants.SETTING_SCOPES): if scope_str in ScopeSetting.__SCOPES: scopes.append(ScopeSetting.__SCOPES[scope_str]) else: scopes += ScopeSetting.__SCOPES.values() validator = None if jo.has(JsonConstants.SETTING_REGEX): validator = RegexValidator(jo.jsonget(JsonConstants.SETTING_REGEX)) return ScopeSetting(identifier, key, description, scopes, validator=validator)
def test_json(self): jo = JsonObject({}) self.assertIsNone(jo.jsonpath(["a"])) self.assertIsNotNone(jo.jsonpath(["a"], {})) self.assertIsNotNone(jo.jsonpath(["a"])) self.assertIsNone(jo.jsonpath(["a", "b"])) self.assertIsNotNone(jo.jsonpath(["a", "b"], {})) self.assertIsNotNone(jo.jsonpath(["a", "b"])) self.assertIsNone(jo.jsonpath(["a", "b", "c"])) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"], "hello")) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"], "world")) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"])) tmpfile = Path(mktemp(".json", "leaf-ut")) jwritefile(tmpfile, jo.json, pp=True) jo = JsonObject(jloadfile(tmpfile)) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"], "hello")) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"], "world")) self.assertEqual("hello", jo.jsonpath(["a", "b", "c"])) with self.assertRaises(ValueError): jo.jsonget("z", mandatory=True) with self.assertRaises(ValueError): jo.jsonpath(["a", "b", "c", "d"]) with self.assertRaises(ValueError): jo.jsonpath(["a", "d", "e"])
def info_node(self): if not self.is_fetched: raise LeafException("Remote is not fetched") return JsonObject(self.content).jsonget(JsonConstants.INFO, default={})
def __init__(self, alias, json, content=None): JsonObject.__init__(self, json) self.__alias = alias self.__content = content
def __init__(self, payload: dict, name: str): JsonObject.__init__(self, payload) self.__name = name
def __init__(self, json: dict, name: str, parent: InstalledPackage): JsonObject.__init__(self, json) self.__location = name self.__ip = parent self.__command = None
def __init__(self, json: dict): JsonObject.__init__(self, json) self.__custom_tags = []
def __init__(self, name, json): JsonObject.__init__(self, json) self.__name = name
def __init__(self, location: str, ip: InstalledPackage, json: dict): JsonObject.__init__(self, json) self.__location = location self.__ip = ip self.__command = None
def __init__(self, payload: dict, name: str, parent: object): JsonObject.__init__(self, payload) self.__name = name self.__parent = parent
def __init__(self, name, folder, json): JsonObject.__init__(self, json) IEnvProvider.__init__(self, "profile {name}".format(name=name)) self.__name = name self.__folder = folder self.__current = False