def delete(self, tipo_estru, hmo, file_name):
     dso = ds.EstruturasDados()
     if tipo_estru == 1:  # read a list
         my_lista = dso.lista
         print('\n\n DELETE LISTA \n')
         my_lista.clear()
         print(my_lista)
         hmo.my_set(my_lista, 1)
         return
     elif tipo_estru == 2:  # create a dictionary
         my_dicio = dso.dicio
         print('\n\n DELETE DICIONARIO \n')
         my_dicio.clear()
         print(my_dicio)
         hmo.my_set(my_dicio, 1)
         return
     elif tipo_estru == 3:  # delete content in thefile
         print('\n\n DELETANDO O ARQUIVO -> {} \n'.format(file_name))
         all_files = glob.glob('*.txt')
         if file_name in all_files:
             os.unlink(file_name)
         hmo.feedback()
         return
     elif tipo_estru == 4:  # create a set
         print('\n\n DELETE CONJUNTO \n')
         my_conju = dso.conj
         my_conju.clear()
         print(my_conju)
         hmo.my_set(my_conju, 4)
         return
     else:
         pass
 def read(self, tipo_estru, file_name):
     dso = ds.EstruturasDados()
     if tipo_estru == 1:  # read the list
         my_lista = dso.lista
         print('\n\n APRESENTACAO DA LISTA \n')
         print(my_lista)
         print('\n\n')
         return
     elif tipo_estru == 2:  # read the dictionary
         my_dicio = dso.dicio
         print('\n\n APRESENTACAO DO DICIONARIO \n')
         print(my_dicio)
         print('\n\n')
         return
     elif tipo_estru == 3:  # read  the file
         print('\n\n LEITURA DE ARQUIVO --> {} \n\n'.format(file_name))
         arquivo = open(file_name, 'r', encoding="utf-8")
         # dados_arq = arquivo.readlines()
         for d in arquivo:
             print(d)
         arquivo.close()
         print('\n\n')
         return
     elif tipo_estru == 4:  # read the set
         print('\n\n APRESENTACAO DO CONJUNTO \n')
         my_conj = dso.conj
         print(my_conj)
         print('\n\n')
         return
     else:
         pass
    def file2oper(self):
        dso = ds.EstruturasDados()
        len = dso.arq.__len__()
        # real_len = len - 1
        print('\n ARQUIVOS DISPONÍVEIS PRA OPERAR \n')

        # file = None
        yes_file = False
        while yes_file is False:
            for ind in range(len):
                p = ind + 1
                print('\n [{}] -> {}'.format(p, dso.arq[ind]))
            quit = 'quit'
            zero = 0
            print('\n [{}] -> {}'.format(zero, quit))
            try:
                option =  int(input('\n Enter your option:  '))
                if option in range(1, len + 1):
                    file = dso.arq[option-1]
                    yes_file = True
                elif option is 0:
                    file = 'quit'
                    yes_file = True
                else:
                    print('\n You entered --> {}'.format(option))
                    print('\n WARNING: INVALID OPTION!!!')
                    print('\n You entered a NUMBER do not listed on MENU ABOUVE\n')
            except Exception as error:
                print('\n WARNING: INVALID OPTION!!!')
                print('\n You entered a STRING/CARACTER')
                print('\n PYTHON SAID: {}'.format(error))
        return file
 def my_get(self, owner):
     dso = ds.EstruturasDados()
     if owner == 1:
         if dso.lista:
             return 1
         else:
             return 0
     elif owner == 2:
         if dso.dicio:
             return 1
         else:
             return 0
     elif owner == 3:
         # print(dso.arq)
         if dso.arq.__len__() > 0:
             return 1
         else:
             return 0
     elif owner == 4:
         if dso.conj:
             return 1
         else:
             return 0
     else:
         pass
 def all_values_conj(self):
     dso = ds.EstruturasDados()
     conj = dso.conj
     preench = True
     ind = conj.__len__()
     valor = None
     while preench is True:
         ind = ind + 1
         print('\n Informe um numero, caractere ou palavra pra Conjunto[%d]' % (ind + 1))
         print('\n quit -> pra sair')
         help_value = input('\n Enter some: ')
         if help_value.isnumeric():
             valor = int(help_value)
             conj.add(valor)
             print(conj)
             ind = ind + 1
         elif help_value.isalpha() and (help_value != 'QUIT' and help_value != 'quit'):
             conj.add(help_value)
             print(conj)
             ind = ind + 1
         elif help_value == 'QUIT' or help_value == 'quit':
             preench = False
             self.my_set(conj, 1)
         elif help_value.isalnum():
             preench = True
         else:
             pass
     return
    def all_values_dict(self):
        dso = ds.EstruturasDados()
        dicio = dso.dicio
        preench = True
        ind = dicio.__len__()
        valor = None
        while preench is True:
            print('\n Informe um numero, caractere ou palavra pra Dicionario[%d]' %(ind + 1))
            print('\n quit -> pra sair')
            help_value = input('\n Enter some: ')

            if help_value.isnumeric():
                ind = ind + 1
                valor = int(help_value)
                dicio[(ind)] = valor
                print(dicio)
            elif help_value.isalpha() and (help_value != 'QUIT' and help_value != 'quit'):
                ind = ind + 1
                dicio[(ind)] = help_value
                print(dicio)
            elif help_value == 'QUIT' or help_value == 'quit':
                preench = False
                self.my_set(dicio, 2)
            elif help_value.isalnum():
                preench = True
            else:
                pass
        return
 def all_values_lista(self):
     dso = ds.EstruturasDados()
     lista = dso.lista
     preench = True
     ind = lista.__len__()
     valor = None
     while preench is True:
         print('\n Informe um numero, caractere ou palavra pra Lista[%d]' %(ind + 1))
         print('\n quit -> pra sair')
         help_value = input('\n Enter some: ')
         if help_value.isnumeric():
             valor = int(help_value)
             lista.append(valor)
             print(lista)
             ind = ind + 1
         elif help_value.isalpha() and (help_value != 'QUIT' and help_value != 'quit'):
             lista.append(help_value)
             print(lista)
             ind = ind + 1
         elif help_value == 'QUIT' or help_value == 'quit':
             preench = False
             self.my_set(lista, 1)
         elif help_value.isalnum():
             preench = True
         else:
             pass
     return
 def my_set(self, instance, value):
     dso = ds.EstruturasDados()
     if value == 1:
         dso.lista = instance
     elif value == 2:
         dso.dicio = instance
     elif value == 3:
         dso.arq = instance
     elif value == 4:
         dso.conj = instance
     else:
         pass
Ejemplo n.º 9
0
def main_app(run):
    dso = ds.EstruturasDados()
    hmo = hm.HelperModule()

    hmo.app_info()

    while run is True:
        root_dir_path = os.path.dirname(os.path.abspath(__file__))
        # os.chdir(root_dir_path)
        print('CURRENT DIR: {}'.format(root_dir_path))
        opcao = hmo.menu()
        if opcao == 1:
            hmo.info_structure('lista')
            dso.metodoLitas(hmo)
        elif opcao is 2:
            hmo.info_structure('dicionario')
            dso.metodoDicionario(hmo)
        elif opcao is 3:
            hmo.info_structure('arquivo')
            dso.metodoArquivo(hmo, root_dir_path)
            dso.arq.clear()  # clear the controll list of files created
        elif opcao == 4:
            hmo.info_structure('conjunto')
            dso.metodoConjuntos(hmo)
        else:
            bye = """
            ------------------------------------
                O(a) Sr(a), escolheu SAIR. 
                A aplicacao sera encerrada.\n
                Grande abraço e Good bye.
            ------------------------------------ 
            """
            print('\n {}'.format(bye))
            print('\n\n\n')
            t.sleep(5)
            run = False
    return
    def update(self, tipo_estru, hmo, file_name, up_type):
        dso = ds.EstruturasDados()

        if tipo_estru == 1:  # read a list
            my_lista = dso.lista
            print('\n\n ATUALIZACAO \n')
            op = int(
                input(
                    ' 1 -> Atualizar lista interia \n 2 -> Apenas um elemento \n\n  Sua opcao aqui:   '
                ))
            print('\r')
            if op is 1:
                aux = True
                k = 0
                tam = my_lista.__len__()
                while aux is True:
                    valor = int(
                        input('\n Informe um valor p/ [%d] ou 0 pra sair:  ' %
                              (k)))
                    if type(valor) is int and valor != 0 and k < tam:
                        my_lista.pop(k)
                        my_lista.insert(k, valor)
                        k = k + 1
                        print(my_lista)
                    elif type(valor) is int and valor != 0 and k >= tam:
                        my_lista.append(valor)
                        k = k + 1
                        print(my_lista)
                    else:
                        hmo.my_set(my_lista, 1)
                        return my_lista
            elif op is 2:
                k = int(input('\n Informe a posicao do elemento:  '))
                v = int(input('\n Informe o novo valor:  '))
                my_lista.pop(k)
                my_lista.insert(k, v)
                print(my_lista)
                print('\n\n\n')
                hmo.my_set(my_lista, 1)
                return
        elif tipo_estru == 2:  # create a dictionary
            my_dicio = dso.dicio
            print('\n\n ATUALIZACAO \n')

            # op = int(input(' 1 -> Atualizar dicionario interio \n 2 -> Apenas um elemento \n\n  Sua opcao aqui:   '))
            options = ['Atualizar dicionario interio', 'Apenas um elemento']
            op = hmo.generate_menu(options)
            print('\r')
            if op is 1:  # Atualizar dicionario interio
                aux = True
                tam = my_dicio.__len__()
                k = 1
                while aux is True:
                    valor = input(
                        '\n Informe um valor p/ [%d] ou "quit" pra sair:  ' %
                        (k))
                    if valor.isalpha() and valor != 'quit' and k <= tam:
                        my_dicio.pop(k)
                        my_dicio.setdefault(k, valor)
                        k = k + 1
                        print(my_dicio)
                    elif valor.isnumeric() and valor != 0 and k <= tam:
                        my_dicio.pop(k)
                        my_dicio.setdefault(k, int(valor))
                        k = k + 1
                    elif valor.isnumeric() and valor != 0 and k > tam:
                        real_value = int(valor)
                        my_dicio.setdefault(k, real_value)
                        k = k + 1
                        print(my_dicio)
                    elif valor.isalpha() and valor != 'quit' and k > tam:
                        my_dicio.setdefault(k, valor)
                        k = k + 1
                        print(my_dicio)
                    elif valor == 'quit':
                        hmo.my_set(my_dicio, 1)
                        return
                    else:
                        pass

            elif op is 2:  # Apenas um elemento
                k = int(input('\n Informe a posicao do elemento:  '))
                v = input('\n Informe o novo valor/dado:  ')
                if k <= 0 or k > my_dicio.__len__():
                    print(
                        '\n\n WARNING: INVALID POSITION \n THIS ACTION WILL BE QUITED \n\n'
                    )
                    t.sleep(4)
                    return
                elif v.isnumeric():
                    my_dicio.pop(k)
                    my_dicio.setdefault(k, float(v))

                    print(my_dicio)
                    print('\n\n\n')
                    hmo.my_set(my_dicio, 1)
                    return
                elif v.isalpha():
                    my_dicio.pop(k)
                    my_dicio.setdefault(k, v)

                    print(my_dicio)
                    print('\n\n\n')
                    hmo.my_set(my_dicio, 1)
                    return
                else:
                    print(
                        '\n\n WARNING: INVALID VALUE \n THIS ACTION WILL BE QUITED \n\n'
                    )
                    t.sleep(4)
                    return
        elif tipo_estru == 3:  # update a file
            print('\n\n ATUALIZACAO DE ARQUIVO --> {}\n'.format(file_name))
            if up_type == 'add':
                self.update_add(hmo, file_name)
                return
            elif up_type == 'replace':
                self.update_replace(hmo, file_name)
                return
            else:
                pass
        elif tipo_estru == 4:  # create a set
            print('\n\n ATUALIZACAO DO CONJUNTO \n')
            my_conj = dso.conj
            op = int(
                input(
                    ' 1 -> Atualizar CONJUNTO interio \n 2 -> Apenas um elemento \n\n  Sua opcao aqui:   '
                ))
            print('\r')
            if op is 1:  # 1 Atualizar CONJUNTO interio
                aux = True
                tam = my_conj.__len__()
                k = 1
                while aux is True:
                    valor = int(
                        input(
                            '\n Informe um inteiro p/ set[%d] ou 0 pra sair:  '
                            % (k)))
                    if type(valor) is int and valor != 0 and k <= tam:
                        my_conj.pop()
                        my_conj.add(valor)
                        k = k + 1
                        print(my_conj)
                    elif type(valor) is int and valor != 0 and k > tam:
                        my_conj.add(valor)
                        k = k + 1
                        print(my_conj)
                    else:
                        hmo.my_set(my_conj, 4)
                        aux = False
                return
            elif op is 2:  #  Atualizar apenas um elemento
                old_value = int(input('\n Informe o valor atual:  '))
                new_value = int(input('\n Digite um novo valor:  '))
                my_conj.remove(old_value)
                my_conj.add(new_value)
                print(my_conj)
                print('\n\n\n')
                hmo.my_set(my_conj, 4)
                return
        else:
            pass
 def prepare2read(self):
     dso = ds.EstruturasDados()
     # self.change_dir(2)
     for file in glob.glob('*.txt'):
         dso.arq.append(file)