Mini Shell
3
�Mf,� � @ s d dl Z d dlZd dlZd dlZejdd� d dlmZ ddlm Z ddlm
Z
ddlmZ dd lmZ dd
l
mZ ddlmZ ddlmZmZ dd
lmZmZmZ d dlZejd�ZddlmZ ddlmZ ddlmZ ddl m!Z!m"Z"m#Z# ed�Z$ed�Z%G dd� de�Z&dS )� N�BlockDevz2.0)r � )�errors)�util)�arch)�flags)�log_method_call)�udev)�DeviceFormat�
get_format)�Size�MiB�
ROUND_DOWNZblivet� )�Device)�
StorageDevice)�DMDevice)�device_path_to_name�device_name_to_disk_by_path�LINUX_SECTOR_SIZEZ500MiBZ256MiBc s� e Zd ZdZdZdZeZd{dd�Zd d
� Z e
� fdd��Zd
d� Z� fdd�Z
e
dd� �Ze
dd� �Ze
dd� �Ze
dd� �Ze
dd� �Ze
dd� �Ze
dd� �Zdd � Zd!d"� Ze
d#d$� d%d$� �Zd|d&d'�Zd(d)� Zd*d+� Ze
d,d$� d-d$� �Zd.d/� Zd0d1� Zd2d3� Ze
� fd4d5��Ze
d6d7� �Z d8d9� Z!d:d;� Z"e
e"e!�Z#d<d=� Z$d>d?� Z%d@dA� Z&dBdC� Z'e
dDdE� �Z(d}� fdFdG� Z)d~� fdHdI� Z*dJdK� Z+dLdM� Z,dNdO� Z-dPdQ� Z.ddRdS�Z/dTdU� Z0e
� fdVdW��Z1e1j2dXdW� �Z1e
� fdYdZ��Z3d[d\� Z4d]d^� Z5d_d`� Z6� fdadb�Z7dcdd� Z8� fdedf�Z9dgdh� Z:didj� Z;e
dkd$� dld$� �Z<e
dmdn� �Z=� fdodp�Z>e
� fdqdr��Z?e
dsdt� �Z@e
� fdudv��ZAdwdx� ZB� fdydz�ZC� ZDS )��PartitionDeviceaJ A disk partition.
On types and flags...
We don't need to deal with numerical partition types at all. The
only type we are concerned with is primary/logical/extended. Usage
specification is accomplished through the use of flags, which we
will set according to the partition's format.
� partitionTNF� c C s^ g | _ g | _d| _d| _d| _d| _td�| _td�| _td�| _ d| _
d| _d| _d| _
d| _d| _d| _d| _| r�|dkr�|dk r�|dk r�td�}n| j}tj| ||||| |
|||
d�
|s�t| j�| _ g | _d| _| jo�| jjo�| jjj �rtjd| j� d| _�n4| j�r�t j! �r�| jj�sDd| _t"j#d| jjj$ ��tj%d| j&� | jjj'j(| j&�| _| j�s�g | _t"j#d | j ��| j&| _| j)� | j*t+j,��r�t-d
| j&dd�| _n | j*t+j.��rBt-d| j&dd�| _nj|dk �r�t|�nt� | _|| _
|| _|| _tt/j0|��| _ || _|| _| j1| _| j1| _|| _
|| _|| _| j�rZ| j2�rZ| j3� dS )
a
:param name: the device name (generally a device node's basename)
:type name: str
:keyword exists: does this device exist?
:type exists: bool
:keyword size: the device's size
:type size: :class::class:`~.size.Size`
:keyword parents: a list of parent devices
:type parents: list of :class:`StorageDevice`
:keyword fmt: this device's formatting
:type fmt: :class:`~.formats.DeviceFormat` or a subclass of it
For existing partitions only:
:keyword str uuid: partition UUID (not filesystem UUID)
:keyword major: the device major
:type major: long
:keyword minor: the device minor
:type minor: long
:keyword sysfs_path: sysfs device path
:type sysfs_path: str
For non-existent partitions only:
:keyword part_type: parted type constant, eg:
:const:`parted.PARTITION_NORMAL`
:type part_type: parted partition type constant
:keyword grow: whether or not to grow the partition
:type grow: bool
:keyword maxsize: max size for growable partitions
:type maxsize: :class:`~.size.Size`
:keyword start: start sector (see note, below)
:type start: long
:keyword end: end sector (see note, below)
:type end: long
:keyword bootable: whether the partition is bootable
:type bootable: bool
:keyword weight: an initial sorting weight to assign
:type weight: int or NoneType
:keyword disk_tags: (str) tags defining candidate disk set
:type disk_tags: iterable
.. note::
If a start sector is specified the partition will not be
adjusted for optimal alignment. That is up to the caller.
.. note::
You can only pass one of parents or disk_tags when instantiating
a non-existent partition. If both disk set and disk tags are
specified, the explicit disk set will be used.
.. note::
Multiple disk tags will be combined using the logical "or" operation.
Nr F)�fmt�uuid�size�major�minor�exists�
sysfs_path�parentsTz%partition %s disklabel is unsupportedzdisk has wrong format '%s'zlooking up parted Partition: %sz,cannot find parted partition instance for %s�prepboot)�devicer �biosboot)4� req_disksZ
req_disk_tags�
req_part_type�req_primary�req_grow�req_bootabler �req_size�
req_base_size�req_max_size�req_base_weight�req_start_sector�req_end_sector�req_name� _bootable�
_part_type�_parted_partitionZ
_orig_path�default_sizer �__init__�listr �disklabel_supportedr �diskZpartitioned�formatZ supported�log�info�namer Ztestingr �DeviceError�type�debug�path�parted_disk�getPartitionByPath�probe�get_flag�partedZPARTITION_PREPr ZPARTITION_BIOS_GRUBr Znumeric_type�_size�status�update_size)�selfr; r r r �grow�maxsize�start�endr r �bootabler r r � part_type�primary�weightZ disk_tags� rQ �/usr/lib/python3.6/partition.pyr4 E sx ?
zPartitionDevice.__init__c C st t j| �}|d| j| j| j| j| j| j| j| j | j
d� 7 }| j rp|d| j jj| j jj
| j jj| j j� d� 7 }|S )Nz� grow = %(grow)s max size = %(maxsize)s bootable = %(bootable)s
part type = %(part_type)s primary = %(primary)s start sector = %(start)s end sector = %(end)s
parted_partition = %(parted_part)s
disk = %(disk)s
) rI rJ rM rN rO rK rL Zparted_partr7 zK start = %(start)s end = %(end)s length = %(length)s
flags = %(flags)s)�lengthrK rL r )r �__repr__r'