[pypy-svn] r16578 - in pypy/dist/pypy: module/posix rpython

tismer at codespeak.net tismer at codespeak.net
Fri Aug 26 11:45:13 CEST 2005


Author: tismer
Date: Fri Aug 26 11:45:11 2005
New Revision: 16578

Modified:
   pypy/dist/pypy/module/posix/__init__.py
   pypy/dist/pypy/module/posix/interp_posix.py
   pypy/dist/pypy/rpython/extfunctable.py
Log:
added some basic extensions to the posix module

Modified: pypy/dist/pypy/module/posix/__init__.py
==============================================================================
--- pypy/dist/pypy/module/posix/__init__.py	(original)
+++ pypy/dist/pypy/module/posix/__init__.py	Fri Aug 26 11:45:11 2005
@@ -27,22 +27,16 @@
     'system'    : 'interp_posix.system',
     'unlink'    : 'interp_posix.unlink',
     'remove'    : 'interp_posix.remove',
+    'getcwd'    : 'interp_posix.getcwd',
+    'chdir'     : 'interp_posix.chdir',
+    'mkdir'     : 'interp_posix.mkdir',
+    'rmdir'     : 'interp_posix.rmdir',
     }
     if hasattr(os, 'ftruncate'):
         interpleveldefs['ftruncate'] = 'interp_posix.ftruncate'
 
 
-for constant in ['EX_CANTCREAT', 'EX_CONFIG', 'EX_DATAERR', 'EX_IOERR',
-                 'EX_NOHOST', 'EX_NOINPUT', 'EX_NOPERM', 'EX_NOUSER',
-                 'EX_OK', 'EX_OSERR', 'EX_OSFILE', 'EX_PROTOCOL',
-                 'EX_SOFTWARE', 'EX_TEMPFAIL', 'EX_UNAVAILABLE', 'EX_USAGE',
-                 'F_OK', 'NGROUPS_MAX', 'O_APPEND', 'O_CREAT', 'O_DIRECT',
-                 'O_DIRECTORY', 'O_DSYNC', 'O_EXCL', 'O_LARGEFILE', 'O_NDELAY',
-                 'O_NOCTTY', 'O_NOFOLLOW', 'O_NONBLOCK', 'O_RDONLY', 'O_RDWR',
-                 'O_RSYNC', 'O_SYNC', 'O_TRUNC', 'O_WRONLY', 'R_OK', 'TMP_MAX',
-                 'WCONTINUED', 'WNOHANG', 'WUNTRACED', 'W_OK', 'X_OK']:
-    try:
-        Module.interpleveldefs[constant] = ("space.wrap(%s)" %
-                                            (getattr(os, constant), ))
-    except AttributeError:
-        pass
+for constant in dir(os):
+    value = getattr(os, constant)
+    if constant.isupper() and type(value) is int:
+        Module.interpleveldefs[constant] = "space.wrap(%s)" % value

Modified: pypy/dist/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/interp_posix.py	(original)
+++ pypy/dist/pypy/module/posix/interp_posix.py	Fri Aug 26 11:45:11 2005
@@ -99,15 +99,6 @@
         return build_stat_result(space, st)
 stat.unwrap_spec = [ObjSpace, str]
 
-def getcwd(space):
-    try:
-        cur = os.getcwd()
-    except OSError, e: 
-        raise wrap_oserror(space, e) 
-    else: 
-        return space.wrap(cur)
-getcwd.unwrap_spec = [ObjSpace]
-
 def dup(space, fd):
     try:
         newfd = os.dup(fd)
@@ -148,3 +139,42 @@
     except OSError, e: 
         raise wrap_oserror(space, e) 
 remove.unwrap_spec = [ObjSpace, str]
+
+def getcwd(space):
+    try:
+        cur = os.getcwd()
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+    else: 
+        return space.wrap(cur)
+getcwd.unwrap_spec = [ObjSpace]
+
+def chdir(space, path):
+    """chdir(path)
+
+Change the current working directory to the specified path."""
+    try:
+        os.chdir(path)
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+chdir.unwrap_spec = [ObjSpace, str]
+
+def mkdir(space, path, mode=0777):
+    """mkdir(path [, mode=0777])
+
+Create a directory."""
+    try:
+        os.mkdir(path, mode)
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+mkdir.unwrap_spec = [ObjSpace, str, int]
+
+def rmdir(space, path):
+    """rmdir(path)
+
+Remove a directory."""
+    try:
+        os.rmdir(path)
+    except OSError, e: 
+        raise wrap_oserror(space, e) 
+rmdir.unwrap_spec = [ObjSpace, str]

Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py	(original)
+++ pypy/dist/pypy/rpython/extfunctable.py	Fri Aug 26 11:45:11 2005
@@ -133,7 +133,6 @@
 declare(os.read     , str           , 'll_os/read')
 declare(os.write    , posannotation , 'll_os/write')
 declare(os.close    , noneannotation, 'll_os/close')
-declare(os.getcwd   , str           , 'll_os/getcwd')
 declare(os.dup      , int           , 'll_os/dup')
 declare(os.lseek    , int           , 'll_os/lseek')
 declare(os.isatty   , bool          , 'll_os/isatty')
@@ -142,8 +141,12 @@
 declare(os.fstat    , statannotation, 'll_os/fstat')
 declare(os.stat     , statannotation, 'll_os/stat')
 declare(os.system   , int           , 'll_os/system')
-declare(os.unlink   , noneannotation, 'll_os/unlink')
 declare(os.strerror , str           , 'll_os/strerror')
+declare(os.unlink   , noneannotation, 'll_os/unlink')
+declare(os.getcwd   , str           , 'll_os/getcwd')
+declare(os.chdir    , noneannotation, 'll_os/chdir')
+declare(os.mkdir    , noneannotation, 'll_os/mkdir')
+declare(os.rmdir    , noneannotation, 'll_os/rmdir')
 declare(os.path.exists, bool        , 'll_os_path/exists')
 declare(os.path.isdir, bool         , 'll_os_path/isdir')
 declare(time.time   , float         , 'll_time/time')



More information about the Pypy-commit mailing list