def relpath(path, start=os.path.curdir):
            """Return a relative version of a path"""
            from os.path import sep, curdir, join, abspath, commonprefix, \
                 pardir, splitunc

            if not path:
                raise ValueError("no path specified")
            start_list = abspath(start).split(sep)
            path_list = abspath(path).split(sep)
            if start_list[0].lower() != path_list[0].lower():
                unc_path, rest = splitunc(path)
                unc_start, rest = splitunc(start)
                if bool(unc_path) ^ bool(unc_start):
                    raise ValueError("Cannot mix UNC and non-UNC paths (%s and %s)"
                                                                        % (path, start))
                else:
                    raise ValueError("path is on drive %s, start on drive %s"
                                                        % (path_list[0], start_list[0]))
            # Work out how much of the filepath is shared by start and path.
            for i in range(min(len(start_list), len(path_list))):
                if start_list[i].lower() != path_list[i].lower():
                    break
            else:
                i += 1

            rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
            if not rel_list:
                return curdir
            return join(*rel_list)
示例#2
0
        def relpath(path, start=os.path.curdir):
            """Return a relative version of a path"""
            from os.path import sep, curdir, join, abspath, commonprefix, \
                 pardir, splitunc

            if not path:
                raise ValueError("no path specified")
            start_list = abspath(start).split(sep)
            path_list = abspath(path).split(sep)
            if start_list[0].lower() != path_list[0].lower():
                unc_path, rest = splitunc(path)
                unc_start, rest = splitunc(start)
                if bool(unc_path) ^ bool(unc_start):
                    raise ValueError(
                        "Cannot mix UNC and non-UNC paths (%s and %s)" %
                        (path, start))
                else:
                    raise ValueError("path is on drive %s, start on drive %s" %
                                     (path_list[0], start_list[0]))
            # Work out how much of the filepath is shared by start and path.
            for i in range(min(len(start_list), len(path_list))):
                if start_list[i].lower() != path_list[i].lower():
                    break
            else:
                i += 1

            rel_list = [pardir] * (len(start_list) - i) + path_list[i:]
            if not rel_list:
                return curdir
            return join(*rel_list)
示例#3
0
    def relpath(path, start=None):
        """Return a relative version of a path"""
        if start is None:
            start = os.curdir
        if not path:
            raise ValueError("no path specified")
        start_list = op.abspath(start).split(op.sep)
        path_list = op.abspath(path).split(op.sep)
        if start_list[0].lower() != path_list[0].lower():
            unc_path, rest = op.splitunc(path)
            unc_start, rest = op.splitunc(start)
            if bool(unc_path) ^ bool(unc_start):
                raise ValueError(("Cannot mix UNC and non-UNC paths "
                                  "(%s and %s)") % (path, start))
            else:
                raise ValueError("path is on drive %s, start on drive %s"
                                 % (path_list[0], start_list[0]))
        # Work out how much of the filepath is shared by start and path.
        for i in range(min(len(start_list), len(path_list))):
            if start_list[i].lower() != path_list[i].lower():
                break
        else:
            i += 1

        rel_list = [op.pardir] * (len(start_list) - i) + path_list[i:]
        if not rel_list:
            return os.curdir
        return op.join(*rel_list)
示例#4
0
def relpath(path, start=None):
    """Return a relative version of a path"""

    try:
        return op.relpath(path, start)
    except AttributeError:
        pass

    if start is None:
        start = os.curdir
    if not path:
        raise ValueError("no path specified")
    start_list = op.abspath(start).split(op.sep)
    path_list = op.abspath(path).split(op.sep)
    if start_list[0].lower() != path_list[0].lower():
        unc_path, rest = op.splitunc(path)
        unc_start, rest = op.splitunc(start)
        if bool(unc_path) ^ bool(unc_start):
            raise ValueError(("Cannot mix UNC and non-UNC paths "
                              "(%s and %s)") % (path, start))
        else:
            raise ValueError("path is on drive %s, start on drive %s" %
                             (path_list[0], start_list[0]))
    # Work out how much of the filepath is shared by start and path.
    for i in range(min(len(start_list), len(path_list))):
        if start_list[i].lower() != path_list[i].lower():
            break
    else:
        i += 1

    rel_list = [op.pardir] * (len(start_list) - i) + path_list[i:]
    if not rel_list:
        return os.curdir
    return op.join(*rel_list)
示例#5
0
	def __init__(self, directory, logger):
		self.directory = directory
		self.logger = logger
		self.unmountRequired = False
		self.invalid = False
		self.diskUsageDB = "MirrorMaker.state"
		if platform() != "Windows":
			self.logger.message("MMDiskMonitor only supports Windows platforms at this time", 3)
			self.invalid = True
		else:
			if splitunc(directory)[0] == "":
				# Local drive
				self.caption = splitdrive(directory)[0]
				self.name = self.caption
			else:
				# Network share
				self.uncRoot = splitunc(directory)[0]
				for i in range(26):
					if system("net use " + ascii_uppercase[i] + ": " + self.uncRoot + " > NUL 2>&1") == 0:
						self.caption = ascii_uppercase[i] + ":"
						self.name = self.uncRoot
						self.directory = join(self.caption, self.uncRoot)
						self.unmountRequired = True
						break
				if self.unmountRequired == False:
					self.logger.message("Error mounting network share " + self.uncRoot + " for monitoring its free space", 3)
					self.invalid = True
			self.logger.message("Disk monitor initialized for " + self.name, 0)
示例#6
0
def _abspath_split(path):
    abs = abspath(op.normpath(path))
    prefix, rest = splitunc(abs)
    is_unc = bool(prefix)
    if not is_unc:
        prefix, rest = splitdrive(abs)
    return is_unc, prefix, [x for x in rest.split(sep) if x]
示例#7
0
 def splitunc(path=("StringPin", "", {PinSpecifires.INPUT_WIDGET_VARIANT: "PathWidget"}), unc=(REF, ("StringPin", "")), rest=(REF, ("StringPin", ""))):
     '''Split the pathname path into a pair (unc, rest) so that unc is the UNC mount point (such as r'\\host\mount'), if present, and rest the rest of the path (such as r'\path\file.ext'). For paths containing drive letters, unc will always be the empty string.'''
     splited = osPath.splitunc(path)
     if len(splited):
         unc(splited[0])
         rest(splited[1])
     else:
         unc("")
         rest("")
     return list(splited)
def pathSplitDirs(p):
    p = pathNorm(p)

    if p.startswith("//"):
        root, p = osp.splitunc(p)
    elif p.startswith("/"):
        dirs = p.split("/", 2)
        root, p = (dirs[1], "") if len(dirs) == 2 else dirs[1:]
        root = "/" + root
    else:
        root, p = osp.splitdrive(p)

    p = p.strip("/")

    res = [root + "/"] if root else []
    if p:
        res.extend(p.split("/"))

    return res
def pathSplitDirs(p):
    p = pathNorm(p)

    if p.startswith("//"):
        root, p = osp.splitunc(p)
    elif p.startswith("/"):
        dirs = p.split("/", 2)
        root, p = (dirs[1], "") if len(dirs) == 2 else dirs[1:]
        root = "/" + root
    else:
        root, p = osp.splitdrive(p)

    p = p.strip("/")

    res = [root + "/"] if root else []
    if p:
        res.extend(p.split("/"))

    return res
示例#10
0
		def path_operator(x):
			return normpath(splitunc(x)[-1])