##// END OF EJS Templates
***
ralonso -
r24:25
parent child
Show More
@@ -1,283 +1,289
1 1 # -*- coding: utf-8 -*-
2 2
3 3 """
4 4 Module implementing MainWindow.
5 5 """
6 6
7 7 from PyQt4.QtGui import QMainWindow
8 8 from PyQt4.QtCore import pyqtSignature
9 9 from Ui_MainWindow import Ui_MainWindow
10 10 from PyQt4 import QtGui
11 11 from subprocess import *
12 12 import sys
13 13 import os
14 14 #import subprocess
15 15 import commands
16 16
17 17 class MainWindow(QMainWindow, Ui_MainWindow):
18 18 """
19 19 Class documentation goes here.
20 20 """
21 21 def __init__(self, parent = None):
22 22 QMainWindow.__init__(self, parent)
23 23 self.setupUi(self)
24 24 self.setupUi2()
25 25
26 26 def setupUi2(self):
27 27 print 'hi'
28 28 self.txtDpath.setText('/home/ricardoar/optional/STORAGE/EW_DRIFTS')
29 29 self.txtRpath.setText('/home/ricardoar/optional/STORAGE/prueba1_jro_backup_manager')
30 30
31 31 @pyqtSignature("")
32 32 def on_btnDpath_clicked(self):
33 33 """
34 34 Slot documentation goes here.
35 35 """
36 36 var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
37 37 self.txtDpath.setText(var_Dpath)
38 38 self.on_txtDpath_editingFinished()
39 39
40 40 @pyqtSignature("")
41 41 def on_btnRpath_clicked(self):
42 42 """
43 43 Slot documentation goes here.
44 44 """
45 45 var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
46 46 self.txtRpath.setText(var_Rpath)
47 47 self.on_txtRpath_editingFinished()
48 48
49 49
50 50 @pyqtSignature("")
51 51 def on_txtDpath_editingFinished(self):
52 52
53 53 #Usando el modulo "subprocess" eric4 pide seleccion del tipo de subproceso (padre o hijo)
54 54 #por ello se prefiere usar el modulo "commands"
55 55 #p1= Popen(['find', var_Dpath, '-name', '*.r'], stdout=PIPE)
56 56 #p2= Popen(['awk', '-F/', '{print substr($NF,2,7)}'], stdin=p1.stdout, stdout=PIPE)
57 57 #output_p2= p2.communicate()[0]
58 58 #self.txtInfo.setText(output_p2)
59 59
60 60 var_Dpath=self.txtDpath.text()
61 61
62 62 #Se verifica que la ruta exista y sea un directorio
63 63 var_cmd="test -d "+str(var_Dpath)
64 64 var_output=commands.getstatusoutput(var_cmd)[0]
65 65 if var_output != 0:
66 66 self.txtInfo.setText("Ruta no valida, output_error:" + str(var_output))
67 67 return
68 68
69 69 #Se buscan los archivos del tipo especificado
70 70 var_Dtype=self.txtDtype.text()
71 71 var_cmd="find " + str(var_Dpath) + " -name *."+ str(var_Dtype) +" | awk -F/ '{print substr($NF,2,7)}' | sort| uniq"
72 72 output_p2=commands.getstatusoutput(var_cmd)[1]
73 73
74 74 #INFO: Muestra los dias que se encontraron
75 75 self.txtInfo.setText(output_p2)
76 76
77 77 #Se cargan las listas para seleccionar StartDay y StopDay
78 78 self.var_list=[]
79 79 for i in range(0, (len(output_p2)+1)/8):
80 80 self.var_list.append(output_p2[8*i:8*(i+1)-1])
81 81
82 82 self.lstStartDay.clear()
83 83 self.lstStopDay.clear()
84 84
85 85 for i in self.var_list:
86 86 self.lstStartDay.addItem(i)
87 87 self.lstStopDay.addItem(i)
88 88
89 89 self.lstStopDay.setCurrentIndex(self.lstStartDay.count()-1)
90 90
91 91 #INFO: Muestra cuantos dias se encontraron
92 92 # self.txtInfo.setText(str(self.lstStartDay.count()))
93 93
94 94
95 95 @pyqtSignature("")
96 96 def on_txtRpath_editingFinished(self):
97 97 """
98 98 Slot documentation goes here.
99 99 """
100 100 var_Rpath=self.txtRpath.text()
101 101 #Se verifica que la ruta exista y sea un directorio
102 102 var_cmd="test -d "+str(var_Rpath)
103 103 var_output=commands.getstatusoutput(var_cmd)[0]
104 104 if var_output != 0:
105 105 self.txtInfo.setText("Ruta no valida, output_error:" + str(var_output))
106 106 return
107 107 else:
108 108 self.txtInfo.setText("Ruta valida, sin error")
109 109
110 110
111 111 @pyqtSignature("int")
112 112 def on_lstDtype_activated(self, index):
113 113 """
114 114 Permite elegir entre los tipos de archivos
115 115 """
116 116 if index == 0:
117 117 var_type='r'
118 118 elif index == 1:
119 119 var_type='pdata'
120 120 elif index == 2:
121 121 var_type='sswma'
122 122
123 123 if index != 3:
124 124 self.txtDtype.setText(var_type)
125 125 self.txtDtype.setReadOnly(True)
126 126 self.on_txtDpath_editingFinished()
127 127 else:
128 128 self.txtDtype.setText('')
129 129 self.txtDtype.setReadOnly(False)
130 130
131 131 @pyqtSignature("")
132 132 def on_txtDtype_editingFinished(self):
133 133 """
134 134 Se activa cuando el tipo de archivo es ingresado manualmente
135 135 """
136 136 self.on_txtDpath_editingFinished()
137 137
138 138 @pyqtSignature("int")
139 139 def on_lstStartDay_activated(self, index):
140 140 """
141 141 Slot documentation goes here.
142 142 """
143 143 #self.txtInfo.setText(str(index))
144 144 var_StopDay_index=self.lstStopDay.count() - self.lstStopDay.currentIndex()
145 145
146 146 self.lstStopDay.clear()
147 147
148 148 for i in self.var_list[index:]:
149 149 self.lstStopDay.addItem(i)
150 150
151 151 self.lstStopDay.setCurrentIndex(self.lstStopDay.count() - var_StopDay_index)
152 152 #self.txtInfo.append(str(var_StopDay_index))
153 153 #self.txtInfo.append(str(self.lstStopDay.count()))
154 154
155 155
156 156 @pyqtSignature("int")
157 157 def on_lstStopDay_activated(self, index):
158 158 """
159 159 Slot documentation goes here.
160 160 """
161 161 #self.txtInfo.setText(str(index))
162 162 var_StartDay_index=self.lstStartDay.currentIndex()
163 163
164 164 var_end_index = self.lstStopDay.count() - index
165 165
166 166 self.lstStartDay.clear()
167 167
168 168 for i in self.var_list[:len(self.var_list) - var_end_index + 1]:
169 169 self.lstStartDay.addItem(i)
170 170
171 171 self.lstStartDay.setCurrentIndex(var_StartDay_index)
172 172 #self.txtInfo.append(str(var_StartDay_index))
173 173 #self.txtInfo.append(str(self.lstStartDay.count()))
174 174
175 175 @pyqtSignature("int")
176 176 def on_lstDcapacity_activated(self, index):
177 177 """
178 178 Permite elegir el tamaño del disco
179 179 """
180 180 if index == 0:
181 181 var_size=25.0
182 182 elif index == 1:
183 183 var_size=8.5
184 184 elif index == 2:
185 185 var_size=4.7
186 186 elif index == 3:
187 187 var_size=0.7
188 188
189 189 if index != 4:
190 190 self.txtDcapacity.setText(str(var_size*10**9/1024**2))
191 191 self.txtDcapacity.setReadOnly(True)
192 192 else:
193 193 self.txtDcapacity.setText('')
194 194 self.txtDcapacity.setReadOnly(False)
195 195
196 196 @pyqtSignature("")
197 197 def on_btnGbkp_clicked(self):
198 198 """
199 199 Cuando se presiona el boton Generate Bkp
200 200 """
201 201
202 202 #CREA LAS CARPETAS "COMENTADO TEMPORALMENTE"
203 203 var_dirs='/{gpath,iso,ppath}'
204 204 var_Rpath=self.txtRpath.text()
205 205 var_cmd="mkdir "+str(var_Rpath)+str(var_dirs)
206 206 self.txtInfo.append(var_cmd)
207 207 #var_output=commands.getstatusoutput(var_cmd)[0]
208 208 #if var_output != 0:
209 209 # self.txtInfo.setText("No se pudieron crear los directorios, output_error:" + str(var_output))
210 210 # return
211 211 #else:
212 212 # self.txtInfo.append('Carpetas creadas correctamente')
213 213
214 214
215 215 var_sublist=[]
216 216 for i in self.var_list[self.lstStartDay.currentIndex():self.lstStartDay.currentIndex() + self.lstStopDay.currentIndex()+1]:
217 217 self.txtInfo.append(i)
218 218 var_sublist.append(i)
219 219
220 220 #Cargando los parametros de busqueda
221 221 var_Dpath=self.txtDpath.text()
222 222 var_Dtype=self.txtDtype.text()
223 223
224 224 var_files_list=[]
225 225 for var_doy in var_sublist:
226 226 var_cmd="find " + str(var_Dpath) + " -name ?"+var_doy+"???."+ str(var_Dtype)
227 227 var_output=commands.getstatusoutput(var_cmd)[1]
228 228 for var_file in var_output.split():
229 229 var_files_list.append(var_file)
230 230
231 231 var_Dcapacity=float(self.txtDcapacity.text())*1024 #tamaño en KB
232 232 self.txtInfo.append(str(var_Dcapacity))
233 233
234 234 # self.txtInfo.append('Lista de archivos')
235 235 # var_n=0
236 236 # for i in var_files_list:
237 237 #self.txtInfo.append(str(os.path.getsize(i)/1024)+'KB')
238 238 #self.txtInfo.append(i)
239 239 #var_n += 1
240 240 #self.txtInfo.append(str(var_n))
241 241
242 242 #lista de archivos a grabar en archivos .
243 243
244 244 #Ruta de los archivos a grabar
245 245 var_Rpath_ppath=var_Rpath=self.txtRpath.text()+"/ppath"
246 var_Dpath=self.txtDpath.text()
246 247
247 248 var_n=0
248 249 var_n_files=0
249 250 var_tmp=0
250 251 var_files_list_2=[]
251 252 self.txtInfo.append(str(len(var_files_list)))
252 253
253 254 for i in var_files_list:
254 255 var_size_i=os.path.getsize(i)/1024+1 #tamaño en KB, se suma 1 KB para evitar problemas al momento de sumar
255 256 var_tmp += var_size_i
256 257
257 258 if var_tmp > var_Dcapacity:
258 259 var_tmp -= var_size_i #se quita el tamaño sumado para mostrar el tamaño real
260 #muestra info
259 261 self.txtInfo.append(str(len(var_files_list_2))+" size:"+str(var_tmp))
260 262
261 263 #se crea un archivo con numeral en el sufijo, y se añaden la lista de archivos
262 264 var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n)+".dat","w")
263 265 for line in var_files_list_2:
266 var_file.write(line.split(var_Dpath)[1]+'=')
264 267 var_file.write(line+'\n')
265 268 var_file.close()
266 269
267 270 var_n_files += len(var_files_list_2)
268 271 var_tmp = var_size_i
269 272 var_files_list_2=[]
270 273 var_files_list_2.append(i)
271 274 var_n += 1
272 275
273 276 else:
274 277 var_files_list_2.append(i)
275 278
279 #muestra info
276 280 self.txtInfo.append(str(len(var_files_list_2))+" size:"+str(var_tmp))
281
277 282 var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n)+".dat","w")
278 283 for line in var_files_list_2:
284 var_file.write(line.split(var_Dpath)[1]+'=')
279 285 var_file.write(line+'\n')
280 286 var_file.close()
281 287
282 288 var_n_files += len(var_files_list_2)
283 289 self.txtInfo.append(str(var_n_files))
General Comments 0
You need to be logged in to leave comments. Login now