B t `@sdZdddgZddlZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z d ZGd ddeZGd dde ZeZdS) z&A plugin that manages temporary files.ITempfileManagerTempfileManagerPluginTempfileManagerN) Interface implements)ManagedSingletonPlugin)declare_optionTc@sZeZdZdZdddZdddZdd Zdd d ZdddZddZ ddZ dddZ dS)rz'Interface for managing temporary files.NFcCsdS)zMReturn the absolute path of a temporary file that is guaranteed to be unique.N)selfsuffixprefixtextdirr r G/tmp/pip-unpacked-wheel-cqckmaqz/pyutilib/component/config/tempfiles.pycreate_tempfilesz ITempfileManager.create_tempfilecCsdS)zRReturn the absolute path of a temporary directory that is guaranteed to be unique.Nr )r r r rr r rcreate_tempdir szITempfileManager.create_tempdircCsdS)z"Declare this file to be temporary.Nr )r filenamer r r add_tempfile#szITempfileManager.add_tempfileTcCsdS)zDelete all temporary files.Nr )r remover r rclear_tempfiles&sz ITempfileManager.clear_tempfilesrcCsdS)z>Start generating sequential files, using the specified counterNr )r ctrr r rsequential_files)sz!ITempfileManager.sequential_filescCsdS)zStart generating unique filesNr )r r r r unique_files,szITempfileManager.unique_filescCsdS)zGPush tempfiles onto a stack. This creates a new context for tempfiles.Nr )r r r rpush/szITempfileManager.pushcCsdS)zQPop tempfiles onto a stack. Tempfiles that are popped off the stack are deleted.Nr )r rr r rpop2szITempfileManager.pop)NNFN)NNN)T)r)T) __name__ __module__ __qualname____doc__rrrrrrrrr r r rrs    c@steZdZdZeeddZdddZddd Zdd d Z dd dZ dddZ ddZ ddZ ddZdddZdS) rz&A plugin that manages temporary files.cKsNt|dddkrdSd|_d|d<tj|f|gg|_tdddd|_dS) N _initializedFTrnametempdir)default)getattrrr__init__ _tempfilesr_ctr)r kwdsr r rr%;s zTempfileManagerPlugin.__init__NFcCs|dkr d}|dkrd}|dkr&|j}tj||||d}t|}tj|dsdtj||d}n|d}t|d|j dkrtj||t |j |}tj |rt |t |||}|j d7_ |jd||S)z Return the absolute path of a temporary filename that is guaranteed to be unique. This function generates the file and returns the filename. Ntmp)r r r rrr#)r!tempfilemkstemplistospathisabsjoincloser'strexistsrshutilmover&append)r r r r rZansfnameZ new_fnamer r rrFs*    z%TempfileManagerPlugin.create_tempfilecCs|dkr d}|dkrd}|dkr&|j}tj|||d}|jdkrtj||t|j|}tj|rrt |t |||}|jd7_|j d ||S)z Return the absolute path of a temporary directory that is guaranteed to be unique. This function generates the directory and returns the directory name. Nr)r*)r r rrr+r#)r!r,mkdtempr'r/r0r2r4r5r6rmtreer7r&r8)r r r rdirnameZ new_dirnamer r rrfs     z$TempfileManagerPlugin.create_tempdirTcCs<tj|}|r(tj|s(td||jd|dS)z"Declare this file to be temporary.zTemporary file does not exist: r#N)r/r0abspathr5IOErrorr&r8)r rr5r*r r rrs  z"TempfileManagerPlugin.add_tempfilecCs,xt|jdkr||qW||dS)zDelete all temporary files.r+N)lenr&r)r rr r rrsz%TempfileManagerPlugin.clear_tempfilesrcCs ||_dS)z>Start generating sequential files, using the specified counterN)r')r rr r rrsz&TempfileManagerPlugin.sequential_filescCs d|_dS)z=Stop generating sequential files, using the specified counterr#N)r')r r r rrsz"TempfileManagerPlugin.unique_filescCs|jg|S)N)r&r8)r r r rrs zTempfileManagerPlugin.pushcCs|jdddS)NT)r)r)r typevalue tracebackr r r__exit__szTempfileManagerPlugin.__exit__c Cs|j}|rx|D]}tj|rtj|rBtj|t dqyt |Wqt k ryt dt |Wn6t k rtrnt d}|d|fYnXYqXqWt|jdkrgg|_dS)N) ignore_errorsr+zpyutilib.component.configz"Unable to delete temporary file %sr)r&rr/r0r5isdirr6r;deletion_errors_are_fatalrZ WindowsErrortimesleeplogging getLoggerwarningr?)r rfilesrloggerr r rrs.      zTempfileManagerPlugin.pop)NNFN)NNN)T)T)r)T)rrrrrrr%rrrrrrrrCrr r r rr6s    )r__all__r/rGr,rIr6Zpyutilib.component.corerrZ(pyutilib.component.config.managed_pluginrZ!pyutilib.component.config.optionsrrFrrrr r r r s