+def Error(*messages):
+ print(10*'!', strftime(TIMEFORMAT), *messages)
+
+
+class YumDnf:
+ def __init__(self):
+ command = DNF_PATH if HAS_DNF else YUM_PATH
+ self.command = command
+
+ options = ""
+ # --verbose option
+ Message("Checking if {} supports --verbose".format(command))
+ if os.system("{} --help | grep -q verbose".format(command)) == 0:
+ Message("It does, using --verbose option")
+ options += " --verbose"
+ else:
+ Message("Unsupported, not using --verbose option")
+ # --sslcertdir option
+ Message("Checking if {} supports SSL certificate checks"
+ .format(command))
+ if os.system("{} --help | grep -q sslcertdir".format(command)) == 0:
+ Message("It does, using --sslcertdir option")
+ sslcertdir = "--sslcertdir=" + SSL_CERT_DIR
+ else:
+ Message("Unsupported, not using --sslcertdir option")
+ sslcertdir = ""
+ self.options = options
+
+ # one individual package
+ def handle_package(self, package):
+ if not self.is_packaged_installed(package):
+ return self.do_package(package, "install")
+ else:
+ return self.do_package(package, "update")
+
+ def is_packaged_installed(self, package):
+ cmd = "rpm -q {} > /dev/null".format(package)
+ return os.system(cmd) == 0
+
+ def do_package(self, package, subcommand):
+ cmd = \
+ "{} {} -y {} {}".format(self.command, self.options,
+ subcommand, package)
+ Message("Invoking {}".format(cmd))
+ return os.system(cmd) == 0
+
+ # update one group
+ def update_group(self, group):
+ # it is important to invoke dnf group *upgrade* and not *update*
+ # because the semantics of groups has changed within dnf
+ overall = True
+ if HAS_DNF:
+ cmd = "{} {} -y group install {}".format(
+ self.command, self.options, group)
+ Message("Invoking {}".format(cmd))
+ if os.system(cmd) != 0:
+ overall = False
+ cmd = "{} {} -y group upgrade {}".format(
+ self.command, self.options, group)
+ Message("Invoking {}".format(cmd))
+ if os.system(cmd) != 0:
+ overall = False
+ else:
+ cmd = "{} {} -y groupinstall {}".format(
+ self.command, self.options, group)
+ Message("Invoking {}".format(cmd))
+ if os.system(cmd) != 0:
+ overall = False
+ return overall
+
+ # update the whole system
+ def update_system(self):
+ cmd = "{} {} -y update".format(self.command, self.options)
+ Message("Invoking {}".format(cmd))
+ return os.system(cmd) == 0
+
+ def clean_all(self):
+ cmd = "{} clean all".format(self.command)
+ Message("Invoking {}".format(cmd))
+ return os.system(cmd) == 0