~ubuntu-branches/ubuntu/natty/duplicity/natty-updates

« back to all changes in this revision

Viewing changes to src/dup_temp.py

  • Committer: Bazaar Package Importer
  • Author(s): Steinar H. Gunderson
  • Date: 2006-11-11 13:32:07 UTC
  • mfrom: (2.1.3 feisty)
  • Revision ID: james.westby@ubuntu.com-20061111133207-9gizpeda242fwmtr
Tags: 0.4.2-10.1
Switch back to python 2.4, as python-central can apparently no longer cope
with 2.3, and 2.4 seems to work ok now; patch from Joey Hess.
(Closes: #396158)

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
                self.fileobj = fileobj
113
113
                self.closed = None
114
114
                self.hooklist = [] # fill later with thunks to run on close
 
115
                # self.second by MDR.  Will be filled by addfilehandle -- poor mans tee
 
116
                self.second = None
115
117
 
116
 
        def write(self, buf): return self.fileobj.write(buf)
 
118
        def write(self, buf):
 
119
                if self.second: self.second.write(buf) # by MDR.  actual tee
 
120
                return self.fileobj.write(buf)
 
121
        
117
122
        def read(self, length = -1): return self.fileobj.read(length)
118
123
 
119
124
        def close(self):
120
125
                """Close fileobj, running hooks right afterwards"""
121
126
                assert not self.fileobj.close()
122
127
                for hook in self.hooklist: hook()
 
128
                if self.second: assert not self.second.close()
123
129
 
124
130
        def addhook(self, hook):
125
131
                """Add hook (function taking no arguments) to run upon closing"""
126
132
                self.hooklist.append(hook)
127
133
 
 
134
        def addfilehandle(self, fh): # by MDR
 
135
                """Add a second filehandle for listening to the input
 
136
                
 
137
                This only works properly for two write handles"""
 
138
                assert not self.second
 
139
                self.second = fh