Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

  • i am installing some package based on operating system output.
  • I want to introduce try-except block (or any better way) for linux1 & linux2 loops to print the package is missing in OS or other error while install
  • 3rd loop (Linux-Others) should just give warning and proceed with rest of package installation even if I have error

.

import platform
operating_system=platform.platform()
def package_install():
    listA=['package1','pa9ckage2','package3']
    listB=['package4','package5','package6']
    listC=['package10','package20','package30']

    if 'linux1' in operating_system:
        self._log.info("Linux-A")
        yum_command = yum_command = [
                    YUM_EXECUTABLE,
                    "-y",
                    "install"
                ] + listA
        return self._executor.execute_command(yum_command)
    elif 'linux2' in operating_system:
        self._log.info("Linux-B")
        yum_command = yum_command = [
                    YUM_EXECUTABLE,
                    "-y",
                    "install"
                ] + listB
        return self._executor.execute_command(yum_command)
    else: 
        self._log.info("Linux-Others")
        yum_command = yum_command = [
                    YUM_EXECUTABLE,
                    "-y",
                    "install"
                ] + listC
        return self._executor.execute_command(yum_command)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
292 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...