# 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
            return False

        return True

    @staticmethod
    def register_volume(vol):
        assert isinstance(vol, LVM.LV)
        LVM._volume_registry.append(vol)
        return vol

    @staticmethod
    def reset_registered_volumes():
        if os.getenv("IMGBASED_KEEP_VOLUMES"):
            return
        run = ExternalBinary()
        run.sync([])
        mtab = dict([itemgetter(9, 4)(m.split())
                     for m in open("/proc/self/mountinfo")])
        for lv in LVM._volume_registry:
            target = mtab.get(lv.dm_path)
            if target:
                run.umount([target])
            try:
                lv.remove(force=True)
            except Exception:
                log.debug("Failed removing LV [%s], skipping", lv.dm_path)

    @staticmethod
    def stop_monitoring():
        LVM._vgchange(["--monitor", "n"])

# 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

            return False

        return True

    @staticmethod
    def register_volume(vol):
        assert isinstance(vol, LVM.LV)
        LVM._volume_registry.append(vol)
        return vol

    @staticmethod
    def reset_registered_volumes():
        if os.getenv("IMGBASED_KEEP_VOLUMES"):
            return
        run = ExternalBinary()
        run.sync([])
        mtab = dict([itemgetter(9, 4)(m.split())
                     for m in open("/proc/self/mountinfo")])
        for lv in LVM._volume_registry:
            target = mtab.get(lv.dm_path)
            if target:
                run.umount([target])
            try:
                lv.remove(force=True)
            except Exception:
                log.debug("Failed removing LV [%s], skipping", lv.dm_path)

    @staticmethod
    def stop_monitoring():
        LVM._vgchange(["--monitor", "n"])

        ExternalBinary().pkill(["dmeventd"])