Debian Codegraph @

src/devedeng/file_copy.py

raw
1 #!/usr/bin/env python3
2
3 # Copyright 2014 (C) Raster Software Vigo (Sergio Costas)
4 #
5 # This file is part of DeVeDe-NG
6 #
7 # DeVeDe-NG is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 3
9 # as published by the Free Software Foundation.
10 #
11 # DeVeDe-NG is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>
18
19 import os
20 import devedeng.configuration_data
21 import devedeng.executor
22
23
24 class file_copy(devedeng.executor.executor):
25
26 def __init__(self, input_path, output_path):
27
28 devedeng.executor.executor.__init__(self)
29 self.config = devedeng.configuration_data.configuration.get_config()
30
31 self.text = _("Copying file %(X)s") % {
32 "X": os.path.basename(input_path)}
33
34 self.command_var = ["dd", f"if={input_path}", f"of=output_path", "status=progress", "bs=1048576"]
35 self.file_size = float(os.stat(input_path).st_size)
36 print("Paso 1")
37
38 def process_stdout(self, data):
39 return
40
41 def process_stderr(self, data):
42 if (data is None) or (len(data) == 0):
43 return
44 parts = data[0].split(" ")
45 if (len(parts) < 2) or (parts[1] != "bytes"):
46 return
47
48 try:
49 copied = float(parts[0])
50 except:
51 return
52
53 p = copied / self.file_size
54 self.progress_bar[1].set_fraction(p)
55 self.progress_bar[1].set_text("%.1f%%" % (p * 100))