Permalink
Browse files

Add environment vars to rsshell because of setup

  • Loading branch information...
1 parent ab9b394 commit 6d52b27798219e4bc49368a8deb0ff7bf62e821d @jgonggrijp jgonggrijp committed Apr 16, 2012
Showing with 32 additions and 6 deletions.
  1. +8 −0 setup.py
  2. +24 −6 src/rsshell.py
View
@@ -7,6 +7,14 @@
Copyright 2012 Julian Gonggrijp
Licensed under the Red Spider Project License.
See the License.txt that shipped with your copy of this software for details.
+
+
+Note: some of the program logic can be made more elegant if we make it
+os.chdir(red_spider_root) soon after verify_root().
+
+A -q option to make it less verbous would probably be nice. Until we have a
+dedicated 'update' command we'll need to run the setup every time one of the
+commands has been changed on master.
'''
from future_builtins import zip, map
View
@@ -7,13 +7,15 @@
'''
Ideas for future changes (unordered):
- use the subprocess module instead of os.system;
- - add variables like PATH and PYTHONPATH;
- - use the PATHEXT variable on windows (strip off the file extension on POSIX);
- cd to RED_SPIDER_ROOT/work, mkdir if it doesn't exist;
- - show a short info message on launch.
+ - move find_red_spider_root to setup.py and make rsshell fully depend
+ on the config file;
+ - show a short info message on launch (more than just the root and
+ 'call exit if you want your normal shell back').
'''
import os
+from os.path import join, exists
import sys
def find_red_spider_root():
@@ -33,17 +35,33 @@ def set_red_spider_root():
else: # POSIX assumed
config_path = os.getenv('HOME') + '/.config/xkcdRedSpider'
config_path = os.path.normpath(config_path)
- if os.path.exists(config_path):
+ if exists(config_path): # most reliable way to find the root
config = open(config_path)
red_spider_root = config.readline()
config.close()
os.putenv('RED_SPIDER_ROOT', red_spider_root)
- print('RED_SPIDER_ROOT =', red_spider_root)
+ print 'RED_SPIDER_ROOT =', red_spider_root
-def main (argv = None):
+def set_environment():
set_red_spider_root()
+ bin_dir = join(red_spider_root, 'bin')
+ lib_dir = join(red_spider_root, 'lib')
+ env_prepend('PATH', bin_dir)
+ env_prepend('PYTHONPATH', lib_dir)
+ if os.name == 'nt': # Windows
+ env_append('PATHEXT', '.py')
+
+def env_prepend (varname, addition):
+ os.putenv(varname, os.pathsep.join([addition, os.getenv(varname, '')]))
+
+def env_append (varname, addition):
+ os.putenv(varname, os.pathsep.join([os.getenv(varname, ''), addition]))
+
+def main (argv = None):
+ set_environment()
if argv and len(argv) > 1: # call the requested program
return os.system(" ".join(argv[1:]))
+ print 'Call "exit" if you want to return to your normal shell'
if os.name == 'nt': # Windows
return os.system(os.getenv('COMSPEC', 'cmd.exe'))
else: # POSIX assumed

0 comments on commit 6d52b27

Please sign in to comment.