Example #1
0
    def do_show(self, line):
        """
        Showing the information about the module

        The things to show are: 'options' and 'command'.
            - 'options' will show the current values of each and every
                parameter.
            - 'command' will show the command needed to launch the module as is
                using the cli applications.

        Args:
        -----
            line: the string of the line typed.
        """
        if line.lower() == "options":
            print(general.emphasis("\n\tOptions\n\t-------\n"))
            for key in self.CONFIG.keys():
                print("\t- " +
                      (key + (" (*)." if self.CONFIG[key]["REQUIRED"] else ".")
                       ).ljust(14) + "" + self.CONFIG[key]["DESCRIPTION"])

            print(general.emphasis("\n\tCurrent values\n\t-------------\n"))
            for key in self.CONFIG.keys():
                print("\t- " +
                      (key + (" (*)" if self.CONFIG[key]["REQUIRED"] else "") +
                       ": ").ljust(14) +
                      general.info("" if self.CONFIG[key]["CURRENT_VALUE"] ==
                                   None else utils.listToString(
                                       self.CONFIG[key]["CURRENT_VALUE"])))

        elif line.lower() == "command":
            print(
                general.emphasis(
                    "\n\tTerminal command\n\t----------------\n\t\t") + "$ " +
                general.info(self.createCommandLine()))
Example #2
0
    def do_run(self, line):
        """
        Command that send the order to the framework to launch this util

        Args:
        -----
            line: The string of the line typed.
        """
        # Checking if all the required parameters have been set
        if self._checkIfRequiredAreSet():
            print(
                general.info("\nCollecting the options set by the user...\n"))
            # Getting the parser...
            parser = mailfy.getParser()

            # Generating the parameters
            params = self._getParams()

            args = parser.parse_args(params)

            print(
                general.info("\nLaunching " + self.UNAME +
                             " with the following parameters:") +
                general.emphasis("\t$ " + self.UNAME + " " +
                                 utils.listToString(params) + "\n"))

            try:
                mailfy.main(args)
            except Exception as e:
                print(
                    general.error(
                        "\n[!!] ERROR. Something happened when launching the utility. Type 'show options' to check the parameters.\n"
                    ))
                print(general.error("Traceback: " + str(e)))
        else:
            print(
                general.error(
                    "\n[!!] ERROR. There are required parameters which have not been set."
                ))
            self.do_show("options")
        print(general.success("Execution ended successfully."))