2016-07-25 7 views
-1

Ich habe den folgenden Code geschrieben, um einige Pakete zu installieren. Ich möchte nicht, dass das Skript Installationsprozessnachrichten in der Ausgabe anzeigt. Wenn die Installation eines Pakets abgeschlossen ist, möchte ich nur eine Eingabeaufforderung in der Ausgabe ausdrucken. Wie kann ich den folgenden Code umschreiben, um diese Aufgabe zu erfüllen.Ubuntu Paketinstallation über Python Code

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

Antwort

0

Korrigiert:

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