##// END OF EJS Templates
***
ralonso -
r35:36
parent child
Show More
@@ -1,485 +1,495
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
22 22 def __init__(self, parent = None):
23 23 QMainWindow.__init__(self, parent)
24 24 self.setupUi(self)
25 25 self.setupUi2()
26 26
27 27 #redirige salida estandar
28 28 sys.stdout = self
29 29
30 30
31 31 def setupUi2(self):
32 32 """
33 33 Se usa para inicializar ciertos parametros para pruebas
34 34 """
35 35 self.txtDpath.setText('/home/ricardoar/optional/STORAGE/Data/RAW_EXP/JASMET/')
36 36 self.txtRpath.setText('/home/ricardoar/optional/STORAGE/prueba1_jro_backup_manager')
37 37 self.txtElabel.setText('JASMET')
38 38 self.statusDpath = True
39 39 self.statusRpath = True
40 40 # self.statusDpath = False
41 41 # self.statusRpath = False
42 42
43 43
44 44 #
45 45 #Deteccion de los dispositvos de grabacion
46 46 #
47 47 #var_cmd="wodim --devices | grep /dev/ | awk -F\' '{print $2}'" #Funciona en consola pero no en python ΒΏ?
48 48 var_cmd="wodim --devices | grep /dev/ | awk '{print $2}' | awk -F= '{print $2}'"
49 49 var_output = commands.getstatusoutput(var_cmd)
50 50 if var_output[0] != 0:
51 51 self.txtInfo.setText("No se pudo encontrar los dispositivos de grabacion, output_error:" + str(var_output))
52 52 else:
53 53 self.txtInfo.append("dispositivos encontrados")
54 54 var_devices = var_output[1].split('\n')
55 55
56 56 var_tmp=[]
57 57 for i in range(0, 4):
58 58 if i < len(var_devices):
59 59 var_len = len(var_devices[i])
60 60 var_tmp.append(var_devices[i][1:var_len - 1])
61 61 else:
62 62 var_tmp.append('')
63 63
64 64 #Se escriben los dispostivos correspodientes, si existen
65 65 self.txtDeviceA.setText(str(var_tmp[0]))
66 66 self.txtDeviceB.setText(str(var_tmp[1]))
67 67 self.txtDeviceC.setText(str(var_tmp[2]))
68 68 self.txtDeviceD.setText(str(var_tmp[3]))
69 69 #Se desactivan los que no existen
70 70 if len(var_tmp[0]) == 0 :
71 71 self.chkDevA.setChecked(False)
72 72 self.chkDevA.setEnabled(False)
73 73 if len(var_tmp[1]) == 0 :
74 74 self.chkDevB.setChecked(False)
75 75 self.chkDevB.setEnabled(False)
76 76 if len(var_tmp[2]) == 0 :
77 77 self.chkDevC.setChecked(False)
78 78 self.chkDevC.setEnabled(False)
79 79 if len(var_tmp[3]) == 0 :
80 80 self.chkDevD.setChecked(False)
81 81 self.chkDevD.setEnabled(False)
82 82
83 83
84 84 def write(self, txt):
85 85 """
86 86 Escribe la salida estandar eb txtInfo
87 87 """
88 88 self.txtInfo.append(str(txt))
89 89
90 90
91 91 @pyqtSignature("")
92 92 def on_btnDpath_clicked(self):
93 93 """
94 94 Permite seleccionar graficamente el direcorio de los datos a grabar
95 95 """
96 96 var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
97 97 self.txtDpath.setText(var_Dpath)
98 98
99 99 #llamada a funcion
100 100 self.on_txtDpath_editingFinished()
101 101
102 102
103 103 @pyqtSignature("")
104 104 def on_btnRpath_clicked(self):
105 105 """
106 106 Permite seleccionar graficamente el direcorio del proyecto
107 107 """
108 108 var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
109 109 self.txtRpath.setText(var_Rpath)
110 110
111 111 #llamada a funcion
112 112 self.on_txtRpath_editingFinished()
113 113
114 114
115 115 @pyqtSignature("")
116 116 def on_txtDpath_editingFinished(self):
117 117 """
118 118 Permite buscar los archivos de extension seleccionada en la ruta de de datos
119 119 y cargar los valores para el rango de tiempo a ser grabado
120 120 """
121 121
122 122 #Usando el modulo "subprocess", eric4 pide seleccion del tipo de subproceso (padre o hijo)
123 123 #por ello se prefiere usar el modulo "commands"
124 124 #p1= Popen(['find', var_Dpath, '-name', '*.r'], stdout=PIPE)
125 125 #p2= Popen(['awk', '-F/', '{print substr($NF,2,7)}'], stdin=p1.stdout, stdout=PIPE)
126 126 #output_p2= p2.communicate()[0]
127 127 #self.txtInfo.setText(output_p2)
128 128
129 129 #Se carga la variable con la ruta de datos
130 130 var_Dpath=self.txtDpath.text()
131 131
132 132 #Se verifica que la ruta exista y sea un directorio
133 133 var_cmd="test -d "+str(var_Dpath)
134 134 var_output=commands.getstatusoutput(var_cmd)[0]
135 135 if var_output != 0:
136 136 self.statusDpath = False
137 137 self.txtInfo.setText("Ruta no valida, output_error:" + str(var_output))
138 138 return
139 139 else:
140 140 self.statusDpath = True
141 141 self.txtInfo.append("Ruta valida, sin error:" + str(var_Dpath))
142 142
143 143 #Se buscan los archivos del tipo especificado
144 144 var_Dtype=self.txtDtype.text()
145 145 var_cmd="find " + str(var_Dpath) + " -name *."+ str(var_Dtype) +" | awk -F/ '{print substr($NF,2,7)}' | sort| uniq"
146 146 output_p2=commands.getstatusoutput(var_cmd)[1]
147 147
148 148 #Se cargan las listas para seleccionar StartDay y StopDay (QComboBox)
149 149 self.var_list=[]
150 150 for i in range(0, (len(output_p2)+1)/8):
151 151 self.var_list.append(output_p2[8*i:8*(i+1)-1])
152 152
153 153 self.lstStartDay.clear()
154 154 self.lstStopDay.clear()
155 155
156 156 for i in self.var_list:
157 157 self.lstStartDay.addItem(i)
158 158 self.lstStopDay.addItem(i)
159 159
160 160 self.lstStopDay.setCurrentIndex(self.lstStartDay.count()-1)
161 161
162 162
163 163 @pyqtSignature("")
164 164 def on_txtRpath_editingFinished(self):
165 165 """
166 166 Valida la ruta del proyecto
167 167 """
168 168 #Se carga la variable con la ruta del proyecto
169 169 var_Rpath=self.txtRpath.text()
170 170
171 171 #Se verifica que la ruta exista y sea un directorio
172 172 var_cmd="test -d "+str(var_Rpath)
173 173 var_output=commands.getstatusoutput(var_cmd)[0]
174 174 if var_output != 0:
175 175 self.statusRpath = False
176 176 self.txtInfo.append("Ruta no valida, output_error:" + str(var_output))
177 177 return
178 178 else:
179 179 self.statusRpath = True
180 180 self.txtInfo.append("Ruta valida, sin error:" + str(var_Rpath))
181 181
182 182
183 183 @pyqtSignature("int")
184 184 def on_lstDtype_activated(self, index):
185 185 """
186 186 Permite elegir entre los tipos de archivos
187 187 """
188 188 if index == 0:
189 189 var_type='r'
190 190 elif index == 1:
191 191 var_type='pdata'
192 192 elif index == 2:
193 193 var_type='sswma'
194 194
195 195 if index != 3:
196 196 self.txtDtype.setText(var_type)
197 197 self.txtDtype.setReadOnly(True)
198 198 self.on_txtDpath_editingFinished()
199 199 else:
200 200 self.txtDtype.setText('')
201 201 self.txtDtype.setReadOnly(False)
202 202
203 203
204 204 @pyqtSignature("")
205 205 def on_txtDtype_editingFinished(self):
206 206 """
207 207 Se activa cuando el tipo de archivo es ingresado manualmente
208 208 """
209 209 #llamada a funcion
210 210 self.on_txtDpath_editingFinished()
211 211
212 212
213 213 @pyqtSignature("int") #CLOSED
214 214 def on_lstStartDay_activated(self, index):
215 215 """
216 216 Cambia la lista de opciones en lstStopDay
217 217 """
218 218 var_StopDay_index=self.lstStopDay.count() - self.lstStopDay.currentIndex()
219 219 self.lstStopDay.clear()
220 220
221 221 for i in self.var_list[index:]:
222 222 self.lstStopDay.addItem(i)
223 223
224 224 self.lstStopDay.setCurrentIndex(self.lstStopDay.count() - var_StopDay_index)
225 225
226 226
227 227 @pyqtSignature("int") #CLOSED
228 228 def on_lstStopDay_activated(self, index):
229 229 """
230 230 Cambia la lista de opciones en lstStartDay
231 231 """
232 232 var_StartDay_index=self.lstStartDay.currentIndex()
233 233 var_end_index = self.lstStopDay.count() - index
234 234 self.lstStartDay.clear()
235 235
236 236 for i in self.var_list[:len(self.var_list) - var_end_index + 1]:
237 237 self.lstStartDay.addItem(i)
238 238
239 239 self.lstStartDay.setCurrentIndex(var_StartDay_index)
240 240
241 241
242 242 @pyqtSignature("int") #CLOSED
243 243 def on_lstDcapacity_activated(self, index):
244 244 """
245 245 Permite elegir el tamaΓ±o del disco
246 246 """
247 247 if index == 0:
248 248 var_size=25.0
249 249 elif index == 1:
250 250 var_size=8.5
251 251 elif index == 2:
252 252 var_size=4.7
253 253 elif index == 3:
254 254 var_size=0.7
255 255
256 256 if index != 4:
257 257 self.txtDcapacity.setText(str(var_size*10**9/1024**2))
258 258 self.txtDcapacity.setReadOnly(True)
259 259 else:
260 260 self.txtDcapacity.setText('')
261 261 self.txtDcapacity.setReadOnly(False)
262 262
263 263
264 264 @pyqtSignature("")
265 265 def on_btnGbkp_clicked(self):
266 266 """
267 267 Cuando se presiona el boton btnGbkp
268 268 """
269 269
270 270 #Verifica que las rutas sean validas
271 271 if self.statusDpath == False or self.statusRpath == False:
272 272 if self.statusDpath == False:
273 273 self.txtInfo.append("Ruta de datos no valida")
274 274 if self.statusRpath == False:
275 275 self.txtInfo.append("Ruta de proyecto no valida")
276 276 return
277 277
278 278 #Crea las carpetas en la ruta del proyecto y verifica que se crearon correctamente
279 279 var_Rpath=self.txtRpath.text()
280 280 var_dirs='/{gpath,iso,ppath}'
281 281 var_cmd="mkdir -p "+str(var_Rpath)+str(var_dirs)
282 282 var_output=commands.getstatusoutput(var_cmd)[0]
283 283 if var_output != 0:
284 284 self.txtInfo.append("No se pudieron crear los directorios, output_error:" + str(var_output))
285 285 return
286 286 else:
287 287 self.txtInfo.append('Carpetas creadas correctamente')
288 288
289 289 #Cargando variables con los parametros
290 290 var_Dpath=self.txtDpath.text()
291 291 var_Rpath=self.txtRpath.text()
292 292 var_Rpath_ppath=var_Rpath+"/ppath" #Ruta de los archivos a grabar
293 293 var_sublist=[]
294 294 for i in self.var_list[self.lstStartDay.currentIndex():self.lstStartDay.currentIndex() + self.lstStopDay.currentIndex()+1]:
295 295 var_sublist.append(i)
296 296 if len(var_sublist) == 0:
297 297 self.txtInfo.append("No existen archivos encontrados")
298 298 return
299 299 #self.txtInfo.append('elementos: '+str(len(var_sublist)))
300 300
301 301
302 302 var_Dtype=self.txtDtype.text()
303 303 var_Dcapacity=float(self.txtDcapacity.text())*1024 #tamaΓ±o en KB
304 304
305 305 #Busca los archivos con los parametros de busqueda
306 306 var_files_list=[]
307 307 for var_doy in var_sublist:
308 308 var_cmd="find " + str(var_Dpath) + " -name ?"+var_doy+"???."+ str(var_Dtype) + " |sort"
309 309 var_output=commands.getstatusoutput(var_cmd)[1]
310 310 for var_file in var_output.split():
311 311 var_files_list.append(var_file) #Almacena cada archivo en la lista
312 312
313 313 #
314 314 #Genera la lista de archivos .dat que contienen los archivos a grabar en cada DVD
315 315 #
316 316 var_n=0 #Numero del DVD actual
317 317 var_tmp=0 #Se usa para acumulanr el tamaΓ±o de los archivos de la lista
318 318 var_files_list_2=[] #Se usa para almacenar la lista de archivos agrbar en cada DVD
319 319
320 320 for i in var_files_list: #Se asignan en i los archivos de la lista
321 321 var_size_i=os.path.getsize(i)/1024+1 #tamaΓ±o en KB del archivo de la lista, se suma 1 KB para evitar problemas al momento de sumar
322 322 var_tmp += var_size_i #Se acumulan el tamaΓ±o de los archivos de la lista
323 323
324 324 #Si el tamaΓ±o acumulado es mayor que el de el DVD
325 325 if var_tmp > var_Dcapacity:
326 326 var_tmp -= var_size_i #se quita el tamaΓ±o sumado para mostrar el tamaΓ±o real
327 327 #se agregan los ceros necesarios
328 328 if len(str(var_n)) < 4:
329 329 var_n2=""
330 330 for k in range(0, 4-len(str(var_n))):
331 331 var_n2 = var_n2+"0"
332 332 #se crea un archivo con numeral en el sufijo y extension .dat
333 333 var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n2)+str(var_n)+".dat","w")
334 334 #Se aΓ±ade la lista de archivos a grabar en el DVD al archivo .dat
335 335 for line in var_files_list_2:
336 336 var_tmp_path=(line.split(var_Dpath)[1]).split('/')
337 337 var_tmp_path2="/"
338 338 for l in range(0, len(var_tmp_path)-1):
339 339 var_tmp_path2=var_tmp_path2+str(var_tmp_path[l])+"/"
340 340 var_file.write(var_tmp_path2+'=')
341 341 var_file.write(line+'\n')
342 342 var_file.close()
343 343
344 344 var_tmp = var_size_i #Se asigna a la variable el tamaΓ±o del archivo actual
345 345 var_files_list_2=[] #Se reinicia la lista
346 346 var_n += 1
347 347 var_files_list_2.append(i)
348 348
349 349 #se agregan los ceros necesarios
350 350 if len(str(var_n)) < 4:
351 351 var_n2=""
352 352 for k in range(0, 4-len(str(var_n))):
353 353 var_n2 = var_n2+"0"
354 354 #se crea un archivo con numeral en el sufijo y extension .dat
355 355 var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n2)+str(var_n)+".dat","w")
356 356 #Se aΓ±ade la lista de archivos a grabar en el DVD al archivo .dat
357 357 for line in var_files_list_2:
358 358 var_tmp_path=(line.split(var_Dpath)[1]).split('/')
359 359 var_tmp_path2="/"
360 360 for l in range(0, len(var_tmp_path)-1):
361 361 var_tmp_path2=var_tmp_path2+str(var_tmp_path[l])+"/"
362 362 var_file.write(var_tmp_path2+'=')
363 363 var_file.write(line+'\n')
364 364 var_file.close()
365 365
366 366 #
367 367 #Genera los archivos postscript
368 368 #
369 369 var_n_files = var_n
370 370 var_n = 0
371 371 for var_n in range(0, var_n_files+1):
372 372 print var_n
373 373 #se agregan los ceros necesarios
374 374 if len(str(var_n)) < 4:
375 375 var_n2=""
376 376 for k in range(0, 4-len(str(var_n))):
377 377 var_n2 = var_n2+"0"
378 378
379 379 #se abren los archivos .dat en modo lectura
380 380 var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n2)+str(var_n)+".dat","r")
381 381 lines=var_file.readlines()
382 382 #print str(len(lines))
383 383
384 384 #Se crean los archivos .print con los cuales se crearan los archivos .ps
385 385 var_first_folder = lines[0].split('=')[0]
386 386 var_first_file = (lines[0].split('=')[1])[:-1]
387 #var_first_file = (lines[0].split('=')[1]).split('/')[-1][1:11]
388
387 var_date_first_file=commands.getstatusoutput("date -r "+var_first_file+" +'%T'")[1]
388
389 389 for j in range(1, len(lines)-1):
390 390 var_tmp_folder = lines[j].split('=')[0]
391 391 var_tmp_file = (lines[j].split('=')[1])[:-1]
392 #var_tmp_file = (lines[j].split('=')[1]).split('/')[-1][1:11]
392
393 393
394 394 # Si el subfolder superior o la fecha del archivo cambia se genera una nueva linea
395 395 if (var_tmp_folder != var_first_folder) or (var_tmp_file[0:-5] != var_first_file[0:-5]):
396
397 var_last_file = (lines[j-1].split('=')[1])[:-1]
398 var_date_last_file=commands.getstatusoutput("date -r "+var_last_file+" +'%T'")[1]
399 # Si el archivo se grabara directamente en la / del DVD y no en un /directorio/
400 # se usa la etiqueta para indicar la parte de la etiqueta donde va el subdirectorio
396 401 if var_first_folder == '/':
397 402 var_folder = self.txtElabel.text()
398 403 else:
399 404 var_folder = var_first_folder.split('/')[1]
400
405 print "Year Doy Folder Set Time range"
401 406 print var_first_file[-12:-8]+" "+var_first_file[-8:-5]+" "+var_folder +" "+var_first_file[-5:-2]+" "\
402 +((lines[j-1].split('=')[1])[:-1])[-5:-2]
407 +var_last_file[-5:-2]+" "+var_date_first_file+" "+var_date_last_file
403 408
404 409 var_first_folder = lines[j].split('=')[0]
405 410 var_first_file = (lines[j].split('=')[1])[:-1]
406
411 var_date_first_file=commands.getstatusoutput("date -r "+var_first_file+" +'%T'")[1]
412
413 var_last_file = (lines[-1].split('=')[1])[:-1]
414 var_date_last_file=commands.getstatusoutput("date -r "+var_last_file+" +'%T'")[1]
407 415
408 416 if var_first_folder == '/':
409 417 var_folder = self.txtElabel.text()
410 418 else:
411 419 var_folder = var_first_folder.split('/')[1]
412 420
421 print "Year Doy Folder Set Time range"
413 422 print var_first_file[-12:-8]+" "+var_first_file[-8:-5]+" "+var_folder +" "+var_first_file[-5:-2]+" "\
414 +((lines[-1].split('=')[1])[:-1])[-5:-2]
423 +var_last_file[-5:-2]+" "+var_date_first_file+" "+var_date_last_file
424
415 425
416 426
417 427
418 428 #Se deshabilita el Tab Parameters y el boton btnGbkp
419 429 self.tabParameters.setEnabled(False)
420 430 self.btnGbkp.setEnabled(False)
421 431
422 432
423 433 @pyqtSignature("")
424 434 def on_btnStartburn_clicked(self):
425 435 """
426 436 Slot documentation goes here.
427 437 """
428 438 sys.stdout = self
429 439 #sys.stderr = self
430 440 print "stdout_!!!"
431 441 var_Rpath=self.txtRpath.text()
432 442 var_Rpath_ppath=var_Rpath+"/ppath"
433 443 var_Rpath_iso=var_Rpath+"/iso"
434 444
435 445 var_label=self.txtElabel.text()
436 446
437 447 file_iso=var_Rpath_iso+'/2.iso'
438 448 file_dat=var_Rpath_ppath+'/EW_DRIFTS_1.dat'
439 449
440 450 var_cmd = 'genisoimage -hide-joliet-trans-tbl -joliet-long -r '
441 451 var_cmd += ' -A '+var_label+' -V '+var_label
442 452 var_cmd += ' -graft-points -path-list '+ file_dat+' -o '+file_iso
443 453 self.txtInfo.append(var_cmd)
444 454
445 455 #var_output=commands.getstatusoutput(str(var_cmd))[1]
446 456 #self.txtInfo.append(var_output)
447 457
448 458 #os.system(str(var_cmd))
449 459 #p = subprocess.Popen(str('ls /'), shell=True, stdout=self)
450 460 #os.waitpid(p.pid, 0)
451 461 ####self.txtInfo.append(str(p.pid))
452 462
453 463
454 464
455 465 @pyqtSignature("")
456 466 def on_btnRestart_clicked(self):
457 467 """
458 468 Slot documentation goes here.
459 469 """
460 470 self.tabParameters.setEnabled(True)
461 471 self.btnGbkp.setEnabled(True)
462 472
463 473 @pyqtSignature("")
464 474 def on_btnTdevA_clicked(self):
465 475 var_dev = str(self.txtDeviceA.text())
466 476 var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
467 477 commands.getstatusoutput(var_cmd)
468 478
469 479 @pyqtSignature("")
470 480 def on_btnTdevB_clicked(self):
471 481 var_dev = str(self.txtDeviceB.text())
472 482 var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
473 483 commands.getstatusoutput(var_cmd)
474 484
475 485 @pyqtSignature("")
476 486 def on_btnTdevC_clicked(self):
477 487 var_dev = str(self.txtDeviceC.text())
478 488 var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
479 489 commands.getstatusoutput(var_cmd)
480 490
481 491 @pyqtSignature("")
482 492 def on_btnTdevD_clicked(self):
483 493 var_dev = str(self.txtDeviceD.text())
484 494 var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
485 495 commands.getstatusoutput(var_cmd)
General Comments 0
You need to be logged in to leave comments. Login now