def is_installed(self, repoq, pkgspec, qf=None, is_pkg=False):
    if (qf is None):
        qf = '%{epoch}:%{name}-%{version}-%{release}.%{arch}\n'
    if (not repoq):
        pkgs = []
        try:
            my = self.yum_base()
            for rid in self.disablerepo:
                my.repos.disableRepo(rid)
            for rid in self.enablerepo:
                my.repos.enableRepo(rid)
            (e, m, _) = my.rpmdb.matchPackageNames([pkgspec])
            pkgs = (e + m)
            if ((not pkgs) and (not is_pkg)):
                pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
        except Exception as e:
            self.module.fail_json(msg=('Failure talking to yum: %s' % to_native(e)))
        return [self.po_to_envra(p) for p in pkgs]
    else:
        global rpmbin
        if (not rpmbin):
            rpmbin = self.module.get_bin_path('rpm', required=True)
        cmd = [rpmbin, '-q', '--qf', qf, pkgspec]
        if (self.installroot != '/'):
            cmd.extend(['--root', self.installroot])
        lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
        (rc, out, err) = self.module.run_command(cmd, environ_update=lang_env)
        if ((rc != 0) and ('is not installed' not in out)):
            self.module.fail_json(msg=('Error from rpm: %s: %s' % (cmd, err)))
        if ('is not installed' in out):
            out = ''
        pkgs = [p for p in out.replace('(none)', '0').split('\n') if p.strip()]
        if ((not pkgs) and (not is_pkg)):
            cmd = [rpmbin, '-q', '--qf', qf, '--whatprovides', pkgspec]
            if (self.installroot != '/'):
                cmd.extend(['--root', self.installroot])
            (rc2, out2, err2) = self.module.run_command(cmd, environ_update=lang_env)
        else:
            (rc2, out2, err2) = (0, '', '')
        if ((rc2 != 0) and ('no package provides' not in out2)):
            self.module.fail_json(msg=('Error from rpm: %s: %s' % (cmd, (err + err2))))
        if ('no package provides' in out2):
            out2 = ''
        pkgs += [p for p in out2.replace('(none)', '0').split('\n') if p.strip()]
        return pkgs
    return []
def is_installed(self, repoq, pkgspec, qf=None, is_pkg=False):
    if (qf is None):
        qf = '%{epoch}:%{name}-%{version}-%{release}.%{arch}\n'
    if (not repoq):
        pkgs = []
        try:
            my = self.yum_base()
            for rid in self.disablerepo:
                my.repos.disableRepo(rid)
            for rid in self.enablerepo:
                my.repos.enableRepo(rid)
            (e, m, _) = my.rpmdb.matchPackageNames([pkgspec])
            pkgs = (e + m)
            if ((not pkgs) and (not is_pkg)):
                pkgs.extend(my.returnInstalledPackagesByDep(pkgspec))
        except Exception as e:
            self.module.fail_json(msg=('Failure talking to yum: %s' % to_native(e)))
        return [self.po_to_envra(p) for p in pkgs]
    else:
        global rpmbin
        if (not rpmbin):
            rpmbin = self.module.get_bin_path('rpm', required=True)
        cmd = [rpmbin, '-q', '--qf', qf, pkgspec]
        if (self.installroot != '/'):
            cmd.extend(['--root', self.installroot])
        lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
        (rc, out, err) = self.module.run_command(cmd, environ_update=lang_env)
        if ((rc != 0) and ('is not installed' not in out)):
            self.module.fail_json(msg=('Error from rpm: %s: %s' % (cmd, err)))
        if ('is not installed' in out):
            out = 
        pkgs = [p for p in out.replace('(none)', '0').split('\n') if p.strip()]
        if ((not pkgs) and (not is_pkg)):
            cmd = [rpmbin, '-q', '--qf', qf, '--whatprovides', pkgspec]
            if (self.installroot != '/'):
                cmd.extend(['--root', self.installroot])
            (rc2, out2, err2) = self.module.run_command(cmd, environ_update=lang_env)
        else:
            (rc2, out2, err2) = (0, , )
        if ((rc2 != 0) and ('no package provides' not in out2)):
            self.module.fail_json(msg=('Error from rpm: %s: %s' % (cmd, (err + err2))))
        if ('no package provides' in out2):
            out2 = 
        pkgs += [p for p in out2.replace('(none)', '0').split('\n') if p.strip()]
        return pkgs
    return []