Esempio n. 1
0
    def from_string(self):
        stream = StringIO()
        writer = TerminalWriter(stream)
        with Assert.raises(ValueError) as exc:
            ProgressBar.from_string('$foo', writer)
        Assert(exc.args[0]) == 'widget not found: foo'

        progressbar = ProgressBar.from_string('hello $hint:world $percentage',
                                              writer,
                                              maxsteps=10)
        progressbar.init()
        progressbar.finish(hint='me')
        Assert(stream.getvalue()) == 'hello world 0%\rhello me 100%\n'
Esempio n. 2
0
    def from_string(self):
        stream = StringIO()
        writer = TerminalWriter(stream)
        with Assert.raises(ValueError) as exc:
            ProgressBar.from_string('$foo', writer)
        Assert(exc.args[0]) == 'widget not found: foo'

        progressbar = ProgressBar.from_string(
            'hello $hint:world $percentage', writer, maxsteps=10
        )
        progressbar.init()
        progressbar.finish(hint='me')
        Assert(stream.getvalue()) == 'hello world 0%\rhello me 100%\n'
Esempio n. 3
0
    def progress(self, description, maxsteps=None, widgets=None):
        """
        Returns a :class:`~brownie.terminal.progress.ProgressBar` object
        which can be used to write the current progress to the stream.

        The progress bar is created from the `description` which is a string
        with the following syntax:

        Widgets -- the parts of the progress bar which are changed with each
        update -- are represented in the form ``$[a-zA-Z]+``.

        Some widgets required that you provide an initial value, this can be
        done by adding ``:string`` where string is either ``[a-zA-Z]+`` or a
        double-quoted string.

        If you want to escape a ``$`` you simply precede it with another ``$``,
        so ``$$foo` will not be treated as a widget and in the progress bar
        ``$foo`` will be shown.

        Quotes (``"``) in strings can be escaped with a backslash (``\``).

        The following widgets are available:

        `hint`
            Shows a string of text that can be given using the `hint` argument
            at any update performed with :meth:`.ProgressBar.init`,
            :meth:`.ProgressBar.next` or :meth:`.ProgressBar.finish`. If the
            argument is not given an empty string is used instead.

        `percentage`
            Shows the progress in percent; this requires `maxsteps` to be set.

        `bar`
            Shows a simple bar which moves which each update not corresponding
            with the progress being made. This is useful if you just want to
            show that something is happening.

        `sizedbar`
            Shows a simple progress bar which is being filled corresponding
            to the percentage of progress. This requires `maxsteps` to be
            set.

        `step`
            Shows the current at maximum number of steps as ``step of steps``,
            this method takes an initial value determining the unit of each
            step e.g. if each step represents a byte and you choose `bytes`
            as a unit a reasonable prefix will be chosen.

            Supported units:

            - `bytes` - Uses a binary prefix.

            This requires `maxsteps` to be set.

        `time`
            Shows the elapsed time in hours, minutes and seconds.

        `speed`
            Shows the speed in bytes (or with a reasonable prefix) per seconds,
            this assumes that each `step` represents a byte.

        If you want to implement your own widget(s) take a look at
        :class:`brownie.terminal.progress.Widget`, you can use them by passing
        them in a dictionary (mapping the name to the widget class) via the
        `widgets` argument. You might also want to take a look at the source
        code of the built-in widgets.

        There are two things you have to look out for:
        :class:`~brownie.terminal.progress.ProgressBar` objects are not
        reusable if you need another object, call this method again. If you
        attempt to write to the :attr:`stream` while using a progress bar the
        behaviour is undefined.

        .. seealso:: :ref:`creating-widgets`
        """
        return ProgressBar.from_string(description,
                                       self,
                                       maxsteps=maxsteps,
                                       widgets=None)
Esempio n. 4
0
    def progress(self, description, maxsteps=None, widgets=None):
        """
        Returns a :class:`~brownie.terminal.progress.ProgressBar` object
        which can be used to write the current progress to the stream.

        The progress bar is created from the `description` which is a string
        with the following syntax:

        Widgets -- the parts of the progress bar which are changed with each
        update -- are represented in the form ``$[a-zA-Z]+``.

        Some widgets required that you provide an initial value, this can be
        done by adding ``:string`` where string is either ``[a-zA-Z]+`` or a
        double-quoted string.

        If you want to escape a ``$`` you simply precede it with another ``$``,
        so ``$$foo` will not be treated as a widget and in the progress bar
        ``$foo`` will be shown.

        Quotes (``"``) in strings can be escaped with a backslash (``\``).

        The following widgets are available:

        `hint`
            Shows a string of text that can be given using the `hint` argument
            at any update performed with :meth:`.ProgressBar.init`,
            :meth:`.ProgressBar.next` or :meth:`.ProgressBar.finish`. If the
            argument is not given an empty string is used instead.

        `percentage`
            Shows the progress in percent; this requires `maxsteps` to be set.

        `bar`
            Shows a simple bar which moves which each update not corresponding
            with the progress being made. This is useful if you just want to
            show that something is happening.

        `sizedbar`
            Shows a simple progress bar which is being filled corresponding
            to the percentage of progress. This requires `maxsteps` to be
            set.

        `step`
            Shows the current at maximum number of steps as ``step of steps``,
            this method takes an initial value determining the unit of each
            step e.g. if each step represents a byte and you choose `bytes`
            as a unit a reasonable prefix will be chosen.

            Supported units:

            - `bytes` - Uses a binary prefix.

            This requires `maxsteps` to be set.

        `time`
            Shows the elapsed time in hours, minutes and seconds.

        `speed`
            Shows the speed in bytes (or with a reasonable prefix) per seconds,
            this assumes that each `step` represents a byte.

        If you want to implement your own widget(s) take a look at
        :class:`brownie.terminal.progress.Widget`, you can use them by passing
        them in a dictionary (mapping the name to the widget class) via the
        `widgets` argument. You might also want to take a look at the source
        code of the built-in widgets.

        There are two things you have to look out for:
        :class:`~brownie.terminal.progress.ProgressBar` objects are not
        reusable if you need another object, call this method again. If you
        attempt to write to the :attr:`stream` while using a progress bar the
        behaviour is undefined.

        .. seealso:: :ref:`creating-widgets`
        """
        return ProgressBar.from_string(
            description, self, maxsteps=maxsteps, widgets=None
        )