Mini Shell

Direktori : /lib/python3.6/site-packages/blivet/devices/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/blivet/devices/__pycache__/device.cpython-36.opt-1.pyc

3

{)c
0�@stddlZddlmZddlmZddlmZddlmZddl	Z	e	j
d�Zdd	lm
Z
ee�Gd
d�dej��ZdS)�N)�
add_metaclass�)�util)�log_method_call)�SynchronizedMetaZblivet�)�
ParentListc@s�eZdZdZdZgZgZdTdd�Zdd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zedd��Zejdd��Zedd��Zedd��Zdd�Zdd �ZdUd"d#�ZdVd$d%�Zd&d'�Zd(d)�ZdWd*d+�ZdXd,d-�Zd.d/�Zd0d1�Zed2d3��Zd4d5�Z d6d7�Z!ed8d9�d:d9�d;d<�Z"ed=d>��Z#ed?d@��Z$edAdB��Z%edCdD��Z&edEdF��Z'edGdH��Z(e(jdIdH��Z(dJdK�Z)e*dLdM��Z+e*dNdO��Z,edPdQ��Z-edRdS��Z.dS)Y�Devicea A generic device.

        Device instances know which devices they depend upon (parents
        attribute). They do not know which devices depend upon them, but
        they do know whether or not they have any dependent devices
        (isleaf attribute).

        A Device's setup method should set up all parent devices as well
        as the device itself. It should not run the resident format's
        setup method.

            Which Device types rely on their parents' formats being active?
                DMCryptDevice

        A Device's teardown method should accept the keyword argument
        recursive, which takes a boolean value and indicates whether or
        not to recursively close parent devices.

        A Device's create method should create all parent devices as well
        as the device itself. It should also run the Device's setup method
        after creating the device. The create method should not create a
        device's resident format.

            Which device type rely on their parents' formats to be created
            before they can be created/assembled?
                VolumeGroup
                DMCryptDevice

        A Device's destroy method should destroy any resident format
        before destroying the device itself.

    ZdeviceNcCsJtjj|�||_|dk	r.t|t�r.td��t�|_|p<g|_	g|_
dS)z�
            :param name: the device name (generally a device node's basename)
            :type name: str
            :keyword parents: a list of parent devices
            :type parents: list of :class:`Device` instances
        Nz*parents must be a list of Device instances)r�ObjectID�__init__�_name�
isinstance�list�
ValueError�set�_tags�parents�	_children)�self�namer�r�/usr/lib/python3.6/device.pyrLs
zDevice.__init__cCstj||ddd�S)z� Create a deep copy of a Device instance.

            We can't do copy.deepcopy on parted objects, which is okay.
            For these parted objects, we just do a shallow copy.
        �node�_parted_partition)ZomitZshallow)r)r)rZ
variable_copy)r�memorrr�__deepcopy__\szDevice.__deepcopy__c
CsRd|jjdt|�|j|j|jtjdd�|jD��tjdd�|jD��d�}|S)Nz�%(type)s instance (%(id)s) --
  name = %(name)s  status = %(status)s  id = %(dev_id)s
  children = %(children)s
  parents = %(parents)s
z%#xcSsg|]}t|��qSr)�str)�.0�crrr�
<listcomp>osz#Device.__repr__.<locals>.<listcomp>cSsg|]}t|��qSr)r)r�prrrrps)�type�idr�statusZdev_id�childrenr)	�	__class__�__name__r"rr#�pprintZpformatr$r)r�srrr�__repr__fszDevice.__repr__cCsd|j|j|jf}|S)Nz
%s %s (%d))r!rr")rr(rrr�
_to_stringtszDevice._to_stringcCstj|j��S)N)rZ	stringizer*)rrrr�__str__xszDevice.__str__cCstj|j��S)N)rZ
unicodeizer*)rrrr�__unicode__{szDevice.__unicode__cCs|j|�dS)zi Called before adding a parent to this device.

            See :attr:`~.ParentList.appendfunc`.
        N)�	add_child)r�parentrrr�_add_parent~szDevice._add_parentcCs|j|�dS)zm Called before removing a parent from this device.

            See :attr:`~.ParentList.removefunc`.
        N)�remove_child)rr.rrr�_remove_parent�szDevice._remove_parentcCs@t|d�st|j|jd�|_xt|j�D]}|jj|�q(WdS)z) Initialize this instance's parent list. �_parents)Z
appendfuncZ
removefuncN)�hasattrrr/r1r2r�remove)rr.rrr�_init_parent_list�s

zDevice._init_parent_listcCs|jS)z) Devices upon which this device is built )r2)rrrrr�szDevice.parentscCs&|j�x|D]}|jj|�qWdS)z" Set this instance's parent list. N)r5r2�append)rrr.rrrr�s
cCst|jdd�tjd�S)z,List of this device's immediate descendants.N)�key)�sortedrrZnatural_sort_key)rrrrr$�szDevice.childrencCs |j|jdd�|jD�d�}|S)NcSsg|]
}|j�qSr)r)rr rrrr�szDevice.dict.<locals>.<listcomp>)r!rr)r!rr)r�drrr�dict�szDevice.dictcCs*t||j|jt|j�d�|jj|�dS)z. Decrement the child counter for this device. )r�child�kidsN)rrr�lenr$rr4)rr;rrrr0�szDevice.remove_childcCs<t||j|jt|j�d�||jkr,td��|jj|�dS)z. Increment the child counter for this device. )rr;r<zchild is already accounted forN)rrrr=r$rrr6)rr;rrrr-�s
zDevice.add_childFcCstd��dS)z Open, or set up, a device. z#setup method not defined for DeviceN)�NotImplementedError)r�origrrr�setup�szDevice.setupcCstd��dS)z  Close, or tear down, a device. z&teardown method not defined for DeviceN)r>)r�	recursiverrr�teardown�szDevice.teardowncCstd��dS)z Create the device. z$create method not defined for DeviceN)r>)rrrr�create�sz
Device.createcCstd��dS)z Destroy the device. z%destroy method not defined for DeviceN)r>)rrrr�destroy�szDevice.destroycCs0t||j|d�x|jD]}|j|d�qWdS)z� Run setup method of all parent devices.

            :keyword orig: set up original format instead of current format
            :type orig: bool
        )rr?)r?N)rrrr@)rr?r.rrr�
setup_parents�szDevice.setup_parentscCs x|jD]}|j|d�qWdS)z� Run teardown method of all parent devices.

            :keyword recursive: tear down all ancestor devices recursively
            :type recursive: bool
        )rAN)rrB)rrAr.rrr�teardown_parents�szDevice.teardown_parentscCs0||jkrdSx|jD]}|j|�rdSqWdS)a� Return True if this device depends on dep.

            This device depends on another device if the other device is an
            ancestor of this device. For example, a PartitionDevice depends on
            the DiskDevice on which it resides.

            :param dep: the other device
            :type dep: :class:`Device`
            :returns: whether this device depends on 'dep'
            :rtype: bool
        TF)r�
depends_on)rZdepr.rrrrG�s

zDevice.depends_oncCst�S)N)r)rrrr�dracut_setup_args�szDevice.dracut_setup_argscCsdS)z4 Is this device currently active and ready for use? Fr)rrrrr#�sz
Device.statuscCs|jS)N)r)rrrr�	_get_name�szDevice._get_namecCs |j|�std|��||_dS)Nz&%s is not a valid name for this device)�
is_name_validrr)r�valuerrr�	_set_names
zDevice._set_namecCs|j�S)N)rI)r(rrr�<lambda>szDevice.<lambda>cCs
|j|�S)N)rL)r(�vrrrrMszThis device's name)�doccCst|j�S)z. True if no other device depends on this one. )�boolr$)rrrr�isleaf	sz
Device.isleafcCs|jS)z$ String describing the device type. )�_type)rrrr�type_descriptionszDevice.type_descriptioncCs|jS)z Device type. )rR)rrrrr!szDevice.typecs@t|g��x,�fdd�|jD�D]}�jt|j��q Wt��S)z= A list of all of this device's ancestors, including itself. csg|]}|�kr|�qSrr)rr9)�	ancestorsrrrsz$Device.ancestors.<locals>.<listcomp>)rr�updaterTr)rr r)rTrrTs
zDevice.ancestorscs4|j�x(|jD]}�j�fdd�|jD��qW�S)z� List of packages required to manage this device and all its
            ancestor devices. Does not contain duplicates.

            :returns: names of packages required by device and all ancestors
            :rtype: list of str
        c3s|]}|�kr|VqdS)Nr)rr )�packagesrr�	<genexpr>*sz"Device.packages.<locals>.<genexpr>)�	_packagesr�extendrV)rr.r)rVrrV szDevice.packagescCs|jS)z+ set of (str) tags describing this device. )r)rrrr�tags.szDevice.tagscCst|�|_dS)N)rr)rZnewtagsrrrrZ3scCsdS)z-Is the device name valid for the device type?Tr)rrrrrrJ7szDevice.is_name_validcCstdd�|jD��S)a1 A list of external dependencies of this device type.

            :returns: a set of external dependencies
            :rtype: set of availability.ExternalResource

            The external dependencies include the dependencies of this
            device type and of all superclass device types.
        css(|] }t|t�r|jD]
}|VqqdS)N)�
issubclassr	�_external_dependencies)rr r9rrrrWKsz4Device.type_external_dependencies.<locals>.<genexpr>)r�__mro__)�clsrrr�type_external_dependencies@s
z!Device.type_external_dependenciescCstdd�|j�D��S)z� A set of unavailable dependencies for this type.

            :return: the unavailable external dependencies for this type
            :rtype: set of availability.ExternalResource
        css|]}|js|VqdS)N)�	available)r�errrrWUsz7Device.unavailable_type_dependencies.<locals>.<genexpr>)rr_)r^rrr�unavailable_type_dependenciesNsz$Device.unavailable_type_dependenciescCstdd�|jD��S)z� A list of external dependencies of this device and its parents.

            :returns: the external dependencies of this device and all parents.
            :rtype: set of availability.ExternalResource
        css |]}|j�D]
}|VqqdS)N)r_)rr r9rrrrW^sz/Device.external_dependencies.<locals>.<genexpr>)rrT)rrrr�external_dependenciesWszDevice.external_dependenciescCstdd�|jD��S)z� Any unavailable external dependencies of this device or its
            parents.

            :returns: A list of unavailable external dependencies.
            :rtype: set of availability.external_resource
        css|]}|js|VqdS)N)r`)rrarrrrWhsz2Device.unavailable_dependencies.<locals>.<genexpr>)rrc)rrrr�unavailable_dependencies`szDevice.unavailable_dependencies)N)F)N)F)N)/r&�
__module__�__qualname__�__doc__rRrXr\rrr)r*r+r,r/r1r5�propertyr�setterr$r:r0r-r@rBrCrDrErFrGrHr#rIrLrrQrSr!rTrVrZrJ�classmethodr_rbrcrdrrrrr	$sZ"






				r	)r'Zsixr�rZstorage_logrZthreadsrZloggingZ	getLogger�log�librr
r	rrrr�<module>s