Beispiel #1
0
 def _clean_db_file():
     # Clean the database. This operation is not suggested.
     Colored.print_warning(
         "Deleting database may cause trouble. Are you sure?[y/N]: ",
         end='')
     if input() == 'y':
         open(settings.DB_NAME, 'w').close()
def check_running_instance():
    "check for running instances."
    if Lock().is_locked:
        Colored.print_warning(
            "Another instance already running."
        )
        sys.exit()
def check_chrome_driver():
    "check the driver exist or not"
    if settings.MASTER_WITH_GUI and not os.path.isfile(settings.CHROME_DRIVER):
        Colored.print_error("Failed to locate chromedriver.")
        Colored.print_error(
            "Please locate the driver under base path "
            "or define it's path in settings.py"
        )
        sys.exit("Exiting...")
def initial_check():
    "do initial checks"
    Colored.print_debug("Initial check. Please wait...")

    check_running_instance()
    check_settings()
    check_ffmpeg_exe()
    check_chrome_driver()

    Colored.print_info("Initial check is done. Everything is well\n")
Beispiel #5
0
def read_console_commands():
    "Waits for console inputs"

    console_executor = ConsoleCommandExecutor(Q)
    COMPLATER.add_options(*console_executor.callables)

    while console_executor:
        Colored.print_debug("Please enter the command: ", end='')
        command = autocomplate_input().strip().lower()

        console_executor(command)
Beispiel #6
0
    def start(self):
        "starts the application. Usage: start"
        self.queue.state = True

        if self.slave and self.slave.is_alive(
        ) and self.master and self.master.is_alive():
            Colored.print_warning("Application is already running!")
            return

        self.slave, self.master = self._create_processes()

        logger.debug("Application starting...")
        self.slave.start()
        self.master.start()
        logger.debug("Application started")
Beispiel #7
0
 def _print_help(self, function_string, printed_helps):
     try:
         function = getattr(self, function_string)
     except AttributeError:
         Colored.print_warning(
             "No help found for {0}".format(function_string))
         return
     if printed_helps and function in printed_helps:
         # Sometimes different functions does the same
         # operation. No need to print them
         return
     printed_helps.append(function)
     docstring = function.__doc__
     help_message, usage = docstring.split("Usage: ")
     name = function.__name__
     Colored.print_green("\t{0:15}: {1}\n\t{2}Usage: {3}".format(
         name, help_message, ' ' * 17, usage))
Beispiel #8
0
    def status():
        "print the status of the program. Usage: status"
        active_processes = active_children()
        active_threads = [
            thread for thread in threading.enumerate()
            if thread.name != "MainThread" and thread.is_alive()
        ]

        Colored.print_yellow("Active Processes:")
        for active_process in active_processes:
            Colored.print_green("\t{0}".format(active_process.name))

        Colored.print_yellow("Active Threads:")
        for active_thread in active_threads:
            Colored.print_green("\t{0}".format(active_thread.name))
Beispiel #9
0
    def clear(self, *options):
        "clears the given output file/folder(s). " \
            "Usage: clear <log/downloads/shared/screen/all>"
        clear_options = ("log", "downloads", "shared", "screen", "all")

        if not options:
            raise TypeError

        for option in options:
            if option not in clear_options:
                Colored.print_error(
                    "\t{0} is not an option for this command".format(option))
                continue

            if option in ("log", "all"):
                self._clean_log_file()
            if option in ("downloads", "all"):
                self._clean_downloads()
            if option in ("shared", "all"):
                self._clean_shared()
            if option in ("screen", "all"):
                os.system("cls")
            if option in ("db", ):
                self._clean_db_file()
Beispiel #10
0
 def set(name, *options):
     "set the value of given name to database. Usage: set <name> <value>"
     value = "".join([str(option) for option in options])
     try:
         set_realtime_setting(name.upper(), value)
     except AttributeError:
         Colored.print_error("No record found to update.")
     except ValueError:
         Colored.print_error("Could not convert string to float.")
     except ZeroDivisionError:
         Colored.print_error("division by zero")
Beispiel #11
0
 def get(name):
     "return the value of given name from database. Usage: get <name>"
     try:
         value = get_realtime_setting(name.upper())
         if value is None:
             Colored.print_error("No record found for {0}".format(name))
         else:
             Colored.print_green(value)
     except AttributeError:
         exc_info = sys.exc_info()
         Colored.print_error(traceback.format_exception(*exc_info))
def check_ffmpeg_exe():
    "check the video upload executable"
    if settings.MASTER_WITH_GUI:
        # In GUI mode, no need execuable
        return
    try:
        imageio.plugins.ffmpeg.get_exe()
    except imageio.core.fetching.NeedDownloadError:
        Colored.print_error("Failed to import video upload library.")
        Colored.print_warning("Downloading the executable. Please wait...")
        imageio.plugins.ffmpeg.download()
        Colored.print_warning(
            "\nDownload has been completed. Program should be restarted."
        )
        sys.exit("Exiting...")
Beispiel #13
0
    def call(self, text):
        "call the related function from string"
        try:
            command, *options = text.split()
        except ValueError:
            return

        try:
            if command not in self.callables:
                raise AttributeError
            getattr(self, command)(*options)
        except AttributeError:
            Colored.print_warning("Unknown command. ", end='')
            correctness = Correctness(self.callables)
            word = correctness.spell_check(command)
            if word:
                Colored.print_warning("Did you mean {0}".format(word))
            else:
                Colored.print_warning(
                    "Type help to see entire commands and it's usages.")
        except TypeError:
            Colored.print_warning(
                "Invalid argument. Type help {0} for help".format(command))
def check_settings():
    "Check the settings"
    if settings.SLAVE_USERNAME is None:
        Colored.print_error("Username of slave not defined.")
        sys.exit()
    if settings.SLAVE_PASSWORD is None:
        Colored.print_error("Password of slave not defined.")
        sys.exit()
    if settings.MASTER_USERNAME is None:
        Colored.print_error("Username of master not defined.")
        sys.exit()
    if settings.MASTER_PASSWORD is None:
        Colored.print_error("Password of master not defined.")
        sys.exit()

    try:
        urllib.request.urlopen("http://www.google.com", timeout=5)
    except urllib.error.URLError:
        Colored.print_error("No internet connection.")
        if settings.DEFAULT_PROXY is None:
            Colored.print_warning("No proxy is set.")
            sys.exit()
        Colored.print_warning("Proxy is found. Will be set after program runs")