2016-07-25 22 views
-1

일부 패키지를 설치하기 위해 다음 코드를 작성했습니다. 스크립트가 설치 프로세스 메시지를 출력에 표시하지 않기를 바란다. 패키지 설치가 끝나면 출력물에 단지 프롬프트를 출력하고 싶습니다. 이 작업을 수행하려면 어떻게해야합니까?Python 코드를 이용한 우분투 패키지 설치

 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

는 고정 :

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")