annotate python/utils/iso9660.py @ 317:e30a77ae359b

Added glue blocks
author Windel Bouwman
date Sun, 22 Dec 2013 15:50:59 +0100
parents 7b38782ed496
children
rev   line source
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
1 #!/usr/bin/env python
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
2
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
3 import argparse
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
4
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
5 __doc__ = """
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
6 ISO 9660 filesystem utility.
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
7 """
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
8
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
9
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
10 class VolumeDescriptor:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
11 @classmethod
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
12 def FromData(cls, d):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
13 ty = d[0]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
14 Id = d[1:6]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
15 assert Id == 'CD001'.encode('ascii')
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
16 ver = d[6]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
17 assert ver == 1
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
18 cls = vol_desc_types[ty]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
19 return cls(d)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
20
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
21
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
22 vol_desc_types = {}
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
23 def vol_type(t):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
24 def reg_func(cls):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
25 vol_desc_types[t] = cls
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
26 return cls
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
27 return reg_func
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
28
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
29
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
30 @vol_type(0)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
31 class BootRecordVolumeDescriptor(VolumeDescriptor):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
32 def __init__(self, d):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
33 boot_sys_id = d[7:39]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
34 boot_id = d[39:71]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
35 print(boot_sys_id)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
36 print(boot_id)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
37
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
38
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
39 @vol_type(1)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
40 class PrimaryVolumeDescriptor(VolumeDescriptor):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
41 def __init__(self, d):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
42 sys_id = d[8:40]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
43 vol_id = d[40:72]
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
44 print(sys_id)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
45 print(vol_id)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
46
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
47
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
48 @vol_type(255)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
49 class VolumeDescriptorTerminator(VolumeDescriptor):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
50 def __init__(self, d):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
51 pass
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
52
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
53
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
54 class ISOfs:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
55 def __init__(self):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
56 self.vol_descriptors = []
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
57
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
58 def read(self, f):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
59 # System area:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
60 self.system_area = f.read(16 * 2048)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
61 while True:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
62 d = f.read(2048)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
63 desc = VolumeDescriptor.FromData(d)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
64 self.vol_descriptors.append(desc)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
65 if type(desc) is VolumeDescriptorTerminator:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
66 break
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
67
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
68 def dump(self):
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
69 for vd in self.vol_descriptors:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
70 print(vd)
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
71
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
72
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
73 if __name__ == '__main__':
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
74 parser = argparse.ArgumentParser(description=__doc__)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
75 parser.add_argument('filename')
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
76 args = parser.parse_args()
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
77 fs = ISOfs()
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
78 with open(args.filename, 'rb') as f:
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
79 fs.read(f)
1c7c1e619be8 File movage
Windel Bouwman
parents: 283
diff changeset
80 fs.dump()
283
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
81
c9781c73e7e2 Added first kernel files
Windel Bouwman
parents:
diff changeset
82