Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/vdo/vdomgmnt/__pycache__/Configuration.cpython-36.pyc

3

x?ag.7�@s�dZddlmZddlmZddlmZddlmZddlmZddlmZdd	lm	Z	dd
l
mZmZddl
m
Z
mZddlZddlZddlZdd
lmZddlZddlZGdd�dee�ZGdd�de�ZdS)z�
  Configuration - VDO manager configuration file handling

  $Id: //eng/vdo-releases/aluminum/src/python/vdo/vdomgmnt/Configuration.py#6 $

�)�absolute_import)�division)�print_function)�unicode_literals�)�
ArgumentError)�StateExitStatus)�
VDOService)�Command�
runCommand)�FileLock�
YAMLObjectN)�ST_MTIMEcs(eZdZdZ�fdd�Zdd�Z�ZS)�BadConfigurationFileErrorzwException raised to indicate an error in processing the
  configuration file, such as a parse error or missing data.
  cstt|�j||�||_dS)N)�superr�__init__�_msg)�self�msg�args�kwargs)�	__class__��#/usr/lib/python3.6/Configuration.pyr3sz"BadConfigurationFileError.__init__cCs|jS)N)r)rrrr�__str__8sz!BadConfigurationFileError.__str__)�__name__�
__module__�__qualname__�__doc__rr�
__classcell__rr)rrr+srcs0eZdZdZejd�ZdgZiZdZ	dZ
dZedd��Z
d:d	d
�Zdd�Zed
d��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zedd ��Ze�fd!d"��Z�fd#d$�Ze�fd%d&��Z�fd'd(�Zd;�fd*d+�	Zd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$d6d7�Z%ed8d9��Z&�Z'S)<�
ConfigurationzConfiguration of VDO volumes.zvdo.vdomgmnt.Configurationi	 z/var/lock/vdo-config-singletonsz!ConfigurationFcCsJd}t|jd��0}|jj|�}|dkr<t|dd�}||j|<WdQRX|S)aRAllocates, as necessary, and returns a modifiable, singleton
    Configuration instance for the specified filepath.  Separate entities can
    thus share one in memory copy of the configuration file allowing for
    encapsulation of per-entity manipulation of the configuration.

    Args:
      filepath (str):   path to config file
    Nzr+F)�readonly)r�
singletonLock�modifiableSingltons�getr )�cls�filepath�config�frrr�modifiableSingletonIs
z!Configuration.modifiableSingletoncCsB|j�|jjdj|��|r.|j|�r.dS||j|<d|_dS)atAdds or replaces a VDOService object in the configuration.
    Generates an assertion error if this object is read-only.

    Arguments:
    name -- name of the VDOService
    vdo -- the VDOService to add or replace
    replace -- if True, any existing VDOService will be replaced
    Returns: False if the VDOService exists and replace is False,
      True otherwise
    z!Adding vdo "{0}" to configurationFT)�_assertCanModify�log�debug�format�haveVdo�_vdos�_dirty)r�name�vdo�replacerrr�addVdo\s
zConfiguration.addVdocCs"tj|j|d�dd�}|jdd�S)zIReturns the configuration's YAML representation to present to users.
    )�filenamer'F)�default_flow_stylez!!python/unicode �)�yaml�dumpr&r3)r�srrr�
asYAMLForUserpszConfiguration.asYAMLForUsercCs|jS)z0Returns the file path of the configuration file.)�	_filename)rrrrr&zszConfiguration.filepathcCs|jS)z#Retrieves a list of all known VDOs.)r/)rrrr�
getAllVdos�szConfiguration.getAllVdoscCs>d}y|j|}Wn&tk
r8ttd�j|���YnX|S)zRetrieves a VDO by name.NzVDO volume {0} not found)r/�KeyErrorr�_r-)rr1r2rrr�getVdo�szConfiguration.getVdocCs
||jkS)z0Returns True if we have a VDO with a given name.)r/)rr1rrrr.�szConfiguration.haveVdocCs<tjj|�}x*|jD] }|tjj|j|j�krdSqWdS)z�Returns a boolean indicating if the configuration contains a VDO using
    the specified device.

    Both the specified device and the device from the vdos present in the
    configuration are fully resolved for the check.
    TF)�os�path�realpathr/�device)rrDr2rrr�isDeviceConfigured�s
z Configuration.isDeviceConfiguredcCs>|jr
dS|js |jjd�dS|jjdj|j��|j�rH|j�dStj	d|idd�}t
j�r�tt
d��t|�d|_dS|jd}tjj|�r�tj|�t|d	��n}|jd
�|jtj�|jdjt
d���|jtj�|jd
�|jtj�|j|�|j�tj|�WdQRXtj||j�|j�d|_dS)
a\Writes out the Configuration if necessary.

    If the Configuration is read-only or has not been modified, this
    method will silently return. If Command.noRunMode is True, any
    new Configuration will be printed to stdout instead of the file.

    This method will generate an assertion failure if the configuration
    file is not open.
    Nz&Configuration is clean, not persistingzWriting configuration to {0}r'F)r6z New configuration (not written):z.new�wzD####################################################################z# {0}z>THIS FILE IS MACHINE GENERATED. DO NOT EDIT THIS FILE BY HAND.)�	_readonlyr0r+r,r-r&�_empty�_removeFiler8r9r
�	noRunMode�printr?rArB�exists�remove�open�write�linesep�flush�fsync�rename�_fsyncDirectory)rr:ZnewFile�fhrrr�persist�sD



zConfiguration.persistcCs|j�|j|=d|_dS)zRemoves a VDO by name.TN)r*r/r0)rr1rrr�	removeVdo�szConfiguration.removeVdocCs�i}d}ytj|j�}|j|td�<Wn@tk
rf}z$|jtjkrF�td�|td�<WYdd}~XnX|dkr�td�|td�<ntjdtj	|t
��|td�<|S)zAReturns a dictionary representing the status of this object.
    NZFilezdoes not existz
not availablez
Last modifiedz%Y-%m-%d %H:%M:%S)rA�statr&r?�OSError�errno�ENOENT�timeZstrftimeZ	localtimer)r�status�st�exrrrr]�s"zConfiguration.statuscCs|d�S)Nz/dev/YAMLInstancer)r%rrr�_yamlMakeInstance�szConfiguration._yamlMakeInstancecCsddgS)N�version�vdosr)rrrr�_yamlAttributeKeys�sz Configuration._yamlAttributeKeyscs$tt|�j}|j|d<|j|d<|S)Nrarb)rr �	_yamlData�_schemaVersionr/)r�data)rrrrds

zConfiguration._yamlDatacs(tt|�j|�|d|_|d|_dS)Nrarb)rr �_yamlSetAttributesrarb)rZ
attributes)rrrrg
s
z Configuration._yamlSetAttributescstt|�j}|jddg�|S)Nrarb)rr �_yamlSpeciallyHandledAttributes�extend)rZspecials)rrrrhsz-Configuration._yamlSpeciallyHandledAttributescsDtt|�j|�|j|_|j|_x|jD]}|j|j|�q(WdS)N)rr �_yamlUpdateFromInstancerarerbr/Z	setConfig)r�instancer2)rrrrjs
z%Configuration._yamlUpdateFromInstanceTcs�tt|�j�i|_tjj|�|_||_d|_	||_
d|_|jsN|j
�d|_|j
rxtjj|j�rxttd�j|j���|r�dnd}y@tjj|�r�tjj|�dkr�t||��}|j|�WdQRXWn.tk
r�}ztt|���WYdd}~XnXdS)	aConstruct a Configuration.

    Args:
      filename (str): The path to the XML configuration file

    Kwargs:
      readonly (bool): If True, the configuration is read-only.
      mustExist (bool): If True, the configuration file must exist.

    Raises:
      ArgumentError
    Fi	 Tz&Configuration file {0} does not exist.�rza+rN)rr rr/rArB�abspathr<rGr0Z
_mustExistre�yaml_has_unicode_ctorsZ_fix_constructorsrLr&rr?r-�getsizerN�_read�IOError�str)rr5r!Z	mustExist�moderUr)rrrr s*


zConfiguration.__init__cCsdjt|�j|j�S)Nz{0}({1}))r-�typerr&)rrrrrDszConfiguration.__str__cCs|jstd��dS)z<Asserts that mutative operations are allowed on this object.zConfiguration is read-onlyN)rG�AssertionError)rrrrr*JszConfiguration._assertCanModifycCst|j�dkS)z,Returns True if this configuration is empty.r)�lenr/)rrrrrHOszConfiguration._emptycCsTtjj|j�}tj�r&td|g�dStj|tj�}ztj	|�Wdtj
|�XdS)zIOpen and issue an fsync on the directory containing the config file.
    rRN)rArB�dirnamer&r
rJrrN�O_RDONLYrR�close)rrw�fdrrrrTTszConfiguration._fsyncDirectoryc&Cs|jjdj|j��y|jdd�tj|�}Wn$tjjk
rRt	t
d���YnXy|d}Wn^tk
r�t	t
d���Yn@tk
r�}z$|jjdj|��t	t
d���WYdd}~XnXy|j
|�WnBtk
�r}z$|jjdj|��t	t
d���WYdd}~XnXd|_dS)	z%Reads in a Configuration from a file.zReading configuration from {0}rzNot a valid configuration filer'z9Not a valid configuration file (missing 'config' section)z#Not a valid configuration file: {0}NF)r+r,r-r&�seekr8Z	safe_load�scannerZScannerErrorrr?r>�	Exceptionrjr0)rrUZconfr'r_rrrrpbs(zConfiguration._readcCs|tj�rtd|jg�dStjj|j�r<tj|j�|j�y&t	|j
d��}tj|j=WdQRXWnt
k
rvYnXdS)zfDeletes the current configuration file.
    In noRun mode, pretend that we're doing an rm of the file.ZrmNzr+)r
rJrr&rArBrLrMrTrr"r r#r>)rr(rrrrI�szConfiguration._removeFilecCs"||jkrttd�j|d���dS)z�Checks a configuration file schema version string against the list
    of supported schemas.

    Args:
      ver (str): the schema version string to check

    Raises:
      BadConfigurationFileError: version not supported.
    z,Configuration file version {v} not supported)�vN)�supportedSchemaVersionsrr?r-)r%Zverrrr�_validateVersion�s
zConfiguration._validateVersion)F)TF)(rrrr�loggingZ	getLoggerr+rr#r"Zyaml_tagrn�classmethodr)r4r;�propertyr&r=r@r.rErVrWr]r`rcrdrgrhrjrrr*rHrTrprIr�rrr)rrr <s@



6	$r )rZ
__future__rrrrr7rrr	Z	vdo.utilsr
rrr
rZr�rArXrr\r8r}rr rrrr�<module>s"

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists