DRIVER=processor
MODALIAS=cpu:type:x86,ven0002fam0017mod0031:feature:,0000,0001,0002,0003,0004,0005,0006,0007,0008,0009,000B,000C,000D,000E,000F,0010,0011,0013,0017,0018,0019,001A,0020,0021,0022,0023,0024,0025,0026,0027,0028,0029,002B,002C,002D,002E,002F,0030,0031,0034,0036,0037,0038,0039,003A,003B,003D,0064,006E,0070,0072,0074,0075,0079,007A,007F,0080,0081,0089,008C,008D,0093,0094,0095,0096,0097,0098,0099,009A,009B,009C,009D,009E,009F,00C0,00C1,00C4,00C5,00C6,00C7,00C8,00C9,00D7,00EA,00ED,00F0,00F1,00F3,00F5,00F9,00FA,00FB,00FC,010F,0114,0115,0120,0121,0123,0125,0127,0128,0132,0133,0134,0137,0138,013D,0140,0141,0142,0165,016C,016E,016F,0170,017C,01A0,01A2,01A9,01AC,01AE,01AF,01B8,01C2,0202,0216,0220,0221,025A,025B,025D,025F,0282,0286,029C,029D

 +C    # Copyright (C) 2005-2011 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from typing import Union, Optional, Type

from . import (
    counted_lock,
    errors,
    lock,
    transactions,
    urlutils,
    )
from .decorators import (
    only_raises,
    )
from .transport import Transport


class LockableFiles:
    """Object representing a set of related files locked within the same scope.

    This coordinates access to the lock along with providing a transaction.

    LockableFiles manage a lock count and can be locked repeatedly by
    a single caller.  (The underlying lock implementation generally does not
    support this.)

    Instances of this class are often called control_files.

    This class is now deprecated; code should move to using the Transport
    directly for file operations and using the lock or CountedLock for
    locking.

    :ivar _lock: The real underlying lock (e.g. a LockDir)
    :ivar _lock_count: If _lock_mode is true, a positive count of the number
        of times the lock has been taken (and not yet released) *by this
        process*, through this particular object instance.
    :ivar _lock_mode: None, or 'r' or 'w'
    """

    _lock_count: int
    # TODO(jelmer): str -> Literal['r', 'w']
    _lock_mode: Optional[str]
    _token_from_lock: Optional[lock.LockToken]
    _transaction: Optional[transactions.Transaction]

    def __init__(self, transport: Transport, lock_name: str, lock_class: Type[lock.Lock]) -> None:
        """Create a LockableFiles group

        :param transport: Transport pointing to the directory holding the
            control files and lock.
        :param lock_name: Name of the lock guarding these files.
        :param lock_class: Class of lock strategy to use: typically
            either LockDir or TransportLock.
        """
        self._transport = transport
        self.lock_name = lock_name
        self._transaction = None
        self._lock_mode = None
        self._lock_count = 0
        self._find_modes()
        esc_name = self._escape(lock_name)
        self._lock = lock_class(transport, esc_name,
                                file_modebits=self._file_mode,
                                dir_modebits=self._dir_mode)
        self._counted_lock = counted_lock.CountedLock(self._lock)

    def create_lock(self) -> None:
        """Create the lock.

        This should normally be called only when the LockableFiles directory
        is first created on disk.
        """
        self._lock.create(mode=self._dir_mode)

    def __repr__(self):
        return '{}({!r})'.format(self.__class__.__name__,
                           self._transport)

   