From e13deb0bf6b3faf9b0e27e0862fcb62feb6ea139 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 29 Jul 2023 20:17:41 -0700 Subject: [PATCH 1/4] adding color progress bar and extra progress bar mode --- docs/Source/cli/index.html | 14 +- docs/Source/hasher/index.html | 116 +-- docs/Source/mixins/index.html | 68 +- docs/Source/utils/index.html | 346 ++++--- docs/api/index.html | 8 + docs/coverage/covindex.html | 20 +- .../d_1bc82e0ab2fcb2ec___init___py.html | 4 +- .../d_1bc82e0ab2fcb2ec___main___py.html | 4 +- docs/coverage/d_1bc82e0ab2fcb2ec_cli_py.html | 619 ++++++------ .../d_1bc82e0ab2fcb2ec_commands_py.html | 4 +- docs/coverage/d_1bc82e0ab2fcb2ec_edit_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_hasher_py.html | 931 +++++++++--------- .../d_1bc82e0ab2fcb2ec_interactive_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_mixins_py.html | 289 +++--- .../d_1bc82e0ab2fcb2ec_rebuild_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_recheck_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_torrent_py.html | 4 +- .../coverage/d_1bc82e0ab2fcb2ec_utils_py.html | 844 ++++++++-------- .../d_1bc82e0ab2fcb2ec_version_py.html | 4 +- .../d_a44f0ac069e85531___init___py.html | 4 +- .../d_a44f0ac069e85531_test_cli_py.html | 4 +- .../d_a44f0ac069e85531_test_commands_py.html | 4 +- .../d_a44f0ac069e85531_test_edit_py.html | 4 +- ..._a44f0ac069e85531_test_interactive_py.html | 4 +- .../d_a44f0ac069e85531_test_rebuild_py.html | 4 +- .../d_a44f0ac069e85531_test_recheck_py.html | 4 +- .../d_a44f0ac069e85531_test_torrent_py.html | 4 +- .../d_a44f0ac069e85531_test_utils_py.html | 4 +- docs/coverage/status.json | 2 +- .../d_1bc82e0ab2fcb2ec___init___py.html | 4 +- .../d_1bc82e0ab2fcb2ec___main___py.html | 4 +- docs/htmlcov/d_1bc82e0ab2fcb2ec_cli_py.html | 619 ++++++------ .../d_1bc82e0ab2fcb2ec_commands_py.html | 4 +- docs/htmlcov/d_1bc82e0ab2fcb2ec_edit_py.html | 4 +- .../htmlcov/d_1bc82e0ab2fcb2ec_hasher_py.html | 931 +++++++++--------- .../d_1bc82e0ab2fcb2ec_interactive_py.html | 4 +- .../htmlcov/d_1bc82e0ab2fcb2ec_mixins_py.html | 289 +++--- .../d_1bc82e0ab2fcb2ec_rebuild_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_recheck_py.html | 4 +- .../d_1bc82e0ab2fcb2ec_torrent_py.html | 4 +- docs/htmlcov/d_1bc82e0ab2fcb2ec_utils_py.html | 844 ++++++++-------- .../d_1bc82e0ab2fcb2ec_version_py.html | 4 +- .../d_a44f0ac069e85531___init___py.html | 4 +- .../d_a44f0ac069e85531_test_cli_py.html | 4 +- .../d_a44f0ac069e85531_test_commands_py.html | 4 +- .../d_a44f0ac069e85531_test_edit_py.html | 4 +- ..._a44f0ac069e85531_test_interactive_py.html | 4 +- .../d_a44f0ac069e85531_test_rebuild_py.html | 4 +- .../d_a44f0ac069e85531_test_recheck_py.html | 4 +- .../d_a44f0ac069e85531_test_torrent_py.html | 4 +- .../d_a44f0ac069e85531_test_utils_py.html | 4 +- docs/htmlcov/index.html | 20 +- docs/htmlcov/status.json | 2 +- docs/objects.inv | Bin 1197 -> 1207 bytes docs/search/search_index.json | 2 +- docs/sitemap.xml | 38 +- docs/sitemap.xml.gz | Bin 335 -> 335 bytes torrentfile/cli.py | 5 +- torrentfile/hasher.py | 9 +- torrentfile/mixins.py | 7 +- torrentfile/utils.py | 20 + 61 files changed, 3189 insertions(+), 2998 deletions(-) diff --git a/docs/Source/cli/index.html b/docs/Source/cli/index.html index a223834..2105003 100644 --- a/docs/Source/cli/index.html +++ b/docs/Source/cli/index.html @@ -1527,7 +1527,8 @@

651 652 653 -654
def execute(args: list = None) -> list:
+654
+655
def execute(args: list = None) -> list:
     """
     Execute program with provided list of arguments.
 
@@ -1685,9 +1686,10 @@ 

metavar="<int>", help=""" set the progress bar level - Options = 0, 1 + Options = 0, 1, 2 (0) = Do not display progress bar. - (1) = Display progress bar.(default) + (1) = Display progress bar for each file.(default) + (2) = Display one progress bar for full torrent. """, ) @@ -2007,11 +2009,11 @@

Source code in torrentfile\cli.py -
660
-661
+        
661
 662
 663
-664
def main() -> None:
+664
+665
def main() -> None:
     """
     Initiate main function for CLI script.
     """
diff --git a/docs/Source/hasher/index.html b/docs/Source/hasher/index.html
index 8c659fd..fbb6e3c 100644
--- a/docs/Source/hasher/index.html
+++ b/docs/Source/hasher/index.html
@@ -822,10 +822,7 @@ 

Source code in torrentfile\hasher.py -
413
-414
-415
-416
+            
416
 417
 418
 419
@@ -846,7 +843,10 @@ 

434 435 436 -437

def __init__(
+437
+438
+439
+440
def __init__(
     self,
     path: str,
     piece_length: int,
@@ -902,9 +902,9 @@ 

Source code in torrentfile\hasher.py -
439
-440
-441
def __iter__(self):
+        
442
+443
+444
def __iter__(self):
     """Return `self`: needed to implement iterator implementation."""
     return self
 
@@ -971,10 +971,7 @@

Source code in torrentfile\hasher.py -
464
-465
-466
-467
+        
467
 468
 469
 470
@@ -1027,7 +1024,10 @@ 

517 518 519 -520

def __next__(self) -> bytes:
+520
+521
+522
+523
def __next__(self) -> bytes:
     """
     Calculate layer hashes for contents of file.
 
@@ -1192,7 +1192,9 @@ 

69 70 71 -72

def __init__(
+72
+73
+74
def __init__(
     self,
     paths: list,
     piece_length: int,
@@ -1207,9 +1209,11 @@ 

self.total = sum(os.path.getsize(i) for i in self.paths) self.index = 0 self.current = open(self.paths[0], "rb") - if self.progress: + if self.progress == 1: total = os.path.getsize(self.paths[0]) self.prog_start(total, self.paths[0]) + elif self.progress == 2: + self.prog_start(self.total, self.paths[0]) logger.debug("Hashing %s", str(self.paths[0]))

@@ -1267,16 +1271,16 @@

Source code in torrentfile\hasher.py -
74
-75
-76
+        
76
 77
 78
 79
 80
 81
 82
-83
def __iter__(self):
+83
+84
+85
def __iter__(self):
     """
     Iterate through feed pieces.
 
@@ -1329,10 +1333,7 @@ 

Source code in torrentfile\hasher.py -
136
-137
-138
-139
+        
139
 140
 141
 142
@@ -1349,7 +1350,10 @@ 

153 154 155 -156

def __next__(self) -> bytes:
+156
+157
+158
+159
def __next__(self) -> bytes:
     """
     Generate piece-length pieces of data from input file list.
 
@@ -1417,9 +1421,7 @@ 

Source code in torrentfile\hasher.py -
115
-116
-117
+        
117
 118
 119
 120
@@ -1436,7 +1438,10 @@ 

131 132 133 -134

def next_file(self) -> bool:
+134
+135
+136
+137
def next_file(self) -> bool:
     """
     Seemlessly transition to next file in file list.
 
@@ -1446,12 +1451,13 @@ 

True if there is a next file otherwise False. """ self.index += 1 - self.prog_close() + if self.progress == 1 or self.index >= len(self.paths): + self.prog_close() if self.index < len(self.paths): path = self.paths[self.index] logger.debug("Hashing %s", str(path)) self.current.close() - if self.progress: + if self.progress == 1: self.prog_start(os.path.getsize(path), path) self.current = open(path, "rb") return True @@ -1546,10 +1552,7 @@

Source code in torrentfile\hasher.py -
294
-295
-296
-297
+            
297
 298
 299
 300
@@ -1562,7 +1565,10 @@ 

307 308 309 -310

def __init__(self, path: str, piece_length: int, progress: bool = True):
+310
+311
+312
+313
def __init__(self, path: str, piece_length: int, progress: bool = True):
     """
     Construct Hasher class instances for each file in torrent.
     """
@@ -1633,10 +1639,7 @@ 

Source code in torrentfile\hasher.py -
334
-335
-336
-337
+        
337
 338
 339
 340
@@ -1674,7 +1677,10 @@ 

372 373 374 -375

def process_file(self, data: bytearray):
+375
+376
+377
+378
def process_file(self, data: bytearray):
     """
     Calculate layer hashes for contents of file.
 
@@ -1807,10 +1813,7 @@ 

Source code in torrentfile\hasher.py -
201
-202
-203
-204
+            
204
 205
 206
 207
@@ -1820,7 +1823,10 @@ 

211 212 213 -214

def __init__(self, path: str, piece_length: int, progress: bool = True):
+214
+215
+216
+217
def __init__(self, path: str, piece_length: int, progress: bool = True):
     """
     Calculate and store hash information for specific file.
     """
@@ -1888,10 +1894,7 @@ 

Source code in torrentfile\hasher.py -
216
-217
-218
-219
+        
219
 220
 221
 222
@@ -1931,7 +1934,10 @@ 

256 257 258 -259

def process_file(self, fd: str):
+259
+260
+261
+262
def process_file(self, fd: str):
     """
     Calculate hashes over 16KiB chuncks of file content.
 
@@ -2050,10 +2056,7 @@ 

Source code in torrentfile\hasher.py -
159
-160
-161
-162
+        
162
 163
 164
 165
@@ -2070,7 +2073,10 @@ 

176 177 178 -179

def merkle_root(blocks: list) -> bytes:
+179
+180
+181
+182
def merkle_root(blocks: list) -> bytes:
     """
     Calculate the merkle root for a seq of sha256 hash digests.
 
diff --git a/docs/Source/mixins/index.html b/docs/Source/mixins/index.html
index f0ee4f3..bf81eb6 100644
--- a/docs/Source/mixins/index.html
+++ b/docs/Source/mixins/index.html
@@ -947,10 +947,7 @@ 

Source code in torrentfile\mixins.py -
205
-206
-207
-208
+        
208
 209
 210
 211
@@ -958,7 +955,10 @@ 

213 214 215 -216

def is_active(self) -> bool:
+216
+217
+218
+219
def is_active(self) -> bool:
     """
     Test to see if there is an active progress bar for object.
 
@@ -994,17 +994,17 @@ 

Source code in torrentfile\mixins.py -
193
-194
-195
-196
+        
+ + + +
196
 197
 198
 199
 200
 201
 202
-203
def prog_close(self):
+203
+204
+205
+206
def prog_close(self):
     """
     Finalize the last bits of progress bar.
 
@@ -1099,13 +1099,24 @@ 

mode +

the progress bar mode

+

+ + TYPE: + int + +

+
Source code in torrentfile\mixins.py -
142
-143
+        
143
 144
 145
 146
@@ -1135,7 +1146,10 @@ 

170 171 172 -173

def prog_start(self,
+173
+174
+175
+176
def prog_start(self,
                total: int,
                path: str,
                length: int = 50,
@@ -1153,6 +1167,8 @@ 

the number of characters of the actual progress bar. unit : str the text representation of the value being measured. + mode : int + the progress bar mode """ title = path width = shutil.get_terminal_size().columns @@ -1213,10 +1229,7 @@

Source code in torrentfile\mixins.py -
175
-176
-177
-178
+        
178
 179
 180
 181
@@ -1229,7 +1242,10 @@ 

188 189 190 -191

def prog_update(self, val: int):
+191
+192
+193
+194
def prog_update(self, val: int):
     """
     Update progress bar.
 
@@ -1492,7 +1508,8 @@ 

128 129 130 -131

def get_progress(self) -> str:
+131
+132
def get_progress(self) -> str:
     """
     Return the size of the filled portion of the progress bar.
 
@@ -1506,7 +1523,8 @@ 

else: fill = math.ceil((self.state / self.total) * self.length) empty = self.length - fill - pbar = ["|", self.fill * fill, self.empty * empty, "| "] + contents = (self.fill * fill) + (self.empty * empty) + pbar = ["|", green(contents), "| "] if self.unit == "GiB": state = self.state / (2**30) elif self.unit == "MiB": @@ -1599,10 +1617,7 @@

Source code in torrentfile\mixins.py -
219
-220
-221
-222
+        
222
 223
 224
 225
@@ -1639,7 +1654,10 @@ 

256 257 258 -259

def waiting(msg: str, flag: list, timeout: int = 20):
+259
+260
+261
+262
def waiting(msg: str, flag: list, timeout: int = 20):
     """
     Show loading message while thread completes processing.
 
diff --git a/docs/Source/utils/index.html b/docs/Source/utils/index.html
index 875000f..37f2dcb 100644
--- a/docs/Source/utils/index.html
+++ b/docs/Source/utils/index.html
@@ -605,6 +605,13 @@
     check_path_writable()
   
   
+
+        
+          
  • + + colored() + +
  • @@ -640,6 +647,13 @@ get_piece_length() +
  • + +
  • + + green() + +
  • @@ -837,13 +851,13 @@

    Source code in torrentfile\utils.py -
    39
    -40
    -41
    -42
    -43
    -44
    -45
    def __init__(self, func):
    +            
    45
    +46
    +47
    +48
    +49
    +50
    +51
    def __init__(self, func):
         """
         Construcor for cache.
         """
    @@ -923,13 +937,7 @@ 

    Source code in torrentfile\utils.py -
    47
    -48
    -49
    -50
    -51
    -52
    -53
    +        
    53
     54
     55
     56
    @@ -942,7 +950,13 @@ 

    63 64 65 -66

    def __call__(self, path: str):
    +66
    +67
    +68
    +69
    +70
    +71
    +72
    def __call__(self, path: str):
         """
         Invoke each time memo function is called.
     
    @@ -1027,14 +1041,14 @@ 

    Source code in torrentfile\utils.py -
    81
    -82
    -83
    -84
    -85
    -86
    -87
    -88
    def __init__(self, message: str = None):
    +            
    87
    +88
    +89
    +90
    +91
    +92
    +93
    +94
    def __init__(self, message: str = None):
         """
         Raise when creating a meta file without specifying target content.
     
    @@ -1115,14 +1129,14 @@ 

    Source code in torrentfile\utils.py -
    101
    -102
    -103
    -104
    -105
    -106
    -107
    -108
    def __init__(self, message: str = None):
    +            
    107
    +108
    +109
    +110
    +111
    +112
    +113
    +114
    def __init__(self, message: str = None):
         """
         Raise when creating a meta file with incorrect piece length value.
     
    @@ -1214,13 +1228,7 @@ 

    Source code in torrentfile\utils.py -
    418
    -419
    -420
    -421
    -422
    -423
    -424
    +        
    424
     425
     426
     427
    @@ -1238,7 +1246,13 @@ 

    439 440 441 -442

    def check_path_writable(path: str) -> bool:
    +442
    +443
    +444
    +445
    +446
    +447
    +448
    def check_path_writable(path: str) -> bool:
         """
         Test if output path is writable.
     
    @@ -1273,6 +1287,37 @@ 

    +

    +colored(string: str, key: int) -> str + +#

    + + +
    + +

    Output terminal content with formatting.

    + +
    + Source code in torrentfile\utils.py +
    458
    +459
    +460
    +461
    +462
    def colored(string: str, key: int) -> str:
    +    """
    +    Output terminal content with formatting.
    +    """
    +    return f"\033[{key}m{string}\033[0m"
    +
    +
    +
    + +
    + +
    + + +

    copypath(source: str, dest: str) -> None @@ -1323,13 +1368,7 @@

    Source code in torrentfile\utils.py -
    361
    -362
    -363
    -364
    -365
    -366
    -367
    +        
    367
     368
     369
     370
    @@ -1353,7 +1392,13 @@ 

    388 389 390 -391

    def copypath(source: str, dest: str) -> None:
    +391
    +392
    +393
    +394
    +395
    +396
    +397
    def copypath(source: str, dest: str) -> None:
         """
         Copy the file located at source to dest.
     
    @@ -1427,16 +1472,16 @@ 

    Source code in torrentfile\utils.py -
    406
    -407
    -408
    -409
    -410
    -411
    -412
    +        
    412
     413
     414
    -415
    def debug_is_on() -> bool:
    +415
    +416
    +417
    +418
    +419
    +420
    +421
    def debug_is_on() -> bool:
         """
         Return True if debug mode is on in environment variables.
     
    @@ -1533,13 +1578,7 @@ 

    Source code in torrentfile\utils.py -
    210
    -211
    -212
    -213
    -214
    -215
    -216
    +        
    216
     217
     218
     219
    @@ -1556,7 +1595,13 @@ 

    230 231 232 -233

    @Memo
    +233
    +234
    +235
    +236
    +237
    +238
    +239
    @Memo
     def filelist_total(pathstring: str) -> os.PathLike:
         """
         Perform error checking and format conversion to os.PathLike.
    @@ -1650,13 +1695,7 @@ 

    Source code in torrentfile\utils.py -
    282
    -283
    -284
    -285
    -286
    -287
    -288
    +        
    288
     289
     290
     291
    @@ -1665,7 +1704,13 @@ 

    294 295 296 -297

    def get_file_list(path: str) -> list:
    +297
    +298
    +299
    +300
    +301
    +302
    +303
    def get_file_list(path: str) -> list:
         """
         Return a sorted list of file paths contained in directory.
     
    @@ -1747,13 +1792,7 @@ 

    Source code in torrentfile\utils.py -
    190
    -191
    -192
    -193
    -194
    -195
    -196
    +        
    196
     197
     198
     199
    @@ -1764,7 +1803,13 @@ 

    204 205 206 -207

    def get_piece_length(size: int) -> int:
    +207
    +208
    +209
    +210
    +211
    +212
    +213
    def get_piece_length(size: int) -> int:
         """
         Calculate the ideal piece length for bittorrent data.
     
    @@ -1792,6 +1837,37 @@ 

    +

    +green(string: str) -> str + +#

    + + +
    + +

    Output terminal content in green color.

    + +
    + Source code in torrentfile\utils.py +
    451
    +452
    +453
    +454
    +455
    def green(string: str) -> str:
    +    """
    +    Output terminal content in green color.
    +    """
    +    return colored(string, 92)
    +
    +
    +
    + +
    + +
    + + +

    humanize_bytes(amount: int) -> str @@ -1848,13 +1924,7 @@

    Source code in torrentfile\utils.py -
    120
    -121
    -122
    -123
    -124
    -125
    -126
    +        
    126
     127
     128
     129
    @@ -1874,7 +1944,13 @@ 

    143 144 145 -146

    def humanize_bytes(amount: int) -> str:
    +146
    +147
    +148
    +149
    +150
    +151
    +152
    def humanize_bytes(amount: int) -> str:
         """
         Convert integer into human readable memory sized denomination.
     
    @@ -1967,13 +2043,7 @@ 

    Source code in torrentfile\utils.py -
    339
    -340
    -341
    -342
    -343
    -344
    -345
    +        
    345
     346
     347
     348
    @@ -1986,7 +2056,13 @@ 

    355 356 357 -358

    def next_power_2(value: int) -> int:
    +358
    +359
    +360
    +361
    +362
    +363
    +364
    def next_power_2(value: int) -> int:
         """
         Calculate the next perfect power of 2 equal to or greater than value.
     
    @@ -2093,13 +2169,7 @@ 

    Source code in torrentfile\utils.py -
    149
    -150
    -151
    -152
    -153
    -154
    -155
    +        
    155
     156
     157
     158
    @@ -2131,7 +2201,13 @@ 

    184 185 186 -187

    def normalize_piece_length(piece_length: int) -> int:
    +187
    +188
    +189
    +190
    +191
    +192
    +193
    def normalize_piece_length(piece_length: int) -> int:
         """
         Verify input piece_length is valid and convert accordingly.
     
    @@ -2236,13 +2312,7 @@ 

    Source code in torrentfile\utils.py -
    321
    -322
    -323
    -324
    -325
    -326
    -327
    +        
    327
     328
     329
     330
    @@ -2251,7 +2321,13 @@ 

    333 334 335 -336

    def path_piece_length(path: str) -> int:
    +336
    +337
    +338
    +339
    +340
    +341
    +342
    def path_piece_length(path: str) -> int:
         """
         Calculate piece length for input path and contents.
     
    @@ -2333,13 +2409,7 @@ 

    Source code in torrentfile\utils.py -
    264
    -265
    -266
    -267
    -268
    -269
    -270
    +        
    270
     271
     272
     273
    @@ -2348,7 +2418,13 @@ 

    276 277 278 -279

    def path_size(path: str) -> int:
    +279
    +280
    +281
    +282
    +283
    +284
    +285
    def path_size(path: str) -> int:
         """
         Return the total size of all files in path recursively.
     
    @@ -2432,13 +2508,7 @@ 

    Source code in torrentfile\utils.py -
    300
    -301
    -302
    -303
    -304
    -305
    -306
    +        
    + + + + @@ -822,36 +826,40 @@

    Source code in torrentfile\hasher.py -

    306
     307
     308
     309
    @@ -2450,7 +2520,13 @@ 

    315 316 317 -318

    def path_stat(path: str) -> tuple:
    +318
    +319
    +320
    +321
    +322
    +323
    +324
    def path_stat(path: str) -> tuple:
         """
         Calculate directory statistics.
     
    @@ -2514,16 +2590,16 @@ 

    Source code in torrentfile\utils.py -
    - + - + @@ -175,10 +175,10 @@

    Coverage report:

    - + - + @@ -203,10 +203,10 @@

    Coverage report:

    - + - + @@ -219,10 +219,10 @@

    Coverage report:

    - + - +
    394
    -395
    -396
    -397
    -398
    -399
    -400
    +        
    - + - + @@ -175,10 +175,10 @@

    Coverage report:

    - + - + @@ -203,10 +203,10 @@

    Coverage report:

    - + - + @@ -219,10 +219,10 @@

    Coverage report:

    - + - +
    400
     401
     402
    -403
    def toggle_debug_mode(switch_on: bool):
    +403
    +404
    +405
    +406
    +407
    +408
    +409
    def toggle_debug_mode(switch_on: bool):
         """
         Switch the environment variable debug indicator on or off.
     
    diff --git a/docs/api/index.html b/docs/api/index.html
    index 20a40a0..ee2257e 100644
    --- a/docs/api/index.html
    +++ b/docs/api/index.html
    @@ -1045,6 +1045,10 @@ 

    Utils Module(bool) Test if output path is writable. +
  • colored(string, key) +(str) + Output terminal content with formatting.
  • +
  • copypath(source, dest) Copy the file located at source to dest.
  • @@ -1061,6 +1065,10 @@

    Utils Module(int) Calculate the ideal piece length for bittorrent data. +
  • green(string) +(str) + Output terminal content in green color.
  • +
  • humanize_bytes(amount) (str) Convert integer into human readable memory sized denomination.
  • diff --git a/docs/coverage/covindex.html b/docs/coverage/covindex.html index e66a6ae..49020ab 100644 --- a/docs/coverage/covindex.html +++ b/docs/coverage/covindex.html @@ -45,7 +45,7 @@

    Coverage report:

    coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    @@ -161,10 +161,10 @@

    Coverage report:

    torrentfile\hasher.py250253 0 0100%100%
    torrentfile\interactive.py
    torrentfile\mixins.py102103 0 4100%100%
    torrentfile\rebuild.py
    torrentfile\utils.py127136 0 5100%100%
    torrentfile\version.py
    Total29812994 0 66100%100%
    @@ -234,7 +234,7 @@

    Coverage report:

    coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    diff --git a/docs/coverage/d_1bc82e0ab2fcb2ec___main___py.html b/docs/coverage/d_1bc82e0ab2fcb2ec___main___py.html index d596dc7..be0d1ce 100644 --- a/docs/coverage/d_1bc82e0ab2fcb2ec___main___py.html +++ b/docs/coverage/d_1bc82e0ab2fcb2ec___main___py.html @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    diff --git a/docs/coverage/d_1bc82e0ab2fcb2ec_cli_py.html b/docs/coverage/d_1bc82e0ab2fcb2ec_cli_py.html index 6337600..1570bc9 100644 --- a/docs/coverage/d_1bc82e0ab2fcb2ec_cli_py.html +++ b/docs/coverage/d_1bc82e0ab2fcb2ec_cli_py.html @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 250 statements   - + 253 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 102 statements   - + 103 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 127 statements   - + 136 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 250 statements   - + 253 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 102 statements   - + 103 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - 127 statements   - + 136 statements   +

    @@ -65,7 +65,7 @@

    » next       coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    torrentfile\hasher.py250253 0 0100%100%
    torrentfile\interactive.py
    torrentfile\mixins.py102103 0 4100%100%
    torrentfile\rebuild.py
    torrentfile\utils.py127136 0 5100%100%
    torrentfile\version.py
    Total29812994 0 66100%100%
    @@ -234,7 +234,7 @@

    Coverage report:

    coverage.py v7.2.7, - created at 2023-07-26 12:16 -0700 + created at 2023-07-29 20:17 -0700

    - +
    - +
    - +
    - +
    - +
    - +
    progress -

    default = None

    +

    the progress mode

    TYPE: @@ -809,7 +801,19 @@

    DEFAULT: - True + 1 + +

    +

    progress_bar +

    a progress bar object if progress mode is 2

    +

    + + DEFAULT: + None

    416
    -417
    -418
    -419
    -420
    -421
    -422
    -423
    -424
    -425
    -426
    -427
    -428
    -429
    -430
    -431
    -432
    -433
    -434
    -435
    -436
    -437
    -438
    -439
    -440
    def __init__(
    +            
    441
    +442
    +443
    +444
    +445
    +446
    +447
    +448
    +449
    +450
    +451
    +452
    +453
    +454
    +455
    +456
    +457
    +458
    +459
    +460
    +461
    +462
    +463
    +464
    +465
    +466
    +467
    +468
    def __init__(
         self,
         path: str,
         piece_length: int,
    -    progress: bool = True,
    +    progress: int = 1,
         hybrid: bool = False,
    +    progress_bar=None,
     ):
         """
         Construct Hasher class instances for each file in torrent.
    @@ -866,11 +874,13 @@ 

    self.padding_file = None self.amount = piece_length // BLOCK_SIZE self.end = False + self.progress = progress + self.progbar = progress_bar + if self.progress == 1: + size = os.path.getsize(self.path) + self.progbar = self.get_progress_tracker(size, self.path) self.current = open(path, "rb") self.hybrid = hybrid - if progress: - self.progressbar = True - self.prog_start(os.path.getsize(path), path)

    @@ -902,9 +912,9 @@

    Source code in torrentfile\hasher.py -
    442
    -443
    -444
    def __iter__(self):
    +        
    470
    +471
    +472
    def __iter__(self):
         """Return `self`: needed to implement iterator implementation."""
         return self
     
    @@ -971,35 +981,7 @@

    Source code in torrentfile\hasher.py -
    467
    -468
    -469
    -470
    -471
    -472
    -473
    -474
    -475
    -476
    -477
    -478
    -479
    -480
    -481
    -482
    -483
    -484
    -485
    -486
    -487
    -488
    -489
    -490
    -491
    -492
    -493
    -494
    -495
    +        
    - + @@ -1198,22 +1206,22 @@

    self, paths: list, piece_length: int, - progress: bool = True, align: bool = False, + progress: int = 1, + progress_bar=None, ): """Generate hashes of piece length data from filelist contents.""" self.piece_length = piece_length self.paths = paths self.align = align - self.progress = progress self.total = sum(os.path.getsize(i) for i in self.paths) self.index = 0 self.current = open(self.paths[0], "rb") + self.progress = progress + self.progbar = progress_bar if self.progress == 1: - total = os.path.getsize(self.paths[0]) - self.prog_start(total, self.paths[0]) - elif self.progress == 2: - self.prog_start(self.total, self.paths[0]) + file_size = os.path.getsize(self.paths[0]) + self.progbar = self.get_progress_tracker(file_size, self.paths[0]) logger.debug("Hashing %s", str(self.paths[0]))

    495
     496
     497
     498
    @@ -1027,7 +1009,36 @@ 

    520 521 522 -523

    def __next__(self) -> bytes:
    +523
    +524
    +525
    +526
    +527
    +528
    +529
    +530
    +531
    +532
    +533
    +534
    +535
    +536
    +537
    +538
    +539
    +540
    +541
    +542
    +543
    +544
    +545
    +546
    +547
    +548
    +549
    +550
    +551
    +552
    def __next__(self) -> bytes:
         """
         Calculate layer hashes for contents of file.
     
    @@ -1051,6 +1062,7 @@ 

    block = bytearray(BLOCK_SIZE) for _ in range(self.amount): size = self.current.readinto(block) + self.progbar.update(size) if not size: self.end = True break @@ -1065,13 +1077,13 @@

    if len(blocks) != self.amount: padding = self._pad_remaining(len(blocks)) blocks.extend(padding) - self.prog_update(total) layer_hash = merkle_root(blocks) self.layer_hashes.append(layer_hash) self.cb(layer_hash) if self.end: + if self.progress == 1: + self.progbar.close_out() self._calculate_root() - self.prog_close() if self.hybrid: if plength > 0: self.padding_file = { @@ -1103,7 +1115,7 @@

    -Hasher(paths: list, piece_length: int, progress: bool = True, align: bool = False) +Hasher(paths: list, piece_length: int, align: bool = False, progress: int = 1, progress_bar = None) #

    @@ -1151,17 +1163,13 @@

    progress**kwargs -

    default = None

    +

    keyword arguments

    TYPE: - int - - - DEFAULT: - True + dict

    @@ -1333,8 +1341,7 @@

    Source code in torrentfile\hasher.py -
    + + + + @@ -1552,23 +1572,38 @@

    Source code in torrentfile\hasher.py -

    139
    -140
    +        
    140
     141
     142
     143
    @@ -1365,14 +1372,13 @@ 

    while True: piece = bytearray(self.piece_length) size = self.current.readinto(piece) + self.progbar.update(size) if size == 0: if not self.next_file(): raise StopIteration elif size < self.piece_length: - self.prog_update(size) return self._handle_partial(piece[:size]) else: - self.prog_update(size) return sha1(piece).digest() # nosec

    @@ -1441,7 +1447,8 @@

    134 135 136 -137

    def next_file(self) -> bool:
    +137
    +138
    def next_file(self) -> bool:
         """
         Seemlessly transition to next file in file list.
     
    @@ -1451,14 +1458,15 @@ 

    True if there is a next file otherwise False. """ self.index += 1 - if self.progress == 1 or self.index >= len(self.paths): - self.prog_close() + if self.progress == 1: + self.progbar.close_out() if self.index < len(self.paths): path = self.paths[self.index] + if self.progress == 1: + total = os.path.getsize(path) + self.progbar = self.get_progress_tracker(total, path) logger.debug("Hashing %s", str(path)) self.current.close() - if self.progress == 1: - self.prog_start(os.path.getsize(path), path) self.current = open(path, "rb") return True return False @@ -1481,7 +1489,7 @@

    -HasherHybrid(path: str, piece_length: int, progress: bool = True) +HasherHybrid(path: str, piece_length: int, progress: int = 1, progress_bar = None) #

    @@ -1531,7 +1539,7 @@

    progress -

    default = None

    +

    the progress mode

    TYPE: @@ -1539,7 +1547,19 @@

    DEFAULT: - True + 1 + +

    +

    progress_bar +

    a progress bar object if progress mode is 2

    +

    + + DEFAULT: + None

    297
    -298
    -299
    -300
    -301
    -302
    -303
    -304
    -305
    -306
    -307
    -308
    -309
    -310
    +            
    310
     311
     312
    -313
    def __init__(self, path: str, piece_length: int, progress: bool = True):
    +313
    +314
    +315
    +316
    +317
    +318
    +319
    +320
    +321
    +322
    +323
    +324
    +325
    +326
    +327
    +328
    +329
    +330
    +331
    +332
    +333
    +334
    +335
    def __init__(
    +    self,
    +    path: str,
    +    piece_length: int,
    +    progress: int = 1,
    +    progress_bar=None,
    +):
         """
         Construct Hasher class instances for each file in torrent.
         """
    @@ -1580,9 +1615,12 @@ 

    self.root = None self.padding_piece = None self.padding_file = None - if progress: - self.prog_start(os.path.getsize(path), path) self.amount = piece_length // BLOCK_SIZE + self.progress = progress + self.progbar = progress_bar + if self.progress == 1: + size = os.path.getsize(self.path) + self.progbar = self.get_progress_tracker(size, self.path) with open(path, "rb") as data: self.process_file(data)

    @@ -1639,28 +1677,7 @@

    Source code in torrentfile\hasher.py -
    + + + + @@ -1813,9 +1865,7 @@

    Source code in torrentfile\hasher.py -

    337
    -338
    -339
    -340
    -341
    -342
    -343
    -344
    -345
    -346
    -347
    -348
    -349
    -350
    -351
    -352
    -353
    -354
    -355
    -356
    -357
    -358
    +        
    358
     359
     360
     361
    @@ -1680,7 +1697,29 @@ 

    375 376 377 -378

    def process_file(self, data: bytearray):
    +378
    +379
    +380
    +381
    +382
    +383
    +384
    +385
    +386
    +387
    +388
    +389
    +390
    +391
    +392
    +393
    +394
    +395
    +396
    +397
    +398
    +399
    +400
    def process_file(self, data: bytearray):
         """
         Calculate layer hashes for contents of file.
     
    @@ -1697,7 +1736,7 @@ 

    block = bytearray(BLOCK_SIZE) for _ in range(self.amount): size = data.readinto(block) - self.prog_update(size) + self.progbar.update(size) if not size: break total += size @@ -1720,8 +1759,9 @@

    } piece.update(bytes(plength)) self.pieces.append(piece.digest()) # nosec + if self.progress == 1: + self.progbar.close_out() self._calculate_root() - self.prog_close()

    @@ -1741,7 +1781,7 @@

    -HasherV2(path: str, piece_length: int, progress: bool = True) +HasherV2(path: str, piece_length: int, progress: int = 1, progress_bar = None) #

    @@ -1792,7 +1832,7 @@

    progress -

    default = None

    +

    the progress mode

    TYPE: @@ -1800,7 +1840,19 @@

    DEFAULT: - True + 1 + +

    +

    progress_bar +

    a progress bar object if progress mode is 2

    +

    + + DEFAULT: + None

    204
    -205
    -206
    +            
    206
     207
     208
     209
    @@ -1826,7 +1876,24 @@ 

    214 215 216 -217

    def __init__(self, path: str, piece_length: int, progress: bool = True):
    +217
    +218
    +219
    +220
    +221
    +222
    +223
    +224
    +225
    +226
    +227
    +228
    def __init__(
    +    self,
    +    path: str,
    +    piece_length: int,
    +    progress: int = 1,
    +    progress_bar=None,
    +):
         """
         Calculate and store hash information for specific file.
         """
    @@ -1836,8 +1903,11 @@ 

    self.layer_hashes = [] self.piece_length = piece_length self.num_blocks = piece_length // BLOCK_SIZE - if progress: - self.prog_start(os.path.getsize(path), path) + self.progress = progress + self.progbar = progress_bar + if self.progress == 1: + size = os.path.getsize(self.path) + self.progbar = self.get_progress_tracker(size, self.path) with open(self.path, "rb") as fd: self.process_file(fd)

    @@ -1894,18 +1964,7 @@

    Source code in torrentfile\hasher.py -
    219
    -220
    -221
    -222
    -223
    -224
    -225
    -226
    -227
    -228
    -229
    -230
    +        
    230
     231
     232
     233
    @@ -1937,7 +1996,18 @@ 

    259 260 261 -262

    def process_file(self, fd: str):
    +262
    +263
    +264
    +265
    +266
    +267
    +268
    +269
    +270
    +271
    +272
    +273
    def process_file(self, fd: str):
         """
         Calculate hashes over 16KiB chuncks of file content.
     
    @@ -1953,9 +2023,9 @@ 

    for _ in range(self.num_blocks): size = fd.readinto(leaf) - self.prog_update(size) if not size: break + self.progbar.update(size) blocks.append(sha256(leaf[:size]).digest()) # blocks is empty mean eof @@ -1972,15 +2042,15 @@

    # pad the the rest with zeroes to fill remaining space. padding = [bytes(32) for _ in range(remaining)] - self.prog_update(HASH_SIZE * remaining) blocks.extend(padding) # calculate the root hash for the merkle tree up to piece-length layer_hash = merkle_root(blocks) self.cb(layer_hash) self.layer_hashes.append(layer_hash) + if self.progress == 1: + self.progbar.close_out() self._calculate_root() - self.prog_close()

    @@ -2154,7 +2224,7 @@

    - + diff --git a/docs/Source/index.html b/docs/Source/index.html index c61fb93..e761a08 100644 --- a/docs/Source/index.html +++ b/docs/Source/index.html @@ -19,7 +19,7 @@ - + @@ -27,7 +27,7 @@ - + @@ -73,7 +73,7 @@ - + @@ -97,9 +97,7 @@ - - -
    +