util: bsp-tool: extract bootstrap exec constants and store them in the bsp image
This commit is contained in:
101
util/lib/manifest.py
Normal file
101
util/lib/manifest.py
Normal file
@@ -0,0 +1,101 @@
|
||||
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
|
||||
self.components = {}
|
||||
|
||||
def load(self):
|
||||
with open(self.path, 'r') as f:
|
||||
self.data = json.load(f)
|
||||
|
||||
if 'components' not in self.data:
|
||||
return 0
|
||||
|
||||
for n, t in self.data['components'].items():
|
||||
component = Component()
|
||||
component.deserialise(t)
|
||||
self.components[n] = component
|
||||
|
||||
|
||||
def save(self):
|
||||
component_data = {}
|
||||
for n, t in self.components.items():
|
||||
d = t.serialise()
|
||||
component_data[n] = d
|
||||
|
||||
self.data['components'] = component_data
|
||||
|
||||
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
|
||||
|
||||
def get_all_components(self):
|
||||
return self.components
|
||||
Reference in New Issue
Block a user