|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
"""
|
|
|
Module implementing MainWindow.
|
|
|
"""
|
|
|
|
|
|
from PyQt4.QtGui import QMainWindow
|
|
|
from PyQt4.QtCore import pyqtSignature
|
|
|
from Ui_MainWindow import Ui_MainWindow
|
|
|
from PyQt4 import QtGui
|
|
|
from subprocess import *
|
|
|
import sys
|
|
|
import os
|
|
|
import subprocess
|
|
|
import commands
|
|
|
|
|
|
class MainWindow(QMainWindow, Ui_MainWindow):
|
|
|
"""
|
|
|
Class documentation goes here.
|
|
|
"""
|
|
|
|
|
|
def __init__(self, parent = None):
|
|
|
QMainWindow.__init__(self, parent)
|
|
|
self.setupUi(self)
|
|
|
self.setupUi2()
|
|
|
#sys.stdout = obj
|
|
|
|
|
|
|
|
|
def setupUi2(self):
|
|
|
self.txtDpath.setText('/home/ricardoar/optional/STORAGE/EW_DRIFTS')
|
|
|
self.txtRpath.setText('/home/ricardoar/optional/STORAGE/prueba1_jro_backup_manager')
|
|
|
self.txtElabel.setText('EW_DRIFTS')
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnDpath_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
|
|
|
self.txtDpath.setText(var_Dpath)
|
|
|
self.on_txtDpath_editingFinished()
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnRpath_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
|
|
|
self.txtRpath.setText(var_Rpath)
|
|
|
self.on_txtRpath_editingFinished()
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_txtDpath_editingFinished(self):
|
|
|
|
|
|
#Usando el modulo "subprocess", eric4 pide seleccion del tipo de subproceso (padre o hijo)
|
|
|
#por ello se prefiere usar el modulo "commands"
|
|
|
#p1= Popen(['find', var_Dpath, '-name', '*.r'], stdout=PIPE)
|
|
|
#p2= Popen(['awk', '-F/', '{print substr($NF,2,7)}'], stdin=p1.stdout, stdout=PIPE)
|
|
|
#output_p2= p2.communicate()[0]
|
|
|
#self.txtInfo.setText(output_p2)
|
|
|
|
|
|
var_Dpath=self.txtDpath.text()
|
|
|
|
|
|
#Se verifica que la ruta exista y sea un directorio
|
|
|
var_cmd="test -d "+str(var_Dpath)
|
|
|
var_output=commands.getstatusoutput(var_cmd)[0]
|
|
|
if var_output != 0:
|
|
|
self.txtInfo.setText("Ruta no valida, output_error:" + str(var_output))
|
|
|
return
|
|
|
|
|
|
#Se buscan los archivos del tipo especificado
|
|
|
var_Dtype=self.txtDtype.text()
|
|
|
var_cmd="find " + str(var_Dpath) + " -name *."+ str(var_Dtype) +" | awk -F/ '{print substr($NF,2,7)}' | sort| uniq"
|
|
|
output_p2=commands.getstatusoutput(var_cmd)[1]
|
|
|
|
|
|
#INFO: Muestra los dias que se encontraron
|
|
|
self.txtInfo.append(output_p2)
|
|
|
|
|
|
#Se cargan las listas para seleccionar StartDay y StopDay
|
|
|
self.var_list=[]
|
|
|
for i in range(0, (len(output_p2)+1)/8):
|
|
|
self.var_list.append(output_p2[8*i:8*(i+1)-1])
|
|
|
|
|
|
self.lstStartDay.clear()
|
|
|
self.lstStopDay.clear()
|
|
|
|
|
|
for i in self.var_list:
|
|
|
self.lstStartDay.addItem(i)
|
|
|
self.lstStopDay.addItem(i)
|
|
|
|
|
|
self.lstStopDay.setCurrentIndex(self.lstStartDay.count()-1)
|
|
|
|
|
|
#INFO: Muestra cuantos dias se encontraron
|
|
|
#self.txtInfo.setText(str(self.lstStartDay.count()))
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_txtRpath_editingFinished(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
|
|
|
#Se verifica que la ruta exista y sea un directorio
|
|
|
var_cmd="test -d "+str(var_Rpath)
|
|
|
var_output=commands.getstatusoutput(var_cmd)[0]
|
|
|
if var_output != 0:
|
|
|
self.txtInfo.append("Ruta no valida, output_error:" + str(var_output))
|
|
|
return
|
|
|
else:
|
|
|
self.txtInfo.append("Ruta valida, sin error")
|
|
|
|
|
|
|
|
|
@pyqtSignature("int")
|
|
|
def on_lstDtype_activated(self, index):
|
|
|
"""
|
|
|
Permite elegir entre los tipos de archivos
|
|
|
"""
|
|
|
if index == 0:
|
|
|
var_type='r'
|
|
|
elif index == 1:
|
|
|
var_type='pdata'
|
|
|
elif index == 2:
|
|
|
var_type='sswma'
|
|
|
|
|
|
if index != 3:
|
|
|
self.txtDtype.setText(var_type)
|
|
|
self.txtDtype.setReadOnly(True)
|
|
|
self.on_txtDpath_editingFinished()
|
|
|
else:
|
|
|
self.txtDtype.setText('')
|
|
|
self.txtDtype.setReadOnly(False)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_txtDtype_editingFinished(self):
|
|
|
"""
|
|
|
Se activa cuando el tipo de archivo es ingresado manualmente
|
|
|
"""
|
|
|
self.on_txtDpath_editingFinished()
|
|
|
|
|
|
|
|
|
@pyqtSignature("int") #CLOSED
|
|
|
def on_lstStartDay_activated(self, index):
|
|
|
"""
|
|
|
Cambia la lista de opciones en lstStopDay
|
|
|
"""
|
|
|
var_StopDay_index=self.lstStopDay.count() - self.lstStopDay.currentIndex()
|
|
|
self.lstStopDay.clear()
|
|
|
|
|
|
for i in self.var_list[index:]:
|
|
|
self.lstStopDay.addItem(i)
|
|
|
|
|
|
self.lstStopDay.setCurrentIndex(self.lstStopDay.count() - var_StopDay_index)
|
|
|
|
|
|
|
|
|
@pyqtSignature("int") #CLOSED
|
|
|
def on_lstStopDay_activated(self, index):
|
|
|
"""
|
|
|
Cambia la lista de opciones en lstStartDay
|
|
|
"""
|
|
|
var_StartDay_index=self.lstStartDay.currentIndex()
|
|
|
var_end_index = self.lstStopDay.count() - index
|
|
|
self.lstStartDay.clear()
|
|
|
|
|
|
for i in self.var_list[:len(self.var_list) - var_end_index + 1]:
|
|
|
self.lstStartDay.addItem(i)
|
|
|
|
|
|
self.lstStartDay.setCurrentIndex(var_StartDay_index)
|
|
|
|
|
|
|
|
|
@pyqtSignature("int") #CLOSED
|
|
|
def on_lstDcapacity_activated(self, index):
|
|
|
"""
|
|
|
Permite elegir el tamaño del disco
|
|
|
"""
|
|
|
if index == 0:
|
|
|
var_size=25.0
|
|
|
elif index == 1:
|
|
|
var_size=8.5
|
|
|
elif index == 2:
|
|
|
var_size=4.7
|
|
|
elif index == 3:
|
|
|
var_size=0.7
|
|
|
|
|
|
if index != 4:
|
|
|
self.txtDcapacity.setText(str(var_size*10**9/1024**2))
|
|
|
self.txtDcapacity.setReadOnly(True)
|
|
|
else:
|
|
|
self.txtDcapacity.setText('')
|
|
|
self.txtDcapacity.setReadOnly(False)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnGbkp_clicked(self):
|
|
|
"""
|
|
|
Cuando se presiona el boton Generate Bkp
|
|
|
"""
|
|
|
|
|
|
#CREA LAS CARPETAS "COMENTADO TEMPORALMENTE"
|
|
|
var_dirs='/{gpath,iso,ppath}'
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
var_cmd="mkdir "+str(var_Rpath)+str(var_dirs)
|
|
|
self.txtInfo.append(var_cmd)
|
|
|
#var_output=commands.getstatusoutput(var_cmd)[0]
|
|
|
#if var_output != 0:
|
|
|
# self.txtInfo.setText("No se pudieron crear los directorios, output_error:" + str(var_output))
|
|
|
# return
|
|
|
#else:
|
|
|
# self.txtInfo.append('Carpetas creadas correctamente')
|
|
|
|
|
|
|
|
|
var_sublist=[]
|
|
|
for i in self.var_list[self.lstStartDay.currentIndex():self.lstStartDay.currentIndex() + self.lstStopDay.currentIndex()+1]:
|
|
|
self.txtInfo.append(i)
|
|
|
var_sublist.append(i)
|
|
|
|
|
|
#Cargando los parametros de busqueda
|
|
|
var_Dpath=self.txtDpath.text()
|
|
|
var_Dtype=self.txtDtype.text()
|
|
|
|
|
|
var_files_list=[]
|
|
|
for var_doy in var_sublist:
|
|
|
var_cmd="find " + str(var_Dpath) + " -name ?"+var_doy+"???."+ str(var_Dtype)
|
|
|
var_output=commands.getstatusoutput(var_cmd)[1]
|
|
|
for var_file in var_output.split():
|
|
|
var_files_list.append(var_file)
|
|
|
|
|
|
var_Dcapacity=float(self.txtDcapacity.text())*1024 #tamaño en KB
|
|
|
self.txtInfo.append(str(var_Dcapacity))
|
|
|
|
|
|
# self.txtInfo.append('Lista de archivos')
|
|
|
# var_n=0
|
|
|
# for i in var_files_list:
|
|
|
#self.txtInfo.append(str(os.path.getsize(i)/1024)+'KB')
|
|
|
#self.txtInfo.append(i)
|
|
|
#var_n += 1
|
|
|
#self.txtInfo.append(str(var_n))
|
|
|
|
|
|
#lista de archivos a grabar en archivos .
|
|
|
|
|
|
#Ruta de los archivos a grabar
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
var_Rpath_ppath=var_Rpath+"/ppath"
|
|
|
var_Dpath=self.txtDpath.text()
|
|
|
|
|
|
var_n=0
|
|
|
var_n_files=0
|
|
|
var_tmp=0
|
|
|
var_files_list_2=[]
|
|
|
self.txtInfo.append(str(len(var_files_list)))
|
|
|
|
|
|
for i in var_files_list:
|
|
|
var_size_i=os.path.getsize(i)/1024+1 #tamaño en KB, se suma 1 KB para evitar problemas al momento de sumar
|
|
|
var_tmp += var_size_i
|
|
|
|
|
|
if var_tmp > var_Dcapacity:
|
|
|
var_tmp -= var_size_i #se quita el tamaño sumado para mostrar el tamaño real
|
|
|
#muestra info
|
|
|
self.txtInfo.append(str(len(var_files_list_2))+" size:"+str(var_tmp))
|
|
|
|
|
|
#se crea un archivo con numeral en el sufijo, y se añaden la lista de archivos
|
|
|
var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n)+".dat","w")
|
|
|
for line in var_files_list_2:
|
|
|
var_file.write(line.split(var_Dpath)[1]+'=')
|
|
|
var_file.write(line+'\n')
|
|
|
var_file.close()
|
|
|
|
|
|
var_n_files += len(var_files_list_2)
|
|
|
var_tmp = var_size_i
|
|
|
var_files_list_2=[]
|
|
|
var_files_list_2.append(i)
|
|
|
var_n += 1
|
|
|
|
|
|
else:
|
|
|
var_files_list_2.append(i)
|
|
|
|
|
|
#muestra info
|
|
|
self.txtInfo.append(str(len(var_files_list_2))+" size:"+str(var_tmp))
|
|
|
|
|
|
var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+str(var_n)+".dat","w")
|
|
|
for line in var_files_list_2:
|
|
|
var_file.write(line.split(var_Dpath)[1]+'=')
|
|
|
var_file.write(line+'\n')
|
|
|
var_file.close()
|
|
|
|
|
|
var_n_files += len(var_files_list_2)
|
|
|
self.txtInfo.append(str(var_n_files))
|
|
|
self.tabParameters.setEnabled(False)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnStartburn_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
var_Rpath_ppath=var_Rpath+"/ppath"
|
|
|
var_Rpath_iso=var_Rpath+"/iso"
|
|
|
|
|
|
var_label=self.txtElabel.text()
|
|
|
|
|
|
file_iso=var_Rpath_iso+'/2.iso'
|
|
|
file_dat=var_Rpath_ppath+'/EW_DRIFTS_1.dat'
|
|
|
|
|
|
var_cmd = 'genisoimage -hide-joliet-trans-tbl -joliet-long -r '
|
|
|
var_cmd += ' -A '+var_label+' -V '+var_label
|
|
|
var_cmd += ' -graft-points -path-list '+ file_dat+' -o '+file_iso
|
|
|
self.txtInfo.append(var_cmd)
|
|
|
|
|
|
#var_output=commands.getstatusoutput(str(var_cmd))[1]
|
|
|
#self.txtInfo.append(var_output)
|
|
|
|
|
|
#os.system(str(var_cmd))
|
|
|
p = subprocess.Popen(str(var_cmd), shell=True)
|
|
|
#os.waitpid(p.pid, 0)
|
|
|
self.txtInfo.append(str(p.pid))
|
|
|
|
|
|
#timer.time = 10
|
|
|
#timer.init()
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnRestart_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
self.tabParameters.setEnabled(True)
|
|
|
|