Anonymous avatar Anonymous committed 8bc44ba

Add --env option to `grab` utility to specify virtualenv home

Comments (0)

Files changed (1)

 
 config = build_global_config()
 
-if config and config['GRAB_ACTIVATE_VIRTUALENV']:
+def activate_env(env_path):
     activate_script = os.path.join(config['GRAB_ACTIVATE_VIRTUALENV'], 'bin/activate_this.py')
     # py3 hack
     if PY3K:
     else:
         execfile(activate_script, dict(__file__=activate_script))
 
-if config and config['GRAB_DJANGO_SETTINGS']:
-    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
 
 def setup_logging(action, level):
     root = logging.getLogger()
     #default_logging(level=level)
 
 
+def process_env_option():
+    parser = ArgumentParser()
+    parser.add_argument('--env')
+    args, trash = parser.parse_known_args()
+    if args.env:
+        activate_env(args.env)
+
+
 def process_command_line():
     # Add current directory to python path
     cur_dir = os.path.realpath(os.getcwd())
     sys.path.insert(0, cur_dir)
 
+    process_env_option()
+
     parser = ArgumentParser()
     parser.add_argument('action', type=str)
     #parser.add_argument('positional_args', nargs='*')
     parser.add_argument('--lock-key')
     parser.add_argument('--ignore-lock', action='store_true', default=False)
     parser.add_argument('--settings', type=str, default='settings')
+    parser.add_argument('--env', type=str)
 
     args, trash = parser.parse_known_args()
 
+    config = build_global_config()
+    if config and config['GRAB_DJANGO_SETTINGS']:
+        os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+
     # Setup logging
     logging_level = getattr(logging, args.logging_level.upper())
     #if args.positional_args:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.