# Path: src/imgbased/utils.py
# class ExternalBinary(object):
#     dry = False
#     squash_output = False
# 
#     def call(self, *args, **kwargs):
#         stdout = bytes()
#         if not self.dry:
#             stdout = command.call(*args, **kwargs)
#             if stdout and not self.squash_output:
#                 log.debug("Returned: %s" % stdout[0:1024])
#         return stdout.decode(errors="replace").strip()
# 
#     def lvs(self, args, **kwargs):
#         return self.call(["lvs"] + args, **kwargs)
# 
#     def vgs(self, args, **kwargs):
#         return self.call(["vgs"] + args, **kwargs)
# 
#     def lvcreate(self, args, **kwargs):
#         return self.call(["lvcreate"] + args, **kwargs)
# 
#     def lvremove(self, args, **kwargs):
#         return self.call(["lvremove"] + args, **kwargs)
# 
#     def lvrename(self, args, **kwargs):
#         return self.call(["lvrename"] + args, **kwargs)
# 
#     def lvextend(self, args, **kwargs):
#         return self.call(["lvextend"] + args, **kwargs)
# 
#     def vgcreate(self, args, **kwargs):
#         return self.call(["vgcreate"] + args, **kwargs)
# 
#     def lvchange(self, args, **kwargs):
#         return self.call(["lvchange"] + args, **kwargs)
# 
#     def vgchange(self, args, **kwargs):
#         return self.call(["vgchange"] + args, **kwargs)
# 
#     def find(self, args, **kwargs):
#         return self.call(["find"] + args, **kwargs)
# 
#     def findmnt(self, args, **kwargs):
#         return self.call(["findmnt"] + args, **kwargs)
# 
#     def du(self, args, **kwargs):
#         return self.call(["du"] + args, **kwargs)
# 
#     def rm(self, args, **kwargs):
#         return self.call(["rm"] + args, **kwargs)
# 
#     def cp(self, args, **kwargs):
#         return self.call(["cp"] + args, **kwargs)
# 
#     def rpm(self, args, **kwargs):
#         self.squash_output = True
#         return self.call(["rpm"] + args, **kwargs)
# 
#     def grubby(self, args, **kwargs):
#         return self.call(["grubby"] + args, **kwargs)
# 
#     def grub2_mkconfig(self, args, **kwargs):
#         return self.call(["grub2-mkconfig"] + args, **kwargs)
# 
#     def grub2_editenv(self, args, **kwargs):
#         return self.call(["grub2-editenv"] + args, **kwargs)
# 
#     def systemctl(self, args, **kwargs):
#         return self.call(["systemctl"] + args, **kwargs)
# 
#     def pkill(self, args, **kwargs):
#         return self.call(["pkill"] + args, **kwargs)
# 
#     def umount(self, args, **kwargs):
#         return self.call(["umount", "-l"] + args, **kwargs)
# 
#     def semanage(self, args, **kwargs):
#         return self.call(["semanage"] + args, **kwargs)
# 
#     def runcon(self, args, **kwargs):
#         return self.call(["runcon"] + args, **kwargs)
# 
#     def lvmconfig(self, args, **kwargs):
#         return self.call(["lvmconfig"] + args, **kwargs)
# 
#     def mount(self, args, **kwargs):
#         return self.call(["mount"] + args, **kwargs)
# 
#     def getenforce(self):
#         return self.call(["getenforce"])
# 
#     def mknod(self, args, **kwargs):
#         return self.call(["mknod"] + args, **kwargs)
# 
#     def ldconfig(self, args, **kwargs):
#         return self.call(["ldconfig"] + args, **kwargs)
# 
#     def sync(self, args, **kwargs):
#         return self.call(["sync"] + args, **kwargs)
# 
# class LvmCLI():
#     lvs = LvmBinary().lvs
#     vgs = LvmBinary().vgs
#     lvcreate = ExternalBinary().lvcreate
#     lvchange = LvmBinary().lvchange
#     lvremove = LvmBinary().lvremove
#     lvrename = LvmBinary().lvrename
#     lvextend = LvmBinary().lvextend
#     vgcreate = LvmBinary().vgcreate
#     vgchange = LvmBinary().vgchange
#     lvmconfig = LvmBinary().lvmconfig
# 
# def find_mount_source(path, raise_on_error=False):
#     mnt_source = findmnt(["SOURCE"], path=path, raise_on_error=raise_on_error)
#     if mnt_source is not None:
#         return mnt_source.strip()
#     return None


import logging
import os
import re
import shlex
from operator import itemgetter
from .utils import ExternalBinary, LvmCLI, find_mount_source
# 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, see <http://www.gnu.org/licenses/>.
#
# Author(s): Fabian Deutsch <fabiand@redhat.com>
#


log = logging.getLogger(__package__)


class MissingLvmThinPool(Exception):
    pass


class ThinPoolMetadataError(Exception):
    pass


class LVM(object):
    _lvs = LvmCLI.lvs
    _vgs = LvmCLI.vgs
    _lvcreate = LvmCLI.lvcreate
    _lvchange = LvmCLI.lvchange
    _lvremove = LvmCLI.lvremove
    _lvrename = LvmCLI.lvrename
    _lvextend = LvmCLI.lvextend
    _vgcreate = LvmCLI.vgcreate
    _vgchange = LvmCLI.vgchange

# Path: src/imgbased/utils.py
# class ExternalBinary(object):
#     dry = False
#     squash_output = False
# 
#     def call(self, *args, **kwargs):
#         stdout = bytes()
#         if not self.dry:
#             stdout = command.call(*args, **kwargs)
#             if stdout and not self.squash_output:
#                 log.debug("Returned: %s" % stdout[0:1024])
#         return stdout.decode(errors="replace").strip()
# 
#     def lvs(self, args, **kwargs):
#         return self.call(["lvs"] + args, **kwargs)
# 
#     def vgs(self, args, **kwargs):
#         return self.call(["vgs"] + args, **kwargs)
# 
#     def lvcreate(self, args, **kwargs):
#         return self.call(["lvcreate"] + args, **kwargs)
# 
#     def lvremove(self, args, **kwargs):
#         return self.call(["lvremove"] + args, **kwargs)
# 
#     def lvrename(self, args, **kwargs):
#         return self.call(["lvrename"] + args, **kwargs)
# 
#     def lvextend(self, args, **kwargs):
#         return self.call(["lvextend"] + args, **kwargs)
# 
#     def vgcreate(self, args, **kwargs):
#         return self.call(["vgcreate"] + args, **kwargs)
# 
#     def lvchange(self, args, **kwargs):
#         return self.call(["lvchange"] + args, **kwargs)
# 
#     def vgchange(self, args, **kwargs):
#         return self.call(["vgchange"] + args, **kwargs)
# 
#     def find(self, args, **kwargs):
#         return self.call(["find"] + args, **kwargs)
# 
#     def findmnt(self, args, **kwargs):
#         return self.call(["findmnt"] + args, **kwargs)
# 
#     def du(self, args, **kwargs):
#         return self.call(["du"] + args, **kwargs)
# 
#     def rm(self, args, **kwargs):
#         return self.call(["rm"] + args, **kwargs)
# 
#     def cp(self, args, **kwargs):
#         return self.call(["cp"] + args, **kwargs)
# 
#     def rpm(self, args, **kwargs):
#         self.squash_output = True
#         return self.call(["rpm"] + args, **kwargs)
# 
#     def grubby(self, args, **kwargs):
#         return self.call(["grubby"] + args, **kwargs)
# 
#     def grub2_mkconfig(self, args, **kwargs):
#         return self.call(["grub2-mkconfig"] + args, **kwargs)
# 
#     def grub2_editenv(self, args, **kwargs):
#         return self.call(["grub2-editenv"] + args, **kwargs)
# 
#     def systemctl(self, args, **kwargs):
#         return self.call(["systemctl"] + args, **kwargs)
# 
#     def pkill(self, args, **kwargs):
#         return self.call(["pkill"] + args, **kwargs)
# 
#     def umount(self, args, **kwargs):
#         return self.call(["umount", "-l"] + args, **kwargs)
# 
#     def semanage(self, args, **kwargs):
#         return self.call(["semanage"] + args, **kwargs)
# 
#     def runcon(self, args, **kwargs):
#         return self.call(["runcon"] + args, **kwargs)
# 
#     def lvmconfig(self, args, **kwargs):
#         return self.call(["lvmconfig"] + args, **kwargs)
# 
#     def mount(self, args, **kwargs):
#         return self.call(["mount"] + args, **kwargs)
# 
#     def getenforce(self):
#         return self.call(["getenforce"])
# 
#     def mknod(self, args, **kwargs):
#         return self.call(["mknod"] + args, **kwargs)
# 
#     def ldconfig(self, args, **kwargs):
#         return self.call(["ldconfig"] + args, **kwargs)
# 
#     def sync(self, args, **kwargs):
#         return self.call(["sync"] + args, **kwargs)
# 
# class LvmCLI():
#     lvs = LvmBinary().lvs
#     vgs = LvmBinary().vgs
#     lvcreate = ExternalBinary().lvcreate
#     lvchange = LvmBinary().lvchange
#     lvremove = LvmBinary().lvremove
#     lvrename = LvmBinary().lvrename
#     lvextend = LvmBinary().lvextend
#     vgcreate = LvmBinary().vgcreate
#     vgchange = LvmBinary().vgchange
#     lvmconfig = LvmBinary().lvmconfig
# 
# def find_mount_source(path, raise_on_error=False):
#     mnt_source = findmnt(["SOURCE"], path=path, raise_on_error=raise_on_error)
#     if mnt_source is not None:
#         return mnt_source.strip()
#     return None


# Path: src/imgbased/lvm.py
import logging
import os
import re
import shlex
from operator import itemgetter
from .utils import ExternalBinary, LvmCLI, find_mount_source

# 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, see <http://www.gnu.org/licenses/>.
#
# Author(s): Fabian Deutsch <fabiand@redhat.com>
#


log = logging.getLogger(__package__)


class MissingLvmThinPool(Exception):
    pass


class ThinPoolMetadataError(Exception):
    pass


class LVM(object):
    _lvs = LvmCLI.lvs
    _vgs = LvmCLI.vgs
    _lvcreate = LvmCLI.lvcreate
    _lvchange = LvmCLI.lvchange
    _lvremove = LvmCLI.lvremove
    _lvrename = LvmCLI.lvrename
    _lvextend = LvmCLI.lvextend
    _vgcreate = LvmCLI.vgcreate
    _vgchange = LvmCLI.vgchange

    _lvmconfig = LvmCLI.lvmconfig