Wrapper Bar
Wrapper-Bar
is a python module to help wrap commands behind a progress bar. Wrapper-Bar
helps in wrapping shell commands, or python codes (both independent and dependent) and downloads with a progress bar and time.
Info
Wrapper-Bar >= 0.1.5
supports wrapping file downloads.
Table of Contents
Installation
To install wrapper-bar
, use pip.
Open a terminal or CMD and run:
Usage
To start creating progress bar with commands we need to import the Wrapper
class from the wrapper-bar
package.
Import the Wrapper
class.
>>> from wrapper_bar import Wrapper
# before v0.1.6, use
# from wrapper_bar.wrapper import Wrapper
The Wrapper
class has the following usage doc
# the Wrapper Class takes one argument - 'marker'
# the default is '▓', which will simulate a loading bar element.
wrapControl = Wrapper()
# let us just create the wrapControl with Default settings
Now we can perform the following tasks with it:
-
Create a fake progress bar for aesthetics.
Use the decoy
method. The decoy method has these parameters –
-
label
: (str) type parameter. Set the Label to be shown at the left of the loading bar.
-
delay
: (float) type parameter. Set the delay between each update of the loading bar.
-
width
: (float) type parameter. Set the width of the loading bar. Default is 50
.
-
timer
: (Literal[str]) type parameter. This can be either ETA
or ElapsedTime
. Default is ETA
.
wrapControl.decoy(
label='Loading',
delay=0.5,
width=70,
timer='ElapsedTime'
)
This will output the following:
Loading |▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓|Elapsed Time: 0:00:50
-
Create a progress bar and run shell commands behind it.
Use the shellWrapper method. The shellWrapper method has the following parameters –
-
shellcommands
: (List[str]) type parameter. Set the commands to be run in the shell in order. Create a list of string with each string representing a full single command.
-
label
: (str) type parameter. Set the Label to be shown at the left of the loading bar.
-
delay
: (float) type parameter. Set the delay between each update of the loading bar.
-
width
: (float) type parameter. Set the width of the loading bar. Default is 50
.
-
timer
: (Literal[str]) type parameter. This can be either ETA
or ElapsedTime
. Default is ETA
.
-
logger
: (bool) type parameter. Set it to True
if the outputs need to be logged.
-
logfile
: (TextIOWrapper) type parameter. Set the log file ref if logger
is set to True
.
-
logfile_auto_close
: (bool) type parameter. Setting it to True
will close the log file ref.
# let us take an example list of shell codes
shell_codes = [
"""sudo apt-get update""",
"""sudo apt-get upgrade""",
]
# let us open a file ref for logging
logfile = open('logfile.log', 'w+')
# now let us create a progress bar that ends after
# completely running these codes in order.
wrapControl.shellWrapper(
label='Shell Codes Running:',
width=80,
timer='ElapsedTime',
logger=True,
logfile=logfile,
logfile_auto_close=True, # this will auto close the logfile
)
This will output the following:
Shell Codes Running: |▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓|Elapsed Time: 0:00:10
-
Create a progress bar and run python scripts behind it.
Use the pyWrapper method. The pyWrapper method has the following parameters –
-
pythonscripts
: (List[str]) type parameter. Set the list of script names.
-
label
: (str) type parameter. Set the Label to be shown at the left of the loading bar.
-
delay
: (float) type parameter. Set the delay between each update of the loading bar.
-
width
: (float) type parameter. Set the width of the loading bar. Default is 50
.
-
timer
: (Literal[str]) type parameter. This can be either ETA
or ElapsedTime
. Default is ETA
.
-
logger
: (bool) type parameter. Set it to True
if the outputs need to be logged.
-
logfile
: (TextIOWrapper) type parameter. Set the log file ref if logger
is set to True
.
-
logfile_auto_close
: (bool) type parameter. Setting it to True
will close the log file ref.
# let us take two different python scripts
pyscripts = [
'abc.py',
'xyz.py'
]
# let us create a logfile ref
log_ref = open('log.logs', 'w+')
# now the progress bar
wrapControl.pyWrapper(
label='Processing'
pythonscripts=pyscripts,
)
The will output the following:
Processing: |▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓|ETA: 0:00:00
-
create a progress bar and run python codes behind it that are dependent on the current script/project or just inline codes
Use pyShellWrapper method. The pyShellWrapper has the following parameters –
-
pythoncodes
: (List[str]) type parameter. Set the actual processing codes here.
-
dependencies
: (List[str]) type parameter. All the dependencies to run any of the codes listed in pythoncodes
goes here.
-
label
: (str) type parameter. Set the Label to be shown at the left of the loading bar.
-
delay
: (float) type parameter. Set the delay between each update of the loading bar.
-
width
: (float) type parameter. Set the width of the loading bar. Default is 50
.
-
timer
: (Literal[str]) type parameter. This can be either ETA
or ElapsedTime
. Default is ETA
.
# let us take an example of simple addition
dependencies = [
"""a, b, c = 10, 20, 15"""
]
# dependencies will have all the values needed for operations
# follow python programming rules and indentation
pycodes = [
"""a += b
b = a + c
d = a + b""",
"""e = a + b"""
]
# pycodes will have all the operation codes
# follow python programming rules and indentation
# now the loading bar
wrapControl.pyShellWrapper(
pythoncodes=pycodes,
dependencies=dependencies,
label='Processing',
)
# to get the results,
results: Dict[str, Any] = wrapControl.pyShellWrapperResults
# will contain values of 'a', 'b', 'c', 'd', 'e' after carrying out both the operations provided in the list
This will again result in a progress bar as shown in above cases.
Warning
Do not use keywords like return, yield, print or functions that use print, yield or return keywords, else they will mess up the loading bar.
Yanked Versions
Issues
Submit any issues here.
Submit your pull requests here.