Skip to content

Commit 271ab1f

Browse files
authored
Merge pull request #7 from widkit/6-feat-install-to-localbin-instead
feat: #6, install to localbin instead
2 parents a138154 + 074848d commit 271ab1f

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/setup.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, subprocess, platform, shutil, tarfile, zipfile, yaml, sys, requests, ctypes
1+
import os, subprocess, platform, shutil, tarfile, zipfile, sys, requests, ctypes
22

33
def create_default_config():
44
home_dir = os.path.expanduser("~")
@@ -61,14 +61,19 @@ def main():
6161
home_dir = os.path.expanduser("~")
6262
config_dir = os.path.join(home_dir, ".config/greetings")
6363

64+
# Install target
65+
targetDir = os.path.join(home_dir, ".local/bin/")
66+
asciiTarget = os.path.join(targetDir, "ascii-image-converter")
67+
greetingsTarget = os.path.join(targetDir, "greetings")
68+
6469
config_file = os.path.join(config_dir, "greetings.yaml") # Define files.
6570
date_dir_file = os.path.join(config_dir, "date.txt")
6671
if not os.path.exists(config_dir):
6772
print(f"Creating files at: {config_dir}")
6873
os.makedirs(config_dir, exist_ok=True) # Create config directories.
6974
os.makedirs(os.path.join(config_dir, "images"))
7075
open(date_dir_file, 'w').close() # Create date file.
71-
create_default_config()
76+
create_default_config()
7277
elif not os.path.exists(config_file):
7378
create_default_config()
7479

@@ -171,15 +176,20 @@ def main():
171176
unixOS = 'linux'
172177
elif system == 'DARWIN':
173178
unixOS = 'macos'
174-
binary_path = os.path.join(extract_dir, 'ascii-image-converter')
175-
subprocess.run(["chmod", "+x", binary_path], check=True)
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.
181+
greetingsSrc = os.path.join(script_dir, f"greetings-{unixOS}")
176182
try:
177-
print("Moving the binaries to /usr/local/bin (you may be prompted for your password)...")
178-
subprocess.run(["sudo", "mv", binary_path, "/usr/local/bin/ascii-image-converter"], check=True)
179-
subprocess.run(["sudo", "cp", f"greetings-{unixOS}", "/usr/local/bin/greetings"], check=True)
183+
print("Moving the binaries to ~/.local/bin...")
184+
os.makedirs(targetDir, exist_ok=True)
185+
shutil.move(binary_path, asciiTarget)
186+
shutil.copy2(greetingsSrc, greetingsTarget)
180187
except Exception as e:
181-
print(f"Failed to move binaries: {e}")
182-
sys.exit(1)
188+
print(f"Failed to move binaries: {e}")
189+
sys.exit(1)
190+
path_env = os.environ.get('PATH', '')
191+
if targetDir not in path_env.split(os.pathsep):
192+
print("Warn: ~/.local/bin not in PATH! Please add it to your PATH for the program to work correctly.")
183193
else: # Windows
184194
os.makedirs("C:\\Program Files\\widkit\\ascii-image-converter", exist_ok=True) # Make directories for ascii-image-converter and greetings.
185195
os.makedirs("C:\\Program Files\\widkit\\greetings", exist_ok=True)

0 commit comments

Comments
 (0)