def main(): sqlIgnore = re.compile("^[--].*") regexNomeTabela = re.compile("CREATE TABLE ([^\s]+)") regexDependencia = re.compile("REFERENCES ([^\s]+)") try: estrutura = open(args.fileName, "r") except FileNotFoundError as err: print(err) #Lista de todas as tabelas referenciadas no arquivo de estrutura listaTabela = ListaTabela() #lista de tabelas povoadas tabelasPovoadas = ListaTabela() linha = "" for line in estrutura: if not (sqlIgnore.match(line)): linha = linha + line if (';' in line): #Faz com que cada bloco do código SQL seja lido em uma única linha linha = linha.replace('\n', ' ') nome = regexNomeTabela.search(linha) dependencias = regexDependencia.findall(linha) if (nome != None): tabela = Tabela(nome.group(1)[1:-1]) listaTabela.add_tabela(tabela) #Adiciona todas as referenências encontradas, retirando os limitadores (aspas) tabela.add_dependencias([d[1:-1] for d in dependencias]) #Adiciona as tabelas sem dependencias na lista de tabelas povoadas if not (dependencias): tabelasPovoadas.add_tabela(tabela) #Limpa a variável para a próxima iteração linha = "" while True: for t in listaTabela.list: if (len(t.dependencias) > 0 and not tabelasPovoadas.find_nome(t.nome)): flag_add_table = True for d in t.dependencias: if not (tabelasPovoadas.find_nome(d)): flag_add_table = False if (flag_add_table): tabelasPovoadas.add_tabela(t) if (len(tabelasPovoadas.list) >= len(listaTabela.list)): break print('\n'.join([t.nome for t in tabelasPovoadas.list]))
def main(): sqlIgnore = re.compile("^[--].*") regexNomeTabela = re.compile("CREATE TABLE ([^\s]+)") regexDependencia = re.compile("REFERENCES ([^\s]+)") try: estrutura = open(args.fileName, "r") except FileNotFoundError as err: print(err) #Lista de todas as tabelas referenciadas no arquivo de estrutura listaTabela = ListaTabela() #lista de tabelas povoadas tabelasPovoadas = ListaTabela() linha = "" for line in estrutura: if not (sqlIgnore.match(line)): linha = linha + line if (';' in line): #Faz com que cada bloco do código SQL seja lido em uma única linha linha = linha.replace('\n', ' ') nome = regexNomeTabela.search(linha) dependencias = regexDependencia.findall(linha) if(nome != None): tabela = Tabela(nome.group(1)[1:-1]) listaTabela.add_tabela(tabela) #Adiciona todas as referenências encontradas, retirando os limitadores (aspas) tabela.add_dependencias([d[1:-1] for d in dependencias]) #Adiciona as tabelas sem dependencias na lista de tabelas povoadas if not(dependencias): tabelasPovoadas.add_tabela(tabela) #Limpa a variável para a próxima iteração linha = "" while True: for t in listaTabela.list: if(len(t.dependencias) > 0 and not tabelasPovoadas.find_nome(t.nome)): flag_add_table = True for d in t.dependencias: if not(tabelasPovoadas.find_nome(d)): flag_add_table = False if(flag_add_table): tabelasPovoadas.add_tabela(t) if (len(tabelasPovoadas.list) >= len(listaTabela.list)): break print ('\n'.join([t.nome for t in tabelasPovoadas.list]))
def dodaj_tabelo(self, tabela=None): # še funkcija dodaj [tabele] if tabela == None: a = True tabela = Tabela(None, self) else: if tabela in self.tabele: print(colored('POZOR!: Ista tabela je dodana večkrat v isto bazo', 'red')) a = False self.tabele.append(tabela) if self.tabele_imena is None: self.tabele_imena = [] self.tabele_imena.append(tabela.tabela_ime) if a == True: return tabela
def req_tabela(self, *args): ids = [self.ids.tex1, self.ids.tex2] self.pop = Popup(title='Tabela', content=Tabela(DataFrame=df, ids_list=ids), size_hint=(0.5, 0.5)) self.pop.open()
k = m - len(str(self.tabele_imena[i])) s = ' ' * k print(space + colored(str(self.tabele_imena[i]), 'magenta') + s + puscica + str(self.tabele[i])) else: print(space + str(None)) print('Prebrano iz SQL: ' + str(self.prebrano_iz_SQL)) print('Neshranjene spremembe: ' + str(self.neshranjene_spremembe)) print() if __name__ == "__main__": b = Baza('Aladeen') b.izpis() t=Tabela('Neki') t.dodaj_vrstico() t.dodaj_vrstico() t.dodaj_vrstico() t.dodaj_vrstico() t.dodaj_vrstico() t1=Tabela('Neki druzga') t1.dodaj_vrstico() t1.dodaj_vrstico() t1.dodaj_vrstico() s1=Stolpec('neki bolšga') s1.izpis() s2=t.dodaj_podoben_stolpec(s1) s3=t1.dodaj_podoben_stolpec(s2) s1.izpis() s2.izpis()
def cb_vnos(self, text): self.qt.tab[self.stolpec_stevilo] = text def ch_vnos(self, text): self.qt.tab[self.stolpec_stevilo] = text if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) a = QtWidgets.QWidget() a.setMinimumSize(300, 300) b = QtWidgets.QVBoxLayout() c = QtFunkcije() t = Tabela('Stoški') i = Stolpec('ime', t) i.attribute = 'le' m = Stolpec('mesečni', t) m.attribute = 'ch' v = Stolpec('vrednost', t) k = Stolpec('kategorija', t) k.attribute = 'cb' t.tabela_ime = 'tabela' t.dodaj_vrstico() v = t.dodaj_vrstico() v.vrstica_vrednosti = [1, 2, 3, 4] t.dodaj_vrstico()
def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.setupUi(self) self.tabela = Tabela(self.tabela) self.tabela2 = Tabela(self.tabela2)
class MyMainWindow(QtGui.QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.setupUi(self) self.tabela = Tabela(self.tabela) self.tabela2 = Tabela(self.tabela2) def add_estado(self): text = str(self.campo_estado.text()) if text == '' or text in self.tabela.y_rotulos: return for t in text: if t not in ascii_uppercase: return self.tabela.add_y_rotulo(text) def add_terminal(self): text = str(self.campo_terminal.text()) if text == '' or text in self.tabela.x_rotulos: return for t in text: if t not in ascii_lowercase: return self.tabela.add_x_rotulo(text) def minimizar(self): a = self.criar_automato() if a is None: return a = a.minimizar() self.automato_para_tabela(a) def determinizar(self): a = self.criar_automato() if a is None: return a = a.determinizar() self.automato_para_tabela(a) def swap_tables(self): t1=self.tabela t2=self.tabela2 t2cc = t2.n_colunas() t2rc = t2.n_linhas() t2bkp=[] for i in range(t2rc): t2bkp.append([]) for j in range(t2cc): t2bkp[i].append(t2.item(i,j)) t2.tabela.setColumnCount(t1.tabela.columnCount()) t2.tabela.setRowCount(t1.tabela.rowCount()) for i in range(t1.n_linhas()): for j in range(t1.n_colunas()): t2.set_item(i, j, t1.item( i, j)) t1.tabela.setColumnCount(t2cc) t1.tabela.setRowCount(t2rc) for i in range(t2rc): for j in range(t2cc): t1.set_item(i, j, t2bkp[i][j]) t1.x_rotulos, t2.x_rotulos = t2.x_rotulos, t1.x_rotulos t1.y_rotulos, t2.y_rotulos = t2.y_rotulos, t1.y_rotulos t1.inicial,t2.inicial = t2.inicial,t1.inicial t1.finais,t2.finais = t2.finais,t1.finais self.tabela.refresh() self.tabela2.refresh() def msg(self, mensagem, informative=''): dialog = QMessageBox() dialog.setText(mensagem) if informative != '': dialog.setInformativeText(informative) dialog.exec_() def criar_automato(self): a = Automato() for terminal in self.tabela.x_rotulos: a.inserir_terminal(terminal) for estado in self.tabela.y_rotulos: a.inserir_estado(estado.lstrip('->*')) for i in range(self.tabela.n_linhas()): line = self.tabela.get_linha(i) atual = self.tabela.y_rotulos[i].lstrip('->*') for j in range(len(line)): terminal = self.tabela.x_rotulos[j] final = line[j] if final == '' or final == '-': continue for letra in final: if final == 'Qerr': break if letra not in ascii_uppercase: if letra not in ['@',',','&']: self.msg('Transicao para nao-estado detectada.', atual+' + '+terminal+' = '+final) return None #Verificar se "final" esta na lista de estados for item in final.split(','): if item not in a.estados and item != '@': self.msg('Transicao para um estado inexistente.', atual+' + '+terminal+' = '+final) return None a.inserir_transicao(atual, terminal, item) a.inserir_estado_inicial(self.tabela.inicial) for final in self.tabela.finais: a.inserir_estado_final( final ) if self.tabela.finais == []: self.msg('O automato deve ter ao menos um estado final.') return None if self.tabela.inicial == '': self.msg('O automato deve ter um estado inicial.') return None return a def set_final(self,i=-1): self.tabela.set_final(i) def set_initial(self,i=-1): self.tabela.set_initial(i) def automato_para_tabela(self, automato): t=self.tabela2 t.reset() for e in sorted(automato.transicoes): t.add_y_rotulo(e) for ter in sorted(automato.alfabeto): t.add_x_rotulo(ter) for i, e in enumerate(sorted(automato.transicoes)): for j, ter in enumerate(sorted(automato.transicoes[e])): finais='' for k, f in enumerate(automato.transicoes[e][ter]): finais = finais + str(f) + ',' finais = finais.rstrip(',') t.set_item(i, j, finais) for f in automato.finais: t.set_final(t.y_rotulos.index(f)) for j, estado in enumerate(t.y_rotulos): if estado.lstrip('->*') == automato.inicial: t.y_rotulos[j] = t.y_rotulos[j].replace('->','') t.set_initial(j) break def gramatica_para_automato(self): text = self.textEdit.toPlainText().toAscii() text = str(text).splitlines() g = Gramatica() for line in text: g.inserir_producao(str(line)) a = g.transformar_automato() a.imprimir() self.automato_para_tabela(a) def automato_para_gramatica(self): a = self.criar_automato() g = Gramatica() lines = g.transformar_gramatica(a) self.textEdit.clear() for line in lines: self.textEdit.append(line) def limpar_tabela(self): self.tabela.reset() def salvar(self, nome='sem_titulo.txt'): text = str(self.line_edit_salvar.text().toAscii()) if text != '': nome = text else: self.msg('Salvo como \"sem_titulo.txt\".') f = open(nome, 'w') if not f: return a = self.criar_automato() dump(a, f) f.close() def carregar(self, nome='sem_titulo.txt'): text = str(self.line_edit_salvar.text().toAscii()) if text != '': nome = text else: self.msg('Tentanto carregar \"sem_titulo.txt\".') f = open(nome) if not f: return a = load(f) self.automato_para_tabela(a) f.close() def listar_sentencas(self): a = self.criar_automato() n = self.spinBox.value() lines = a.enumerar_sentencas(n) self.textEdit_2.clear() for line in lines: self.textEdit_2.append(line) def reconhecer_sentenca(self): s = str(self.textEdit_2.toPlainText().toAscii()) if len(s.splitlines()) > 1: self.msg('Atencao: Apenas a primeira linha do campo eh levada em consideracao.') s = s.splitlines()[0] a = self.criar_automato() if not a: return if a.reconhecer_sentenca(s): self.msg('Sentenca reconhecida.') else: self.msg('Sentenca nao reconhecida.') def comparar_ERs(self): er1 = str(self.line_edit_ER1.text().toAscii()) er2 = str(self.line_edit_ER2.text().toAscii()) ER = Expressao_Regular() a1 = ER.thompson_modificado(er1) a2 = ER.thompson_modificado(er2) t = Transformacoes() resposta = t.automatos_equivalentes(a1, a2, Automato()) if resposta: self.msg('Expressoes equivalentes.') else: self.msg('Expressoes nao equivalentes.') def ER_para_automato(self): text = str(self.line_edit_ER_para_automato.text().toAscii()) if text == '': self.msg('Expressao vazia!') return ER = Expressao_Regular() a = ER.thompson_modificado(text) self.automato_para_tabela(a)