from .struct import Field as _Field
from .util import byte_order as _byte_order
from .util import need_to_reorder_bytes as _need_to_reorder_bytes
+from .util import _bytes
from .record import RECORD_TYPE as _RECORD_TYPE
from .record.base import UnknownRecord as _UnknownRecord
from .record.base import UnusedRecord as _UnusedRecord
if filename in cwd:
raise ValueError('collision on name {} in {}'.format(
filename, ':'.join(d for d,cwd in dir_stack)))
+
+def walk(filesystem, callback, dirpath=None):
+ """Walk a packed experiment filesystem, operating on each key,value pair.
+ """
+ if dirpath is None:
+ dirpath = []
+ for key,value in sorted((_bytes(k),v) for k,v in filesystem.items()):
+ callback(dirpath, key, value)
+ if isinstance(value, dict):
+ walk(filesystem=value, callback=callback, dirpath=dirpath+[key])
'angleQ1': <WaveRecord ...>,
'radiusData': <WaveRecord ...>,
'radiusQ1': <WaveRecord ...>}}
+<BLANKLINE>
+walking filesystem:
+walk callback on ([], root, {'K0': 0.0,...})
+walk callback on (['root'], K0, 0.0)
+walk callback on (['root'], K1, 0.0)
+walk callback on (['root'], K10, 0.0)
+...
+walk callback on (['root'], K9, 0.0)
+walk callback on (['root'], Packages, {'PolarGraphs': ...})
+walk callback on (['root', 'Packages'], PolarGraphs, {...})
+walk callback on (['root', 'Packages', 'PolarGraphs'], V_bottom, 232.0)
+...
+walk callback on (['root', 'Packages'], WMDataBase, {...})
+...
+walk callback on (['root'], radiusQ1, <WaveRecord ...>)
"""
import os.path
from igor import LOG
from igor.binarywave import load as loadibw
from igor.packed import load as loadpxp
+from igor.packed import walk as _walk
from igor.record.base import TextRecord
from igor.record.folder import FolderStartRecord, FolderEndRecord
from igor.record.variables import VariablesRecord
data = loadibw(path)
pprint(data)
-def dumppxp(filename):
+def walk_callback(dirpath, key, value):
+ print('walk callback on ({}, {}, {})'.format(
+ dirpath, key, pformat(value)))
+
+def dumppxp(filename, walk=True):
LOG.info('Testing {}\n'.format(filename))
path = os.path.join(_data_dir, filename)
records,filesystem = loadpxp(path)
pprint(record)
print('\nfilesystem:')
pprint(filesystem)
+ if walk:
+ print('\nwalking filesystem:')
+ _walk(filesystem, walk_callback)
def pprint(data):
lines = pformat(data).splitlines()