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