forked from cnvogelg/amitools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geotool
executable file
·80 lines (78 loc) · 2.19 KB
/
geotool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python2.7
import sys
import os.path
import amitools.util.KeyValue as KeyValue
import amitools.util.ByteSize as ByteSize
from amitools.fs.blkdev.DiskGeometry import DiskGeometry
from amitools.fs.blkdev.BlkDevFactory import BlkDevFactory
a = sys.argv
n = len(a)
if n < 3:
print "Usage: (detect <size|file> [options] | setup <options> | open <file> [options] | create <file> <options>)"
print """Options:
size=<size>
chs=<n>,<n>,<n>
c=<n> h=<n> s=<n>
algo=1|2
"""
else:
cmd = a[1]
# detect disk geometry from given image file
if cmd == 'detect':
if os.path.exists(a[2]):
# its a file
size = os.path.getsize(a[2])
else:
# parse size string
size = ByteSize.parse_byte_size_str(a[2])
if size == None:
print "Invalid size!"
else:
d = DiskGeometry()
opts = None
if n > 3:
opts = KeyValue.parse_key_value_strings(a[3:])
print "size: ",size
print "opts: ",opts
size = d.detect(size, opts)
if size != None:
print "geo: ",d
else:
print "FAILED"
# setup a new disk geometry from options
elif cmd == 'setup' :
d = DiskGeometry()
opts = KeyValue.parse_key_value_strings(a[2:])
print "opts: ",opts
size = d.setup(opts)
if size != None:
print "setup: ",size,ByteSize.to_byte_size_str(size)
print "geo: ",d
else:
print "FAILED"
# open a blkdev and detect geometry
elif cmd == 'open':
opts = None
if n > 3:
opts = KeyValue.parse_key_value_strings(a[3:])
print "opts: ",opts
f = BlkDevFactory()
blkdev = f.open(a[2], options=opts)
if blkdev != None:
print "blkdev: ",blkdev.__class__.__name__
print "geo: ",blkdev.get_geometry()
blkdev.close()
else:
print "FAILED"
# create a new blkdev with setup geometry
elif cmd == 'create':
opts = KeyValue.parse_key_value_strings(a[3:])
print "opts: ",opts
f = BlkDevFactory()
blkdev = f.create(a[2], options=opts)
if blkdev != None:
print "blkdev: ",blkdev.__class__.__name__
print "geo: ",blkdev.get_geometry()
blkdev.close()
else:
print "FAILED"