Skip to content

Commit f693250

Browse files
committed
add neat version check and upgrade and cleaned meta info
1 parent 0fa7cb3 commit f693250

File tree

5 files changed

+108
-18
lines changed

5 files changed

+108
-18
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# PyDVPL Cli Converter
2-
- A Cli Tool Coded In Python3 To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 High Compression.
2+
- A Cli Tool Coded In Python3 To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 Compression.
33

44
Package & Module Structure :
55

@@ -30,6 +30,8 @@ Usage :
3030
-i, --ignore: specifies comma-separated file extensions to ignore during compression.
3131
-v, --verbose: shows verbose information for all processed files.
3232
-t, --threads: specifies the number of threads to use for processing. Default is 1.
33+
--version: check version info/update and meta info.
34+
--upgrade: update to the latest version.
3335

3436
• mode can be one of the following:
3537

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "pydvpl"
33
description = "A CLI Tool Coded In Python3 To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 High Compression."
44
readme = "README.md"
5-
version = "0.7.0"
5+
version = "0.8.0"
66
authors = [{ name = "RifsxD", email = "support@rxd-mods.xyz" }]
77
license = { text = "MIT License" }
88
requires-python = ">=3.10"

src/pydvpl/_pydvpl.py

Lines changed: 98 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,77 @@
1313
PYDVPL_DIR = os.path.dirname(os.path.abspath(__file__))
1414
sys.path.append(os.path.dirname(PYDVPL_DIR))
1515

16-
from pydvpl.version import __version__, __description__, __title__, __date__, __repo__, __author__
16+
from pydvpl.version import __version__, __description__, __title__, __repo__, __author__, __license__
1717
from pydvpl.dvpl import compress_dvpl, decompress_dvpl, read_dvpl_footer, DVPL_FOOTER_SIZE, DVPL_TYPE_NONE, DVPL_TYPE_LZ4
1818
from pydvpl.color import Color
1919

20+
21+
import pkg_resources
22+
import requests
2023

21-
class Meta:
24+
def meta_info():
2225
NAME = __title__
2326
VERSION = __version__
24-
DATE = __date__
2527
DEV = __author__
2628
REPO = __repo__
2729
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"\rChecking 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("\nError occurred while checking for updates:", e)
50+
return
51+
except Exception as e:
52+
print("\nUnexpected 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(' ')
2887

2988

3089
output_lock = threading.Lock()
@@ -237,6 +296,19 @@ def process_mode(directory_or_file, config):
237296
raise ValueError("Incorrect mode selected. Use '--help' for information.")
238297

239298

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+
240312
def parse_command_line_args():
241313
parser = argparse.ArgumentParser()
242314
parser.add_argument("-m", "--mode",
@@ -252,9 +324,24 @@ def parse_command_line_args():
252324
help="Number of threads to use for processing. Default is 1.")
253325
parser.add_argument("-c", "--compression", choices=['default', 'fast', 'hc'],
254326
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")
255331

256332
args = parser.parse_args()
257333

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+
258345
if not args.mode:
259346
parser.error("No mode selected. Use '--help' for usage information")
260347

@@ -291,6 +378,8 @@ def print_help_message():
291378
-i, --ignore: specifies comma-separated file extensions to ignore during compression.
292379
-v, --verbose: shows verbose information for all processed files.
293380
-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.
294383
295384
• mode can be one of the following:
296385
@@ -349,16 +438,15 @@ def print_elapsed_time(elapsed_time):
349438

350439

351440
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-
359441
start_time = time.time()
360442
config = parse_command_line_args()
361443

444+
if config.version:
445+
meta_info()
446+
return
447+
448+
brand_ascii()
449+
362450
if config.threads <= 0:
363451
print(f"\n{Color.YELLOW}No threads specified.{Color.RESET} No processing will be done.\n")
364452
return

src/pydvpl/version/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
__description__,
33
__title__,
44
__version__,
5-
__date__,
65
__repo__,
7-
__author__
6+
__author__,
7+
__license__
88
)

src/pydvpl/version/_version.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = "PyDVPL"
2-
__description__ = "A CLI Tool Coded In Python3 To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 High Compression."
3-
__version__ = "0.7.0"
4-
__date__ = "2024-03-14"
2+
__description__ = "A CLI Tool Coded In Python3 To Convert WoTB ( Dava ) SmartDLC DVPL File Based On LZ4 Compression."
3+
__version__ = "0.8.0"
54
__author__ = "RifsxD"
6-
__repo__ = "https://github.com/rifsxd/pydvpl"
5+
__repo__ = "https://github.com/rifsxd/pydvpl"
6+
__license__ = "MIT"

0 commit comments

Comments
 (0)