ptrack


Logs | Files | README | README | LICENSE | LICENSE | GitLab


1
commit f5744e306760ef0d65590370eba5a746b71e67dc
2
Author: Connor Etherington <[email protected]>
3
Date:   Sun Aug 27 21:01:32 2023 +0200
4
5
    Auto-Commit Update 27.08.2023 - 21:01:32
6
---
7
 .gitlab/media/new-download.gif       | Bin 0 -> 3910164 bytes
8
 PKGBUILD                             |   2 +-
9
 README.md                            |   9 +-
10
 build/lib/ptrack/__init__.py         |  16 ---
11
 build/lib/ptrack/main.py             | 207 -----------------------------------
12
 build/lib/ptrack/methods.py          | 136 -----------------------
13
 dist/ptrack-0.2.2-py3-none-any.whl   | Bin 6551 -> 0 bytes
14
 dist/ptrack-0.2.2.tar.gz             | Bin 6568 -> 0 bytes
15
 ptrack.egg-info/PKG-INFO             |   7 --
16
 ptrack.egg-info/SOURCES.txt          |  12 --
17
 ptrack.egg-info/dependency_links.txt |   1 -
18
 ptrack.egg-info/entry_points.txt     |   5 -
19
 ptrack.egg-info/requires.txt         |   6 -
20
 ptrack.egg-info/top_level.txt        |   1 -
21
 ptrack/__init__.py                   |   2 +-
22
 recipe/meta.yaml                     |   2 +-
23
 setup.py                             |   2 +-
24
 17 files changed, 12 insertions(+), 396 deletions(-)
25
26
diff --git a/.gitlab/media/new-download.gif b/.gitlab/media/new-download.gif
27
new file mode 100644
28
index 0000000..6d77a66
29
Binary files /dev/null and b/.gitlab/media/new-download.gif differ
30
diff --git a/PKGBUILD b/PKGBUILD
31
index 29ada20..7e7c626 100644
32
--- a/PKGBUILD
33
+++ b/PKGBUILD
34
@@ -1,7 +1,7 @@
35
 # Maintainer: Connor Etherington <[email protected]>
36
 # ---
37
 pkgname=ptrack
38
-pkgver=0.2.2
39
+pkgver=0.2.3
40
 pkgrel=1
41
 pkgdesc="A simple CLI utility for asthetically tracking progress when copying, moving or downloading files."
42
 arch=(x86_64)
43
diff --git a/README.md b/README.md
44
index f1130dd..d15ed1f 100644
45
--- a/README.md
46
+++ b/README.md
47
@@ -3,7 +3,7 @@
48
 ### Welcome to ptrack, a powerful and user-friendly CLI utility for tracking the progress of your file operations.
49
 ### Designed to be as concise, efficient and performance-optimized, ptrack works swiftly and accurately, while providing insight into the progress of the task at hand.
50
 
51
-*Version: 0.2.2*
52
+*Version: 0.2.3*
53
 
54
 ***
55
 
56
@@ -18,6 +18,13 @@
57
 + Interruption Handling: ptrack is built to respect your system's interruption signals. It will promptly stop operations when such signals are received, reducing the risk of data corruption.
58
 + High Performance: Above all, ptrack stands out for its speed and accuracy. It ensures your file operations are executed swiftly and with a high degree of precision.
59
 
60
+## Introducing the new ptrack file downloader
61
+
62
+### In the latest release, ptrack has made all around changes increasing the visible stats/details of file opperaitions.
63
+### This is easily noticable in features such as ptracks new file/URL downloader (ptd) or (ptrack -d):
64
+
65
+![New Downloads Update](./.gitlab/media/download-new.gif)
66
+
67
 
68
 ## Installation:
69
 
70
diff --git a/build/lib/ptrack/__init__.py b/build/lib/ptrack/__init__.py
71
deleted file mode 100644
72
index 112f15e..0000000
73
--- a/build/lib/ptrack/__init__.py
74
+++ /dev/null
75
@@ -1,16 +0,0 @@
76
-import argparse
77
-version="0.2.2"
78
-
79
-parser = argparse.ArgumentParser(description='A simple CLI utility for asthetically tracking progress when copying or moving files.')
80
-parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
81
-parser.add_argument('-c', '--copy', action='store_true', help='copy files (You can use `ptc` instead of `ptrack -c`)')
82
-parser.add_argument('-m', '--move', action='store_true', help='move files (You can use `ptm` instead of `ptrack -m`)')
83
-parser.add_argument('-d', '--download', action='store_true', help='download files (You can use `ptd` instead of `ptrack -d`)')
84
-parser.add_argument('-V', '--version', action='version', version='%(prog)s' + version)
85
-
86
-args, unknown = parser.parse_known_args()
87
-
88
-verbose = args.verbose
89
-copy = args.copy
90
-move = args.move
91
-download = args.download
92
diff --git a/build/lib/ptrack/main.py b/build/lib/ptrack/main.py
93
deleted file mode 100644
94
index 48523fa..0000000
95
--- a/build/lib/ptrack/main.py
96
+++ /dev/null
97
@@ -1,207 +0,0 @@
98
-import os
99
-import re
100
-import sys
101
-import ptrack
102
-from ptrack.methods import format_file_size, regular_copy, verbose_copy, hlp, getTotalSize, CustomFileSizeColumn
103
-from rich.progress import Progress, BarColumn, TextColumn, TimeRemainingColumn, FileSizeColumn
104
-from rich.console import Console
105
-from datetime import timedelta
106
-import shutil
107
-import requests
108
-import validators
109
-
110
-verbose = ptrack.verbose
111
-argCopy = ptrack.copy
112
-argMove = ptrack.move
113
-argDownload = ptrack.download
114
-
115
-
116
-def run(process):
117
-    console = Console()
118
-
119
-    if len(sys.argv) < 3:
120
-        hlp()
121
-        if process == "Copying":
122
-            console.print("[bold cyan]Usage: ptc [OPTIONS] SOURCE... DESTINATION[/bold cyan]")
123
-        elif process == "Moving":
124
-            console.print("[bold cyan]Usage: ptm [OPTIONS] SOURCE... DESTINATION[/bold cyan]")
125
-        sys.exit(1)
126
-
127
-    src_paths = sys.argv[1:-1]
128
-    dst = sys.argv[-1]
129
-    srcPaths = []
130
-
131
-    for path in src_paths:
132
-        if path.endswith('/'):
133
-            path = path[:-1]
134
-        srcPaths.append(path)
135
-
136
-    if os.path.isdir(dst):
137
-        dst_dir = dst
138
-        new_name = None
139
-    else:
140
-        dst_dir = os.path.dirname(dst)
141
-        new_name = os.path.basename(dst)
142
-
143
-    total_files = sum(len(files) for path in srcPaths for r, d, files in os.walk(path) if os.path.isdir(path)) + sum(1 for path in srcPaths if os.path.isfile(path))
144
-    total_size = getTotalSize(srcPaths)
145
-
146
-    current_file = 1
147
-
148
-    if total_files > 1:
149
-        console.print(f"\n[#ea2a6f]{process}:[/#ea2a6f] [bold cyan]{total_files} files[/bold cyan]\n")
150
-    else:
151
-        for src_path in srcPaths:
152
-            if os.path.isfile(src_path):
153
-                console.print(f"\n[#ea2a6f]{process}:[/#ea2a6f] [bold cyan] {os.path.basename(src_path)} [/bold cyan]\n")
154
-
155
-    if verbose:
156
-        for src_path in srcPaths:
157
-            if os.path.isfile(src_path):
158
-                dst_path = os.path.join(dst_dir, os.path.basename(src_path) if not new_name else new_name)
159
-                terminate = verbose_copy(src_path, dst_path, console, current_file, total_files, file_name=os.path.basename(src_path))
160
-                current_file += 1
161
-                if terminate == 'c':
162
-                    console.print("\n[bold red]\[-][/bold red][bold white] Operation cancelled by user.[/bold white]\n")
163
-                    sys.exit(1)
164
-            else:
165
-                for root, dirs, files in os.walk(src_path):
166
-                    for file in files:
167
-                        src_file_path = os.path.join(root, file)
168
-                        relative_path = os.path.relpath(src_file_path, start=src_path)
169
-                        dst_file_path = os.path.join(dst_dir, os.path.basename(src_path) if not new_name else new_name, relative_path)
170
-                        os.makedirs(os.path.dirname(src_file_path), exist_ok=True)
171
-                        terminate = verbose_copy(src_file_path, dst_file_path, console, current_file, total_files, file_name=file)
172
-                        current_file += 1
173
-                        if terminate == 'c':
174
-                            console.print("\n[bold red]\[-][/bold red][bold white] Operation cancelled by user.[/bold white]\n")
175
-                            sys.exit(1)
176
-    else:
177
-        with Progress(
178
-            BarColumn(bar_width=50),
179
-            "[progress.percentage]{task.percentage:>3.0f}%",
180
-            TimeRemainingColumn(),
181
-            "[#ea2a6f][[/#ea2a6f]",
182
-            FileSizeColumn(),
183
-            "[#ea2a6f]/[/#ea2a6f]",
184
-            TextColumn("[bold cyan]{task.fields[total_size]}[/bold cyan]"),
185
-            "[#ea2a6f]][/#ea2a6f]",
186
-            console=console,
187
-            auto_refresh=False
188
-        ) as progress:
189
-            task = progress.add_task("", total=total_size, total_size=format_file_size(total_size))
190
-
191
-            for src_path in srcPaths:
192
-                if os.path.isfile(src_path):
193
-                    dst_file_path = os.path.join(dst_dir, os.path.basename(src_path) if not new_name else new_name)
194
-                    terminate = regular_copy(src_path, dst_file_path, console, task, progress, file_name=os.path.basename(src_path))
195
-                    if terminate == 'c':
196
-                        console.print("\n[bold red]\[-][/bold red][bold white] Operation cancelled by user.[/bold white]\n")
197
-                        sys.exit(1)
198
-                else:
199
-                    for root, dirs, files in os.walk(src_path):
200
-                        for file in files:
201
-                            src_file_path = os.path.join(root, file)
202
-                            relative_path = os.path.relpath(src_file_path, start=src_path)
203
-                            dst_file_path = os.path.join(dst_dir, os.path.basename(src_path) if not new_name else new_name, relative_path)
204
-                            os.makedirs(os.path.dirname(dst_file_path), exist_ok=True)
205
-                            terminate = regular_copy(src_file_path, dst_file_path, console, task, progress, file_name=file)
206
-                            if terminate == 'c':
207
-                                console.print("\n[bold red]\[-][/bold red][bold white] Operation cancelled by user.[/bold white]\n")
208
-                                sys.exit(1)
209
-
210
-    return srcPaths
211
-
212
-
213
-def download():
214
-    console = Console()
215
-    urls = sys.argv[1:]
216
-
217
-    if len(urls) == 0:
218
-        console.print("\n[bold red][-][/bold red] No URL provided.\n")
219
-        sys.exit()
220
-
221
-    num_urls = len(urls)
222
-    for url in urls:
223
-        if url.startswith('-'):
224
-            num_urls -= 1
225
-        elif not validators.url(url):
226
-            console.print(f"\n[bold red][-][/bold red] Invalid URL: [bold yellow]{url}[/bold yellow]\n")
227
-            sys.exit()
228
-
229
-    console.print(f"\n[#ea2a6f]Downloading:[/#ea2a6f] [bold yellow]{num_urls}[/bold yellow] [bold cyan]files[/bold cyan]\n")
230
-
231
-    errors = []
232
-    for url in urls:
233
-        try:
234
-            if url.startswith('-'):
235
-                continue
236
-
237
-            response = requests.get(url, stream=True, allow_redirects=True)
238
-            total_size_in_bytes = int(response.headers.get('content-length', 0))
239
-            content_disposition = response.headers.get('content-disposition')
240
-            if content_disposition:
241
-                destination_path = re.findall('filename="(.+)"', content_disposition)[0]
242
-            else:
243
-                destination_path = os.path.basename(url)
244
-
245
-            with Progress(
246
-                BarColumn(bar_width=50),
247
-                "[progress.percentage]{task.percentage:>3.0f}%",
248
-                TimeRemainingColumn(),
249
-                "[#ea2a6f][[/#ea2a6f]",
250
-                CustomFileSizeColumn(),
251
-                "[#ea2a6f]][/#ea2a6f]",
252
-                f" {destination_path}",  # This line will print the filename at the end
253
-                console=console,
254
-                auto_refresh=True
255
-            ) as progress:
256
-                task_id = progress.add_task("Downloading", total=total_size_in_bytes)
257
-                block_size = 1024  # 1 Kibibyte
258
-                with open(destination_path, 'wb') as file:
259
-                    for data in response.iter_content(block_size):
260
-                        file.write(data)
261
-                        progress.update(task_id, advance=block_size)
262
-        except KeyboardInterrupt:
263
-            console.print("\n[bold red]\[-][/bold red][bold white] Operation cancelled by user.[/bold white]\n")
264
-            sys.exit(1)
265
-
266
-        except Exception as e:
267
-            console.print(f"\n[bold red]\[-][/bold red][bold white] Could not download file: [bold yellow]{url}[/bold yellow]\n")
268
-            print(e)
269
-            errors.append(url)
270
-
271
-    if len(errors) == 0:
272
-        console.print("\n[bold green]Download completed![/bold green]\n")
273
-    else:
274
-        console.print("[bold red]The following files could not be downloaded:[/bold red]\n")
275
-        for error in errors:
276
-            console.print(f"[bold red]   -[/bold red][bold yellow]{error}[/bold yellow]\n")
277
-
278
-
279
-def copy():
280
-    run('Copying')
281
-
282
-
283
-def move():
284
-    src_paths = run('Moving')
285
-    for src_path in src_paths:
286
-        if os.path.isfile(src_path):
287
-            os.remove(src_path)
288
-        else:
289
-            shutil.rmtree(src_path)
290
-
291
-
292
-def main():
293
-    if argMove:
294
-        move()
295
-    elif argCopy:
296
-        copy()
297
-    elif argDownload:
298
-        download()
299
-    else:
300
-        hlp()
301
-
302
-
303
-if __name__ == "__main__":
304
-    main()
305
diff --git a/build/lib/ptrack/methods.py b/build/lib/ptrack/methods.py
306
deleted file mode 100644
307
index d79173d..0000000
308
--- a/build/lib/ptrack/methods.py
309
+++ /dev/null
310
@@ -1,136 +0,0 @@
311
-import os
312
-import sys
313
-import requests
314
-from rich.console import Console
315
-from rich.progress import Progress, TextColumn, BarColumn, TimeRemainingColumn, FileSizeColumn, Task, DownloadColumn, TimeElapsedColumn
316
-from rich.text import Text
317
-from datetime import timedelta
318
-from humanize import naturalsize
319
-
320
-console = Console()
321
-
322
-
323
-def getTotalSize(srcPaths):
324
-    total_size = 0
325
-    for path in srcPaths:
326
-        if os.path.isfile(path):
327
-            total_size += os.path.getsize(path)
328
-        else:
329
-            for r, d, files in os.walk(path):
330
-                for f in files:
331
-                    fp = os.path.join(r, f)
332
-                    total_size += os.path.getsize(fp)
333
-    return total_size
334
-
335
-
336
-def format_file_size(file_size):
337
-    if file_size >= 1000 ** 4:  # Terabyte
338
-        return f"{round(file_size / (1000 ** 4))} TB"
339
-    elif file_size >= 1000 ** 3:  # Gigabyte
340
-        return f"{round(file_size / (1000 ** 3))} GB"
341
-    elif file_size >= 1000 ** 2:  # Megabyte
342
-        return f"{round(file_size / (1000 ** 2))} MB"
343
-    elif file_size >= 1000:  # Kilobyte
344
-        return f"{round(file_size / 1000)} kB"
345
-    else:  # Byte
346
-        return f"{file_size} bytes"
347
-
348
-
349
-def regular_copy(src, dst, console, task, progress, file_name):
350
-    operation_cancelled = False
351
-    try:
352
-        with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
353
-            while True:
354
-                buf = fsrc.read(1024*1024)
355
-                if not buf or operation_cancelled:
356
-                    break
357
-                fdst.write(buf)
358
-                progress.update(task, advance=len(buf))
359
-                progress.refresh()
360
-
361
-    except KeyboardInterrupt:
362
-        operation_cancelled = True
363
-        progress.stop()
364
-        return "c"
365
-
366
-
367
-def verbose_copy(src, dst, console, current, total_files, file_name):
368
-    operation_cancelled = False
369
-    file_size = os.path.getsize(src)
370
-
371
-    with Progress(
372
-        BarColumn(bar_width=50),
373
-        "[progress.percentage]{task.percentage:>3.0f}%",
374
-        TimeRemainingColumn(),
375
-        "[#ea2a6f][[/#ea2a6f]",
376
-        FileSizeColumn(),
377
-        "[#ea2a6f]/[/#ea2a6f]",
378
-        TextColumn(f"[bold cyan]{format_file_size(file_size)}[/bold cyan]"),
379
-        "[#ea2a6f]][/#ea2a6f]",
380
-        f"({current} of {total_files}) - {file_name}",
381
-        console=console,
382
-        auto_refresh=False
383
-    ) as progress:
384
-        task = progress.add_task("", total=file_size, file_size=format_file_size(file_size))
385
-
386
-        try:
387
-            with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
388
-                while not progress.finished:
389
-                    buf = fsrc.read(1024*1024)
390
-                    if not buf or operation_cancelled:
391
-                        break
392
-                    fdst.write(buf)
393
-                    progress.update(task, advance=len(buf))
394
-                    progress.refresh()
395
-        except KeyboardInterrupt:
396
-            operation_cancelled = True
397
-            progress.stop()
398
-            return "c"
399
-
400
-
401
-def hlp():
402
-    print("""
403
-usage: ptrack [-h] [-v] [-c] [-m] [-d] [-V]
404
-
405
-A simple CLI utility for asthetically tracking progress when copying or moving files.
406
-
407
-options:
408
-  -h, --help      show this help message and exit
409
-  -v, --verbose   verbose output
410
-  -c, --copy      copy files (You can use `ptc` instead of `ptrack -c`)
411
-  -m, --move      move files (You can use `ptm` instead of `ptrack -m`)
412
-  -d, --download  download files (You can use `ptd` instead of `ptrack -d`)
413
-  -V, --version   show program's version number and exit
414
-""")
415
-
416
-
417
-class CustomFileSizeColumn(FileSizeColumn, TimeElapsedColumn):
418
-    def render(self, task):
419
-        completed = task.completed
420
-        total = task.total
421
-        elapsed = task.elapsed
422
-
423
-        if elapsed > 0.0:  # Prevent division by zero
424
-            download_speed = completed / elapsed  # calculate download rate
425
-        else:
426
-            download_speed = 0
427
-
428
-        if total:
429
-            size = Text.assemble(
430
-                (f"{self._human_readable_size(completed)}", "green"),  # completed
431
-                (" / ", "none"),  # separator
432
-                (f"{self._human_readable_size(total)}", "red"),  # total
433
-                (" [", "none"),  # opening square bracket
434
-                (f"{self._human_readable_size(download_speed)}/s", "blue"),  # download rate
435
-                ("]", "none"),  # closing square bracket
436
-            )
437
-        else:
438
-            size = Text(str(self._human_readable_size(completed)))
439
-        return size
440
-
441
-    def _human_readable_size(self, size: int) -> str:
442
-        for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
443
-            if abs(size) < 1024.0:
444
-                return f"{size:.1f}{unit}"
445
-            size /= 1024.0
446
-        return f"{size:.1f}PB"
447
diff --git a/dist/ptrack-0.2.2-py3-none-any.whl b/dist/ptrack-0.2.2-py3-none-any.whl
448
deleted file mode 100644
449
index b1836bd..0000000
450
Binary files a/dist/ptrack-0.2.2-py3-none-any.whl and /dev/null differ
451
diff --git a/dist/ptrack-0.2.2.tar.gz b/dist/ptrack-0.2.2.tar.gz
452
deleted file mode 100644
453
index ac589df..0000000
454
Binary files a/dist/ptrack-0.2.2.tar.gz and /dev/null differ
455
diff --git a/ptrack.egg-info/PKG-INFO b/ptrack.egg-info/PKG-INFO
456
deleted file mode 100644
457
index 2ce3426..0000000
458
--- a/ptrack.egg-info/PKG-INFO
459
+++ /dev/null
460
@@ -1,7 +0,0 @@
461
-Metadata-Version: 2.1
462
-Name: ptrack
463
-Version: 0.2.2
464
-Summary: A simple CLI utility for asthetically tracking progress when copying, moving or downloading files.
465
-Author: Connor Etherington
466
-Author-email: [email protected]
467
-License-File: LICENSE
468
diff --git a/ptrack.egg-info/SOURCES.txt b/ptrack.egg-info/SOURCES.txt
469
deleted file mode 100644
470
index 086a784..0000000
471
--- a/ptrack.egg-info/SOURCES.txt
472
+++ /dev/null
473
@@ -1,12 +0,0 @@
474
-LICENSE
475
-README.md
476
-setup.py
477
-ptrack/__init__.py
478
-ptrack/main.py
479
-ptrack/methods.py
480
-ptrack.egg-info/PKG-INFO
481
-ptrack.egg-info/SOURCES.txt
482
-ptrack.egg-info/dependency_links.txt
483
-ptrack.egg-info/entry_points.txt
484
-ptrack.egg-info/requires.txt
485
-ptrack.egg-info/top_level.txt
486
diff --git a/ptrack.egg-info/dependency_links.txt b/ptrack.egg-info/dependency_links.txt
487
deleted file mode 100644
488
index 8b13789..0000000
489
--- a/ptrack.egg-info/dependency_links.txt
490
+++ /dev/null
491
@@ -1 +0,0 @@
492
-
493
diff --git a/ptrack.egg-info/entry_points.txt b/ptrack.egg-info/entry_points.txt
494
deleted file mode 100644
495
index ea851b3..0000000
496
--- a/ptrack.egg-info/entry_points.txt
497
+++ /dev/null
498
@@ -1,5 +0,0 @@
499
-[console_scripts]
500
-ptc = ptrack.main:copy
501
-ptd = ptrack.main:download
502
-ptm = ptrack.main:move
503
-ptrack = ptrack.main:main
504
diff --git a/ptrack.egg-info/requires.txt b/ptrack.egg-info/requires.txt
505
deleted file mode 100644
506
index d19a378..0000000
507
--- a/ptrack.egg-info/requires.txt
508
+++ /dev/null
509
@@ -1,6 +0,0 @@
510
-rich
511
-argparse
512
-requests
513
-validators
514
-setuptools
515
-humanize
516
diff --git a/ptrack.egg-info/top_level.txt b/ptrack.egg-info/top_level.txt
517
deleted file mode 100644
518
index c003217..0000000
519
--- a/ptrack.egg-info/top_level.txt
520
+++ /dev/null
521
@@ -1 +0,0 @@
522
-ptrack
523
diff --git a/ptrack/__init__.py b/ptrack/__init__.py
524
index 112f15e..efccb54 100644
525
--- a/ptrack/__init__.py
526
+++ b/ptrack/__init__.py
527
@@ -1,5 +1,5 @@
528
 import argparse
529
-version="0.2.2"
530
+version="0.2.3"
531
 
532
 parser = argparse.ArgumentParser(description='A simple CLI utility for asthetically tracking progress when copying or moving files.')
533
 parser.add_argument('-v', '--verbose', action='store_true', help='verbose output')
534
diff --git a/recipe/meta.yaml b/recipe/meta.yaml
535
index 3747a0a..34421b8 100644
536
--- a/recipe/meta.yaml
537
+++ b/recipe/meta.yaml
538
@@ -1,6 +1,6 @@
539
 package:
540
   name: ptrack
541
-  version: 0.2.2
542
+  version: 0.2.3
543
 
544
 source:
545
   path: ..
546
diff --git a/setup.py b/setup.py
547
index 4728915..5c4abc3 100644
548
--- a/setup.py
549
+++ b/setup.py
550
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
551
 
552
 setup(
553
     name='ptrack',
554
-    version="0.2.2",
555
+    version="0.2.3",
556
     description='A simple CLI utility for asthetically tracking progress when copying, moving or downloading files.',
557
     author='Connor Etherington',
558
     author_email='[email protected]',