我编写了以下代码来安装一些软件包。我不希望脚本在输出中显示安装过程消息。完成包的安装后,我只想在输出中打印一个提示。如何重写以下代码来完成此任务。
def package_installation(self):
self.apt = "apt install -y "
self.packages = "python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 python-magic python-gridfs python-libvirt python-bottle python-pefile python-chardet git build-essential autoconf automake libtool dh-autoreconf libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox dkms python-pyrex"
self.color.print_green("[+] Phase 2 : Installation of the ubuntu packages is starting:")
for self.items in self.packages.split():
self.command = str(self.apt) + str(self.items)
subprocess.run(self.command.split())
self.color.print_blue("\t[+] Package [{}] Installed".format(str(self.items)))
self.color.print_green("[+] Phase 2 Accomplished. ")
答案 0 :(得分:0)
修正:
def package_installation(self):
self.apt = "apt install -y "
self.packages = "python-pip python-sqlalchemy mongodb python-bson python-dpkt python-jinja2 python-magic python-gridfs python-libvirt python-bottle python-pefile python-chardet git build-essential autoconf automake libtool dh-autoreconf libcurl4-gnutls-dev libmagic-dev python-dev tcpdump libcap2-bin virtualbox dkms python-pyrex"
self.color.print_green("[+] Phase 2 : Installation of the ubuntu packages is starting:")
for self.items in self.packages.split():
self.command = str(self.apt) + str(self.items)
if (subprocess.run(self.command.split(), stdout=DEVNULL, stderr=DEVNULL)):
self.color.print_blue("\t[+] Package [{}] Installed".format(str(self.items)))
else:
self.color.print_red("\t[+] Package [{}] Don't Installed".format(str(self.items)))
self.color.print_red("[+] Phase 2 Accomplished.\n")