-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.py
More file actions
224 lines (185 loc) · 6.66 KB
/
Copy pathfile.py
File metadata and controls
224 lines (185 loc) · 6.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import sys
from Btree import BTree
from dropdown import dropdown
class File(object):
def __init__(self, ruta1=None, ruta2=None):
self.ruta1 = ruta1
self.ruta2 = ruta2
self.buffer = []
def remove_chars(self, lista, cadena):
for char in lista:
cadena = cadena.replace(char, "")
return cadena
def write_tree(self, BTree):
B_tree = BTree
with open("Index_Tree.txt", "w+") as f:
f.write(str(B_tree))
#print (B_tree)
def getRecords(self):
lista_records = []
with open(self.ruta1, "r+")as file:
lista_tipos = file.readline()
lista_tipos = self.remove_chars(["[","]","'","\n"," "],lista_tipos)
lista_tipos = lista_tipos.split(",")
lista_nombres = file.readline()
lista_nombres = self.remove_chars(["[","]","'","\n"," "],lista_nombres)
lista_nombres = lista_nombres.split(",")
cant = int(file.readline())
windo = dropdown(lista_nombres)
windo.show()
if windo.exec_():
valor = windo.reto()
indice = int(lista_nombres.index(valor))
aux = lista_nombres[0]
lista_nombres[0]= lista_nombres[indice]
lista_nombres[indice]= aux
aux = lista_tipos[0]
lista_tipos[0]= lista_tipos[indice]
lista_tipos[indice]= aux
for i in range(cant):
cadena = file.readline()
cadena = cadena.replace("\n","")
cadena = cadena.split("|")
aux = cadena[0]
cadena[0]= cadena[indice]
cadena[indice]= aux
lista_records.append(cadena)
return lista_records , [lista_tipos,lista_nombres,cant]
def getTypeF1(self):
file = open(self.ruta1, "r+")
tipos = file.readline()
tipos = self.remove_chars(["[", "]", "'", "\n"], tipos)
tipos = tipos.split(",")
file.close()
return tipos
def getTypeF2(self):
file = open(self.ruta2, "r+")
tipos = file.readline()
tipos = self.remove_chars(["[", "]", "'", "\n"], tipos)
tipos = tipos.split(",")
file.close()
return tipos
def getCeldasF1(self):
file = open(self.ruta1, "r+")
campos = file.readline()
campos = file.readline()
campos = self.remove_chars(["[", "]", "'", "\n"], campos)
campos = campos.split(",")
file.close()
return campos
def getCeldasF2(self):
file = open(self.ruta2, "r+")
campos = file.readline()
campos = file.readline()
campos = self.remove_chars(["[", "]", "'", "\n"], campos)
campos = campos.split(",")
file.close()
return campos
def getCantFile1(self):
file = open(self.ruta1, "r+")
file.readline()
file.readline()
cant= file.readline()
cant= cant.split("&")
#totales,head = aux[0],aux[1]
print "FILE 1",cant[0]
return int(cant[0])
def getCantFile2(self):
file = open(self.ruta2, "r+")
file.readline()
file.readline()
cant= file.readline()
cant = cant.split("&")
print "FILE 2",cant[0]
return int(cant[0])
def createNewFile(self,tipos, campos, cantidad):
self.tipos= tipos
self.campos= campos
self.cant= cantidad
file = open("mergeFile.qls", "w+")
file.write(str(self.tipos)+"\n")
file.write(str(self.campos)+"\n")
par = '%' + str(10) + 'd'
new_size = (par % self.cant)
file.write(str(new_size)+"&"+str(000000-1)+"\n")
file.close()
def write_in_newFile(self, indexList1, indexList2):
self.indexList1 = indexList1
self.indexList2= indexList2
print "-------"
print self.indexList1
print self.indexList2
file = open("mergeFile.qls", "r+")
file.readline()
file.readline()
file.readline()
file1 = open(self.ruta1, "r+")
file2 = open(self.ruta2, "r+")
file1.readline()
file1.readline()
file1.readline()
file2.readline()
file2.readline()
file2.readline()
lista_temp = []
print("este es cant" +str(self.cant))
for k in range(self.cant):
temp=[]
#print(k)
cadena1 = file1.readline()
cadena1 = cadena1.split("|")
cadena2 = file2.readline()
cadena2 = cadena2.split("|")
for j in range(len(self.indexList1)):
#print(str(cadena)+"--------------------i")
temp.append(cadena1[self.indexList1[j]]+"|")
print(len(self.indexList2))
for i in range(len(self.indexList2)):
#print(str(cadena)+"--------------------j")
if i==len(self.indexList2)-1:
temp.append(cadena2[self.indexList2[i]])
else:
temp.append(cadena2[self.indexList2[i]]+"|")
lista_temp.append(str(temp))
print "LENGTH", len(lista_temp)
for i in range(len(lista_temp)):
print(i)
print lista_temp[i]
print("escribire entry")
self.write_Entrys(lista_temp)
print("ya")
file.close()
file2.close()
file.close()
def write_Entrys(self, registros):
file = open("mergeFile.qls", "r+")
file.readline()
file.readline()
file.readline()
for i in range(len(registros)):
cadena = registros[i]
cadena = self.remove_chars(["[", "]", "'", ","], cadena)
file.write(str(cadena)+"\n")
print "FUCK YA-----------"
def write_entry(self,buffer):
self.buffer = buffer
for registro in self.buffer:
with open(self.ruta1, "a+") as file:
cadena = ""
for i in range(len(registro)):
if i == len(registro)-1:
cadena += str(registro[i])+"\n"
else:
cadena += str(registro[i])+"|"
file.write(cadena)
with open(self.ruta1, "r+") as file:
aux = ""
for i in range(3):
aux = file.readline()
par = '%' + str(10) + 'd'
total = int(aux.split("&")[0])+len(self.buffer)
new_size = (par % total)
end = (par%int(aux.split("&")[1]))
file.seek(-22, 1)
file.write(new_size+"&"+end+"\n")
self.buffer = []