From a path given in any format, converts to posix path format
    fromwinpath=True forces the input path to be recognized as a Windows path (useful on Unix machines to unit test Windows paths)
971118
def path2unix(path, nojoin=False, fromwinpath=False):
    ''''''
    if fromwinpath:
        pathparts = list(PureWindowsPath(path).parts)
    else:
        pathparts = list(PurePath(path).parts)
    if nojoin:
        return pathparts
    else:
        return posixpath.join(*pathparts)
800420
public static boolean isAbsolutePath (final String path) {
        if (path == null || path.trim().length() == 0) {
            return false;
        }

        if (File.separator.equals(UNIX_SEPARATOR)) {
            return path.startsWith(UNIX_SEPARATOR);
        } else

        if (File.separator.equals(WINDOWS_SEPARATOR) && path.length() > 2) {
            return path.matches("([a-zA-Z]:|\\\\)\\\\.*");
        }

        return false;
    }
427148
def posixpath_normpath(pathname):
    
    backslash = '\\'
    pathname2 = os.path.normpath(pathname) or "."
    if backslash in pathname2:
        pathname2 = pathname2.replace(backslash, '/')
    return pathname2
1177528
def __get_posix_path(self):
        """"""
        if os_sep_is_slash:
            return self
        else:
            entry = self.get()
            r = entry.get_path().replace(OS_SEP, '/')
            return SCons.Subst.SpecialAttrWrapper(r, entry.name + "_posix")
809520
def _get_cygwin_path(self, windows_path):
        
        conv_cmd = [os.path.join(self._cygwin_bin_location, "cygpath.exe"),
                    "-u", windows_path]
        process = Popen(conv_cmd,
                        stdout=PIPE, stderr=PIPE, shell=False)
        out, err = process.communicate()
        if err:
            print(err)
            raise Exception(err)

        return out.strip()
1137737
def absolute_path(self, path, start):
        
        if posixpath.isabs(path):
            path = posixpath.join(staticfiles_storage.location, path)
        else:
            path = posixpath.join(start, path)
        return posixpath.normpath(path)
1004202
private static String resolveSibling(String fromPath, String toPath) {
    // If the destination is an absolute path, nothing to do.
    if (toPath.startsWith("/")) {
      return toPath;
    }

    List<String> fromPathParts = new ArrayList<>(Arrays.asList(fromPath.split("/")));
    List<String> toPathParts = new ArrayList<>(Arrays.asList(toPath.split("/")));
    if (!fromPathParts.isEmpty()) {
      fromPathParts.remove(fromPathParts.size() - 1);
    }

    while (!fromPathParts.isEmpty() && !toPathParts.isEmpty()) {
      if (toPathParts.get(0).equals(".")) {
        toPathParts.remove(0);
      } else if (toPathParts.get(0).equals("..")) {
        toPathParts.remove(0);
        fromPathParts.remove(fromPathParts.size() - 1);
      } else {
        break;
      }
    }

    fromPathParts.addAll(toPathParts);
    return String.join("/", fromPathParts);
  }
788650
def convert_path(path):
    
    if os.path.isabs(path):
        raise Exception("Cannot include file with absolute path {}. Please use relative path instead".format((path)))

    path = os.path.normpath(path)

    return path
958593
def output_path(self, path_name):
                
        # make sure it is a valid posix format
        path = to_posix(path_name)
        
        assert (path == path_name), "path_name passed to output_path must be in posix format"
        
        if posixpath.isabs(path):
            if self.output == self.cache:
                # worth seeing if an absolute path can be avoided
                path = posixpath.relpath(path, self.output)

            else:
                return posixpath.realpath(path)
    
        if path.startswith('../'):
            joined = posixpath.join(self.output, path)
            return posixpath.realpath(joined)
    
        return path
529524
def os_parityPath(path):
    
    path = os.path.normpath(os.path.expanduser(path))
    if path.startswith('\\'):
        return 'C:' + path
    return path
701843
def from_path_by_ext(dir_path, ext):
        
        if isinstance(ext, (list, set, dict)): # collection of extension
            def filter(winfile):
                if winfile.ext in ext:
                    return True
                else:
                    return False
        else: # str
            def filter(winfile):
                if winfile.ext == ext:
                    return True
                else:
                    return False

        return FileCollection.from_path_by_criterion(
            dir_path, filter, keepboth=False)
1119099
def PathToComponents(path):
  
  precondition.AssertType(path, Text)
  if path and not path.startswith("/"):
    raise ValueError("Path '{}' is not absolute".format(path))

  if path:
    return tuple(path.split("/")[1:])
  else:
    return ()
526568
def posix_commonpath(paths):
    """"""

    if not paths:
        raise ValueError('commonpath() arg is an empty sequence')

    check_arg_types('commonpath', *paths)

    if isinstance(paths[0], bytes):
        sep = b'/'
        curdir = b'.'
    else:
        sep = '/'
        curdir = '.'

    split_paths = [path.split(sep) for path in paths]

    try:
        isabs, = set(p[:1] == sep for p in paths)
    except ValueError:
        raise ValueError("Can't mix absolute and relative paths")

    split_paths = [[c for c in s if c and c != curdir] for s in split_paths]
    s_min = min(split_paths)
    s_max = max(split_paths)
    common = s_min
    for i, run_c in enumerate(s_min):
        if run_c != s_max[i]:
            common = s_min[:i]
            break

    prefix = sep if isabs else sep[:0]
    return prefix + sep.join(common)
1050826
def readlink(path):
    '''
    
    '''
    if six.PY3 or not salt.utils.platform.is_windows():
        return os.readlink(path)

    if not HAS_WIN32FILE:
        log.error('Cannot read %s, missing required modules', path)

    reparse_data = _get_reparse_data(path)

    if not reparse_data:
        # Reproduce *NIX behavior when os.readlink is performed on a path that
        # is not a symbolic link.
        raise OSError(errno.EINVAL, 'Invalid argument: \'{0}\''.format(path))

    # REPARSE_DATA_BUFFER structure - see
    # http://msdn.microsoft.com/en-us/library/ff552012.aspx

    # parse the structure header to work out which type of reparse point this is
    header_parser = struct.Struct('L')
    ReparseTag, = header_parser.unpack(reparse_data[:header_parser.size])
    # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365511.aspx
    if not ReparseTag & 0xA000FFFF == 0xA000000C:
        raise OSError(
            errno.EINVAL,
            '{0} is not a symlink, but another type of reparse point '
            '(0x{0:X}).'.format(ReparseTag)
        )

    # parse as a symlink reparse point structure (the structure for other
    # reparse points is different)
    data_parser = struct.Struct('LHHHHHHL')
    ReparseTag, ReparseDataLength, Reserved, SubstituteNameOffset, \
    SubstituteNameLength, PrintNameOffset, \
    PrintNameLength, Flags = data_parser.unpack(reparse_data[:data_parser.size])

    path_buffer_offset = data_parser.size
    absolute_substitute_name_offset = path_buffer_offset + SubstituteNameOffset
    target_bytes = reparse_data[absolute_substitute_name_offset:absolute_substitute_name_offset+SubstituteNameLength]
    target = target_bytes.decode('UTF-16')

    if target.startswith('\\??\\'):
        target = target[4:]

    try:
        # comes out in 8.3 form; convert it to LFN to make it look nicer
        target = win32file.GetLongPathName(target)
    except pywinerror as exc:
        # If target is on a UNC share, the decoded target will be in the format
        # "UNC\hostanme\sharename\additional\subdirs\under\share". So, in
        # these cases, return the target path in the proper UNC path format.
        if target.startswith('UNC\\'):
            return re.sub(r'^UNC\\+', r'\\\\', target)
        # if file is not found (i.e. bad symlink), return it anyway like on *nix
        if exc.winerror == 2:
            return target
        raise

    return target
1042171
def islink(path):
    
    if platform.system() == "Windows":
        if sys.version_info[:2] < (3, 5):
            try:
                # pylint: disable=undefined-variable
                attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(path))  # noqa
                assert attrs != -1
                return bool(attrs & FILE_ATTRIBUTE_REPARSE_POINT)
            except (AttributeError, AssertionError):
                return False
        try:
            st = os.lstat(path)  # pylint: disable=invalid-name
        except (OSError, AttributeError):
            return False
        # pylint: disable=no-member
        return stat.S_ISLNK(st.st_mode) or st.st_file_attributes & stat.FILE_ATTRIBUTE_REPARSE_POINT
    return os.path.islink(path)
584714
def fs_link(path, linkpath, linktype='soft'):
    
    global WIN_SOFTLINK
    global WIN_HARDLINK
    WIN_NO_ERROR = 22

    assert linktype in ('soft', 'hard')

    path, linkpath = pathlib.Path(path), pathlib.Path(linkpath)

    # Checks
    if not path.exists():    # particularly important on Windows to prevent false success
        raise QuiltException("Path to link to does not exist: {}".format(path))
    if linkpath.exists():
        raise QuiltException("Link path already exists: {}".format(linkpath))

    # Windows
    if os.name == 'nt':
        # clear out any pre-existing, un-checked errors
        ctypes.WinError()
            
        # Check Windows version (reasonably) supports symlinks
        if not sys.getwindowsversion()[0] >= 6:
            raise QuiltException("Unsupported operation: This version of Windows does not support linking.")

        # Acquire the windows CreateXLinkW() function
        if linktype == 'soft':
            if WIN_SOFTLINK is None:
                WIN_SOFTLINK = ctypes.windll.kernel32.CreateSymbolicLinkW
                WIN_SOFTLINK.restype = ctypes.c_bool
            create_link = lambda l, p: WIN_SOFTLINK(str(l), str(p), p.is_dir())
        elif linktype == 'hard':
            if WIN_HARDLINK is None:
                WIN_HARDLINK = ctypes.windll.kernel32.CreateHardLinkW
                WIN_HARDLINK.restype = ctypes.c_bool
            create_link = WIN_HARDLINK

        # Call and check results
        create_link(linkpath, path)
        # Check WinError, because the return value for CreateSymbolicLinkW's type is suspect due to a
        # (possible) bug: https://stackoverflow.com/questions/33010440/createsymboliclink-on-windows-10
        # We have user results with similar effects (success reported, but not actual)
        error = ctypes.WinError()
        if error.winerror:
            raise QuiltException("Linking failed: " + str(error), original_error=error)
        # Handle the case wehere linking failed and windows gave no error:
        if not linkpath.exists() and linkpath.is_symlink():
            raise QuiltException("Linking failed: Expected symlink at: {}".format(linkpath))
    # Linux, OSX
    else:
        try:
            if linktype == 'soft':
                linkpath.symlink_to(path)
            elif linktype == 'hard':
                os.link(str(path), str(linkpath))
        except OSError as error:
            raise QuiltException("Linking failed: " + str(error), original_error=error)
70281
def convert_path(cls, file):
        

        if isinstance(file,str):
            return file
        elif isinstance(file, list) and all([isinstance(x, str) for x in file]):
            return "/".join(file)
        else:
            print("Incorrect path specified")
            return -1