-
Notifications
You must be signed in to change notification settings - Fork 5
/
export.py
64 lines (61 loc) · 2.22 KB
/
export.py
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 25 19:00:13 2013
@author: yves
"""
import os
# Block size
def raw_write(self, source, target):
bs=4096
b = os.path.getsize("/documents/boot-nonfree.iso")
ifc=open(source, "rb",1)
ofc= open("/documents/test.iso", 'wb',0)
progress = self.wTree.get_widget("progressbar")
progress.set_sensitive(True)
progress.set_text(_('Writing ')+source.split('/')[-1]+_(' to ')+self.dev)
self.logger(_('Executing copy from ')+source+' to '+target)
while gtk.events_pending():
gtk.main_iteration(True)
#output = Popen(['dd if='+source+' of='+target+' bs=1024'], stdout=PIPE, stderr=STDOUT, shell=True)
#self.ddpid = output.pid
#while output.stdout.readline():
# line = output.stdout.readline().strip()
steps=range(0, b, b/100)
indice=1
written=0
for i in xrange(0,b,bs):
try:
buf=ifc.read(bs)
except:
self.logger(_("Reading error."))
return False
try:
ofc.write(buf)
except:
self.logger(_("Writing error."))
return False
written= written+bs
if written > steps[indice]:
indice +=1
while gtk.events_pending():
gtk.main_iteration(True)
#if line.endswith('MB/s'):
# target_size = line.split()[0]
self.logger(_('Wrote: ')+written+' bytes')
#size = float(target_size)*100/float(src_size)
while gtk.events_pending():
gtk.main_iteration(True)
progress.set_fraction(float(indice/100))
#pid, sts = os.waitpid(output.pid, 0)
#if sts != 0:
# self.logger(_('The dd process ended with an error !'))
# self.emergency()
# return False
progress.set_fraction(1.0)
self.logger(_('Image ')+source.split('/')[-1]+_(' successfully written to')+target)
self.logger(_("%s octets écrits")%written)
self.success()
# tous les 5%
ifc.close()
ofc.close()
print