From: <pj...@us...> - 2009-11-16 01:58:12
|
Revision: 6945 http://jython.svn.sourceforge.net/jython/?rev=6945&view=rev Author: pjenvey Date: 2009-11-16 01:58:00 +0000 (Mon, 16 Nov 2009) Log Message: ----------- fix chown's visibility and posix.setpgrp and port the remaining posix calls to PosixModule fixes #1477 Modified Paths: -------------- trunk/jython/Lib/posix.py trunk/jython/NEWS trunk/jython/src/org/python/modules/posix/PosixModule.java Modified: trunk/jython/Lib/posix.py =================================================================== --- trunk/jython/Lib/posix.py 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/Lib/posix.py 2009-11-16 01:58:00 UTC (rev 6945) @@ -14,7 +14,7 @@ import sys __all__ = [name for name in _posix.__all__ if not name.startswith('__doc__')] -__all__.extend(['fsync', 'getenv', 'isatty', 'popen', 'putenv', +__all__.extend(['getenv', 'isatty', 'popen', 'putenv', 'rename', 'rmdir', 'system', 'unsetenv', 'urandom', 'utime']) @@ -169,153 +169,6 @@ import os return os.environ.get(key, default) -if _name == 'posix': - def symlink(src, dst): - """symlink(src, dst) - - Create a symbolic link pointing to src named dst. - """ - _posix_impl.symlink(src, sys.getPath(dst)) - - def readlink(path): - """readlink(path) -> path - - Return a string representing the path to which the symbolic link - points. - """ - return _posix_impl.readlink(sys.getPath(path)) - - def getegid(): - """getegid() -> egid - - Return the current process's effective group id.""" - return _posix_impl.getegid() - - def geteuid(): - """geteuid() -> euid - - Return the current process's effective user id.""" - return _posix_impl.geteuid() - - def getgid(): - """getgid() -> gid - - Return the current process's group id.""" - return _posix_impl.getgid() - - def getlogin(): - """getlogin() -> string - - Return the actual login name.""" - return _posix_impl.getlogin() - - def getpgrp(): - """getpgrp() -> pgrp - - Return the current process group id.""" - return _posix_impl.getpgrp() - - def getppid(): - """getppid() -> ppid - - Return the parent's process id.""" - return _posix_impl.getppid() - - def getuid(): - """getuid() -> uid - - Return the current process's user id.""" - return _posix_impl.getuid() - - def setpgrp(): - """setpgrp() - - Make this process a session leader.""" - return _posix_impl.setpgrp() - - def setsid(): - """setsid() - - Call the system call setsid().""" - return _posix_impl.setsid() - - # This implementation of fork partially works on - # Jython. Diagnosing what works, what doesn't, and fixing it is - # left for another day. In any event, this would only be - # marginally useful. - - # def fork(): - # """fork() -> pid - # - # Fork a child process. - # Return 0 to child process and PID of child to parent process.""" - # return _posix_impl.fork() - - def kill(pid, sig): - """kill(pid, sig) - - Kill a process with a signal.""" - return _posix_impl.kill(pid, sig) - - def wait(): - """wait() -> (pid, status) - - Wait for completion of a child process.""" - import jarray - status = jarray.zeros(1, 'i') - res_pid = _posix_impl.wait(status) - if res_pid == -1: - raise OSError(status[0], strerror(status[0])) - return res_pid, status[0] - - def waitpid(pid, options): - """waitpid(pid, options) -> (pid, status) - - Wait for completion of a given child process.""" - import jarray - status = jarray.zeros(1, 'i') - res_pid = _posix_impl.waitpid(pid, status, options) - if res_pid == -1: - raise OSError(status[0], strerror(status[0])) - return res_pid, status[0] - - def fdatasync(fd): - """fdatasync(fildes) - - force write of file with filedescriptor to disk. - does not force update of metadata. - """ - _fsync(fd, False) - - __all__.extend(['symlink', 'readlink', 'getegid', 'geteuid', - 'getgid', 'getlogin', 'getpgrp', 'getppid', 'getuid', - 'setpgrp', 'setsid', 'kill', 'wait', 'waitpid', - 'fdatasync']) - -def fsync(fd): - """fsync(fildes) - - force write of file with filedescriptor to disk. - """ - _fsync(fd, True) - -def _fsync(fd, metadata): - """Internal fsync impl""" - from org.python.core.io import FileDescriptors - rawio = FileDescriptors.get(fd) - rawio.checkClosed() - - from java.io import IOException - from java.nio.channels import FileChannel - channel = rawio.getChannel() - if not isinstance(channel, FileChannel): - raise OSError(errno.EINVAL, strerror(errno.EINVAL)) - - try: - channel.force(metadata) - except IOException, ioe: - raise OSError(ioe) - def isatty(fileno): """isatty(fd) -> bool Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/NEWS 2009-11-16 01:58:00 UTC (rev 6945) @@ -9,6 +9,7 @@ - [ 1470 ] os.mkdir Errno difference from cpython - [ 1496 ] fix os.listdir errno for non-existing dirs - [ 1499 ] PostgreSQL datahandler should return Decimals instead of floats for NUMERIC/DECIMAL columns + - [ 1477 ] os.setpgrp and posix.setpgrp fail with TypeError - Fix runtime issues during exitfuncs triggered via SystemRestart (such as during Django or Pylons development mode reloading) Modified: trunk/jython/src/org/python/modules/posix/PosixModule.java =================================================================== --- trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-15 05:18:17 UTC (rev 6944) +++ trunk/jython/src/org/python/modules/posix/PosixModule.java 2009-11-16 01:58:00 UTC (rev 6945) @@ -9,6 +9,9 @@ import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; +import java.nio.channels.Channel; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.FileChannel; import java.util.Map; import org.jruby.ext.posix.FileStat; @@ -199,7 +202,7 @@ public static PyString __doc__chown = new PyString( "chown(path, uid, gid)\n\n" + "Change the owner and group id of path to the numeric uid and gid."); - @Hide(OS.POSIX) + @Hide(OS.NT) public static void chown(String path, int uid, int gid) { if (posix.chown(absolutePath(path), uid, gid) < 0) { throw errorFromErrno(path); @@ -248,6 +251,43 @@ } } + public static PyString __doc__fdatasync = new PyString( + "fdatasync(fildes)\n\n" + + "force write of file with filedescriptor to disk.\n" + + "does not force update of metadata."); + @Hide(OS.NT) + public static void fdatasync(PyObject fd) { + fsync(fd, false); + } + + public static PyString __doc__fsync = new PyString( + "fsync(fildes)\n\n" + + "force write of file with filedescriptor to disk."); + public static void fsync(PyObject fd) { + fsync(fd, true); + } + + /** + * Internal fsync implementation. + */ + private static void fsync(PyObject fd, boolean metadata) { + RawIOBase rawIO = FileDescriptors.get(fd); + rawIO.checkClosed(); + Channel channel = rawIO.getChannel(); + if (!(channel instanceof FileChannel)) { + throw Py.OSError(Errno.EINVAL); + } + + try { + ((FileChannel)channel).force(metadata); + } catch (ClosedChannelException cce) { + // In the rare case it's closed but the rawIO wasn't + throw Py.ValueError("I/O operation on closed file"); + } catch (IOException ioe) { + throw Py.OSError(ioe); + } + } + public static PyString __doc__ftruncate = new PyString( "ftruncate(fd, length)\n\n" + "Truncate a file to a specified length."); @@ -273,6 +313,54 @@ return Py.newUnicode(Py.getSystemState().getCurrentWorkingDir()); } + public static PyString __doc__getegid = new PyString( + "getegid() -> egid\n\n" + + "Return the current process's effective group id."); + @Hide(OS.NT) + public static int getegid() { + return posix.getegid(); + } + + public static PyString __doc__geteuid = new PyString( + "geteuid() -> euid\n\n" + + "Return the current process's effective user id."); + @Hide(OS.NT) + public static int geteuid() { + return posix.geteuid(); + } + + public static PyString __doc__getgid = new PyString( + "getgid() -> gid\n\n" + + "Return the current process's group id."); + @Hide(OS.NT) + public static int getgid() { + return posix.getgid(); + } + + public static PyString __doc__getlogin = new PyString( + "getlogin() -> string\n\n" + + "Return the actual login name."); + @Hide(OS.NT) + public static PyObject getlogin() { + return new PyString(posix.getlogin()); + } + + public static PyString __doc__getppid = new PyString( + "getppid() -> ppid\n\n" + + "Return the parent's process id."); + @Hide(OS.NT) + public static int getppid() { + return posix.getppid(); + } + + public static PyString __doc__getuid = new PyString( + "getuid() -> uid\n\n" + + "Return the current process's user id."); + @Hide(OS.NT) + public static int getuid() { + return posix.getuid(); + } + public static PyString __doc__getpid = new PyString( "getpid() -> pid\n\n" + "Return the current process id"); @@ -281,6 +369,46 @@ return posix.getpid(); } + public static PyString __doc__getpgrp = new PyString( + "getpgrp() -> pgrp\n\n" + + "Return the current process group id."); + @Hide(OS.NT) + public static int getpgrp() { + return posix.getpgrp(); + } + + public static PyString __doc__kill = new PyString( + "kill(pid, sig)\n\n" + + "Kill a process with a signal."); + @Hide(OS.NT) + public static void kill(int pid, int sig) { + if (posix.kill(pid, sig) < 0) { + throw errorFromErrno(); + } + } + + public static PyString __doc__lchmod = new PyString( + "lchmod(path, mode)\n\n" + + "Change the access permissions of a file. If path is a symlink, this\n" + + "affects the link itself rather than the target."); + @Hide(OS.NT) + public static void lchmod(String path, int mode) { + if (posix.lchmod(absolutePath(path), mode) < 0) { + throw errorFromErrno(path); + } + } + + public static PyString __doc__lchown = new PyString( + "lchown(path, uid, gid)\n\n" + + "Change the owner and group id of path to the numeric uid and gid.\n" + + "This function will not follow symbolic links."); + @Hide(OS.NT) + public static void lchown(String path, int uid, int gid) { + if (posix.lchown(absolutePath(path), uid, gid) < 0) { + throw errorFromErrno(path); + } + } + public static PyString __doc__link = new PyString( "link(src, dst)\n\n" + "Create a hard link to a file."); @@ -417,6 +545,18 @@ } } + public static PyString __doc__readlink = new PyString( + "readlink(path) -> path\n\n" + + "Return a string representing the path to which the symbolic link points."); + @Hide(OS.NT) + public static String readlink(String path) { + try { + return posix.readlink(absolutePath(path)); + } catch (IOException ioe) { + throw Py.OSError(ioe); + } + } + public static PyString __doc__remove = new PyString( "remove(path)\n\n" + "Remove a file (same as unlink(path))."); @@ -424,6 +564,26 @@ unlink(path); } + public static PyString __doc__setpgrp = new PyString( + "setpgrp()\n\n" + + "Make this process a session leader."); + @Hide(OS.NT) + public static void setpgrp() { + if (posix.setpgrp(0, 0) < 0) { + throw errorFromErrno(); + } + } + + public static PyString __doc__setsid = new PyString( + "setsid()\n\n" + + "Call the system call setsid()."); + @Hide(OS.NT) + public static void setsid() { + if (posix.setsid() < 0) { + throw errorFromErrno(); + } + } + public static PyString __doc__strerror = new PyString( "strerror(code) -> string\n\n" + "Translate an error code to a message string."); @@ -441,6 +601,15 @@ return new PyString(errno.toString()); } + public static PyString __doc__symlink = new PyString( + "symlink(src, dst)\n\n" + + "Create a symbolic link pointing to src named dst."); + @Hide(OS.NT) + public static void symlink(String src, String dst) { + ensurePath(src); + posix.symlink(src, absolutePath(dst)); + } + public static PyString __doc__umask = new PyString( "umask(new_mask) -> old_mask\n\n" + "Set the current numeric umask and return the previous umask."); @@ -469,6 +638,31 @@ } } + public static PyString __doc__wait = new PyString( + "wait() -> (pid, status)\n\n" + + "Wait for completion of a child process."); + @Hide(OS.NT) + public static PyObject wait$() { + int[] status = new int[1]; + int pid = posix.wait(status); + if (pid < 0) { + throw errorFromErrno(); + } + return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0])); + } + + public static PyString __doc__waitpid = new PyString( + "wait() -> (pid, status)\n\n" + + "Wait for completion of a child process."); + public static PyObject waitpid(int pid, int options) { + int[] status = new int[1]; + pid = posix.waitpid(pid, status, options); + if (pid < 0) { + throw errorFromErrno(); + } + return new PyTuple(Py.newInteger(pid), Py.newInteger(status[0])); + } + public static PyString __doc__write = new PyString( "write(fd, string) -> byteswritten\n\n" + "Write a string to a file descriptor."); @@ -539,6 +733,10 @@ return Py.OSError(Errno.EBADF); } + private static PyException errorFromErrno() { + return Py.OSError(Errno.valueOf(posix.errno())); + } + private static PyException errorFromErrno(String path) { return Py.OSError(Errno.valueOf(posix.errno()), path); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |