|
|
# -*- 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
|
|
|
from functions import functions
|
|
|
from functions import functions2
|
|
|
|
|
|
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 = self #redirige salida estandar
|
|
|
|
|
|
def setupUi2(self):
|
|
|
|
|
|
self.var_Dpath = self.txtDpath.text()
|
|
|
self.var_Rpath = self.txtRpath.text()
|
|
|
self.statusDpath = False
|
|
|
self.statusRpath = False
|
|
|
|
|
|
self.var_Dtype = self.txtDtype.text()
|
|
|
self.var_Elabel = self.txtElabel.text()
|
|
|
self.var_Copys = self.txtCopys.value()
|
|
|
|
|
|
self.var_n_files=0
|
|
|
self.var_list=[]
|
|
|
|
|
|
functions2.set_parameters(self) #Establece ciertos parametros, para pruebas
|
|
|
functions2.detect_devices(self) #busca los dispositivos de grabacion
|
|
|
|
|
|
|
|
|
def write(self, txt):
|
|
|
"""
|
|
|
Escribe la salida estandar eb txtInfo
|
|
|
"""
|
|
|
self.txtInfo.append(str(txt))
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnDpath_clicked(self):
|
|
|
"""
|
|
|
Permite seleccionar graficamente el direcorio de los datos a grabar
|
|
|
"""
|
|
|
self.var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
|
|
|
self.txtDpath.setText(self.var_Dpath)
|
|
|
self.on_txtDpath_editingFinished() #llamada a funcion
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnRpath_clicked(self):
|
|
|
"""
|
|
|
Permite seleccionar graficamente el direcorio del proyecto
|
|
|
"""
|
|
|
self.var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
|
|
|
self.txtRpath.setText(self.var_Rpath)
|
|
|
self.on_txtRpath_editingFinished() #llamada a funcion
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_txtDpath_editingFinished(self):
|
|
|
"""
|
|
|
Permite buscar los archivos de extension seleccionada en la ruta de de datos
|
|
|
y cargar los valores para el rango de tiempo a ser grabado
|
|
|
"""
|
|
|
self.var_Dpath=self.txtDpath.text() #Se carga la variable con la ruta recien editada
|
|
|
self.statusDpath = functions.dir_exists(self.var_Dpath, self)
|
|
|
functions.load_days(self)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_txtRpath_editingFinished(self):
|
|
|
"""
|
|
|
Valida la ruta del proyecto
|
|
|
"""
|
|
|
self.var_Rpath=self.txtRpath.text() #Se carga la variable con la ruta recien editada
|
|
|
self.statusRpath = functions.dir_exists(self.var_Rpath, self)
|
|
|
|
|
|
|
|
|
@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)
|
|
|
functions.load_days(self)
|
|
|
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.var_Dtype=self.txtDtype.text()
|
|
|
#llamada a funcion
|
|
|
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 btnGbkp
|
|
|
"""
|
|
|
|
|
|
#Verifica que las rutas sean validas
|
|
|
if self.statusDpath == False or self.statusRpath == False:
|
|
|
if self.statusDpath == False:
|
|
|
self.txtInfo.append("Ruta de datos no valida")
|
|
|
if self.statusRpath == False:
|
|
|
self.txtInfo.append("Ruta de proyecto no valida")
|
|
|
return
|
|
|
|
|
|
#Crea las carpetas en la ruta del proyecto y verifica que se crearon correctamente
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
list_dirs=['gpath', 'iso', 'ppath']
|
|
|
functions.make_dirs(var_Rpath, list_dirs, self)
|
|
|
|
|
|
#Cargando variables con los parametros
|
|
|
var_Dpath=self.txtDpath.text()
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
var_Rpath_ppath=var_Rpath+"/ppath" #Ruta de los archivos a grabar
|
|
|
var_sublist=[]
|
|
|
for i in self.var_list[self.lstStartDay.currentIndex():self.lstStartDay.currentIndex() + self.lstStopDay.currentIndex()+1]:
|
|
|
var_sublist.append(i)
|
|
|
if len(var_sublist) == 0:
|
|
|
self.txtInfo.append("No existen archivos encontrados")
|
|
|
return
|
|
|
#self.txtInfo.append('elementos: '+str(len(var_sublist)))
|
|
|
|
|
|
|
|
|
var_Dtype=self.txtDtype.text()
|
|
|
var_Dcapacity=float(self.txtDcapacity.text())*1024 #tamaño en KB
|
|
|
|
|
|
#Busca los archivos con los parametros de busqueda
|
|
|
var_files_list=[]
|
|
|
for var_doy in var_sublist:
|
|
|
var_cmd="find " + str(var_Dpath) + " -name ?"+var_doy+"???."+ str(var_Dtype) + " |sort"
|
|
|
var_output=commands.getstatusoutput(var_cmd)[1]
|
|
|
for var_file in var_output.split():
|
|
|
var_files_list.append(var_file) #Almacena cada archivo en la lista
|
|
|
|
|
|
#
|
|
|
#Genera la lista de archivos .dat que contienen los archivos a grabar en cada DVD
|
|
|
#
|
|
|
var_n=0 #Numero del DVD actual
|
|
|
var_tmp=0 #Se usa para acumulanr el tamaño de los archivos de la lista
|
|
|
var_files_list_2=[] #Se usa para almacenar la lista de archivos agrbar en cada DVD
|
|
|
|
|
|
for i in var_files_list: #Se asignan en i los archivos de la lista
|
|
|
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
|
|
|
var_tmp += var_size_i #Se acumulan el tamaño de los archivos de la lista
|
|
|
|
|
|
#Si el tamaño acumulado es mayor que el de el DVD
|
|
|
if var_tmp > var_Dcapacity:
|
|
|
var_tmp -= var_size_i #se quita el tamaño sumado para mostrar el tamaño real
|
|
|
#se crea un archivo con numeral en el sufijo y extension .dat
|
|
|
var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+functions.i2s(var_n)+".dat","w")
|
|
|
#Se añade la lista de archivos a grabar en el DVD al archivo .dat
|
|
|
for line in var_files_list_2:
|
|
|
var_tmp_path=(line.split(var_Dpath)[1]).split('/')
|
|
|
var_tmp_path2="/"
|
|
|
for l in range(0, len(var_tmp_path)-1):
|
|
|
var_tmp_path2=var_tmp_path2+str(var_tmp_path[l])+"/"
|
|
|
var_file.write(var_tmp_path2+'=')
|
|
|
var_file.write(line+'\n')
|
|
|
var_file.close()
|
|
|
|
|
|
var_tmp = var_size_i #Se asigna a la variable el tamaño del archivo actual
|
|
|
var_files_list_2=[] #Se reinicia la lista
|
|
|
var_n += 1
|
|
|
var_files_list_2.append(i)
|
|
|
|
|
|
#se crea un archivo con numeral en el sufijo y extension .dat
|
|
|
var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+functions.i2s(var_n)+".dat","w")
|
|
|
#Se añade la lista de archivos a grabar en el DVD al archivo .dat
|
|
|
for line in var_files_list_2:
|
|
|
var_tmp_path=(line.split(var_Dpath)[1]).split('/')
|
|
|
var_tmp_path2="/"
|
|
|
for l in range(0, len(var_tmp_path)-1):
|
|
|
var_tmp_path2=var_tmp_path2+str(var_tmp_path[l])+"/"
|
|
|
var_file.write(var_tmp_path2+'=')
|
|
|
var_file.write(line+'\n')
|
|
|
var_file.close()
|
|
|
|
|
|
#
|
|
|
#Genera los archivos .print con los cuales se creara los postscript
|
|
|
#
|
|
|
self.var_n_files = var_n # Numero del ultimo archivo .dat creado
|
|
|
var_n = 0 # Se reinicia a cero y se usa para poder acceder a cada una de los archivos
|
|
|
|
|
|
# Se leen todos los archivos .dat creados para crear las etiquetas en los archivos .ps
|
|
|
for var_n in range(0, self.var_n_files+1):
|
|
|
print var_n
|
|
|
|
|
|
#se abren los archivos .dat en modo lectura
|
|
|
var_file = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+functions.i2s(var_n)+".dat","r")
|
|
|
lines=var_file.readlines() # Se lee las lineas en el archivo y se almacenan en la lista
|
|
|
|
|
|
# Se crea el archivo .print
|
|
|
var_file_print = open(var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+functions.i2s(var_n)+".print","w")
|
|
|
var_file_print.write(self.txtElabel.text()+" "+functions.i2s(var_n)+"/"+str(self.var_n_files)+"\n")
|
|
|
var_file_print.write("Year Doy Folder Set Time range\n")
|
|
|
|
|
|
#Se crean los archivos .print con los cuales se crearan los archivos .ps
|
|
|
var_first_folder = lines[0].split('=')[0]
|
|
|
var_first_file = (lines[0].split('=')[1])[:-1]
|
|
|
var_date_first_file=commands.getstatusoutput("date -r "+var_first_file+" +'%T'")[1]
|
|
|
|
|
|
for j in range(1, len(lines)-1):
|
|
|
var_tmp_folder = lines[j].split('=')[0]
|
|
|
var_tmp_file = (lines[j].split('=')[1])[:-1]
|
|
|
|
|
|
# Si el subfolder superior o la fecha del archivo cambia se genera una nueva linea
|
|
|
if (var_tmp_folder != var_first_folder) or (var_tmp_file[0:-5] != var_first_file[0:-5]):
|
|
|
|
|
|
var_last_file = (lines[j-1].split('=')[1])[:-1]
|
|
|
var_date_last_file=commands.getstatusoutput("date -r "+var_last_file+" +'%T'")[1]
|
|
|
# Si el archivo se grabara directamente en la / del DVD y no en un /directorio/
|
|
|
# se usa la etiqueta para indicar la parte de la etiqueta donde va el subdirectorio
|
|
|
if var_first_folder == '/':
|
|
|
var_folder = self.txtElabel.text()
|
|
|
else:
|
|
|
var_folder = var_first_folder.split('/')[1]
|
|
|
|
|
|
var_file_print.write(var_first_file[-12:-8]+" "+var_first_file[-8:-5]+" "+var_folder +" "+var_first_file[-5:-2]+" "
|
|
|
+var_last_file[-5:-2]+" "+var_date_first_file+" "+var_date_last_file+"\n")
|
|
|
|
|
|
var_first_folder = lines[j].split('=')[0]
|
|
|
var_first_file = (lines[j].split('=')[1])[:-1]
|
|
|
var_date_first_file=commands.getstatusoutput("date -r "+var_first_file+" +'%T'")[1]
|
|
|
|
|
|
var_last_file = (lines[-1].split('=')[1])[:-1]
|
|
|
var_date_last_file=commands.getstatusoutput("date -r "+var_last_file+" +'%T'")[1]
|
|
|
|
|
|
if var_first_folder == '/':
|
|
|
var_folder = self.txtElabel.text()
|
|
|
else:
|
|
|
var_folder = var_first_folder.split('/')[1]
|
|
|
|
|
|
var_file_print.write(var_first_file[-12:-8]+" "+var_first_file[-8:-5]+" "+var_folder +" "+var_first_file[-5:-2]+" "
|
|
|
+var_last_file[-5:-2]+" "+var_date_first_file+" "+var_date_last_file+"\n")
|
|
|
|
|
|
var_file.close()
|
|
|
var_file_print.close()
|
|
|
|
|
|
|
|
|
#Se deshabilita el Tab Parameters y el boton btnGbkp
|
|
|
self.tabParameters.setEnabled(False)
|
|
|
self.btnGbkp.setEnabled(False)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnRestart_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
self.tabParameters.setEnabled(True)
|
|
|
self.btnGbkp.setEnabled(True)
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnStartburn_clicked(self):
|
|
|
"""
|
|
|
Se inicia el proceso de grabacion
|
|
|
"""
|
|
|
sys.stdout = self
|
|
|
#sys.stderr = self
|
|
|
print "stdout_!!!"
|
|
|
|
|
|
#Inicializando variables
|
|
|
var_Rpath=self.txtRpath.text()
|
|
|
var_Rpath_ppath=var_Rpath+"/ppath"
|
|
|
var_Rpath_iso=var_Rpath+"/iso"
|
|
|
var_label=self.txtElabel.text()
|
|
|
|
|
|
# Se leen todos los archivos .dat creados para crear las etiquetas en los archivos .ps
|
|
|
for var_n in range(0, self.var_n_files+1):
|
|
|
print var_n
|
|
|
|
|
|
file_iso=var_Rpath_iso+"/"+functions.i2s(var_n)+".iso"
|
|
|
file_dat=var_Rpath_ppath+"/"+self.txtElabel.text()+"_"+functions.i2s(var_n)+".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))[0]
|
|
|
self.txtInfo.append(str(var_output))
|
|
|
|
|
|
#os.system(str(var_cmd))
|
|
|
#p = subprocess.Popen(str('ls /'), shell=True, stdout=self)
|
|
|
#os.waitpid(p.pid, 0)
|
|
|
####self.txtInfo.append(str(p.pid))
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnStopburn_clicked(self):
|
|
|
"""
|
|
|
Slot documentation goes here.
|
|
|
"""
|
|
|
# TODO: not implemented yet
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnTdevA_clicked(self):
|
|
|
var_dev = str(self.txtDeviceA.text())
|
|
|
var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
|
|
|
commands.getstatusoutput(var_cmd)
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnTdevB_clicked(self):
|
|
|
var_dev = str(self.txtDeviceB.text())
|
|
|
var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
|
|
|
commands.getstatusoutput(var_cmd)
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnTdevC_clicked(self):
|
|
|
var_dev = str(self.txtDeviceC.text())
|
|
|
var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
|
|
|
commands.getstatusoutput(var_cmd)
|
|
|
|
|
|
@pyqtSignature("")
|
|
|
def on_btnTdevD_clicked(self):
|
|
|
var_dev = str(self.txtDeviceD.text())
|
|
|
var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
|
|
|
commands.getstatusoutput(var_cmd)
|
|
|
|