I am attempting to run a python script from Xcode in the Build Pre-actions:

#! /usr/bin/env python
import shutil
import os
app_name = 'name'
def skinfunction(root_src_dir, root_dst_dir):
for src_dir, dirs, files in os.walk(root_src_dir):
print(str(files))
dst_dir = src_dir.replace(root_src_dir, root_dst_dir)
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
for file_ in files:
src_file = os.path.join(src_dir, file_)
dst_file = os.path.join(dst_dir, file_)
if os.path.exists(dst_file):
os.remove(dst_file)
shutil.copy(src_file, dst_dir)
root_src_dir = '${PROJECT_DIR}/skins/'+str(app_name)+'/authorize_bg.imageset'
root_dst_dir = '${PROJECT_DIR}/iDetail/Images.xcassets/authorize_bg.imageset'
skinfunction(root_src_dir,root_dst_dir);
Nearing the end of the script I am trying to get the PROJECT_DIR Xcode environment variable, but it is just not working properly. Either the value is invalid or my formatting is off.
If I hard code the PROJECT_DIR value (the full url to where the project resides) and the script runs successfully.
Am I missing something in trying to get the environment variable.
Ok, I figured it out, instead of trying to get the environment variable directly by using ${PROJECT_DIR} you need to call os.getenv() function. I was able to get the environment variable by calling:
proj_dir = os.getenv('PROJECT_DIR')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With