@@ -75,22 +75,35 @@ def set_args():
75
75
parser .add_argument ("--fullsize" , action = 'store_true' , help = "Do not stretch images to the profile's device resolution" )
76
76
parser .add_argument ("--cache" , action = 'store_true' , help = "Avoid downloading chapters and use already downloaded chapters instead (offline)" )
77
77
parser .add_argument ("--remove-alpha" , action = 'store_true' , help = "When converting to PDF remove alpha channel on images using ImageMagick Wand" )
78
- parser .add_argument ("--version" , "-v" , action = 'version' , help = "Display current InMangaKindle version" , version = version () )
78
+ parser .add_argument ("--version" , "-v" , action = CheckVersion , help = "Display current InMangaKindle version" , version = VERSION )
79
79
args = parser .parse_args ()
80
80
81
- def version ():
82
- return f'{ Style .BRIGHT } %(prog)s { Fore .CYAN } { VERSION } { Style .RESET_ALL } '
81
+ class CheckVersion (argparse .Action ):
82
+ def __init__ (self , option_strings , version = VERSION , ** kwargs ):
83
+ super (CheckVersion , self ).__init__ (option_strings , nargs = 0 , ** kwargs )
84
+ self .version = version
85
+ def __call__ (self , parser , namespace , values , option_string = None ):
86
+ if not is_python_version_supported ():
87
+ print_colored (python_not_supported (), Fore .RED )
88
+ print_colored (NAME , Style .BRIGHT , end = ' ' )
89
+ print_colored (self .version , Style .BRIGHT , Fore .CYAN )
90
+ if check_version ():
91
+ print_colored ('✅ Up to date' , Fore .GREEN )
92
+ exit ()
83
93
84
94
def check_version ():
85
- latest_version = VERSION
95
+ latest_version = None
86
96
try :
87
97
response = requests .get (f'https://api.github.com/repos/Carleslc/{ NAME } /releases/latest' )
88
- latest_version = load_json (response .content , 'tag_name' )
89
98
html_url = load_json (response .content , 'html_url' )
99
+ latest_version = load_json (response .content , 'tag_name' )
90
100
except :
91
101
if not args .cache :
92
102
print_dim (f'Cannot check for updates. Version: { VERSION } ' , Fore .YELLOW )
93
- if latest_version != VERSION :
103
+ if latest_version is None :
104
+ return False
105
+ is_updated = latest_version == VERSION
106
+ if not is_updated :
94
107
print_colored (f'New version is available! { VERSION } -> { latest_version } ' , Style .BRIGHT , Fore .GREEN )
95
108
print_colored (f'Upgrade to the latest version: { html_url } ' , Fore .GREEN )
96
109
if os .path .isdir ('.git' ):
@@ -103,6 +116,7 @@ def check_version():
103
116
except :
104
117
print ('If you want to update later manually use ' , end = '' )
105
118
print_colored (f'git fetch && git checkout { latest_version } ' , Fore .YELLOW )
119
+ return is_updated
106
120
107
121
def is_python_version_supported ():
108
122
min_version , max_version = SUPPORT_PYTHON
@@ -115,7 +129,7 @@ def python_not_supported():
115
129
min_version , max_version = SUPPORT_PYTHON
116
130
min_version = '.' .join (map (str , min_version ))
117
131
max_version = '.' .join (map (str , max_version ))
118
- return f'Your Python version { platform .python_version ()} is not supported ({ sys .executable } --version). Please, use a Python version between { min_version } and { max_version } \n { RECOMMENDED_PYTHON } '
132
+ return f'Your Python version { platform .python_version ()} is not fully supported ({ sys .executable } --version). Please, use a Python version between { min_version } and { max_version } \n { RECOMMENDED_PYTHON } '
119
133
120
134
def print_colored (message , * colors , end = '\n ' ):
121
135
def printnoln (s ):
0 commit comments