sys.getPath

Here are the examples of the python api sys.getPath taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

56 Examples 7

Example 1

Project: neuroConstruct
Source File: javapath.py
View license
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists()

Example 2

Project: babble
Source File: os.py
View license
def rename(path, newpath):
    """rename(old, new)

    Rename a file or directory.
    """
    if not File(sys.getPath(path)).renameTo(File(sys.getPath(newpath))):
        raise OSError(0, "couldn't rename file", path)

Example 3

Project: neuroConstruct
Source File: javapath.py
View license
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size

Example 4

Project: babble
Source File: os.py
View license
def listdir(path):
    """listdir(path) -> list_of_strings

    Return a list containing the names of the entries in the directory.

        path: path of directory to list

    The list is in arbitrary order.  It does not include the special
    entries '.' and '..' even if they are present in the directory.
    """
    l = File(sys.getPath(path)).list()
    if l is None:
        raise OSError(0, 'No such directory', path)
    return list(l)

Example 5

Project: imagrium
Source File: javapath.py
View license
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size

Example 6

Project: babble
Source File: os.py
View license
def mkdir(path, mode='ignored'):
    """mkdir(path [, mode=0777])

    Create a directory.

    The optional parameter is currently ignored.
    """
    if not File(sys.getPath(path)).mkdir():
        raise OSError(0, "couldn't make directory", path)

Example 7

Project: babble
Source File: os.py
View license
def remove(path):
    """remove(path)

    Remove a file (same as unlink(path)).
    """
    if not File(sys.getPath(path)).delete():
        raise OSError(0, "couldn't delete file", path)

Example 8

Project: babble
Source File: os.py
View license
def chmod(path, mode):
    """chmod(path, mode)

    Change the access permissions of a file.
    """
    # XXX no error handling for chmod in jna-posix
    # catch not found errors explicitly here, for now
    abs_path = sys.getPath(path)
    if not File(abs_path).exists():
        raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path)
    _posix.chmod(abs_path, mode)

Example 9

Project: medicare-demo
Source File: javapath.py
View license
def getmtime(path):
    path = _tostr(path, "getmtime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 10

Project: medicare-demo
Source File: javapath.py
View license
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size

Example 11

Project: babble
Source File: javapath.py
View license
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 12

Project: babble
Source File: os.py
View license
    def symlink(src, dst):
        """symlink(src, dst)

        Create a symbolic link pointing to src named dst.
        """
        _posix.symlink(src, sys.getPath(dst))

Example 13

Project: imagrium
Source File: javapath.py
View license
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 14

Project: neuroConstruct
Source File: javapath.py
View license
def getmtime(path):
    path = _tostr(path, "getmtime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 15

Project: neuroConstruct
Source File: javapath.py
View license
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size

Example 16

Project: babble
Source File: javapath.py
View license
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists()

Example 17

Project: neuroConstruct
Source File: javapath.py
View license
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 18

Project: neuroConstruct
Source File: javapath.py
View license
def getmtime(path):
    path = _tostr(path, "getmtime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 19

Project: neuroConstruct
Source File: javapath.py
View license
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 20

Project: medicare-demo
Source File: javapath.py
View license
def getatime(path):
    # We can't detect access time so we return modification time. This
    # matches the behaviour in os.stat().
    path = _tostr(path, "getatime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 21

Project: medicare-demo
Source File: javapath.py
View license
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists()

Example 22

Project: imagrium
Source File: javapath.py
View license
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists()

Example 23

Project: babble
Source File: os.py
View license
def rmdir(path):
    """rmdir(path)

    Remove a directory."""
    if not File(sys.getPath(path)).delete():
        raise OSError(0, "couldn't delete directory", path)

Example 24

Project: babble
Source File: os.py
View license
    def link(src, dst):
        """link(src, dst)
    
        Create a hard link to a file.
        """
        _posix.link(sys.getPath(src), sys.getPath(dst))

Example 25

Project: babble
Source File: javapath.py
View license
def getsize(path):
    path = _tostr(path, "getsize")
    f = File(sys.getPath(path))
    size = f.length()
    # Sadly, if the returned length is zero, we don't really know if the file
    # is zero sized or does not exist.
    if size == 0 and not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return size

Example 26

Project: babble
Source File: os.py
View license
    def readlink(path):
        """readlink(path) -> path
    
        Return a string representing the path to which the symbolic link
        points.
        """
        return _posix.readlink(sys.getPath(path))

Example 27

Project: imagrium
Source File: javapath.py
View license
def getmtime(path):
    path = _tostr(path, "getmtime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 28

Project: babble
Source File: javapath.py
View license
def getmtime(path):
    path = _tostr(path, "getmtime")
    f = File(sys.getPath(path))
    if not f.exists():
        raise OSError(0, 'No such file or directory', path)
    return f.lastModified() / 1000.0

Example 29

Project: neuroConstruct
Source File: javapath.py
View license
def exists(path):
    """Test whether a path exists.

    Returns false for broken symbolic links.

    """
    path = _tostr(path, "exists")
    return File(sys.getPath(path)).exists()

Example 30

Project: neuroConstruct
Source File: javapath.py
View license
def isfile(path):
    """Test whether a path is a regular file"""
    path = _tostr(path, "isfile")
    return File(sys.getPath(path)).isFile()

Example 31

Project: neuroConstruct
Source File: javapath.py
View license
def isdir(path):
    """Test whether a path is a directory"""
    path = _tostr(path, "isdir")
    return File(sys.getPath(path)).isDirectory()

Example 32

Project: imagrium
Source File: javapath.py
View license
def _abspath(path):
    # Must use normpath separately because getAbsolutePath doesn't normalize
    # and getCanonicalPath would eliminate symlinks.
    return normpath(asPyString(File(sys.getPath(path)).getAbsolutePath()))

Example 33

Project: neuroConstruct
Source File: javapath.py
View license
def _abspath(path):
    # Must use normpath separately because getAbsolutePath doesn't normalize
    # and getCanonicalPath would eliminate symlinks.
    return normpath(asPyString(File(sys.getPath(path)).getAbsolutePath()))

Example 34

Project: neuroConstruct
Source File: javapath.py
View license
def _realpath(path):
    try:
        return asPyString(File(sys.getPath(path)).getCanonicalPath())
    except java.io.IOException:
        return _abspath(path)

Example 35

Project: babble
Source File: os.py
View license
def makedirs(path, mode='ignored'):
    """makedirs(path [, mode=0777])

    Super-mkdir; create a leaf directory and all intermediate ones.

    Works like mkdir, except that any intermediate path segment (not
    just the rightmost) will be created if it does not exist.
    The optional parameter is currently ignored.
    """
    sys_path = sys.getPath(path)
    if File(sys_path).mkdirs():
        return

    # if making a /x/y/z/., java.io.File#mkdirs inexplicably fails. So we need
    # to force it
    
    # need to use _path instead of path, because param is hiding
    # os.path module in namespace!
    head, tail = _path.split(sys_path)
    if tail == curdir:
        if File(_path.join(head)).mkdirs():
            return
                
    raise OSError(0, "couldn't make directories", path)

Example 36

Project: neuroConstruct
Source File: javapath.py
View license
def isfile(path):
    """Test whether a path is a regular file"""
    path = _tostr(path, "isfile")
    return File(sys.getPath(path)).isFile()

Example 37

Project: neuroConstruct
Source File: javapath.py
View license
def isdir(path):
    """Test whether a path is a directory"""
    path = _tostr(path, "isdir")
    return File(sys.getPath(path)).isDirectory()

Example 38

Project: babble
Source File: javapath.py
View license
def isfile(path):
    """Test whether a path is a regular file"""
    path = _tostr(path, "isfile")
    return File(sys.getPath(path)).isFile()

Example 39

Project: neuroConstruct
Source File: javapath.py
View license
def _abspath(path):
    # Must use normpath separately because getAbsolutePath doesn't normalize
    # and getCanonicalPath would eliminate symlinks.
    return normpath(asPyString(File(sys.getPath(path)).getAbsolutePath()))

Example 40

Project: neuroConstruct
Source File: javapath.py
View license
def _realpath(path):
    try:
        return asPyString(File(sys.getPath(path)).getCanonicalPath())
    except java.io.IOException:
        return _abspath(path)

Example 41

Project: imagrium
Source File: javapath.py
View license
def isfile(path):
    """Test whether a path is a regular file"""
    path = _tostr(path, "isfile")
    return File(sys.getPath(path)).isFile()

Example 42

Project: imagrium
Source File: javapath.py
View license
def _realpath(path):
    try:
        return asPyString(File(sys.getPath(path)).getCanonicalPath())
    except java.io.IOException:
        return _abspath(path)

Example 43

Project: babble
Source File: javapath.py
View license
def isdir(path):
    """Test whether a path is a directory"""
    path = _tostr(path, "isdir")
    return File(sys.getPath(path)).isDirectory()

Example 44

Project: neuroConstruct
Source File: ntpath.py
View license
        def abspath(path):
            """Return the absolute version of a path."""
            try:
                if isinstance(path, unicode):
                    # Result must be unicode
                    if path:
                        path = sys.getPath(path)
                    else:
                        # Empty path must return current working directory
                        path = os.getcwdu()
                else:
                    # Result must be bytes
                    if path:
                        path = sys.getPath(path).encode('latin-1')
                    else:
                        # Empty path must return current working directory
                        path = os.getcwd()
            except EnvironmentError:
                 pass # Bad path - return unchanged.
            return normpath(path)

Example 45

Project: babble
Source File: os.py
View license
def access(path, mode):
    """access(path, mode) -> True if granted, False otherwise
        
    Use the real uid/gid to test for access to a path.  Note that most
    operations will use the effective uid/gid, therefore this routine can
    be used in a suid/sgid environment to test if the invoking user has the
    specified access to the path.  The mode argument can be F_OK to test
    existence, or the inclusive-OR of R_OK, W_OK, and X_OK.
    """
    if not isinstance(mode, (int, long)):
        raise TypeError('an integer is required')

    f = File(sys.getPath(path))
    if not f.exists():
      return False
    if mode & R_OK and not f.canRead():
        return False
    if mode & W_OK and not f.canWrite():
        return False
    if mode & X_OK:
        return False
    return True

Example 46

Project: neuroConstruct
Source File: ntpath.py
View license
        def abspath(path):
            """Return the absolute version of a path."""
            try:
                if isinstance(path, unicode):
                    # Result must be unicode
                    if path:
                        path = sys.getPath(path)
                    else:
                        # Empty path must return current working directory
                        path = os.getcwdu()
                else:
                    # Result must be bytes
                    if path:
                        path = sys.getPath(path).encode('latin-1')
                    else:
                        # Empty path must return current working directory
                        path = os.getcwd()
            except EnvironmentError:
                 pass # Bad path - return unchanged.
            return normpath(path)

Example 47

Project: babble
Source File: os.py
View license
def stat(path):
    """stat(path) -> stat result

    Perform a stat system call on the given path.

    The Java stat implementation only returns a small subset of
    the standard fields: size, modification time and change time.
    """
    abs_path = sys.getPath(path)
    try:
        return stat_result.from_jnastat(_posix.stat(abs_path))
    except NotImplementedError:
        pass
    except:
        raise
    f = File(abs_path)
    if not f.exists():
        raise OSError(errno.ENOENT, errno.strerror(errno.ENOENT), path)
    size = f.length()
    mtime = f.lastModified() / 1000.0
    mode = 0
    if f.isDirectory():
        mode = _stat.S_IFDIR
    elif f.isFile():
        mode = _stat.S_IFREG
    if f.canRead():
        mode = mode | _stat.S_IREAD
    if f.canWrite():
        mode = mode | _stat.S_IWRITE
    return stat_result((mode, 0, 0, 0, 0, 0, size, mtime, mtime, 0))

Example 48

Project: medicare-demo
Source File: javapath.py
View license
def isfile(path):
    """Test whether a path is a regular file"""
    path = _tostr(path, "isfile")
    return File(sys.getPath(path)).isFile()

Example 49

Project: babble
Source File: javapath.py
View license
def _abspath(path):
    # Must use normpath separately because getAbsolutePath doesn't normalize
    # and getCanonicalPath would eliminate symlinks.
    return normpath(File(sys.getPath(path)).getAbsolutePath())

Example 50

Project: imagrium
Source File: javapath.py
View license
def isdir(path):
    """Test whether a path is a directory"""
    path = _tostr(path, "isdir")
    return File(sys.getPath(path)).isDirectory()