Created
July 18, 2014 16:05
-
-
Save geopelia/fe92115b0e9e3700061e to your computer and use it in GitHub Desktop.
Script para cambiar la barra inclinada o slash en rutas de Windows o convertir las rutas en formato de Cygwin
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""NOMBRE: | |
chg_path - Script para cambiar la barra inclinada o slash en rutas de Windows | |
o convertir las rutas en formato de Cygwin | |
SINOPSIS: | |
chg_path [OPCION] [ruta] | |
DESCRIPCIÓN: | |
Usa -c para ruta Cygwin | |
Usa -w para ruta Windows con barras invertidas | |
Usa -h o --help para mostrar esta ayuda | |
¡Recuerda poner la ruta del archivo a convertir! | |
""" | |
import re | |
import sys | |
import getopt | |
def usage(): | |
print __doc__ | |
def rutaWin(cadena): | |
p = re.compile(r"\\") | |
return p.sub("/", cadena); | |
def rutaCyg(cadena): | |
p = re.compile(r"^\w\:") | |
a = re.match(r"^\w", cadena) | |
letra = a.group(0).lower() | |
return p.sub("/cygdrive/" + letra, rutaWin(cadena)); | |
def main(argv): | |
try: | |
opts, args = getopt.getopt(argv, "hwc", ["help"]) | |
except getopt.GetoptError: | |
usage() | |
sys.exit(2) | |
if len(opts) < 1: | |
usage() | |
sys.exit(2) | |
source = "".join(args) | |
if not source: | |
usage() | |
sys.exit(2) | |
k = "" | |
for opt, arg in opts: | |
if opt in ("-h", "--help"): | |
usage() | |
sys.exit() | |
elif opt == '-w': | |
k = rutaWin(source) | |
elif opt in ("-c"): | |
k = rutaCyg(source) | |
else: | |
assert False, "unhandled option" | |
print k | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment