@@ -26,25 +26,25 @@ def create_default_config():
2626#- -y
2727# Since PyYAML parser is sensitive to inline and in between comments, flags must be moved just after the active flags.
2828# Flag descriptions:
29- # -C Display ascii art with original colors
30- # --color-bg Use color on character background
31- # -b Use braille characters
32- # -g Display grayscale ascii art
33- # -c Use more ascii chars
34- # -f Use largest dimensions
35- # -n Negative colors
36- # -x Flip horizontally
37- # -y Flip vertically
29+ # -C Display ascii art with original colors
30+ # --color-bg Use color on character background
31+ # -b Use braille characters
32+ # -g Display grayscale ascii art
33+ # -c Use more ascii chars
34+ # -f Use largest dimensions
35+ # -n Negative colors
36+ # -x Flip horizontally
37+ # -y Flip vertically
3838#
3939# The following flags must be used in two separate lines:
4040# Example:
4141# -d
4242# 60,30
4343#
44- # -d 60,30 Set width and height for ascii art
45- # -W 60 Set width for ascii art
46- # -H 60 Set height for ascii art
47- # -m .-+#@ Custom ascii characters
44+ # -d 60,30 Set width and height for ascii art
45+ # -W 60 Set width for ascii art
46+ # -H 60 Set height for ascii art
47+ # -m .-+#@ Custom ascii characters
4848'''
4949 with open (config_file , 'w' ) as f :
5050 f .write (config_text )
@@ -73,7 +73,7 @@ def main():
7373 os .makedirs (config_dir , exist_ok = True ) # Create config directories.
7474 os .makedirs (os .path .join (config_dir , "images" ))
7575 open (date_dir_file , 'w' ).close () # Create date file.
76- create_default_config ()
76+ create_default_config ()
7777 elif not os .path .exists (config_file ):
7878 create_default_config ()
7979
@@ -149,20 +149,43 @@ def main():
149149
150150 # Extract the downloaded file.
151151 extract_dir = os .path .join (config_dir , "ascii-image-converter" )
152- if releaseName .endswith (".zip" ): # Extracts the correct file with correct library.
152+ binary_path = None # Initialize binary_path to None
153+
154+ if releaseName .endswith (".zip" ): # Extracts the correct file with correct library.
153155 try :
154156 with zipfile .ZipFile (outputFile , 'r' ) as zip_ref :
155157 zip_ref .extractall (extract_dir )
156158 print ("File extracted successfully." )
159+
160+ # Search for the executable in the extracted directory
161+ for root , _ , files in os .walk (extract_dir ):
162+ for file in files :
163+ if file == ('ascii-image-converter.exe' if system == 'WINDOWS' else 'ascii-image-converter' ):
164+ binary_path = os .path .join (root , file )
165+ break
166+ if binary_path :
167+ break # Found it, stop searching
168+
157169 except Exception as e :
158170 print (f"Error extracting file: { e } " )
159171 sys .exit (1 )
160172
161173 elif releaseName .endswith (".tar.gz" ):
162174 try :
175+ # Add filter='data' to prevent the DeprecationWarning in Python 3.14+
163176 with tarfile .open (outputFile , "r:gz" ) as tar_ref :
164- tar_ref .extractall (extract_dir )
177+ tar_ref .extractall (extract_dir , filter = 'data' )
165178 print ("File extracted successfully." )
179+
180+ # Search for the executable in the extracted directory
181+ for root , _ , files in os .walk (extract_dir ):
182+ for file in files :
183+ if file == 'ascii-image-converter' :
184+ binary_path = os .path .join (root , file )
185+ break
186+ if binary_path :
187+ break # Found it, stop searching
188+
166189 except Exception as e :
167190 print (f"Error extracting file: { e } " )
168191 sys .exit (1 )
@@ -176,8 +199,18 @@ def main():
176199 unixOS = 'linux'
177200 elif system == 'DARWIN' :
178201 unixOS = 'macos'
179- binary_path = os .path .join (extract_dir , releaseName .replace ('.tar.gz' , '' ).replace ('.zip' , '' ), 'ascii-image-converter' )
180- subprocess .run (["chmod" , "+x" , binary_path ], check = True ) # Set as executable.
202+
203+ # Verify binary_path was found during extraction
204+ if not binary_path or not os .path .exists (binary_path ):
205+ print (f"Error: Expected binary 'ascii-image-converter' not found after extraction in '{ extract_dir } '." )
206+ sys .exit (1 )
207+
208+ try :
209+ subprocess .run (["chmod" , "+x" , binary_path ], check = True ) # Set as executable.
210+ except subprocess .CalledProcessError as e :
211+ print (f"Failed to set executable permissions on '{ binary_path } ': { e } " )
212+ sys .exit (1 )
213+
181214 greetingsSrc = os .path .join (script_dir , f"greetings-{ unixOS } " )
182215 try :
183216 print ("Moving the binaries to ~/.local/bin..." )
@@ -193,7 +226,12 @@ def main():
193226 else : # Windows
194227 os .makedirs ("C:\\ Program Files\\ widkit\\ ascii-image-converter" , exist_ok = True ) # Make directories for ascii-image-converter and greetings.
195228 os .makedirs ("C:\\ Program Files\\ widkit\\ greetings" , exist_ok = True )
196- binary_path = os .path .join (extract_dir , releaseName .replace ('.zip' , '' ), 'ascii-image-converter.exe' )
229+
230+ # Verify binary_path was found during extraction
231+ if not binary_path or not os .path .exists (binary_path ):
232+ print (f"Error: Expected binary 'ascii-image-converter.exe' not found after extraction in '{ extract_dir } '." )
233+ sys .exit (1 )
234+
197235 shutil .move (binary_path , "C:\\ Program Files\\ widkit\\ ascii-image-converter\\ ascii-image-converter.exe" ) # Moves the file.
198236 shutil .copy ("greetings-windows.exe" , "C:\\ Program Files\\ widkit\\ greetings\\ greetings.exe" ) # Copies itself into Program Files.
199237
@@ -208,4 +246,4 @@ def main():
208246 print ("Setup complete." )
209247
210248if __name__ == "__main__" : # Return to main.py
211- main ()
249+ main ()
0 commit comments