Exemplo n.º 1
0
 def __init__(self, msg):
     """
     :type: str or unicode 
     """
     msg = six.u(msg)
     super(PathError, self).__init__(msg)
     self._msg = msg
Exemplo n.º 2
0
 def __init__(self, msg):
     """
     :type: str or unicode 
     """
     msg = six.u(msg)
     super(PathError, self).__init__(msg)
     self._msg = msg
Exemplo n.º 3
0
 def __unicode__(self):
     """
     Return the decoded message using 'unicode_escape'
     
     :rtype: unicode 
     """
     msg = six.u(self._msg).decode('unicode_escape')
     return msg
Exemplo n.º 4
0
 def __unicode__(self):
     """
     Return the decoded message using 'unicode_escape'
     
     :rtype: unicode 
     """
     msg = six.u(self._msg).decode('unicode_escape')
     return msg
Exemplo n.º 5
0
def normPath(path):
    """
    Return a normalized path containing only forward slashes.
    
    :type path: str
    :rtype: unicode 
    """
    path = path.replace("\\", "/")
    path = six.u(path)
    return path.rstrip("/")
Exemplo n.º 6
0
def normPath(path):
    """
    Return a normalized path containing only forward slashes.
    
    :type path: str
    :rtype: unicode 
    """
    path = path.replace("\\", "/")
    path = six.u(path)
    return path.rstrip("/")
Exemplo n.º 7
0
def formatPath(formatString, path="", **kwargs):
    """
    Resolve the given string with the given path and kwargs.

    Example:
        print formatPath("{dirname}/meta.json", path="C:/hello/world.json")
        # "C:/hello/meta.json"

    :type formatString: str
    :type path: str
    :type kwargs: dict
    :rtype: str
    """
    logger.debug("Format String: %s", formatString)

    dirname, name, extension = splitPath(path)

    encoding = locale.getpreferredencoding()

    # Environment variables return raw strings so we need to convert them to
    # unicode using the preferred system encoding

    temp = tempfile.gettempdir()
    if temp:
        temp = temp.decode(encoding)

    username = user()
    if username:
        username = username.decode(encoding)

    local = os.getenv('APPDATA') or os.getenv('HOME')
    if local:
        local = local.decode(encoding)

    kwargs.update(os.environ)

    labels = {
        "name": name,
        "path": path,
        "root": path,  # legacy
        "user": username,
        "temp": temp,
        "home": local,  # legacy
        "local": local,
        "dirname": dirname,
        "extension": extension,
    }

    kwargs.update(labels)

    resolvedString = six.u(formatString).format(**kwargs)

    logger.debug("Resolved String: %s", resolvedString)

    return normPath(resolvedString)
Exemplo n.º 8
0
def formatPath(formatString, path="", **kwargs):
    """
    Resolve the given string with the given path and kwargs.

    Example:
        print formatPath("{dirname}/meta.json", path="C:/hello/world.json")
        # "C:/hello/meta.json"

    :type formatString: str
    :type path: str
    :type kwargs: dict
    :rtype: str
    """
    logger.debug("Format String: %s", formatString)

    dirname, name, extension = splitPath(path)

    encoding = locale.getpreferredencoding()

    # Environment variables return raw strings so we need to convert them to
    # unicode using the preferred system encoding

    temp = tempfile.gettempdir()
    if temp:
        temp = temp.decode(encoding)

    username = user()
    if username:
        username = username.decode(encoding)

    local = os.getenv('APPDATA') or os.getenv('HOME')
    if local:
        local = local.decode(encoding)

    kwargs.update(os.environ)

    labels = {
        "name": name,
        "path": path,
        "root": path,  # legacy
        "user": username,
        "temp": temp,
        "home": local,  # legacy
        "local": local,
        "dirname": dirname,
        "extension": extension,
    }

    kwargs.update(labels)

    resolvedString = six.u(formatString).format(**kwargs)

    logger.debug("Resolved String: %s", resolvedString)

    return normPath(resolvedString)
Exemplo n.º 9
0
def movePath(src, dst):
    """
    Move the given source path to the given destination path.

    :type src: str
    :type dst: str
    :rtype: str
    """
    src = six.u(src)
    dirname, name, extension = splitPath(src)

    if not os.path.exists(src):
        raise MovePathError(u'No such file or directory: {0}'.format(src))

    if os.path.isdir(src):
        dst = u'{0}/{1}{2}'.format(dst, name, extension)
        dst = generateUniquePath(dst)

    shutil.move(src, dst)
    return dst
Exemplo n.º 10
0
def movePath(src, dst):
    """
    Move the given source path to the given destination path.

    :type src: str
    :type dst: str
    :rtype: str
    """
    src = six.u(src)
    dirname, name, extension = splitPath(src)

    if not os.path.exists(src):
        raise MovePathError(u'No such file or directory: {0}'.format(src))

    if os.path.isdir(src):
        dst = u'{0}/{1}{2}'.format(dst, name, extension)
        dst = generateUniquePath(dst)

    shutil.move(src, dst)
    return dst