text
stringlengths
0
828
""""""
if not environ:
environ = os.environ
# make sure we have data
if not text:
return ''
# check for circular dependencies
cache = cache or {}
# return the cleaned variable
output = nstr(text)
keys = re.findall('\$(\w+)|\${(\w+)\}|\%(\w+)\%', text)
for first, second, third in keys:
repl = ''
key = ''
if first:
repl = '$%s' % first
key = first
elif second:
repl = '${%s}' % second
key = second
elif third:
repl = '%%%s%%' % third
key = third
else:
continue
value = environ.get(key)
if value:
if key not in cache:
cache[key] = value
value = self.expandvars(value, environ, cache)
else:
err = '%s environ variable causes an infinite loop.' % key
logger.warning(err)
value = cache[key]
else:
value = repl
output = output.replace(repl, value)
return os.path.expanduser(output)"
2008,"def pushPath(self, path):
""""""
Pushes the inputted path at the front of the sys.path variable, making
it the first path python uses when importing a module.
:param path
:type str
:return bool: success
""""""
# normalize the path
path = os.path.normcase(nstr(path)).strip()
if path and path != '.' and path not in sys.path:
sys.path.append(path)
self._addedpaths.insert(0, path)
return True
return False"
2009,"def requires(self, *modules):
""""""
Registers the system paths for the inputted modules so that they can
be imported properly. By default, this will check to see if the
key PROJEX_[MODULE]_PATH exists in the environment, and if so, insert
that path to the front of the sys.path for import. Out of the box
installations will register import paths to default projex folders
and won't need to define these path variables. (lib/,stdplug/,userplug)
:param *modules ( <str>, .. )
:usage |>>> import projex
|>>> projex.logger.setLevel( projex.logging.DEBUG )
|>>> projex.environ().requires( 'orb', 'anansi' )
|DEBUG: EnvManager.requires: PROJEX_ORB_PATH
|DEBUG: EnvManager.requires: PROJEX_ANANSI_PATH
|>>> import opb
|>>> import openwebdk
""""""
self._setup()
for module in modules:
if '-' in module:
parts = module.split('-')
module = parts[0]
version = '-'.join(parts)
else:
version = ''
if module in self._loadedRequires:
continue
self._loadedRequires.append(module)
path_key = 'PROJEX_%s_PATH' % nstr(module).upper()
env_path = os.getenv(path_key)
logger.debug('Looking up %s: %s' % (path_key, env_path))