From e3721c12a369368a114430969b9740b93fb5b892 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 20 Oct 2013 22:27:23 -0700 Subject: [PATCH] swc-windows-installer.py: Generalize update_bash_profile And rename from make_bash_profile now that we're appending instead of creating (since c5d5414, Append exports to end of .bash_profile instead of overwriting, 2013-09-19). This more general form can be used to add even more paths, for example our IPython and nosetest entry points. --- setup/swc-windows-installer.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/setup/swc-windows-installer.py b/setup/swc-windows-installer.py index c4c7f41..341fac6 100755 --- a/setup/swc-windows-installer.py +++ b/setup/swc-windows-installer.py @@ -67,22 +67,25 @@ def create_nosetests_entry_point(python_scripts_directory): f.write(contents) -def make_bash_profile(home_dir, nano_dir): - """Creates a .bash_profile file for nano setup - - Adds nano to the path and sets the default editor to nano +def update_bash_profile(extra_paths=()): + """Create or append to a .bash_profile for Software Carpentry + Adds nano to the path, sets the default editor to nano, and adds + additional paths for other executables. """ - - nano_path = make_posix_path(nano_dir) - contents = '\n'.join(['', - '# Add nano to path and set as default editor', - '# Added by the Software Carpentry nano installer', - 'export PATH=$PATH:%s' % nano_path, - 'export EDITOR=nano', - '']) - with open(os.path.join(home_dir, '.bash_profile'), 'a') as f: - f.write(contents) + lines = [ + '', + '# Add paths for Software-Carpentry-installed scripts and executables', + 'export PATH=$PATH:{}'.format(':'.join( + make_posix_path(path) for path in extra_paths),), + '', + '# Make nano the default editor', + 'export EDITOR=nano', + '', + ] + config_path = os.path.join(os.path.expanduser('~'), '.bash_profile') + with open(config_path, 'a') as f: + f.write('\n'.join(lines)) def make_posix_path(windows_path): """Convert a Windows path to a posix path""" -- 2.26.2