Created
March 7, 2011 16:25
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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