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