forked from galaxyproject/galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_tempfile.py
31 lines (25 loc) · 988 Bytes
/
log_tempfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# override tempfile methods for debugging
import tempfile
import traceback
import logging
log = logging.getLogger( __name__ )
class TempFile( object ):
def __init__( self ):
tempfile._NamedTemporaryFile = tempfile.NamedTemporaryFile
tempfile._mkstemp = tempfile.mkstemp
tempfile.NamedTemporaryFile = self.NamedTemporaryFile
tempfile.mkstemp = self.mkstemp
def NamedTemporaryFile( self, *args, **kwargs ):
f = tempfile._NamedTemporaryFile( *args, **kwargs )
try:
log.debug( ( "Opened tempfile %s with NamedTemporaryFile:\n" % f.name ) + "".join( traceback.format_stack() ) )
except AttributeError:
pass
return f
def mkstemp( self, *args, **kwargs ):
f = tempfile._mkstemp( *args, **kwargs )
try:
log.debug( ( "Opened tempfile %s with mkstemp:\n" % f[1] ) + "".join( traceback.format_stack() ) )
except TypeError:
pass
return f