Skip to content

Instantly share code, notes, and snippets.

@xlarsx
Created March 7, 2011 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xlarsx/858720 to your computer and use it in GitHub Desktop.
Save xlarsx/858720 to your computer and use it in GitHub Desktop.
Utilidad que valida la variable de entorno PATH y aquellas variables de entorno con las que está relacionado
import os, re
def evalua(matchobj):
textoAnterior = matchobj.group(0)
llave = textoAnterior[1 : len(textoAnterior) - 1]
if llave in os.environ:
return os.environ[llave]
return textoAnterior
def validaRutas(texto):
p = re.compile('%.*%')
for ruta in texto.split(";"):
rutaCompleta = p.sub(evalua, ruta)
yield ruta, os.path.exists(rutaCompleta)
if __name__ == "__main__":
pathValido = ""
agregado = []
for (ruta, valida) in validaRutas(os.environ['PATH']):
print valida, "\t", ruta
if valida and ruta not in agregado:
agregado.append(ruta)
pathValido += ruta + ";"
print "\n\n"
print pathValido
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment