2026-02-19 19:23:28 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Component:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
self.headers = []
|
|
|
|
|
self.binaries = []
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
def add_headers(self, src, dest):
|
|
|
|
|
for h in self.headers:
|
|
|
|
|
if h['src'] == src and h['dest'] == dest:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
headers = {}
|
|
|
|
|
headers['src'] = src
|
|
|
|
|
headers['dest'] = dest
|
|
|
|
|
self.headers.append(headers)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_binary(self, src, dest):
|
|
|
|
|
for b in self.binaries:
|
|
|
|
|
if b['src'] == src and b['dest'] == dest:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
binary = {}
|
|
|
|
|
binary['src'] = src
|
|
|
|
|
binary['dest'] = dest
|
|
|
|
|
self.binaries.append(binary)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def serialise(self):
|
|
|
|
|
data = {}
|
|
|
|
|
if len(self.headers) > 0:
|
|
|
|
|
data['headers'] = self.headers
|
|
|
|
|
|
|
|
|
|
if len(self.binaries) > 0:
|
|
|
|
|
data['binaries'] = self.binaries
|
|
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def deserialise(self, data):
|
|
|
|
|
if 'headers' in data:
|
|
|
|
|
self.headers = data['headers']
|
|
|
|
|
if 'binaries' in data:
|
|
|
|
|
self.binaries = data['binaries']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_headers(self):
|
|
|
|
|
return self.headers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_binaries(self):
|
|
|
|
|
return self.binaries
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Manifest:
|
|
|
|
|
def __init__(self, path):
|
|
|
|
|
self.path = path
|
2026-02-21 23:21:52 +00:00
|
|
|
self.base = None
|
2026-02-19 19:23:28 +00:00
|
|
|
self.components = {}
|
|
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
|
with open(self.path, 'r') as f:
|
|
|
|
|
self.data = json.load(f)
|
|
|
|
|
|
2026-02-21 23:21:52 +00:00
|
|
|
if 'components' in self.data:
|
|
|
|
|
for n, t in self.data['components'].items():
|
|
|
|
|
component = Component()
|
|
|
|
|
component.deserialise(t)
|
|
|
|
|
self.components[n] = component
|
2026-02-19 19:23:28 +00:00
|
|
|
|
2026-02-21 23:21:52 +00:00
|
|
|
if 'base' in self.data:
|
|
|
|
|
self.base = self.data['base']
|
2026-02-19 19:23:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def save(self):
|
|
|
|
|
component_data = {}
|
|
|
|
|
for n, t in self.components.items():
|
|
|
|
|
d = t.serialise()
|
|
|
|
|
component_data[n] = d
|
|
|
|
|
|
|
|
|
|
self.data['components'] = component_data
|
|
|
|
|
|
2026-02-21 23:21:52 +00:00
|
|
|
if self.base is not None:
|
|
|
|
|
self.data['base'] = self.base
|
|
|
|
|
|
2026-02-19 19:23:28 +00:00
|
|
|
with open(self.path, 'w') as f:
|
|
|
|
|
json.dump(self.data, f, indent=4)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reset(self):
|
|
|
|
|
self.data = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_component(self, name):
|
|
|
|
|
if name in self.components:
|
|
|
|
|
return self.components[name]
|
|
|
|
|
|
|
|
|
|
component = Component()
|
|
|
|
|
self.components[name] = component
|
|
|
|
|
return component
|
|
|
|
|
|
2026-02-21 23:21:52 +00:00
|
|
|
|
|
|
|
|
def set_base(self, path):
|
|
|
|
|
self.base = path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_base(self):
|
|
|
|
|
return self.base
|
|
|
|
|
|
|
|
|
|
|
2026-02-19 19:23:28 +00:00
|
|
|
def get_all_components(self):
|
|
|
|
|
return self.components
|