Changeset 259 in tailor


Ignore:
Timestamp:
04/18/05 18:19:55 (8 years ago)
Author:
lele@…
Hash name:
20050418161955-97f81-2178e866f307ee80cd2d0d0cafc247b46c5f2c2d
Message:

Revisited zooko's ReopenableNamedTemporaryFile? patch

Location:
vcpx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • vcpx/cvsps.py

    r258 r259  
    1414__docformat__ = 'reStructuredText' 
    1515 
    16 from shwrap import SystemCommand, shrepr 
     16from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 
    1717from source import UpdatableSourceWorkingDir, ChangesetApplicationFailure, \ 
    1818     InvocationError 
     
    172172            yield Changeset(**pset) 
    173173 
    174 import tempfile 
    175  
    176 class ReopeableNamedTemporaryFile: 
    177     """ 
    178     This uses tempfile.mkstemp() to generate a secure temp file.  It then closes 
    179     the file, leaving a zero-length file as a placeholder.  You can get the 
    180     filename with ReopenableNamedTemporaryFile.name.  When the 
    181     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/pyutil 
    185     """ 
    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) 
    194174 
    195175class CvspsWorkingDir(UpdatableSourceWorkingDir, 
  • vcpx/svn.py

    r258 r259  
    1212__docformat__ = 'reStructuredText' 
    1313 
    14 from shwrap import SystemCommand, shrepr 
     14from shwrap import SystemCommand, shrepr, ReopenableNamedTemporaryFile 
    1515from source import UpdatableSourceWorkingDir, \ 
    1616     ChangesetApplicationFailure, GetUpstreamChangesetsFailure 
     
    4545    COMMAND = "svn propset --quiet %(property)s %(value)s %(entry)s" 
    4646 
    47 import shutil, tempfile 
    48  
    49 class ReopeableNamedTemporaryFile: 
    50     """ 
    51     This uses tempfile.mkstemp() to generate a secure temp file.  It then closes 
    52     the file, leaving a zero-length file as a placeholder.  You can get the 
    53     filename with ReopenableNamedTemporaryFile.name.  When the 
    54     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/pyutil 
    58     """ 
    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) 
    6747 
    6848class SvnLog(SystemCommand): 
    6949    COMMAND = "TZ=UTC svn log %(quiet)s %(xml)s --revision %(startrev)s:%(endrev)s %(entry)s > %(tempfilename)s 2>&1" 
    7050     
    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):       
    7452        quiet = kwargs.get('quiet', True) 
    7553        if quiet == True: 
     
    9371            kwargs['endrev'] = 'HEAD' 
    9472 
    95         rontf = ReopenableNamedTemporaryFile('svn', 'tailor') 
    96         logfn = kwargs['tempfilename'] = rontf.name 
     73        self.rontf = ReopenableNamedTemporaryFile('svn', 'tailor') 
     74        logfn = kwargs['tempfilename'] = self.rontf.name 
    9775         
    9876        SystemCommand.__call__(self, output=False, dry_run=dry_run, **kwargs) 
    9977 
    10078        return open(logfn) 
    101  
    10279 
    10380class SvnCommit(SystemCommand): 
     
    11289                log = open(rontf.name, "w") 
    11390                log.write(logmessage) 
    114                 log.close() 
    115              
     91                log.close()             
    11692            kwargs['logfile'] = rontf.name 
    11793         
  • vcpx/shwrap.py

    r233 r259  
    1010from sys import stderr 
    1111 
     12 
    1213def shrepr(str): 
    1314    str = str.replace("'", "\\'") 
    1415    return "'" + str + "'" 
     16 
     17 
     18class 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 
    1541 
    1642class VerboseStringIO(StringIO): 
  • vcpx/cvs.py

    r258 r259  
    1212__docformat__ = 'reStructuredText' 
    1313 
    14 from shwrap import SystemCommand 
     14from shwrap import SystemCommand, ReopenableNamedTemporaryFile 
    1515from cvsps import CvspsWorkingDir 
    1616from source import GetUpstreamChangesetsFailure 
     
    3636    return cmp(r1, r2) 
    3737 
    38  
    39 import tempfile 
    40  
    41 class ReopeableNamedTemporaryFile: 
    42     """ 
    43     This uses tempfile.mkstemp() to generate a secure temp file.  It then closes 
    44     the file, leaving a zero-length file as a placeholder.  You can get the 
    45     filename with ReopenableNamedTemporaryFile.name.  When the 
    46     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/pyutil 
    50     """ 
    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) 
    5938 
    6039class CvsLog(SystemCommand): 
     
    6241        
    6342    def __call__(self, output=None, dry_run=False, **kwargs): 
    64         from tempfile import mktemp 
    65          
    6643        since = kwargs.get('since') 
    6744        if since: 
     
    7552         
    7653        self.rontf = ReopenableNamedTemporaryFile('cvs', 'tailor') 
    77         logfn = kwargs['tempfilename'] = rontf.name 
     54        logfn = kwargs['tempfilename'] = self.rontf.name 
    7855         
    7956        SystemCommand.__call__(self, output=False, dry_run=dry_run, **kwargs) 
Note: See TracChangeset for help on using the changeset viewer.