Commits

haypo  committed 490d529

* Remove PROC_DIRNAME and procFilename() from ptrace.linux_proc
* python-ptrace now depends on Python 2.5
* Set version to 0.6

  • Participants
  • Parent commits 6d721fa
  • Tags python-ptrace-0.6

Comments (0)

Files changed (3)

 Changelog
 =========
 
-python-ptrace 0.5.1
--------------------
+python-ptrace 0.6
+-----------------
 
+ * python-ptrace now depends on Python 2.5
  * Invalid memory access: add fault address in the name
  * Fix interpretation of memory fault on MOSVW instruction (source is ESI and
    destination is EDI, and not the inverse!)
  * Fix locateProgram() for relative path
  * Fix support of Python 3.0 final
+ * Remove PROC_DIRNAME and procFilename() from ptrace.linux_proc
 
 python-ptrace 0.5 (2008-09-13)
 ------------------------------

File ptrace/linux_proc.py

 """
 Functions and variables to access to Linux proc directory.
 
-Variables:
- - PROC_DIRNAME: Name of the directory ('/proc')
- - PAGE_SIZE: size of a memory page
+Constant:
+
+   - PAGE_SIZE: size of a memory page
 """
-
+from __future__ import with_statement
 from os import readlink, listdir
-from os.path import join as path_join
 from resource import getpagesize
 from ptrace.tools import timestampUNIX
 from datetime import timedelta
 
+PAGE_SIZE = getpagesize()
+
 class ProcError(Exception):
     """
     Linux proc directory error.
     """
     pass
 
-PROC_DIRNAME = '/proc'
-PAGE_SIZE = getpagesize()
-
-def procFilename(*args):
-    """
-    Create a filename in proc directory.
-    """
-    return path_join(PROC_DIRNAME, *args)
-
 def openProc(path):
     """
     Open a proc entry in read only mode.
     """
+    filename = "/proc/%s" % path
     try:
-        filename = procFilename(path)
         return open(filename)
     except IOError, err:
         raise ProcError("Unable to open %r: %s" % (filename, err))
     Read the content of a proc entry.
     Eg. readProc("stat") to read /proc/stat.
     """
-    procfile = openProc(path)
-    content = procfile.read()
-    procfile.close()
-    return content
+    with openProc(path) as procfile:
+        return procfile.read()
 
 def readProcessProc(pid, key):
     """
     Eg. readProcessProc(pid, "status") to read /proc/pid/status.
     """
     try:
-        return readProc(path_join(str(pid), str(key)))
-    except ProcError, error:
-        raise ProcError("Process %s doesn't exist: %s" % (
-            pid, error))
+        filename = "/proc/%s/%s" % (pid, key)
+        with open(filename) as proc:
+            return proc.read()
+    except IOError, err:
+        raise ProcError("Process %s doesn't exist: %s" % (pid, err))
 
 class ProcessState:
     """
     Read a process link.
     """
     try:
-        filename = procFilename(str(pid), str(key))
+        filename = "/proc/%s/%s" % (pid, key)
         return readlink(filename)
     except OSError, err:
         raise ProcError("Unable to read proc link %r: %s" % (filename, err))
 
        for pid in readProcesses(): ...
     """
-    for filename in listdir(PROC_DIRNAME):
+    for filename in listdir('/proc'):
         try:
             yield int(filename)
         except ValueError:

File ptrace/version.py

 PACKAGE = "python-ptrace"
-VERSION = "0.5.1"
+VERSION = "0.6"
 WEBSITE = "http://python-ptrace.hachoir.org/"
 LICENSE = "GNU GPL v2"