Mixins
mixins
#
Collection of classes that can be used as Mixins with other base classes.
Classes such as TorrentFile, TorrentFilev2, and all Hasher classes can use the progress bar mixin. And any class is eligible to use the callback mixin.
CbMixin
#
Mixin class to set a callback hook during procedure.
cb(*args, **kwargs)
classmethod
#
Do nothing.
Source code in torrentfile\mixins.py
40 41 42 |
|
set_callback(func)
classmethod
#
Assign a callback to the Hashing class.
PARAMETER | DESCRIPTION |
---|---|
func |
the callback function
TYPE:
|
Source code in torrentfile\mixins.py
44 45 46 47 48 49 50 51 52 53 54 |
|
ProgMixin
#
Progress bar mixin class.
Displays progress of hashing individual files, usefull when hashing really big files.
NoProg
#
Stand-in object for when progress mode is set to 0.
update(value)
staticmethod
#
Return the value.
PARAMETER | DESCRIPTION |
---|---|
value |
the input and output
|
RETURNS | DESCRIPTION |
---|---|
int
|
same as input |
Source code in torrentfile\mixins.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
|
get_progress_tracker(total: int, message: str)
#
Return the progress bar object for external management.
PARAMETER | DESCRIPTION |
---|---|
total |
total size to track
TYPE:
|
message |
prompt message for what is being tracked
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ProgressBar
|
progress bar object instance |
Source code in torrentfile\mixins.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
ProgressBar(total: int, title: str, length: int, unit: str, start: int)
#
Holds the state and details of the terminal progress bars.
PARAMETER | DESCRIPTION |
---|---|
total |
the total amount to be accumulated.
TYPE:
|
title |
the subject of the progress tracker
TYPE:
|
length |
the width of the progress bar
TYPE:
|
unit |
the text representation incremented
TYPE:
|
start |
column where the progress bar should be drawn
TYPE:
|
Construct the progress bar object and store state of it’s properties.
Source code in torrentfile\mixins.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
close_out()
staticmethod
#
Finalize the last bits of progress bar.
Increment the terminal by one line leaving the progress bar in place, and deleting the progress bar object to clear a space for the next one.
Source code in torrentfile\mixins.py
135 136 137 138 139 140 141 142 143 144 |
|
get_progress() -> str
#
Return the size of the filled portion of the progress bar.
RETURNS | DESCRIPTION |
---|---|
str
|
the progress bar characters
TYPE:
|
Source code in torrentfile\mixins.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
new(total: int, path: str, length: int = 50, unit: str = 'bytes')
classmethod
#
Generate a new progress bar for the given file path.
PARAMETER | DESCRIPTION |
---|---|
total |
the total amount of units accumulating towards.
TYPE:
|
path |
path to file being hashed.
TYPE:
|
length |
the number of characters of the actual progress bar.
TYPE:
|
unit |
the text representation of the value being measured.
TYPE:
|
Source code in torrentfile\mixins.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
update(val: int)
#
Update progress bar.
Using the value provided, increment the progress bar by that value.
PARAMETER | DESCRIPTION |
---|---|
val |
the number of bytes count the progress bar should increase.
TYPE:
|
Source code in torrentfile\mixins.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
waiting(msg: str, flag: list, timeout: int = 20)
#
Show loading message while thread completes processing.
PARAMETER | DESCRIPTION |
---|---|
msg |
Message string printed before the progress bar
TYPE:
|
flag |
Once flag is filled exit loop
TYPE:
|
timeout |
max amount of time to run the function.
TYPE:
|
Source code in torrentfile\mixins.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
|