Write clears table as a list of tables in toml
parent
16b2937d23
commit
f1fe369bbf
58
piker/pp.py
58
piker/pp.py
|
@ -140,20 +140,28 @@ class Position(Struct):
|
||||||
d = self.to_dict()
|
d = self.to_dict()
|
||||||
clears = d.pop('clears')
|
clears = d.pop('clears')
|
||||||
expiry = d.pop('expiry')
|
expiry = d.pop('expiry')
|
||||||
|
|
||||||
# if not expiry is None:
|
# if not expiry is None:
|
||||||
# breakpoint()
|
# breakpoint()
|
||||||
|
|
||||||
if expiry:
|
if expiry:
|
||||||
d['expiry'] = str(expiry)
|
d['expiry'] = str(expiry)
|
||||||
# clears_list = []
|
|
||||||
|
|
||||||
inline_table = toml.TomlDecoder().get_empty_inline_table()
|
clears_list = []
|
||||||
|
|
||||||
for tid, data in clears.items():
|
for tid, data in clears.items():
|
||||||
inline_table[f'{tid}'] = data
|
inline_table = toml.TomlDecoder().get_empty_inline_table()
|
||||||
|
# inline_table[f'{tid}'] = data
|
||||||
|
# inline_table = type('uhh', (dict, toml.decoder.InlineTableDict()),
|
||||||
|
inline_table['tid'] = tid
|
||||||
|
|
||||||
# clears_list.append(inline_table)
|
for k, v in data.items():
|
||||||
|
inline_table[k] = v
|
||||||
|
|
||||||
# d['clears'] = clears_list
|
clears_list.append(inline_table)
|
||||||
d['clears'] = inline_table
|
|
||||||
|
d['clears'] = clears_list
|
||||||
|
# d['clears'] = inline_table
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def update_from_msg(
|
def update_from_msg(
|
||||||
|
@ -295,7 +303,9 @@ def update_pps(
|
||||||
)
|
)
|
||||||
|
|
||||||
# track clearing data
|
# track clearing data
|
||||||
pp.clears[f'"{r.tid}"'] = {'cost': r.cost}
|
pp.clears[r.tid] = {
|
||||||
|
'cost': r.cost,
|
||||||
|
}
|
||||||
|
|
||||||
assert len(set(pp.clears)) == len(pp.clears)
|
assert len(set(pp.clears)) == len(pp.clears)
|
||||||
return pps
|
return pps
|
||||||
|
@ -416,6 +426,21 @@ class PpsEncoder(toml.TomlEncoder):
|
||||||
'''
|
'''
|
||||||
separator = ','
|
separator = ','
|
||||||
|
|
||||||
|
def dump_list(self, v):
|
||||||
|
# breakpoint()
|
||||||
|
# super().dump_list(section)
|
||||||
|
|
||||||
|
retval = "[\n"
|
||||||
|
for u in v:
|
||||||
|
if isinstance(u, toml.decoder.InlineTableDict):
|
||||||
|
out = self.dump_inline_table(u)
|
||||||
|
else:
|
||||||
|
out = str(self.dump_value(u))
|
||||||
|
|
||||||
|
retval += " " + out + "," + "\n"
|
||||||
|
retval += "]"
|
||||||
|
return retval
|
||||||
|
|
||||||
def dump_inline_table(self, section):
|
def dump_inline_table(self, section):
|
||||||
"""Preserve inline table in its compact syntax instead of expanding
|
"""Preserve inline table in its compact syntax instead of expanding
|
||||||
into subsection.
|
into subsection.
|
||||||
|
@ -549,16 +574,20 @@ def update_pps_conf(
|
||||||
|
|
||||||
# convert clears sub-tables (only in this form
|
# convert clears sub-tables (only in this form
|
||||||
# for toml re-presentation) back into a master table.
|
# for toml re-presentation) back into a master table.
|
||||||
clears = entry['clears']
|
clears_list = entry['clears']
|
||||||
|
|
||||||
|
# index clears entries in "object" form by tid in a top
|
||||||
|
# level dict instead of a list (as is presented in our
|
||||||
|
# ``pps.toml``).
|
||||||
|
clears = {}
|
||||||
|
for clears_table in clears_list:
|
||||||
|
tid = clears_table.pop('tid')
|
||||||
|
clears[tid] = clears_table
|
||||||
|
|
||||||
expiry = entry.get('expiry')
|
expiry = entry.get('expiry')
|
||||||
if expiry:
|
if expiry:
|
||||||
expiry = pendulum.parse(expiry)
|
expiry = pendulum.parse(expiry)
|
||||||
|
|
||||||
# clears = {}
|
|
||||||
# for k, v in clears.items():
|
|
||||||
# print((k, v))
|
|
||||||
# clears.update(table)
|
|
||||||
|
|
||||||
pp_objs[fqsn] = Position(
|
pp_objs[fqsn] = Position(
|
||||||
Symbol.from_fqsn(fqsn, info={}),
|
Symbol.from_fqsn(fqsn, info={}),
|
||||||
size=entry['size'],
|
size=entry['size'],
|
||||||
|
@ -604,7 +633,8 @@ def update_pps_conf(
|
||||||
|
|
||||||
enc = PpsEncoder(preserve=True)
|
enc = PpsEncoder(preserve=True)
|
||||||
# TODO: why tf haven't they already done this for inline tables smh..
|
# TODO: why tf haven't they already done this for inline tables smh..
|
||||||
# enc.dump_funcs[dict] = enc.dump_inline_table
|
# table_bs_type = type(toml.TomlDecoder().get_empty_inline_table())
|
||||||
|
enc.dump_funcs[toml.decoder.InlineTableDict] = enc.dump_inline_table
|
||||||
|
|
||||||
config.write(
|
config.write(
|
||||||
conf,
|
conf,
|
||||||
|
|
Loading…
Reference in New Issue