B @`P@szddlZddlZddlZddlZddlZddlmZyddlmZ Wne k r\dZ YnXdZ GdddZ e ZdS)N)deprecation_warning)TempfileManagerTc@steZdZdZddZdddZddd Zdd d Zdd dZd ddZ ddZ ddZ ddZ ddZ d!ddZdS)"TempfileManagerClassz%A class that manages temporary files.cKsd|_gg|_d|_dS)N)tempdir _tempfiles_ctr)selfkwdsr :/tmp/pip-unpacked-wheel-bi3529v6/pyomo/common/tempfiles.py__init__%szTempfileManagerClass.__init__NFcCs|dkr d}|dkrd}|dkrP|j}|dkrPtdk rPtj}|dk rPtdddtj||||d}t|}tj|dstj ||d}n|d}t |d |j d krtj ||t |j |}tj |rt|t|||}|j d7_ |jd ||S) zCreate a unique temporary file Returns the absolute path of a temporary filename that is guaranteed to be unique. This function generates the file and returns the filename. NtmpzThe use of the PyUtilib TempfileManager.tempdir to specify the default location for Pyomo temporary files has been deprecated. Please set TempfileManager.tempdir in pyomo.common.tempfilesz5.7.2)version)suffixprefixtextdirrr)r pyutilib_mngrrtempfilemkstemplistospathisabsjoincloserstrexistsremoveshutilmoverappend)r rrrrZansfnameZ new_fnamer r r create_tempfile*s6    z$TempfileManagerClass.create_tempfilecCs|dkr d}|dkrd}|dkrP|j}|dkrPtdk rPtj}|dk rPtdddtj|||d}|jdkrtj||t |j|}tj |rt |t |||}|jd 7_|jd ||S) zCreate a unique temporary directory Returns the absolute path of a temporary directory that is guaranteed to be unique. This function generates the directory and returns the directory name. NrrzThe use of the PyUtilib TempfileManager.tempdir to specify the default location for Pyomo temporary directories has been deprecated. Please set TempfileManager.tempdir in pyomo.common.tempfilesz5.7.2)r)rrrrrr)rrrrmkdtemprrrrrr r"rmtreer#rr$)r rrrdirnameZ new_dirnamer r r create_tempdirUs,    z#TempfileManagerClass.create_tempdirTcCs<tj|}|r(tj|s(td||jd|dS)z"Declare this file to be temporary.zTemporary file does not exist: rN)rrabspathr IOErrorrr$)r filenamer rr r r add_tempfile{s  z!TempfileManagerClass.add_tempfilecCs,xt|jdkr||qW||dS)zDelete all temporary files.rN)lenrpop)r r!r r r clear_tempfilessz$TempfileManagerClass.clear_tempfilesrcCs ||_dS)z>Start generating sequential files, using the specified counterN)r)r Zctrr r r sequential_filessz%TempfileManagerClass.sequential_filescCs d|_dS)z=Stop generating sequential files, using the specified counterrN)r)r r r r unique_filessz!TempfileManagerClass.unique_filescCs|jg|S)N)rr$)r r r r pushs zTempfileManagerClass.pushcCs |dS)N)r4)r r r r __enter__szTempfileManagerClass.__enter__cCs|jdddS)NT)r!)r0)r typevalue tracebackr r r __exit__szTempfileManagerClass.__exit__c Cs|j}|rx|D]}tj|rtj|rBtj|t dqyt |Wqt k ryt dt |Wn6t k rtrnt t}|d|fYnXYqXqWt|jdkrgg|_dS)N) ignore_errorsrz"Unable to delete temporary file %sr)rr0rrr isdirr"r(deletion_errors_are_fatalr!Z WindowsErrortimesleeplogging getLogger__name__warningr/)r r!filesr-loggerr r r r0s,       zTempfileManagerClass.pop)NNFN)NNN)T)T)r)T)rA __module__ __qualname____doc__r r&r*r.r1r2r3r4r5r9r0r r r r r"s + &   r) rr=rr?r"Zpyomo.common.deprecationrZ#pyutilib.component.config.tempfilesrr ImportErrorr<rr r r r s