[cedar-backup-svn] SF.net SVN: cedar-backup:[1000] cedar-backup2/trunk
Brought to you by:
pronovic
|
From: <pro...@us...> - 2010-07-07 20:17:15
|
Revision: 1000
http://cedar-backup.svn.sourceforge.net/cedar-backup/?rev=1000&view=rev
Author: pronovic
Date: 2010-07-07 20:17:08 +0000 (Wed, 07 Jul 2010)
Log Message:
-----------
Remove Python 2.3-compatible versions of util.nullDevice() and util.Pipe
Modified Paths:
--------------
cedar-backup2/trunk/CREDITS
cedar-backup2/trunk/CedarBackup2/util.py
cedar-backup2/trunk/Changelog
cedar-backup2/trunk/TODO
Modified: cedar-backup2/trunk/CREDITS
===================================================================
--- cedar-backup2/trunk/CREDITS 2010-07-07 19:58:25 UTC (rev 999)
+++ cedar-backup2/trunk/CREDITS 2010-07-07 20:17:08 UTC (rev 1000)
@@ -41,8 +41,8 @@
Source code annotated as "(c) 2001, 2002 Python Software Foundation" was
originally taken from or derived from code within the Python 2.3 codebase.
This code was released under the Python 2.3 license, which is an MIT-style
-academic license. Items under this license include the util.Pipe
-implementation based on popen2.Popen4.
+academic license. Items under this license include the function
+util.getFunctionReference().
Source code annotated as "(c) 2000-2004 CollabNet" was originally released
under the CollabNet License, which is an Apache/BSD-style license. Items
Modified: cedar-backup2/trunk/CedarBackup2/util.py
===================================================================
--- cedar-backup2/trunk/CedarBackup2/util.py 2010-07-07 19:58:25 UTC (rev 999)
+++ cedar-backup2/trunk/CedarBackup2/util.py 2010-07-07 20:17:08 UTC (rev 1000)
@@ -84,6 +84,7 @@
import time
import logging
import string # pylint: disable-msg=W0402
+from subprocess import Popen, STDOUT, PIPE
from CedarBackup2.release import VERSION, DATE
@@ -94,17 +95,7 @@
except ImportError:
_UID_GID_AVAILABLE = False
-try:
- from subprocess import Popen
- _PIPE_IMPLEMENTATION = "subprocess.Popen"
-except ImportError:
- try:
- from popen2 import Popen4
- _PIPE_IMPLEMENTATION = "popen2.Popen4"
- except ImportError:
- raise ImportError("Unable to import either subprocess.Popen or popen2.Popen4 for use by Pipe class.")
-
########################################################################
# Module-wide constants and variables
########################################################################
@@ -855,101 +846,30 @@
# Pipe class definition
########################################################################
-if _PIPE_IMPLEMENTATION == "subprocess.Popen":
+class Pipe(Popen):
+ """
+ Specialized pipe class for use by C{executeCommand}.
- from subprocess import STDOUT, PIPE
+ The L{executeCommand} function needs a specialized way of interacting
+ with a pipe. First, C{executeCommand} only reads from the pipe, and
+ never writes to it. Second, C{executeCommand} needs a way to discard all
+ output written to C{stderr}, as a means of simulating the shell
+ C{2>/dev/null} construct.
- class Pipe(Popen):
- """
- Specialized pipe class for use by C{executeCommand}.
+ All of this functionality is provided (in Python 2.4 or later) by the
+ C{subprocess.Popen} class, so when that class is available, we'll use it.
+ Otherwise, there's another implementation based on C{popen2.Popen4},
+ which unfortunately only works on UNIX platforms.
+ """
+ def __init__(self, cmd, bufsize=-1, ignoreStderr=False):
+ stderr = STDOUT
+ if ignoreStderr:
+ devnull = nullDevice()
+ stderr = os.open(devnull, os.O_RDWR)
+ Popen.__init__(self, shell=False, args=cmd, bufsize=bufsize, stdin=None, stdout=PIPE, stderr=stderr)
+ self.fromchild = self.stdout # for compatibility with original interface based on popen2.Popen4
- The L{executeCommand} function needs a specialized way of interacting
- with a pipe. First, C{executeCommand} only reads from the pipe, and
- never writes to it. Second, C{executeCommand} needs a way to discard all
- output written to C{stderr}, as a means of simulating the shell
- C{2>/dev/null} construct.
- All of this functionality is provided (in Python 2.4 or later) by the
- C{subprocess.Popen} class, so when that class is available, we'll use it.
- Otherwise, there's another implementation based on C{popen2.Popen4},
- which unfortunately only works on UNIX platforms.
- """
- def __init__(self, cmd, bufsize=-1, ignoreStderr=False):
- stderr = STDOUT
- if ignoreStderr:
- devnull = nullDevice()
- stderr = os.open(devnull, os.O_RDWR)
- Popen.__init__(self, shell=False, args=cmd, bufsize=bufsize, stdin=None, stdout=PIPE, stderr=stderr)
- self.fromchild = self.stdout # for compatibility with original interface based on popen2.Popen4
-
-else: # _PIPE_IMPLEMENTATION == "popen2.Popen4"
-
- from popen2 import _cleanup, _active
-
- class Pipe(Popen4):
- """
- Specialized pipe class for use by C{executeCommand}.
-
- The L{executeCommand} function needs a specialized way of interacting with a
- pipe that isn't satisfied by the standard C{Popen3} and C{Popen4} classes in
- C{popen2}. First, C{executeCommand} only reads from the pipe, and never
- writes to it. Second, C{executeCommand} needs a way to discard all output
- written to C{stderr}, as a means of simulating the shell C{2>/dev/null}
- construct.
-
- This class inherits from C{Popen4}. If the C{ignoreStderr} flag is passed in
- as C{False}, then the standard C{Popen4} constructor will be called and
- C{stdout} and C{stderr} will be intermingled in the output.
-
- Otherwise, we'll call a custom version of the constructor which was
- basically stolen from the real constructor in C{python2.3/Lib/popen2.py}.
- This custom constructor will redirect the C{stderr} file descriptor to
- C{/dev/null}. I've done this based on a suggestion from Donn Cave on
- comp.lang.python.
-
- In either case, the C{tochild} file object is always closed before returning
- from the constructor, since it is never needed by C{executeCommand}.
-
- I really wish there were a prettier way to do this. Unfortunately, I
- need access to the guts of the constructor implementation because of the
- way the pipe process is forked, etc. It doesn't work to just call the
- superclass constructor and then modify a few things afterwards. Even
- worse, I have to access private C{popen2} module members C{_cleanup} and
- C{_active} in order to duplicate the implementation.
-
- Hopefully this whole thing will continue to work properly. At least we
- can use the other L{subprocess.Popen}-based implementation when that
- class is available.
-
- @copyright: Some of this code, prior to customization, was originally part
- of the Python 2.3 codebase. Python code is copyright (c) 2001, 2002 Python
- Software Foundation; All Rights Reserved.
- """
-
- def __init__(self, cmd, bufsize=-1, ignoreStderr=False):
- if not ignoreStderr:
- Popen4.__init__(self, cmd, bufsize)
- else:
- _cleanup()
- p2cread, p2cwrite = os.pipe()
- c2pread, c2pwrite = os.pipe()
- self.pid = os.fork()
- if self.pid == 0: # Child
- os.dup2(p2cread, 0)
- os.dup2(c2pwrite, 1)
- devnull = nullDevice()
- null = os.open(devnull, os.O_RDWR)
- os.dup2(null, 2)
- os.close(null)
- self._run_child(cmd)
- os.close(p2cread)
- self.tochild = os.fdopen(p2cwrite, 'w', bufsize)
- os.close(c2pwrite)
- self.fromchild = os.fdopen(c2pread, 'r', bufsize)
- _active.append(self)
- self.tochild.close() # we'll never write to it, and this way we don't confuse anything.
-
-
########################################################################
# Diagnostics class definition
########################################################################
@@ -1863,20 +1783,8 @@
The null device is something like C{/dev/null} on a UNIX system. The name
varies on other platforms.
-
- In Python 2.4 and better, we can use C{os.devnull}. Since we want to be
- portable to python 2.3, getting the value in earlier versions of Python
- takes some screwing around. Basically, this function will only work on
- either UNIX-like systems (the default) or Windows.
"""
- try:
- return os.devnull
- except AttributeError:
- import platform
- if platform.platform().startswith("Windows"):
- return "NUL"
- else:
- return "/dev/null"
+ return os.devnull
##############################
Modified: cedar-backup2/trunk/Changelog
===================================================================
--- cedar-backup2/trunk/Changelog 2010-07-07 19:58:25 UTC (rev 999)
+++ cedar-backup2/trunk/Changelog 2010-07-07 20:17:08 UTC (rev 1000)
@@ -5,6 +5,7 @@
- Change file headers, comments, manual, etc. to reference Python 2.5
- Convert to use @staticmethod rather than x = staticmethod(x)
- Change interpreter checks in test.py, cli.py and span.py
+ - Remove Python 2.3-compatible versions of util.nullDevice() and util.Pipe
* Configure pylint and execute it against the entire codebase.
- Fix a variety of minor warnings and suggestions from pylint
- Move unit tests into testcase folder to avoid test.py naming conflict
Modified: cedar-backup2/trunk/TODO
===================================================================
--- cedar-backup2/trunk/TODO 2010-07-07 19:58:25 UTC (rev 999)
+++ cedar-backup2/trunk/TODO 2010-07-07 20:17:08 UTC (rev 1000)
@@ -34,9 +34,6 @@
============================
-Move to Python 2.5 -- is available in etch
-Move to decorators for things like staticmethod (more readable)
-Change all checks to match new version -- maybe list required version in release file or something?
New images for manual (something I have given up on several times)
Remove action.py
Use decorator in places like cli._usage() rather than passing in file descriptor?
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|