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__/VDOOperation.cpython-36.opt-1.pyc

3

x?ag�q�@s�dZddlmZddlmZddlmZddlmZddlmZddlmZdd	lm	Z	dd
lm
Z
ddlmZddlmZdd
lm
Z
ddlmZddlmZmZmZddlmZmZmZmZddlmZmZmZddlmZmZddlmZddlZddlZddl Z!ddl"Z"ddl#Z#ddl$Z$ddl%Z%e&�Z'dd�Z(dd�Z)dd�Z*Gdd�dee+�Z,Gdd�de-�Z.Gdd �d e.�Z/Gd!d"�d"e.�Z0Gd#d$�d$e.�Z1Gd%d&�d&e.�Z2Gd'd(�d(e.�Z3Gd)d*�d*e.�Z4Gd+d,�d,e.�Z5Gd-d.�d.e.�Z6Gd/d0�d0e.�Z7Gd1d2�d2e.�Z8Gd3d4�d4e.�Z9Gd5d6�d6e.�Z:Gd7d8�d8e.�Z;Gd9d:�d:e.�Z<Gd;d<�d<e.�Z=Gd=d>�d>e.�Z>Gd?d@�d@e.�Z?GdAdB�dBe?�Z@GdCdD�dDe?�ZAGdEdF�dFe?�ZBGdGdH�dHe?�ZCe#jDdI�ZEdJdK�ZFdLdM�ZGeGeH�dS)Nz�
  VDOOperation - an object representing a vdo script command

  $Id: //eng/vdo-releases/aluminum/src/python/vdo/vdomgmnt/VDOOperation.py#12 $
�)�absolute_import)�division)�print_function)�unicode_literals�)�
ArgumentError)�CommandLock)�
Configuration)�	Constants)�Defaults)�
MgmntUtils)�Service)�VDOKernelModuleService)�
VDOService�VDOServiceError� VDOServicePreviousOperationError)�
ExitStatus�StateExitStatus�SystemExitStatus�UserExitStatus)�Command�CommandError�
runCommand)�Transaction�
transactional)�partialNc
Osb|d}tjj|j�}tjj|�}|jdd�d}tjjtj|�}t	||��|||�SQRXdS)Nr�/�_z.lock)
�os�path�abspath�confFile�realpath�replace�joinr
ZLOCK_DIRr)ZisExclusive�func�args�kwargsZcommandArgsr!ZlockFileBaseZlockFile�r(�"/usr/lib/python3.6/VDOOperation.py�lock4sr*cs�fdd�}|S)zDDecorator that locks the configuration for exclusive (write) access.cstd�f|�|�S)NF)r*)r&r')r%r(r)�wrapCszexclusivelock.<locals>.wrapr()r%r+r()r%r)�
exclusivelockAsr,cs�fdd�}|S)z@Decorator that locks the configuration for shared (read) access.cstd�f|�|�S)NF)r*)r&r')r%r(r)r+Iszsharedlock.<locals>.wrapr()r%r+r()r%r)�
sharedlockGsr-cs(eZdZdZ�fdd�Zdd�Z�ZS)�OperationErrorz=Exception raised to indicate an error executing an operation.cstt|�j||�||_dS)N)�superr.�__init__�_msg)�self�msgr&r')�	__class__r(r)r0\szOperationError.__init__cCs|jS)N)r1)r2r(r(r)�__str__`szOperationError.__str__)�__name__�
__module__�__qualname__�__doc__r0r5�
__classcell__r(r()r4r)r.Ns
r.c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�VDOOperationz�Every instance of this class runs one of the subcommands
  requested when 'vdo [<options>] <subcommand>' is called via the
  execute() method.cCs>g}|jr|j|j�j��n|j|�|j|j|j��|S)z�Return a list of VDOService objects to be operated on depending
    on the settings of the --name and --all options.
    Arguments:
      args: The arguments passed into vdo.
      conf: The config file
    Raises:
      ArgumentError
    )�all�extend�
getAllVdos�values�
_checkForName�append�getVdo�name)r2r&�confZservicesr(r(r)�getVdoServicesls	
zVDOOperation.getVdoServicescKs�d}d}|jdd�r$t|jf|�}ntj|j�}xJ|j||�D]:}y|||�Wq>tk
rv}z
|}WYdd}~Xq>Xq>W|jdd�s�|j�|dk	r�|�dS)a�Apply a method to all specified VDOs. An exception applying the method
    to some VDO will not prevent it from being applied to any other VDO,
    however any exception will result in applyToVDOs raising an exception.

    If the 'readonly' keyword argument is False, the configuration will be
    persisted after the method has been applied to all the VDOs (whether or
    not it succeeded for any of them).

    Arguments:
      args (dict):       The command line arguments
      method (callable): The method to call on each VDO; will be called as
                         method(args, vdo)
      kwargs:            Keyword args controlling what gets returned
                          and to use when making the Configuration
    N�readonlyT)�getr	r!�modifiableSingletonrE�	Exception�persist)r2r&�methodr'Z	exceptionrD�vdo�exr(r(r)�applyToVDOs~szVDOOperation.applyToVDOscCs |jjtd�j|j��t�dS)a!Execute this operation. This method should be overridden by operation
    classes, and is intended only to be called from within the run() method
    below.

    Arguments:
      unused_args (dict): The command line arguments (used by subclasses)
    Raises:
      NotImplementedError
    z{0} unimplementedN)�log�errorr�formatrC�NotImplementedError)r2�unused_argsr(r(r)�execute�s
zVDOOperation.executecCs�|jr.tj�dkr.td�j|j�}t|td��|jrfx0d
D](}t	j
|�s:td�j|�}t|td��q:W|jr�t
j�r�td�j|j�}t|td��d	S)z�Perform checks prior to actually executing the command.

    Arguments:
      args (dict): The command line arguments (used by subclasses)
    Raises:
      OperationError
    rz)You must be root to use the "{0}" command)�
exitStatus�
vdodumpconfig�vdoforcerebuild�	vdoformatz#executable '{0}' not found in $PATHz&{0} command not available with --noRunN)rVrWrX)�requiresRootr�getuidrrQrCr.r�
checkBinariesrZwhichr�requiresRunModerZ	noRunMode)r2r&r3�
executabler(r(r)�	preflight�s
zVDOOperation.preflightcCsBtj|_y|j|_Wntk
r(YnX|j|�|j|�dS)z�Run this operation. This is the external entry point for users of
    VDOOperation.

    Arguments:
      args (dict): The command line arguments
    N)rr!�KeyErrorr^rT)r2r&r(r(r)�run�s
zVDOOperation.runcKsrtjddt|�j�}|dj�|dd�|_tjd�|_|j	dd�|_
|j	dd	�|_|j	d
d	�|_|t
|j<dS)Nz
Operation$�rrzvdo.vdomgmnt.VDOOperationrYTr[Fr\)�re�sub�typer6�lowerrC�loggingZ	getLoggerrOrGrYr[r\�
vdoOperations)r2r'rCr(r(r)r0�szVDOOperation.__init__cCs(|jdks|jj�dkr$ttd���dS)z|Check that the args contain a non-None name.
    Arguments:
      args: the args passed
    Raises:
      ArgumentError
    Nraz"Missing required argument '--name')rC�striprr)r2r&r(r(r)r@�szVDOOperation._checkForNameN)r6r7r8r9rErNrTr^r`r0r@r(r(r(r)r;ds$r;cs4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)�ActivateOperationz Implements the activate command.cstt|�j�dS)N)r/rir0)r2)r4r(r)r0�szActivateOperation.__init__cCs|j||jdd�dS)NF)rF)rN�	_activate)r2r&r(r(r)rT�szActivateOperation.executecCs|j�dS)N)Zactivate)r2r&rLr(r(r)rjszActivateOperation._activate)	r6r7r8r9r0r,rTrjr:r(r()r4r)ri�srics4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)�ChangeWritePolicyOperationz)Implements the changeWritePolicy command.cstt|�j�dS)N)r/rkr0)r2)r4r(r)r0sz#ChangeWritePolicyOperation.__init__cCs0t|d�|_|jdkrdS|j||jdd�dS)NZwritePolicyF)rF)�getattr�_newWritePolicyrN�_changeWritePolicy)r2r&r(r(r)rTs
z"ChangeWritePolicyOperation.executecCs|j|j�dS)N)ZsetWritePolicyrm)r2r&rLr(r(r)rnsz-ChangeWritePolicyOperation._changeWritePolicy)	r6r7r8r9r0r,rTrnr:r(r()r4r)rk
s
rkcs,eZdZdZ�fdd�Zedd��Z�ZS)�ConvertOperationzImplements the convert command.cstt|�j�dS)N)r/ror0)r2)r4r(r)r0(szConvertOperation.__init__cCs6tj|j�}|j|�|j|j�}|j�|j�dS)N)r	rHr!r@rBrCZconvertrJ)r2r&rDrLr(r(r)rT,s

zConvertOperation.execute)r6r7r8r9r0r,rTr:r(r()r4r)ro"srocs<eZdZdZ�fdd�Z�fdd�Zeedd���Z�Z	S)�CreateOperationzImplements the create command.cstt|�jdd�dS)NT)r[)r/rpr0)r2)r4r(r)r0<szCreateOperation.__init__cs8tt|�j|�|js"ttd���|js4ttd���dS)Nz"Missing required argument '--name'z$Missing required argument '--device')r/rpr^rCrr�device)r2r&)r4r(r)r^@s
zCreateOperation.preflightcCsjtj|j�}t|�j�}|d}|d=t|j|f|�}tj�}|j	|j
�|j|j�|j
�|j�dS)NrC)r	rHr!�vars�copyrrCr�transactionZcreate�forceZaddUndoStage�removerJ�
announceReady)r2r&rD�argsDictrCrLrtr(r(r)rTJszCreateOperation.execute)
r6r7r8r9r0r^r,rrTr:r(r()r4r)rp6s

rpcs4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)�DeactivateOperationz"Implements the deactivate command.cstt|�j�dS)N)r/ryr0)r2)r4r(r)r0dszDeactivateOperation.__init__cCs|j||jdd�dS)NF)rF)rN�_deactivate)r2r&r(r(r)rThszDeactivateOperation.executecCs|j�dS)N)Z
deactivate)r2r&rLr(r(r)rzoszDeactivateOperation._deactivate)	r6r7r8r9r0r,rTrzr:r(r()r4r)ry^srycs,eZdZdZ�fdd�Zedd��Z�ZS)�GrowLogicalOperationz#Implements the growLogical command.cstt|�j�dS)N)r/r{r0)r2)r4r(r)r0yszGrowLogicalOperation.__init__cCs:tj|j�}|j|�|j|j�}|j|j�|j�dS)N)	r	rHr!r@rBrCZgrowLogicalZvdoLogicalSizerJ)r2r&rDrLr(r(r)rT}s

zGrowLogicalOperation.execute)r6r7r8r9r0r,rTr:r(r()r4r)r{ssr{cs,eZdZdZ�fdd�Zedd��Z�ZS)�GrowPhysicalOperationz$Implements the growPhysical command.cstt|�j�dS)N)r/r|r0)r2)r4r(r)r0�szGrowPhysicalOperation.__init__cCs6tj|j�}|j|�|j|j�}|j�|j�dS)N)r	rHr!r@rBrCZgrowPhysicalrJ)r2r&rDrLr(r(r)rT�s

zGrowPhysicalOperation.execute)r6r7r8r9r0r,rTr:r(r()r4r)r|�sr|cs<eZdZdZ�fdd�Z�fdd�Zeedd���Z�Z	S)�ImportOperationzImplements the import command.cstt|�jdd�dS)NT)r[)r/r}r0)r2)r4r(r)r0�szImportOperation.__init__cs8tt|�j|�|js"ttd���|js4ttd���dS)Nz"Missing required argument '--name'z$Missing required argument '--device')r/r}r^rCrrrq)r2r&)r4r(r)r^�s
zImportOperation.preflightcCsJtj|j�}t|�j�}|d}|d=t|j|f|�}|j�|j�dS)NrC)	r	rHr!rrrsrrCZimportDevicerw)r2r&rDrxrCrLr(r(r)rT�szImportOperation.execute)
r6r7r8r9r0r^r,rrTr:r(r()r4r)r}�s

r}cs(eZdZdZ�fdd�Zdd�Z�ZS)�
ListOperationzImplements the list command.cstt|�j�dS)N)r/r~r0)r2)r4r(r)r0�szListOperation.__init__c	Cs�t�}dddddg}x^t|dd�j�D]J}|jdd	�jd
�\}}}|jd�dd
kr&|jtjj	|jd�d��q&W|j
r�t|j�}|t|j
�j��O}t|�}|j�ttjj|��dS)NZlsblkz--pairsz--pathsz--outputz	type,nameT)�noThrow�"ra� �=rrL)�setr�
splitlinesr#�	partition�split�addrr�basenamer<r	r!r>�keys�list�sort�print�linesepr$)	r2r&�vdos�cmd�lineZblktypeZfoorCrDr(r(r)rT�s 
zListOperation.execute)r6r7r8r9r0rTr:r(r()r4r)r~�sr~cs@eZdZdZ�fdd�Zedd��Z�fdd�Zdd	�Z�Z	S)
�ModifyOperationzImplements the modify command.cstt|�j�dS)N)r/r�r0)r2)r4r(r)r0�szModifyOperation.__init__cCs|j||jdd�dS)NF)rF)rN�
_modifyVDO)r2r&r(r(r)rT�szModifyOperation.executecstt|�j|�tj|�dS)N)r/r�r^rZvalidateModifiableOptions)r2r&)r4r(r)r^�szModifyOperation.preflightcCs|j|�dS)N)ZsetModifiableOptions)r2r&rLr(r(r)r��szModifyOperation._modifyVDO)
r6r7r8r9r0r,rTr^r�r:r(r()r4r)r��s
	r�cs,eZdZdZ�fdd�Zedd��Z�ZS)�PrintConfigFileOperationz'Implements the printConfigFile command.cstt|�jddd�dS)NFT)rYr\)r/r�r0)r2)r4r(r)r0�sz!PrintConfigFileOperation.__init__cCst|jdd�}t|j��dS)NT)Z	mustExist)r	r!r�Z
asYAMLForUser)r2r&rDr(r(r)rTsz PrintConfigFileOperation.execute)r6r7r8r9r0r-rTr:r(r()r4r)r��sr�cs4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)�RemoveOperationzImplements the remove command.cstt|�j�dS)N)r/r�r0)r2)r4r(r)r0szRemoveOperation.__init__cCs|j||jdd�dS)zImplements the remove command.F)rFN)rN�
_removeVDO)r2r&r(r(r)rTszRemoveOperation.executecCshg}y|j|j|d�WnJtk
rbttd��ttd��ttd��ttjj|���YnXdS)N)�removeStepszA previous operation failed.z;Recovery from the failure either failed or was interrupted.z;Add '--force' to 'remove' to perform the following cleanup.)rvrurr�rrr�r$)r2r&rLr�r(r(r)r�szRemoveOperation._removeVDO)	r6r7r8r9r0r,rTr�r:r(r()r4r)r�sr�cs8eZdZdZ�fdd�Zedd��Zedd��Z�Z	S)�StartOperationzImplements the start command.cstt|�jdd�dS)NT)r[)r/r�r0)r2)r4r(r)r0/szStartOperation.__init__cCs|j||jdd�dS)NF)rF)rN�	_startVDO)r2r&r(r(r)rT3szStartOperation.executecCs@|js&td�j|j�d�}t|td��|j|j�|jd�dS)NzVDO volume {name} not activated)rC)rUF)	Z	activatedrrQ�getNamer.r�startZforceRebuildrw)r2r&rLr3r(r(r)r�:s
zStartOperation._startVDO)
r6r7r8r9r0r,rTrr�r:r(r()r4r)r�)sr�cs,eZdZdZ�fdd�Zedd��Z�ZS)�StatusOperationzImplements the status command.cstt|�jdddd�dS)NFT)rYr[r\)r/r�r0)r2)r4r(r)r0IszStatusOperation.__init__cCs�t|jdd�}|jsd|_�y|i}td�|i}tddgddd�|td�<td	d
gddd�|td�<tj�dkr~td�|td�<td�t�j	�i}td�|j	�i}i}td�|i}xb|j
||�D]R}	y|	j	|j�||	j�<Wq�t
k
�r}
zt|
�||	j�<WYdd}
~
Xq�Xq�Wttj|dd�dd��ttj|dd�dd��ttj|dd�dd��ttj|dtd�d�dd��tjj�tjj�Wn6tk
�r�}
z|jjdj|
��WYdd}
~
XnXdS)NF)rFTz
VDO status�unamez-n)rrhZNodeZdatez--rfc-3339=secondsZDaterzNot running as root,z some status may be unavailableZNotez
Kernel moduler	ZVDOs)�default_flow_styler�inf)r��widthzexception ignored: {0}z3Not running as root, some status may be unavailable���r�r�r�)r	r!rCr<rrrrZrZstatusrE�pendingr�r�strr��yamlZ	safe_dump�float�sys�stdout�flush�stderr�IOErrorrO�debugrQ)r2r&rDr?Z	vdoStatusZkernelStatusZ
confStatusr�ZperVdoStatusrLrMr(r(r)rTOs<&

zStatusOperation.execute)r6r7r8r9r0r,rTr:r(r()r4r)r�Csr�cs4eZdZdZ�fdd�Zedd��Zdd�Z�ZS)�
StopOperationzImplements the stop command.cstt|�j�dS)N)r/r�r0)r2)r4r(r)r0�szStopOperation.__init__cCs|j||jdd�dS)NF)rF)rN�_stopVDO)r2r&r(r(r)rT�szStopOperation.executecCs|j|j�dS)N)�stopru)r2r&rLr(r(r)r��szStopOperation._stopVDO)	r6r7r8r9r0r,rTr�r:r(r()r4r)r�~sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�VersionOperationzImplements the version command.cstt|�jdddd�dS)NFT)rYr[r\)r/r�r0)r2)r4r(r)r0�szVersionOperation.__init__cCs2tddgdd�}tjd|�}tddj|��dS)NrXz	--versionT)rz\d+z
VDO version: �.)rrb�findallr�r$)r2rS�output�versionr(r(r)rT�szVersionOperation.execute)r6r7r8r9r0rTr:r(r()r4r)r��sr�cs6eZdZdZd	�fdd�	Zedd��Zdd�Z�ZS)
�OptionTogglezCBase class for operations which either enable or disable an option.Fcs"tt|�j|d�||_||_dS)N)r[)r/r�r0Z_enableZ_optionName)r2�enableZ
optionNamer[)r4r(r)r0�szOptionToggle.__init__cCs|j||jdd�dS)NF)rF)rN�
_configure)r2r&r(r(r)rT�szOptionToggle.executecCs |jjtd�j|j��t�dS)zlActually update the configuration for this operation. This method must
    be overridden by derived classes.z{0} unimplementedN)rOrPrrQrCrR)r2r&rLr(r(r)r��szOptionToggle._configure)F)	r6r7r8r9r0r,rTr�r:r(r()r4r)r��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�DisableCompressionOperationz*Implements the disableCompression command.cstt|�jdd�dS)NF�compression)r/r�r0)r2)r4r(r)r0�sz$DisableCompressionOperation.__init__cCs|jd�dS)NF)�setCompression)r2r&rLr(r(r)r��sz&DisableCompressionOperation._configure)r6r7r8r9r0r�r:r(r()r4r)r��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�DisableDeduplicationOperationz-Implements the disable deduplication command.cstt|�jdd�dS)NF�
deduplication)r/r�r0)r2)r4r(r)r0�sz&DisableDeduplicationOperation.__init__cCs|jd�dS)NF)�setDeduplication)r2r&rLr(r(r)r��sz(DisableDeduplicationOperation._configure)r6r7r8r9r0r�r:r(r()r4r)r��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�EnableCompressionOperationz)Implements the enableCompression command.cstt|�jdd�dS)NTr�)r/r�r0)r2)r4r(r)r0�sz#EnableCompressionOperation.__init__cCs|jd�dS)NT)r�)r2r&rLr(r(r)r��sz%EnableCompressionOperation._configure)r6r7r8r9r0r�r:r(r()r4r)r��sr�cs(eZdZdZ�fdd�Zdd�Z�ZS)�EnableDeduplicationOperationz+Implements the enableDeduplication command.cstt|�jdddd�dS)NTr�)r[)r/r�r0)r2)r4r(r)r0�sz%EnableDeduplicationOperation.__init__cCs|jd�dS)NT)r�)r2r&rLr(r(r)r��sz'EnableDeduplicationOperation._configure)r6r7r8r9r0r�r:r(r()r4r)r��sr�z^[A-Z].*Operation$cCs tj|�o|jdkotj|j�S)Nr;)�inspectZisclassr6�operationRE�match)�memberr(r(r)�_isOperation�sr�cCs*x$tjtj|t�D]}|d�qWdS)Nr)r�Z
getmembersr��modulesr�)Z
moduleNameZ	operationr(r(r)�makeOperationssr�)Ir9Z
__future__rrrrrarrr	r
rrr
rrrrrrrrZ	vdo.utilsrrrrr�	functoolsrr�rf�__main__�mainrrbr�r��dictrgr*r,r-rIr.�objectr;rirkrorpryr{r|r}r~r�r�r�r�r�r�r�r�r�r�r�r��compiler�r�r�r6r(r(r(r)�<module>sp
($;


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