Current File : //lib/python2.7/site-packages/vdo/utils/FileUtils.pyo
�
.�t_c@s'dZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZddl
m
Z
mZejd�defd	��YZd
efd��YZdefd
��YZdefd��YZdefd��YZdS(s�

  FileUtils - Provides dmmgmnt file-related capabilities.

  $Id: //eng/vdo-releases/magnesium/src/python/vdo/utils/FileUtils.py#1 $

i����(tprint_functionNi(tCommand(tTimeouttTimeoutErrortutilstFileBasecBsheZdZejd�Zed��Zd�Zd�Z	d�Z
ed��Zejd��ZRS(s�The FileBase object; provides basic file control.

  Class attributes:
    log (logging.Logger) - logger for this class
  Attributes:
    None
  sutils.FileBasecCs|jS(N(t_FileBase__filePath(tself((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pytpath:scOsAtt|�j�tjj|�|_|jdd�|_	dS(s:
    Arguments:
      None
    Returns:
      Nothing
    tfdN(
tsuperRt__init__tosRtrealpathRtgettNonet
_FileBase__fd(RtfilePathtargstkwargs((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRAscCs|S(N((R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt	__enter__MscCstS(N(tFalse(Rt
exceptionTypetexceptionValuet	traceback((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt__exit__QscCs|jS(N(R(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt_fdXscCs
||_dS(N(R(Rtvalue((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR_s(
t__name__t
__module__t__doc__tloggingt	getLoggertlogtpropertyRRRRRtsetter(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR-s			t	FileTouchcBs8eZdZejd�Zd�Zd�Zd�ZRS(s�The FileTouch object; touches the file.

  Class attributes:
    log (logging.Logger) - logger for this class
  Attributes:
    None
  sutils.FileTouchcOs tt|�j|||�dS(s:
    Arguments:
      None
    Returns:
      Nothing
    N(R
R$R(RRRR((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRyscCs�tt|�j�|jdkr�tjj|j�}tj|tj	�snt
dd|g�}|j�ntj|jtj	�s�|j�q�n|S(s0Make certain the file exists and return ourself.tmkdirs-pN(
R
R$RRRRRtdirnametaccesstF_OKRtrunt_createFile(RtdirPathtcmd((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s
cCs#td|jg�}|j�dS(sCreates the targe file.ttouchN(RRR)(RR,((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR*�s(	RRRRR R!RRR*(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR$hs
		
	tFileOpencBs�eZdZejd�Zed��Zd�Zdd�Z	dd�Z
dd�Ze
jd�Zdd	�Zd
�Zd�Zd�Zd
�Zd�Zdd�Zd�Zed��ZRS(s�The FileOpen object; provides basic access to a file.

  Class attributes:
    log (logging.Logger) - logger for this class
  Attributes:
    None
  sutils.FileOpencCs|jS(N(t_FileOpen__file(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pytfile�scCs|jj�dS(N(R0tflush(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR1�si����cCs|jj|�S(N(R0tread(Rt
numberOfBytes((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR2�scCs|jj|�S(N(R0treadline(RR3((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR4�scCs-|dkr|jj�S|jj|�SdS(N(RR0t	readlines(RtnumberOfBytesHint((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR5�s
cCs|jj||�dS(N(R0tseek(Rtoffsettwhence((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR7�scCs0|dkr|jj�n|jj|�dS(N(RR0ttruncate(Rtsize((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR:�scCs|jj|�dS(N(R0twrite(Rtstring((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR<�scCs|jj|�dS(N(R0t	writeline(RtsequenceOfStrings((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt
writelines�scCs
|jj�S(N(R0tnext(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRA�scCs_tt|�j�|jdkr@tj|j|j�|_ntj	|j|j
�|_|S(s!Open the file and return ourself.N(R
R.RRRRtopenRt_osModetfdopent_FileOpen__modeR/(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s
cCs)|jj�tt|�j|||�S(s Close the file.(R0tcloseR
R.R(RRRR((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s
trcOs�tt|�j|||�d}t|�dkrPd|dkrPtj}nH|ddkrltj}n,|ddkr�tjtj	B}n	tj}|ddkr�|tj
B}nd|_||_||_
dS(s:
    Arguments:
      None
    Returns:
      Nothing
    it+iRGtwtaN(R
R.RRtlenRtO_RDWRtO_RDONLYtO_WRONLYtO_TRUNCtO_APPENDR/REt_FileOpen__osMode(RRtmodeRRtosMode((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s"			cCs|S(N((R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt__iter__scCs|jS(N(RQ(R((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRCsN(RRRRR R!R"R0R1R2R4RR5RtSEEK_SETR7R:R<R@RARRRRTRC(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR.�s"								tFileLockcBs;eZdZejd�Zdd�Zd�Zd�Z	RS(sThe FileLock object; a context manager providing interlocked access on
  a file.

  The file is created, if necessary.

  Class attributes:
    log (logging.Logger) - logger for this class
  Attributes:
    _timeout - timeout in seconds (None = no timeout)
  sutils.FileLockcOs&tt|�j||�||_dS(s�
    Arguments:
      filePath - (str) path to file
      mode - (str) open mode
      timeout - (int) timeout in seconds; may be None
    Returns:
      Nothing
    N(R
RVRt_timeout(RRRRttimeoutRR((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR:s	cCstt|�j�|jtjkr7tj}d}ntj}d}|j	dk	r�|jjdj
d|jd|j	d|��t|j	td�j
d|jd|j	���tj|j|�WdQXn8|jjd	j
d|jd|��tj|j|�|S(
s_If the open mode is read-only the file is locked shared else it is
    locked exclusively.
    tsharedt	exclusives'attempting to lock {f} in {s}s mode {m}tftstms!Could not lock {f} in {s} secondsNsattempting to lock {f} mode {m}(R
RVRRCRRMtfcntltLOCK_SHtLOCK_EXRWRR!tdebugtformatRRt_tflockR0(Rt	flockModetlockModeString((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRGs(					
	
cCs`tj|jtj�|tk	rD|jjdjd|j��nt	t
|�j|||�S(s Unlocks and closes the file.sreleased lock {f}R[(R^RdR0tLOCK_UNRR!RaRbRR
RVR(RRRR((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRds"N(
RRRRR R!RRRR(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRV&s

	
	tFileTempcBs8eZdZejd�Zdddd�Zd�ZRS(s�The FileTemp object; a context manager providing temporary files
  with specified (or default) owner and permissions.
  An optional destination parameter specifies the location to which the
  temp file should be moved at exit, if no exception is encountered.
  The move, if specified, is performed after performing the owner
  manipulations.

  Class attributes:
    log (logging.Logger) - logger for this class
  Attributes:
    None
  sutils.FileTempcOs|tj�}tt|�j|ddd|d�|sNttj��}n|s]d}n||_||_	||_
dS(s�
    Arguments:
      owner - (str) the owner to set for the file
      ownerPerm - (str) the permissions to set for the owner
      destination (str) the path to which to move the temp file on exit
    Returns:
      Nothing
    isr+R	itrwN(ttempfiletmkstempR
RhRtstrRtgeteuidt_FileTemp__ownert_FileTemp__ownerPermt_FileTemp__destination(Rtownert	ownerPermtdestinationRRttmpFile((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s
'			cCs6|}|dkr�|jdk	r�y�td|j|jg�}|j�tddjd|jg�|jg�}|j�|jj	�td|j|jg�}|j�Wq�t
k
r�}|}q�Xn|dk	s�|jdkry#td|jg�}|j�WqqXntt|�j
|||�S(Ntchowntchmodt=tutmvtrm(RRpRRnRR)tjoinRoR0RFt	ExceptionR
RhR(RRRRt	exceptionR,tex((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyR�s*
*


N(	RRRRR R!RRR(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyRhws	(Rt
__future__RterrnoR^tgettexttgrpRRtstatRjttimeRRRtinstalltobjectRR$R.RVRh(((s7/usr/lib/python2.7/site-packages/vdo/utils/FileUtils.pyt<module>s$
;=�Q