Skip to content

Instantly share code, notes, and snippets.

@yarko
Created February 13, 2014 22:54
Show Gist options
  • Save yarko/8985636 to your computer and use it in GitHub Desktop.
Save yarko/8985636 to your computer and use it in GitHub Desktop.
patch for #2520, pavelib/utils/envs.py
diff --git a/pavelib/utils/envs.py b/pavelib/utils/envs.py
index 798cb3c..e120ba8 100644
--- a/pavelib/utils/envs.py
+++ b/pavelib/utils/envs.py
@@ -4,6 +4,7 @@ Helper functions for loading environment settings.
import os
import sys
import json
+import re
from lazy import lazy
from path import path
@@ -19,6 +20,18 @@ class Env(object):
# Service variant (lms, cms, etc.) configured with an environment variable
# We use this to determine which envs.json file to load.
SERVICE_VARIANT = os.environ.get('SERVICE_VARIANT', None)
+ # If service variant not configured in env, then pass the correct
+ # environment for lms / cms
+ if not SERVICE_VARIANT:
+ # ignore command line environments, e.g. "paver var=val"
+ clean_args = [x for x in sys.argv[1:] if x.find('=')<0]
+ # consider only words remaining (parse out separators)
+ p = re.compile(r'\W+')
+ clean_args = p.split(' '.join(clean_args))
+ # if lms or cms is among command line words, use it's env
+ SERVICE_VARIANT = 'lms' if 'lms' in clean_args \
+ else 'cms' if ('cms' in clean_args) or ('studio' in clean_args) \
+ else SERVICE_VARIANT
@lazy
def env_tokens(self):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment