# Yum package checker and installer

__author__ = "Frederico Martins"
__license__ = "GPLv3"
__version__ = 1.2

from os import system

from output_handler import OutputWaiting


class Package(object):
    
    def __init__(self, packages):
        
        
        if type(packages) is list or type(packages) is tuple or type(packages) is set:
            pass
        elif type(packages) is str:
            packages = [packages]
        else:
            OutputWaiting.Info('Packages to be asserted must be in string or list format')
            exit(-1)
        
        if self.Check(packages):
            self.Install('Installing {}'.format(' and '.join(self.packages)), True)
    
    def Check(self, packages):
        
        self.packages = []
        
        for each in packages:
            if system('rpm -q {} > /dev/null'.format(each)):
                self.packages.append(each)
            
        return self.packages
        
    @OutputWaiting
    def Install(self):
    
        return system('yum -y install {} > /dev/null'.format(' '.join(self.packages)))
