Пример #1
0
    def get_def_strings(self):
        """Returns pretty definition strings to be output to console

        :return: Tuple with main and translation strings
        """
        str_def_main, str_def_trans = "", ""
        if len(self.proposed_def) == 1:
            str_def_main = self.proposed_def[0]['Main']
            if 'Translation' in self.proposed_def[0]:
                str_def_trans = self.proposed_def[0]['Translation']
        else:
            # Show list with index of there is multiple definitions. Unselected definitions are shown in gray
            str_def_main, str_def_trans = "[", "["
            for i, definition in enumerate(self.proposed_def):
                i_ = i + 1
                color = ach.AnsiColorCode.DEFAULT
                if not self.selected_def[i]:
                    color = ach.AnsiColorCode.GRAY
                str_def_main += ach.color_str("%d: %s" % (i_, definition['Main']), color) + ", "
                str_aux_trans = ""
                if 'Translation' in definition:
                    str_aux_trans += definition['Translation']
                str_def_trans += ach.color_str("%d: %s" % (i_, str_aux_trans), color) + ", "
            str_def_main = str_def_main[:-2] + "]"
            str_def_trans = str_def_trans[:-2] + "]"

        return str_def_main, str_def_trans
Пример #2
0
def print_logo():
    """Prints the program starting logo"""
    # Georgia 11
    color = ach.AnsiColorCode.DARK_YELLOW
    print("")
    print(
        ach.color_str(
            "      db       .g8\"\"\"bgd `7MM\"\"\"Mq.   .g8\"\"8q. `7MN.   `7MF`YMM'   `MM`7MMM.     ,MMF'     db  MMP\"\"MM\"\"YMM `7MM\"\"\"YMM ",
            color))
    print(
        ach.color_str(
            "     ;MM:    .dP'     `M   MM   `MM..dP'    `YM. MMN.    M   VMA   ,V   MMMb    dPMM      ;MM: P'   MM   `7   MM    `7 ",
            color))
    print(
        ach.color_str(
            "    ,V^MM.   dM'       `   MM   ,M9 dM'      `MM M YMb   M    VMA ,V    M YM   ,M MM     ,V^MM.     MM        MM   d   ",
            color))
    print(
        ach.color_str(
            "   ,M  `MM   MM            MMmmdM9  MM        MM M  `MN. M     VMMP     M  Mb  M' MM    ,M  `MM     MM        MMmmMM   ",
            color))
    print(
        ach.color_str(
            "   AbmmmqMA  MM.           MM  YM.  MM.      ,MP M   `MM.M      MM      M  YM.P'  MM    AbmmmqMA    MM        MM   Y  ,",
            color))
    print(
        ach.color_str(
            "  A'     VML `Mb.     ,'   MM   `Mb.`Mb.    ,dP' M     YMM      MM      M  `YM'   MM   A'     VML   MM        MM     ,M",
            color))
    print(
        ach.color_str(
            ".AMA.   .AMMA. `\"bmmmd'  .JMML. .JMM. `\"bmmd\"' .JML.    YM    .JMML.  .JML. `'  .JMML.AMA.   .AMMA.JMML.    .JMMmmmmMMM",
            color))
    print("Acronymate", dv.define_acronymate_version, " - SAHR Projects 2021")
    print("")
Пример #3
0
 def get_str_pretty_definition_list(self, def_list):
     """Return formatted string with all definition ordered"""
     str_out = ""
     if len(def_list):
         str_out += "["
         for i, definition in enumerate(def_list):
             if i != 0:
                 str_out += ", "
             str_out += "{'%s'" % definition['Main']
             if 'Translation' in definition:
                 str_out += ", '%s'" % definition['Translation']
             str_out += "}"
         str_out += "]"
     else:
         str_out = ach.color_str(_("No encontrado"), ach.AnsiColorCode.GRAY)
     return str_out
Пример #4
0
def get_docx_filepath_from_user(acro_dict_handler):
    """Asks the user for a word document and returns it"""
    flag_finish = False
    print("")
    print(
        ach.color_str(
            _("INFO: Escribe 'config' como ruta para acceder al menú de configuración rápida"
              ), ach.AnsiColorCode.DARK_CYAN))
    while not flag_finish:
        input_path = input(
            _("Copia la ruta de la carpeta donde se encuentra el archivo a procesar: "
              ))
        if input_path.strip() == "config":
            config_menu(acro_dict_handler)
        else:
            try:
                files_in_path = Path(input_path).glob('*.docx')
                path_list = []
                counter = 0
                for f in files_in_path:
                    filename = pathHelpers.get_filename_from_path(f)
                    if filename[0] != '~':
                        print("  %d -" % (counter + 1),
                              pathHelpers.get_filename_from_path(f))
                        path_list.append(f)
                        counter += 1
                if len(path_list) == 0:
                    print_error(
                        _("ERROR - No se encuentran archivos '.docx' en la ruta seleccionada"
                          ))
                else:
                    flag_finish = True
            except OSError:
                print_error(
                    _("ERROR - El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos"
                      ))
    user_num = get_num_from_user(_("Selecciona el archivo a procesar"),
                                 lower=1,
                                 upper=len(path_list))

    filepath = path_list[user_num - 1]

    return filepath
Пример #5
0
def print_ok(str_in):
    """Prints a green string"""
    print(ach.color_str(str_in, ach.AnsiColorCode.GREEN))
Пример #6
0
def print_warn(str_in):
    """Prints a yellow string"""
    print(ach.color_str(str_in, ach.AnsiColorCode.YELLOW))
Пример #7
0
def print_error(str_in):
    """Prints a red string"""
    print(ach.color_str(str_in, ach.AnsiColorCode.RED))
Пример #8
0
def process_acro_found_one_by_one(acro_dict_handler, flag_auto_command):
    """Main interface, process acronyms one by one asking the user what to do

    :param acro_dict_handler: Acronym dictionary object
    :param flag_auto_command: Set to true to enter in semiautomatic mode
    """
    acro_list = sorted(acro_dict_handler.acros_found.keys(),
                       key=strHlprs.acro_ordering)
    acro_idx = 0
    flag_undo = False  # If True the acronym will try to be reverted
    while acro_idx < len(acro_list):
        # Create an auxilary object for each acronym
        aux_acro_obj = acroAuxObj.AcroAuxObj(acro_list[acro_idx],
                                             acro_dict_handler)
        if flag_undo:
            aux_acro_obj.remove_used_acro()
        flag_undo = False

        # Generate header and prints it
        max_acros = len(acro_dict_handler.acros_found.keys())
        str_header = (" %s (%d/%d) " %
                      (acro_list[acro_idx], acro_idx + 1, max_acros)).center(
                          80, '-')
        str_half_header = "_" * round(len(str_header) / 2)

        print("")
        print(str_header)

        # Print acronym matches
        print(ach.color_str(_("Coincidencias:"), ach.AnsiColorCode.BOLD),
              acro_dict_handler.acros_found[acro_list[acro_idx]]['Count'])
        for context in acro_dict_handler.acros_found[
                acro_list[acro_idx]]['Context']:
            print("     ", context)

        # Print found definitions
        print(str_half_header)

        print(_("Tabla del documento: "), end="")
        print(
            aux_acro_obj.get_str_pretty_definition_list(
                aux_acro_obj.def_list_doc_table))
        print(_("      Base de datos: "), end="")
        print(
            aux_acro_obj.get_str_pretty_definition_list(
                aux_acro_obj.def_list_db))
        if aux_acro_obj.defs_discrepancy():
            print_warn(
                _("Discrepancia detectada entre base de datos y tabla del documento"
                  ))

        # Ask the user for commands
        print(str_half_header)
        flag_finish = False
        while not flag_finish:
            str_def_main, str_def_trans = aux_acro_obj.get_def_strings()
            print(ach.color_str(_("  Acrónimo:"), ach.AnsiColorCode.BOLD),
                  acro_list[acro_idx],
                  end="")
            if aux_acro_obj.is_blacklisted():
                print(
                    ach.color_str(_(" (EN LISTA NEGRA)"),
                                  ach.AnsiColorCode.DARK_YELLOW))
            else:
                print("")
            print(ach.color_str(_(" Principal:"), ach.AnsiColorCode.BOLD),
                  str_def_main)
            print(ach.color_str(_("Traducción:"), ach.AnsiColorCode.BOLD),
                  str_def_trans)

            # Obtain user command or process automatic selection
            user_command = ""
            if flag_auto_command:
                if aux_acro_obj.is_blacklisted():
                    user_command = 'n'  # Skip blacklisted acronym
                else:
                    if aux_acro_obj.is_in_db(
                    ) and not aux_acro_obj.has_multiple_defs(
                    ) and not aux_acro_obj.defs_discrepancy():
                        user_command = 'y'
            if user_command == "":
                user_command = input(
                    _("Introduce comando") +
                    " (y/n/e/a/s/b/d/z/m/h): ").lower()

            if user_command == 'y':  # -- ACCEPT CHANGES --
                flag_finish = process_acro_command_accept(aux_acro_obj)
            elif user_command == 'n':  # -- DISCARD ACRONYM --
                flag_finish = process_acro_command_skip()
            elif user_command == 'e':  # -- EDIT --
                flag_finish = process_acro_command_edit(aux_acro_obj)
            elif user_command == 'a':  # -- ADD --
                flag_finish = process_acro_command_add(aux_acro_obj)
            elif user_command == 's':  # -- SELECT --
                flag_finish = process_acro_command_select(aux_acro_obj)
            elif user_command == 'b':  # -- BLACKLIST --
                flag_finish = process_acro_command_blacklist(aux_acro_obj)
            elif user_command == 'd':  # -- DELETE --
                flag_finish = process_acro_command_delete(aux_acro_obj)
            elif user_command == 'z':  # -- UNDO --
                flag_finish, acro_idx, flag_undo = process_acro_undo(acro_idx)
            elif user_command == 'm':  # -- MODE --
                flag_auto_command = process_acro_change_mode(flag_auto_command)
            elif user_command == 'h':  # -- HELP --
                print_process_acro_found_help()
            # -- default --
            else:
                print_error_unrecognized_command()
        acro_idx = acro_idx + 1