Changeset 259 in tailor
- Timestamp:
- 04/18/05 18:19:55 (8 years ago)
- Hash name:
- 20050418161955-97f81-2178e866f307ee80cd2d0d0cafc247b46c5f2c2d
- Location:
- vcpx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
vcpx/cvsps.py
r258 r259 14 14 __docformat__ = 'reStructuredText' 15 15 16 from shwrap import SystemCommand, shrepr 16 from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 17 17 from source import UpdatableSourceWorkingDir, ChangesetApplicationFailure, \ 18 18 InvocationError … … 172 172 yield Changeset(**pset) 173 173 174 import tempfile175 176 class ReopeableNamedTemporaryFile:177 """178 This uses tempfile.mkstemp() to generate a secure temp file. It then closes179 the file, leaving a zero-length file as a placeholder. You can get the180 filename with ReopenableNamedTemporaryFile.name. When the181 ReopenableNamedTemporaryFile instance is garbage collected or its shutdown()182 method is called, it deletes the file.183 184 Copied from Zooko's pyutil.fileutil, http://zooko.com/repos/pyutil185 """186 def __init__(self, suffix=None, prefix=None, dir=None, text=None):187 self.name = mkstemp(suffix, prefix, dir, text)[1]188 189 def __del__(self):190 self.shutdown()191 192 def shutdown(self):193 os.remove(self.name)194 174 195 175 class CvspsWorkingDir(UpdatableSourceWorkingDir, -
vcpx/svn.py
r258 r259 12 12 __docformat__ = 'reStructuredText' 13 13 14 from shwrap import SystemCommand, shrepr 14 from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 15 15 from source import UpdatableSourceWorkingDir, \ 16 16 ChangesetApplicationFailure, GetUpstreamChangesetsFailure … … 45 45 COMMAND = "svn propset --quiet %(property)s %(value)s %(entry)s" 46 46 47 import shutil, tempfile48 49 class ReopeableNamedTemporaryFile:50 """51 This uses tempfile.mkstemp() to generate a secure temp file. It then closes52 the file, leaving a zero-length file as a placeholder. You can get the53 filename with ReopenableNamedTemporaryFile.name. When the54 ReopenableNamedTemporaryFile instance is garbage collected or its shutdown()55 method is called, it deletes the file.56 57 Copied from Zooko's pyutil.fileutil, http://zooko.com/repos/pyutil58 """59 def __init__(self, suffix=None, prefix=None, dir=None, text=None):60 self.name = mkstemp(suffix, prefix, dir, text)[1]61 62 def __del__(self):63 self.shutdown()64 65 def shutdown(self):66 os.remove(self.name)67 47 68 48 class SvnLog(SystemCommand): 69 49 COMMAND = "TZ=UTC svn log %(quiet)s %(xml)s --revision %(startrev)s:%(endrev)s %(entry)s > %(tempfilename)s 2>&1" 70 50 71 def __call__(self, output=None, dry_run=False, **kwargs): 72 from tempfile import mktemp 73 51 def __call__(self, output=None, dry_run=False, **kwargs): 74 52 quiet = kwargs.get('quiet', True) 75 53 if quiet == True: … … 93 71 kwargs['endrev'] = 'HEAD' 94 72 95 rontf = ReopenableNamedTemporaryFile('svn', 'tailor')96 logfn = kwargs['tempfilename'] = rontf.name73 self.rontf = ReopenableNamedTemporaryFile('svn', 'tailor') 74 logfn = kwargs['tempfilename'] = self.rontf.name 97 75 98 76 SystemCommand.__call__(self, output=False, dry_run=dry_run, **kwargs) 99 77 100 78 return open(logfn) 101 102 79 103 80 class SvnCommit(SystemCommand): … … 112 89 log = open(rontf.name, "w") 113 90 log.write(logmessage) 114 log.close() 115 91 log.close() 116 92 kwargs['logfile'] = rontf.name 117 93 -
vcpx/shwrap.py
r233 r259 10 10 from sys import stderr 11 11 12 12 13 def shrepr(str): 13 14 str = str.replace("'", "\\'") 14 15 return "'" + str + "'" 16 17 18 class ReopenableNamedTemporaryFile: 19 """ 20 This uses tempfile.mkstemp() to generate a secure temp file. It 21 then closes the file, leaving a zero-length file as a placeholder. 22 You can get the filename with ReopenableNamedTemporaryFile.name. 23 When the ReopenableNamedTemporaryFile instance is garbage 24 collected or its shutdown() method is called, it deletes the file. 25 26 Copied from Zooko's pyutil.fileutil, http://zooko.com/repos/pyutil 27 """ 28 def __init__(self, suffix=None, prefix=None, dir=None, text=None): 29 from tempfile import mkstemp 30 31 self.name = mkstemp(suffix, prefix, dir, text)[1] 32 33 def __del__(self): 34 self.shutdown() 35 36 def shutdown(self): 37 from os import remove 38 39 remove(self.name) 40 15 41 16 42 class VerboseStringIO(StringIO): -
vcpx/cvs.py
r258 r259 12 12 __docformat__ = 'reStructuredText' 13 13 14 from shwrap import SystemCommand 14 from shwrap import SystemCommand, ReopenableNamedTemporaryFile 15 15 from cvsps import CvspsWorkingDir 16 16 from source import GetUpstreamChangesetsFailure … … 36 36 return cmp(r1, r2) 37 37 38 39 import tempfile40 41 class ReopeableNamedTemporaryFile:42 """43 This uses tempfile.mkstemp() to generate a secure temp file. It then closes44 the file, leaving a zero-length file as a placeholder. You can get the45 filename with ReopenableNamedTemporaryFile.name. When the46 ReopenableNamedTemporaryFile instance is garbage collected or its shutdown()47 method is called, it deletes the file.48 49 Copied from Zooko's pyutil.fileutil, http://zooko.com/repos/pyutil50 """51 def __init__(self, suffix=None, prefix=None, dir=None, text=None):52 self.name = mkstemp(suffix, prefix, dir, text)[1]53 54 def __del__(self):55 self.shutdown()56 57 def shutdown(self):58 os.remove(self.name)59 38 60 39 class CvsLog(SystemCommand): … … 62 41 63 42 def __call__(self, output=None, dry_run=False, **kwargs): 64 from tempfile import mktemp65 66 43 since = kwargs.get('since') 67 44 if since: … … 75 52 76 53 self.rontf = ReopenableNamedTemporaryFile('cvs', 'tailor') 77 logfn = kwargs['tempfilename'] = rontf.name54 logfn = kwargs['tempfilename'] = self.rontf.name 78 55 79 56 SystemCommand.__call__(self, output=False, dry_run=dry_run, **kwargs)
Note: See TracChangeset
for help on using the changeset viewer.
