def check_url(expanded: ExpandedURL, progress_bar: ProgressBar):
    host, rest = split(expanded.url)

    # sleep some random time to prevent server side throttling
    time.sleep(randint(1, 4))

    progress_bar.update(1)

    conn = HTTPSConnection(host)
    conn.request("HEAD", rest)
    response = conn.getresponse()

    if response.status == 200:
        logger.debug("SUCCESS: URL check for {} {} MongoDB {}".format(
            expanded.os_name,
            expanded.os_version,
            expanded.version,
        ))
    else:
        logger.error((
            "FAIL: URL check for {} {} "
            "MongoDB {}, {}, reason: {} {}"
        ).format(
            expanded.os_name,
            expanded.os_version,
            expanded.version,
            expanded.url,
            response.status,
            response.reason
        ))
        return expanded
Beispiel #2
0
    def __init__(self,
                 iterable,
                 length=None,
                 fill_char='#',
                 empty_char=' ',
                 bar_template='%(bar)s',
                 info_sep='  ',
                 show_eta=True,
                 show_percent=None,
                 show_pos=False,
                 item_show_func=None,
                 label=None,
                 file=None,
                 color=None,
                 width=30):

        # If the file is not a tty we don't need any control symbols.
        if file and not file.isatty():
            click._termui_impl.BEFORE_BAR = ''
            click._termui_impl.AFTER_BAR = ''

        ProgressBar.__init__(self, iterable, length, fill_char, empty_char,
                             bar_template, info_sep, show_eta, show_percent,
                             show_pos, item_show_func, label, file, color,
                             width)

        # This progress bar is never hidden
        self.is_hidden = False
    def _handle_files(self: _T, all_files: ProgressBar) -> int:
        self._total = all_files.length
        min_found: int = max(9, all_files.length // 20) + 1
        filename: Path
        self._count = 0
        self._skipped = 0
        for filename in all_files:
            item: str = None
            if self._callbacks.progressbar(all_files):
                break

            rpgmaker_header: bytes
            file_header: bytes
            png_ihdr: bytes
            with click.open_file(filename, "rb") as file:
                rpgmaker_header = file.read(16)
                file_header = file.read(16)
                png_ihdr = file.read(17)
            if rpgmaker_header == RPG_MAKER_MV_MAGIC and _is_png_image(
                    png_ihdr):
                item = int_xor(file_header, PNG_HEADER).hex()
                self._count += 1
                self.keys = item
                if len(self.keys) == 1 and self._count >= min_found:
                    all_files.update(self._total - self._count)
                    self._report_results(item)
                    break
            else:
                self._skipped += 1
                self._total -= 1
                min_found = max(10, ((self._total // 20) + 1))

        self._callbacks.progressbar(None)
Beispiel #4
0
 def __enter__(self):
     if self.show_progress:
         pg = ProgressBar(self.iter,**(self.kwargs), empty_char='-',
                          bar_template='%(label)s  [%(bar)s]  %(info)s',
                          width=36)
         pg.__enter__()
         return pg
     return self.iter
Beispiel #5
0
    def update(self, n_steps):
        """

        :param n_steps: number of steps executed
        :return: None
        """
        # Seek to the beginning of the file if that's possible.
        try:
            self.file.seek(0)
        except UnsupportedOperation:
            pass

        ProgressBar.update(self, n_steps)
Beispiel #6
0
    def __enter__(self):
        from blueshift.utils.helpers import if_notebook
        if if_notebook():
            return self.iter

        if self.show_progress:
            pg = ProgressBar(self.iter,
                             **(self.kwargs),
                             empty_char='-',
                             bar_template='%(label)s  [%(bar)s]  %(info)s',
                             width=36)
            pg.__enter__()
            return pg
        return self.iter
Beispiel #7
0
 def __init__(self, iterable, length=None, fill_char='#', empty_char=' ',
              bar_template='%(bar)s', info_sep='  ', show_eta=True,
              show_percent=None, show_pos=False, item_show_func=None,
              label=None, file=None, color=None, width=30,  # @ReservedAssignment
              start_show_func=None, finish_show_func=None):
     """
     New parameters added on top of ProgressBar: start_show_func and
     finish_show_func to drive some display at the start and finish of a
     progression.
     """
     ProgressBar.__init__(self, iterable, length=length, fill_char=fill_char,
                          empty_char=empty_char, bar_template=bar_template,
                          info_sep=info_sep, show_eta=show_eta,
                          show_percent=show_percent, show_pos=show_pos,
                          item_show_func=item_show_func, label=label,
                          file=file, color=color, width=width)
     self.start_show_func = start_show_func
     self.finish_show_func = finish_show_func
def create_loading_bar(label: str, iterable_generator, length: int):
    return ProgressBar(
        iterable_generator,
        length=length,
        label=label,
        fill_char="*",
        empty_char="-",
        bar_template="%(label)s [%(bar)s] %(info)s",
        color="blue",
    )
Beispiel #9
0
 def __enter__(self):
     self.render_start()
     return ProgressBar.__enter__(self)
Beispiel #10
0
 def render_progress(self):
     if not self.is_hidden:
         return ProgressBar.render_progress(self)