Mercurial > lcfOS
view python/utils/iso9660.py @ 317:e30a77ae359b
Added glue blocks
author | Windel Bouwman |
---|---|
date | Sun, 22 Dec 2013 15:50:59 +0100 |
parents | 7b38782ed496 |
children |
line wrap: on
line source
#!/usr/bin/env python import argparse __doc__ = """ ISO 9660 filesystem utility. """ class VolumeDescriptor: @classmethod def FromData(cls, d): ty = d[0] Id = d[1:6] assert Id == 'CD001'.encode('ascii') ver = d[6] assert ver == 1 cls = vol_desc_types[ty] return cls(d) vol_desc_types = {} def vol_type(t): def reg_func(cls): vol_desc_types[t] = cls return cls return reg_func @vol_type(0) class BootRecordVolumeDescriptor(VolumeDescriptor): def __init__(self, d): boot_sys_id = d[7:39] boot_id = d[39:71] print(boot_sys_id) print(boot_id) @vol_type(1) class PrimaryVolumeDescriptor(VolumeDescriptor): def __init__(self, d): sys_id = d[8:40] vol_id = d[40:72] print(sys_id) print(vol_id) @vol_type(255) class VolumeDescriptorTerminator(VolumeDescriptor): def __init__(self, d): pass class ISOfs: def __init__(self): self.vol_descriptors = [] def read(self, f): # System area: self.system_area = f.read(16 * 2048) while True: d = f.read(2048) desc = VolumeDescriptor.FromData(d) self.vol_descriptors.append(desc) if type(desc) is VolumeDescriptorTerminator: break def dump(self): for vd in self.vol_descriptors: print(vd) if __name__ == '__main__': parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('filename') args = parser.parse_args() fs = ISOfs() with open(args.filename, 'rb') as f: fs.read(f) fs.dump()