13
13
PYDVPL_DIR = os .path .dirname (os .path .abspath (__file__ ))
14
14
sys .path .append (os .path .dirname (PYDVPL_DIR ))
15
15
16
- from pydvpl .version import __version__ , __description__ , __title__ , __date__ , __repo__ , __author__
16
+ from pydvpl .version import __version__ , __description__ , __title__ , __repo__ , __author__ , __license__
17
17
from pydvpl .dvpl import compress_dvpl , decompress_dvpl , read_dvpl_footer , DVPL_FOOTER_SIZE , DVPL_TYPE_NONE , DVPL_TYPE_LZ4
18
18
from pydvpl .color import Color
19
19
20
+
21
+ import pkg_resources
22
+ import requests
20
23
21
- class Meta :
24
+ def meta_info () :
22
25
NAME = __title__
23
26
VERSION = __version__
24
- DATE = __date__
25
27
DEV = __author__
26
28
REPO = __repo__
27
29
INFO = __description__
30
+ LICENSE = __license__
31
+
32
+ print ()
33
+
34
+ # Loading animation while checking for updates
35
+ animation = "|/-\\ "
36
+ idx = 0
37
+ while True :
38
+ print (f"\r Checking for updates... { animation [idx % len (animation )]} " , end = '' , flush = True )
39
+ idx += 1
40
+ if idx == 20 : # Number of animation iterations
41
+ break
42
+ time .sleep (0.05 ) # Adjust sleep time for faster animation
43
+
44
+ try :
45
+ response = requests .get (f"https://pypi.org/pypi/{ NAME } /json" , timeout = 3 ) # Set timeout for request
46
+ response .raise_for_status () # Raise exception for non-200 status codes
47
+ latest_version = response .json ()["info" ]["version" ]
48
+ except requests .exceptions .RequestException as e :
49
+ print ("\n Error occurred while checking for updates:" , e )
50
+ return
51
+ except Exception as e :
52
+ print ("\n Unexpected error occurred:" , e )
53
+ return
54
+
55
+ if latest_version :
56
+ installed_version = pkg_resources .parse_version (VERSION )
57
+ latest_pypi_version = pkg_resources .parse_version (latest_version )
58
+
59
+ if latest_pypi_version > installed_version :
60
+ print (f"\n \n { Color .BLUE } • Version:{ Color .RESET } { VERSION } (New version { latest_version } is available. Run `pydvpl --upgrade` to install latest version)" )
61
+ elif installed_version > latest_pypi_version :
62
+ print (f"\n \n { Color .BLUE } • Version:{ Color .RESET } { VERSION } (Whoa are you from the future? Cuz you have a newer version { VERSION } than available on PyPI { latest_version } )" )
63
+
64
+ else :
65
+ print (f"\n \n { Color .BLUE } • Version:{ Color .RESET } { VERSION } (You have the latest version.)" )
66
+ else :
67
+ print (f"\n \n { Color .BLUE } • Version:{ Color .RESET } { VERSION } (Failed to retrieve latest version from PyPI)" )
68
+
69
+ print (f"{ Color .BLUE } • Name:{ Color .RESET } { NAME } " )
70
+ print (f"{ Color .BLUE } • Dev:{ Color .RESET } { DEV } " )
71
+ print (f"{ Color .BLUE } • Repo:{ Color .RESET } { REPO } " )
72
+ print (f"{ Color .BLUE } • LICENSE:{ Color .RESET } { LICENSE } " )
73
+ print (f"{ Color .BLUE } • Info:{ Color .RESET } { INFO } \n " )
74
+
75
+
76
+ def brand_ascii ():
77
+ print (' ' )
78
+ print ('██████╗ ██╗ ██╗██████╗ ██╗ ██╗██████╗ ██╗ ' )
79
+ print ('██╔══██╗╚██╗ ██╔╝██╔══██╗██║ ██║██╔══██╗██║ ' )
80
+ print ('██████╔╝ ╚████╔╝ ██║ ██║██║ ██║██████╔╝██║ ' )
81
+ print ('██╔═══╝ ╚██╔╝ ██║ ██║╚██╗ ██╔╝██╔═══╝ ██║ ' )
82
+ print ('██║ ██║ ██████╔╝ ╚████╔╝ ██║ ███████╗' )
83
+ print ('╚═╝ ╚═╝ ╚═════╝ ╚═══╝ ╚═╝ ╚══════╝' )
84
+ print (' ' )
85
+ print (f'{ __description__ } ' )
86
+ print (' ' )
28
87
29
88
30
89
output_lock = threading .Lock ()
@@ -237,6 +296,19 @@ def process_mode(directory_or_file, config):
237
296
raise ValueError ("Incorrect mode selected. Use '--help' for information." )
238
297
239
298
299
+ def confirm_upgrade ():
300
+ while True :
301
+ user_input = input ("Are you sure you want to upgrade pydvpl? (y, yes / n, no): " ).strip ().lower ()
302
+ if user_input in ['yes' , 'y' ]:
303
+ return True
304
+ elif user_input in ['no' , 'n' ]:
305
+ return False
306
+ else :
307
+ print ("Invalid input. Please enter 'yes' (y) or 'no' (n)." )
308
+ sys .exit (1 ) # Exit the script if invalid input is provided
309
+
310
+
311
+
240
312
def parse_command_line_args ():
241
313
parser = argparse .ArgumentParser ()
242
314
parser .add_argument ("-m" , "--mode" ,
@@ -252,9 +324,24 @@ def parse_command_line_args():
252
324
help = "Number of threads to use for processing. Default is 1." )
253
325
parser .add_argument ("-c" , "--compression" , choices = ['default' , 'fast' , 'hc' ],
254
326
help = "Select compression level: 'default' for default compression, 'fast' for fast compression, 'hc' for high compression. Only available for 'compress' mode." )
327
+ parser .add_argument ("--version" , action = "store_true" ,
328
+ help = "show version information and updates and exit." )
329
+ parser .add_argument ("--upgrade" , action = "store_true" ,
330
+ help = "upgrade pydvpl to the latest version" )
255
331
256
332
args = parser .parse_args ()
257
333
334
+ if args .version :
335
+ meta_info ()
336
+ sys .exit ()
337
+
338
+ if args .upgrade :
339
+ if confirm_upgrade ():
340
+ os .system ('pip install pydvpl --upgrade' )
341
+ else :
342
+ print ("Upgrade cancelled." )
343
+ sys .exit ()
344
+
258
345
if not args .mode :
259
346
parser .error ("No mode selected. Use '--help' for usage information" )
260
347
@@ -291,6 +378,8 @@ def print_help_message():
291
378
-i, --ignore: specifies comma-separated file extensions to ignore during compression.
292
379
-v, --verbose: shows verbose information for all processed files.
293
380
-t, --threads: specifies the number of threads to use for processing. Default is 1.
381
+ --version: check version info/update and meta info.
382
+ --upgrade: update to the latest version.
294
383
295
384
• mode can be one of the following:
296
385
@@ -349,16 +438,15 @@ def print_elapsed_time(elapsed_time):
349
438
350
439
351
440
def cli ():
352
- print (f"\n { Color .BLUE } • Name:{ Color .RESET } { Meta .NAME } " )
353
- print (f"{ Color .BLUE } • Version:{ Color .RESET } { Meta .VERSION } " )
354
- print (f"{ Color .BLUE } • Commit:{ Color .RESET } { Meta .DATE } " )
355
- print (f"{ Color .BLUE } • Dev:{ Color .RESET } { Meta .DEV } " )
356
- print (f"{ Color .BLUE } • Repo:{ Color .RESET } { Meta .REPO } " )
357
- print (f"{ Color .BLUE } • Info:{ Color .RESET } { Meta .INFO } \n " )
358
-
359
441
start_time = time .time ()
360
442
config = parse_command_line_args ()
361
443
444
+ if config .version :
445
+ meta_info ()
446
+ return
447
+
448
+ brand_ascii ()
449
+
362
450
if config .threads <= 0 :
363
451
print (f"\n { Color .YELLOW } No threads specified.{ Color .RESET } No processing will be done.\n " )
364
452
return
0 commit comments