Revision 586da0a0
b/image_creator/disk.py | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import pbs |
13 | 13 |
from pbs import dd |
14 |
from clint.textui import progress |
|
14 | 15 |
|
15 | 16 |
|
16 | 17 |
class DiskError(Exception): |
... | ... | |
121 | 122 |
device.destroy() |
122 | 123 |
|
123 | 124 |
|
125 |
def progress_generator(total): |
|
126 |
position = 0; |
|
127 |
for i in progress.bar(range(total)): |
|
128 |
if i < position: |
|
129 |
continue |
|
130 |
position = yield |
|
131 |
|
|
132 |
|
|
124 | 133 |
class DiskDevice(object): |
125 | 134 |
"""This class represents a block device hosting an Operating System |
126 | 135 |
as created by the device-mapper. |
... | ... | |
130 | 139 |
"""Create a new DiskDevice.""" |
131 | 140 |
self.device = device |
132 | 141 |
self.bootable = bootable |
142 |
self.progress_bar = None |
|
133 | 143 |
|
134 | 144 |
self.g = guestfs.GuestFS() |
145 |
self.g.add_drive_opts(device, readonly=0) |
|
135 | 146 |
|
136 |
self.g.set_trace(1) |
|
147 |
#self.g.set_trace(1) |
|
148 |
#self.g.set_verbose(1) |
|
137 | 149 |
|
138 |
self.g.add_drive_opts(device, readonly=0)
|
|
150 |
eh = self.g.set_event_callback(self.progress_callback, guestfs.EVENT_PROGRESS)
|
|
139 | 151 |
self.g.launch() |
152 |
self.g.delete_event_callback(eh) |
|
153 |
|
|
140 | 154 |
roots = self.g.inspect_os() |
141 | 155 |
if len(roots) == 0: |
142 | 156 |
raise DiskError("No operating system found") |
... | ... | |
154 | 168 |
# Close the guestfs handler |
155 | 169 |
self.g.close() |
156 | 170 |
|
171 |
def progress_callback(self, ev, eh, buf, array): |
|
172 |
position = array[2] |
|
173 |
total = array[3] |
|
174 |
|
|
175 |
if self.progress_bar is None: |
|
176 |
self.progress_bar = progress_generator(total) |
|
177 |
self.progress_bar.next() |
|
178 |
if position == 1: |
|
179 |
return |
|
180 |
|
|
181 |
self.progress_bar.send(position) |
|
182 |
|
|
183 |
if position == total: |
|
184 |
self.progress_bar = None |
|
185 |
|
|
157 | 186 |
def mount(self): |
158 | 187 |
"""Mount all disk partitions in a correct order.""" |
159 | 188 |
mps = self.g.inspect_get_mountpoints(self.root) |
b/setup.py | ||
---|---|---|
47 | 47 |
license='BSD', |
48 | 48 |
packages=['image_creator'], |
49 | 49 |
include_package_data=True, |
50 |
install_requires=['losetup', 'pbs'], |
|
50 |
install_requires=['losetup', 'pbs', 'clint'],
|
|
51 | 51 |
entry_points={ |
52 | 52 |
'console_scripts': ['snf-image-creator = image_creator.main:main'] |
53 | 53 |
} |
Also available in: Unified diff