Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def to(input, toType=PathConvType.AUTO):
"""
Convert between 3 types of path used widely in WSL.
Parameters
----------
input : str
the string of the original path.
toType : PathConvType
the type user wants to convert to. Default is PathConvType.AUTO.
Returns
-------
string of converted path.
Raises
------
ValueError
An error occurred when the input is invalid.
"""
if re.match(r'\/mnt\/[A-Za-z]', input) is not None: # Linux Path
if toType == PathConvType.AUTO:
return __Lin2Win__(input)
elif toType == PathConvType.WIN:
return __Lin2Win__(input)
elif toType == PathConvType.LINUX:
return input
elif toType == PathConvType.WINDOUBLE:
return __Win2Dwin__(__Lin2Win__(input))
else:
raise ValueError("ERROR: Invalid Conversion Type "+toType)
elif re.match(r'[A-Za-z]:\\\\', input) is not None: # Windows Path /w Double Dashline
if toType == PathConvType.AUTO:
return __DWin2Lin__(input)
elif toType == PathConvType.LINUX:
return __DWin2Lin__(input)
elif toType == PathConvType.WIN:
return __Lin2Win__(__DWin2Lin__(input))
elif toType == PathConvType.WINDOUBLE:
return input
else:
raise ValueError("ERROR: Invalid Conversion Type "+toType)
elif re.match(r'[A-Za-z]:', input) is not None: # Windows Path
if toType == PathConvType.AUTO:
return __DWin2Lin__(__Win2Dwin__(input))
elif toType == PathConvType.LINUX:
return __DWin2Lin__(__Win2Dwin__(input))
elif toType == PathConvType.WIN:
return input