##// END OF EJS Templates
mas funciones implementadas y control de botones paso a paso parte 1
ralonso -
r43:44
parent child
Show More
@@ -1,3 +1,5
1 # -*- coding: utf-8 -*-
2
1 3 #class BKmanager:
2 4 # def __init__(self):
3 5
@@ -7,17 +9,17
7 9 import subprocess
8 10 import commands
9 11
12
10 13 #Entero a cadena agregando ceros delante
11 14 def i2s(var_n, var_length=4):
12 15 var_n2=str(var_n)
13 16 while len(var_n2) < var_length:
14 17 var_n2 = "0"+var_n2
15 18 return var_n2
16
17 19
18 20
21 #Crea directorios en la ruta indicada
19 22 def make_dirs(var_path, list_dirs, self):
20
21 23 var_cmd="mkdir -p "+str(var_path)
22 24 for var_dir in list_dirs:
23 25 var_output=commands.getstatusoutput(var_cmd+'/'+var_dir)[0]
@@ -27,3 +29,48
27 29 return
28 30 else:
29 31 self.txtInfo.append('Carpetas creadas correctamente')
32
33
34 #Se verifica que la ruta exista y sea un directorio
35 def dir_exists(var_dir, self):
36 var_cmd="test -d "+str(var_dir)
37 var_output=commands.getstatusoutput(var_cmd)[0]
38 if var_output != 0:
39 self.txtInfo.append("Ruta no valida, output_error:" + str(var_output))
40 return False
41 else:
42 self.txtInfo.append("Ruta valida, sin error:" + str(var_dir))
43 return True
44
45
46 #Se buscan los archivos del tipo especificado
47 def load_days(self):
48
49 self.var_list=[]
50 self.lstStartDay.clear()
51 self.lstStopDay.clear()
52
53 if self.statusDpath == False:
54 self.btnGbkp.setEnabled(False)
55 return
56
57 var_cmd="find " + str(self.var_Dpath) + " -name *."+ str(self.var_Dtype) +" | awk -F/ '{print substr($NF,2,7)}' | sort| uniq"
58 output=commands.getstatusoutput(var_cmd)[1]
59
60 #Si no se encuentra ningun archivo
61 if len(output) == 0:
62 self.btnGbkp.setEnabled(False)
63 return
64
65 #Se cargan las listas para seleccionar StartDay y StopDay (QComboBox)
66 for i in range(0, (len(output)+1)/8):
67 self.var_list.append(output[8*i:8*(i+1)-1])
68
69 for i in self.var_list:
70 self.lstStartDay.addItem(i)
71 self.lstStopDay.addItem(i)
72 self.lstStopDay.setCurrentIndex(self.lstStartDay.count()-1)
73
74 self.btnGbkp.setEnabled(True)
75
76
@@ -1,3 +1,6
1 # -*- coding: utf-8 -*-
2
3
1 4 from subprocess import *
2 5 import sys
3 6 import os
@@ -5,3 +8,58
5 8 import commands
6 9
7 10
11 def set_parameters(self):
12 """
13 Se usa para inicializar ciertos parametros para pruebas
14 """
15 #self.txtDpath.setText('/home/ricardoar/optional/STORAGE/Data/RAW_EXP/JASMET/')
16 #self.txtRpath.setText('/home/ricardoar/optional/STORAGE/prueba1_jro_backup_manager/')
17 self.txtDpath.setText('/home/ricardoar/optional/STORAGE/EW_DRIFTS/')
18 self.txtRpath.setText('/home/ricardoar/optional/prueba1_jro_backup_manager/')
19 self.txtElabel.setText('EW_DRIFTS')
20 self.statusDpath = True
21 self.statusRpath = True
22 self.var_n_files=0
23
24
25 def detect_devices(self):
26 """
27 Deteccion de los dispositvos de grabacion
28 """
29 #var_cmd="wodim --devices | grep /dev/ | awk -F\' '{print $2}'" #Funciona en consola pero no en python ΒΏ?
30 var_cmd="wodim --devices | grep /dev/ | awk '{print $2}' | awk -F= '{print $2}'"
31 var_output = commands.getstatusoutput(var_cmd)
32 if var_output[0] != 0:
33 self.txtInfo.append("No se pudo encontrar los dispositivos de grabacion, output_error:" + str(var_output))
34 else:
35 self.txtInfo.append("dispositivos encontrados")
36 var_devices = var_output[1].split('\n')
37
38 var_tmp=[]
39 for i in range(0, 4):
40 if i < len(var_devices):
41 var_len = len(var_devices[i])
42 var_tmp.append(var_devices[i][1:var_len - 1])
43 else:
44 var_tmp.append('')
45
46 #Se escriben los dispostivos correspodientes, si existen
47 self.txtDeviceA.setText(str(var_tmp[0]))
48 self.txtDeviceB.setText(str(var_tmp[1]))
49 self.txtDeviceC.setText(str(var_tmp[2]))
50 self.txtDeviceD.setText(str(var_tmp[3]))
51 #Se desactivan los que no existen
52 if len(var_tmp[0]) == 0 :
53 self.chkDevA.setChecked(False)
54 self.chkDevA.setEnabled(False)
55 if len(var_tmp[1]) == 0 :
56 self.chkDevB.setChecked(False)
57 self.chkDevB.setEnabled(False)
58 if len(var_tmp[2]) == 0 :
59 self.chkDevC.setChecked(False)
60 self.chkDevC.setEnabled(False)
61 if len(var_tmp[3]) == 0 :
62 self.chkDevD.setChecked(False)
63 self.chkDevD.setEnabled(False)
64
65
@@ -1,7 +1,7
1 1 <?xml version="1.0" encoding="UTF-8"?>
2 2 <!DOCTYPE Project SYSTEM "Project-4.6.dtd">
3 3 <!-- eric4 project file for project jro_backup_manager -->
4 <!-- Saved: 2010-05-16, 21:21:21 -->
4 <!-- Saved: 2010-05-16, 23:51:59 -->
5 5 <!-- Copyright (C) 2010 , -->
6 6 <Project version="4.6">
7 7 <Language>en</Language>
@@ -20,6 +20,7
20 20 <Source>functions/__init__.py</Source>
21 21 <Source>functions/functions.py</Source>
22 22 <Source>functions/functions2.py</Source>
23 <Source>functions/func_doc.py</Source>
23 24 </Sources>
24 25 <Forms>
25 26 <Form>ui/MainWindow.ui</Form>
@@ -31,6 +32,7
31 32 <Interfaces>
32 33 </Interfaces>
33 34 <Others>
35 <Other>functions/doc_tmp.txt</Other>
34 36 </Others>
35 37 <MainScript>main.py</MainScript>
36 38 <Vcs>
@@ -25,84 +25,41
25 25 QMainWindow.__init__(self, parent)
26 26 self.setupUi(self)
27 27 self.setupUi2()
28
29 #redirige salida estandar
30 sys.stdout = self
31
28 sys.stdout = self #redirige salida estandar
32 29
33 30 def setupUi2(self):
34 """
35 Se usa para inicializar ciertos parametros para pruebas
36 """
37 #self.txtDpath.setText('/home/ricardoar/optional/STORAGE/Data/RAW_EXP/JASMET/')
38 #self.txtRpath.setText('/home/ricardoar/optional/STORAGE/prueba1_jro_backup_manager/')
39 self.txtDpath.setText('/home/ricardoar/optional/STORAGE/EW_DRIFTS/')
40 self.txtRpath.setText('/home/ricardoar/optional/prueba1_jro_backup_manager/')
41 self.txtElabel.setText('EW_DRIFTS')
42 self.statusDpath = True
43 self.statusRpath = True
31
32 self.var_Dpath = self.txtDpath.text()
33 self.var_Rpath = self.txtRpath.text()
34 self.statusDpath = False
35 self.statusRpath = False
36
37 self.var_Dtype = self.txtDtype.text()
38 self.var_Elabel = self.txtElabel.text()
39 self.var_Copys = self.txtCopys.value()
40
44 41 self.var_n_files=0
45 # self.statusDpath = False
46 # self.statusRpath = False
47
48
49 #
50 #Deteccion de los dispositvos de grabacion
51 #
52 #var_cmd="wodim --devices | grep /dev/ | awk -F\' '{print $2}'" #Funciona en consola pero no en python ΒΏ?
53 var_cmd="wodim --devices | grep /dev/ | awk '{print $2}' | awk -F= '{print $2}'"
54 var_output = commands.getstatusoutput(var_cmd)
55 if var_output[0] != 0:
56 self.txtInfo.setText("No se pudo encontrar los dispositivos de grabacion, output_error:" + str(var_output))
57 else:
58 self.txtInfo.append("dispositivos encontrados")
59 var_devices = var_output[1].split('\n')
60
61 var_tmp=[]
62 for i in range(0, 4):
63 if i < len(var_devices):
64 var_len = len(var_devices[i])
65 var_tmp.append(var_devices[i][1:var_len - 1])
66 else:
67 var_tmp.append('')
68
69 #Se escriben los dispostivos correspodientes, si existen
70 self.txtDeviceA.setText(str(var_tmp[0]))
71 self.txtDeviceB.setText(str(var_tmp[1]))
72 self.txtDeviceC.setText(str(var_tmp[2]))
73 self.txtDeviceD.setText(str(var_tmp[3]))
74 #Se desactivan los que no existen
75 if len(var_tmp[0]) == 0 :
76 self.chkDevA.setChecked(False)
77 self.chkDevA.setEnabled(False)
78 if len(var_tmp[1]) == 0 :
79 self.chkDevB.setChecked(False)
80 self.chkDevB.setEnabled(False)
81 if len(var_tmp[2]) == 0 :
82 self.chkDevC.setChecked(False)
83 self.chkDevC.setEnabled(False)
84 if len(var_tmp[3]) == 0 :
85 self.chkDevD.setChecked(False)
86 self.chkDevD.setEnabled(False)
87
88
42 self.var_list=[]
43
44 functions2.set_parameters(self) #Establece ciertos parametros, para pruebas
45 functions2.detect_devices(self) #busca los dispositivos de grabacion
46
47
89 48 def write(self, txt):
90 49 """
91 50 Escribe la salida estandar eb txtInfo
92 51 """
93 52 self.txtInfo.append(str(txt))
94
95
53
54
96 55 @pyqtSignature("")
97 56 def on_btnDpath_clicked(self):
98 57 """
99 58 Permite seleccionar graficamente el direcorio de los datos a grabar
100 59 """
101 var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
102 self.txtDpath.setText(var_Dpath)
103
104 #llamada a funcion
105 self.on_txtDpath_editingFinished()
60 self.var_Dpath= QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
61 self.txtDpath.setText(self.var_Dpath)
62 self.on_txtDpath_editingFinished() #llamada a funcion
106 63
107 64
108 65 @pyqtSignature("")
@@ -110,11 +67,9
110 67 """
111 68 Permite seleccionar graficamente el direcorio del proyecto
112 69 """
113 var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
114 self.txtRpath.setText(var_Rpath)
115
116 #llamada a funcion
117 self.on_txtRpath_editingFinished()
70 self.var_Rpath = QtGui.QFileDialog.getExistingDirectory(self, 'Open Directory', './', QtGui.QFileDialog.ShowDirsOnly)
71 self.txtRpath.setText(self.var_Rpath)
72 self.on_txtRpath_editingFinished() #llamada a funcion
118 73
119 74
120 75 @pyqtSignature("")
@@ -123,46 +78,9
123 78 Permite buscar los archivos de extension seleccionada en la ruta de de datos
124 79 y cargar los valores para el rango de tiempo a ser grabado
125 80 """
126
127 #Usando el modulo "subprocess", eric4 pide seleccion del tipo de subproceso (padre o hijo)
128 #por ello se prefiere usar el modulo "commands"
129 #p1= Popen(['find', var_Dpath, '-name', '*.r'], stdout=PIPE)
130 #p2= Popen(['awk', '-F/', '{print substr($NF,2,7)}'], stdin=p1.stdout, stdout=PIPE)
131 #output_p2= p2.communicate()[0]
132 #self.txtInfo.setText(output_p2)
133
134 #Se carga la variable con la ruta de datos
135 var_Dpath=self.txtDpath.text()
136
137 #Se verifica que la ruta exista y sea un directorio
138 var_cmd="test -d "+str(var_Dpath)
139 var_output=commands.getstatusoutput(var_cmd)[0]
140 if var_output != 0:
141 self.statusDpath = False
142 self.txtInfo.setText("Ruta no valida, output_error:" + str(var_output))
143 return
144 else:
145 self.statusDpath = True
146 self.txtInfo.append("Ruta valida, sin error:" + str(var_Dpath))
147
148 #Se buscan los archivos del tipo especificado
149 var_Dtype=self.txtDtype.text()
150 var_cmd="find " + str(var_Dpath) + " -name *."+ str(var_Dtype) +" | awk -F/ '{print substr($NF,2,7)}' | sort| uniq"
151 output_p2=commands.getstatusoutput(var_cmd)[1]
152
153 #Se cargan las listas para seleccionar StartDay y StopDay (QComboBox)
154 self.var_list=[]
155 for i in range(0, (len(output_p2)+1)/8):
156 self.var_list.append(output_p2[8*i:8*(i+1)-1])
157
158 self.lstStartDay.clear()
159 self.lstStopDay.clear()
160
161 for i in self.var_list:
162 self.lstStartDay.addItem(i)
163 self.lstStopDay.addItem(i)
164
165 self.lstStopDay.setCurrentIndex(self.lstStartDay.count()-1)
81 self.var_Dpath=self.txtDpath.text() #Se carga la variable con la ruta recien editada
82 self.statusDpath = functions.dir_exists(self.var_Dpath, self)
83 functions.load_days(self)
166 84
167 85
168 86 @pyqtSignature("")
@@ -170,19 +88,8
170 88 """
171 89 Valida la ruta del proyecto
172 90 """
173 #Se carga la variable con la ruta del proyecto
174 var_Rpath=self.txtRpath.text()
175
176 #Se verifica que la ruta exista y sea un directorio
177 var_cmd="test -d "+str(var_Rpath)
178 var_output=commands.getstatusoutput(var_cmd)[0]
179 if var_output != 0:
180 self.statusRpath = False
181 self.txtInfo.append("Ruta no valida, output_error:" + str(var_output))
182 return
183 else:
184 self.statusRpath = True
185 self.txtInfo.append("Ruta valida, sin error:" + str(var_Rpath))
91 self.var_Rpath=self.txtRpath.text() #Se carga la variable con la ruta recien editada
92 self.statusRpath = functions.dir_exists(self.var_Rpath, self)
186 93
187 94
188 95 @pyqtSignature("int")
@@ -200,7 +107,7
200 107 if index != 3:
201 108 self.txtDtype.setText(var_type)
202 109 self.txtDtype.setReadOnly(True)
203 self.on_txtDpath_editingFinished()
110 functions.load_days(self)
204 111 else:
205 112 self.txtDtype.setText('')
206 113 self.txtDtype.setReadOnly(False)
@@ -211,6 +118,7
211 118 """
212 119 Se activa cuando el tipo de archivo es ingresado manualmente
213 120 """
121 self.var_Dtype=self.txtDtype.text()
214 122 #llamada a funcion
215 123 self.on_txtDpath_editingFinished()
216 124
@@ -496,4 +404,3
496 404 var_dev = str(self.txtDeviceD.text())
497 405 var_cmd = 'eject ' + var_dev + '; eject -t ' + var_dev
498 406 commands.getstatusoutput(var_cmd)
499
@@ -6,7 +6,7
6 6 <rect>
7 7 <x>0</x>
8 8 <y>0</y>
9 <width>809</width>
9 <width>754</width>
10 10 <height>737</height>
11 11 </rect>
12 12 </property>
@@ -160,9 +160,12
160 160 <widget class="QLineEdit" name="txtElabel"/>
161 161 </item>
162 162 <item>
163 <widget class="QLineEdit" name="txtCopys">
164 <property name="text">
165 <string>0</string>
163 <widget class="QSpinBox" name="txtCopys">
164 <property name="sizePolicy">
165 <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
166 <horstretch>0</horstretch>
167 <verstretch>0</verstretch>
168 </sizepolicy>
166 169 </property>
167 170 </widget>
168 171 </item>
@@ -765,7 +768,7
765 768 <rect>
766 769 <x>0</x>
767 770 <y>0</y>
768 <width>809</width>
771 <width>754</width>
769 772 <height>21</height>
770 773 </rect>
771 774 </property>
@@ -823,7 +826,6
823 826 <tabstop>txtDtype</tabstop>
824 827 <tabstop>chkMST</tabstop>
825 828 <tabstop>txtElabel</tabstop>
826 <tabstop>txtCopys</tabstop>
827 829 <tabstop>lstStartDay</tabstop>
828 830 <tabstop>lstStopDay</tabstop>
829 831 <tabstop>chkSimultaneously</tabstop>
@@ -2,7 +2,7
2 2
3 3 # Form implementation generated from reading ui file '/home/ricardoar/JRO_SVN/eric4/jro_backup_manager/ui/MainWindow.ui'
4 4 #
5 # Created: Sun May 16 20:10:40 2010
5 # Created: Sun May 16 22:58:10 2010
6 6 # by: PyQt4 UI code generator 4.7.2
7 7 #
8 8 # WARNING! All changes made in this file will be lost!
@@ -12,7 +12,7
12 12 class Ui_MainWindow(object):
13 13 def setupUi(self, MainWindow):
14 14 MainWindow.setObjectName("MainWindow")
15 MainWindow.resize(809, 737)
15 MainWindow.resize(754, 737)
16 16 self.centralwidget = QtGui.QWidget(MainWindow)
17 17 self.centralwidget.setObjectName("centralwidget")
18 18 self.verticalLayout = QtGui.QVBoxLayout(self.centralwidget)
@@ -94,7 +94,12
94 94 self.txtElabel = QtGui.QLineEdit(self.tabParameters)
95 95 self.txtElabel.setObjectName("txtElabel")
96 96 self.horizontalLayout_5.addWidget(self.txtElabel)
97 self.txtCopys = QtGui.QLineEdit(self.tabParameters)
97 self.txtCopys = QtGui.QSpinBox(self.tabParameters)
98 sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
99 sizePolicy.setHorizontalStretch(0)
100 sizePolicy.setVerticalStretch(0)
101 sizePolicy.setHeightForWidth(self.txtCopys.sizePolicy().hasHeightForWidth())
102 self.txtCopys.setSizePolicy(sizePolicy)
98 103 self.txtCopys.setObjectName("txtCopys")
99 104 self.horizontalLayout_5.addWidget(self.txtCopys)
100 105 self.verticalLayout_2.addLayout(self.horizontalLayout_5)
@@ -426,7 +431,7
426 431 self.verticalLayout.addLayout(self.horizontalLayout_2)
427 432 MainWindow.setCentralWidget(self.centralwidget)
428 433 self.menubar = QtGui.QMenuBar(MainWindow)
429 self.menubar.setGeometry(QtCore.QRect(0, 0, 809, 21))
434 self.menubar.setGeometry(QtCore.QRect(0, 0, 754, 21))
430 435 self.menubar.setObjectName("menubar")
431 436 self.menuFile = QtGui.QMenu(self.menubar)
432 437 self.menuFile.setObjectName("menuFile")
@@ -471,8 +476,7
471 476 MainWindow.setTabOrder(self.lstDtype, self.txtDtype)
472 477 MainWindow.setTabOrder(self.txtDtype, self.chkMST)
473 478 MainWindow.setTabOrder(self.chkMST, self.txtElabel)
474 MainWindow.setTabOrder(self.txtElabel, self.txtCopys)
475 MainWindow.setTabOrder(self.txtCopys, self.lstStartDay)
479 MainWindow.setTabOrder(self.txtElabel, self.lstStartDay)
476 480 MainWindow.setTabOrder(self.lstStartDay, self.lstStopDay)
477 481 MainWindow.setTabOrder(self.lstStopDay, self.chkSimultaneously)
478 482 MainWindow.setTabOrder(self.chkSimultaneously, self.chkSequentially)
@@ -513,7 +517,6
513 517 self.chkMST.setText(QtGui.QApplication.translate("MainWindow", "MST-ISR Data", None, QtGui.QApplication.UnicodeUTF8))
514 518 self.lblElabel.setText(QtGui.QApplication.translate("MainWindow", "Exp. Label at device", None, QtGui.QApplication.UnicodeUTF8))
515 519 self.lblCopys.setText(QtGui.QApplication.translate("MainWindow", "Copys", None, QtGui.QApplication.UnicodeUTF8))
516 self.txtCopys.setText(QtGui.QApplication.translate("MainWindow", "0", None, QtGui.QApplication.UnicodeUTF8))
517 520 self.lblStartDay.setText(QtGui.QApplication.translate("MainWindow", "Start Day:", None, QtGui.QApplication.UnicodeUTF8))
518 521 self.lblStopDay.setText(QtGui.QApplication.translate("MainWindow", "Stop Day:", None, QtGui.QApplication.UnicodeUTF8))
519 522 self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabParameters), QtGui.QApplication.translate("MainWindow", "Parameters", None, QtGui.QApplication.UnicodeUTF8))
General Comments 0
You need to be logged in to leave comments. Login now