PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/log_tempfile.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 27 lines | 23 code | 3 blank | 1 comment | 0 complexity | fd064375febae9ec8e52513440362ec5 MD5 | raw file
 1# override tempfile methods for debugging
 2
 3import tempfile, traceback
 4
 5import logging
 6log = logging.getLogger( __name__ )
 7
 8class TempFile( object ):
 9    def __init__( self ):
10        tempfile._NamedTemporaryFile = tempfile.NamedTemporaryFile
11        tempfile._mkstemp = tempfile.mkstemp
12        tempfile.NamedTemporaryFile = self.NamedTemporaryFile
13        tempfile.mkstemp = self.mkstemp
14    def NamedTemporaryFile( self, *args, **kwargs ):
15        f = tempfile._NamedTemporaryFile( *args, **kwargs )
16        try:
17            log.debug( ( "Opened tempfile %s with NamedTemporaryFile:\n" % f.name ) + "".join( traceback.format_stack() ) )
18        except AttributeError:
19            pass
20        return f
21    def mkstemp( self, *args, **kwargs ):
22        f = tempfile._mkstemp( *args, **kwargs )
23        try:
24            log.debug( ( "Opened tempfile %s with mkstemp:\n" % f[1] ) + "".join( traceback.format_stack() ) )
25        except TypeError:
26            pass
27        return f