Bug 790995 - Change how root commands are executed; r=jhammel
authorGregory Szorc <gps@mozilla.com>
Thu, 13 Sep 2012 17:21:49 -0700
changeset 113300 150886c947f07dfb5ad59eb3af862f8510eb8d66
parent 113299 8604438c67ad8f9f39f81063f878209ac9b78372
child 113301 34395b7b10f6608967b15e5b1adcee14a93f5c24
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjhammel
bugs790995
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 790995 - Change how root commands are executed; r=jhammel os.system has been replaced with subprocess.check_call. We also check the effective UID to determine whether to run via sudo.
python/mozboot/mozboot/base.py
python/mozboot/mozboot/centos.py
python/mozboot/mozboot/fedora.py
python/mozboot/mozboot/mint.py
python/mozboot/mozboot/ubuntu.py
--- a/python/mozboot/mozboot/base.py
+++ b/python/mozboot/mozboot/base.py
@@ -1,26 +1,53 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
+from __future__ import print_function, unicode_literals
+
 import os
+import subprocess
 
 class BaseBootstrapper(object):
     """Base class for system bootstrappers."""
-    def __init__(self):
-        pass
 
     def install_system_packages(self):
         raise NotImplemented('%s must implement install_system_packages()' %
             __name__)
 
     def which(self, name):
         """Python implementation of which.
 
         It returns the path of an executable or None if it couldn't be found.
         """
         for path in os.environ['PATH'].split(os.pathsep):
             test = os.path.join(path, name)
             if os.path.exists(test) and os.access(test, os.X_OK):
                 return test
 
         return None
+
+    def run_as_root(self, command):
+        if os.geteuid() != 0:
+            command.insert(0, 'sudo')
+
+        print('Executing as root:', subprocess.list2cmdline(command))
+
+        subprocess.check_call(command)
+
+    def yum_install(self, *packages):
+        command = ['yum', 'install']
+        command.extend(packages)
+
+        self.run_as_root(command)
+
+    def yum_groupinstall(self, *packages):
+        command = ['yum', 'groupinstall']
+        command.extend(packages)
+
+        self.run_as_root(command)
+
+    def apt_install(self, *packages):
+        command = ['apt-get', 'install']
+        command.extend(packages)
+
+        self.run_as_root(command)
--- a/python/mozboot/mozboot/centos.py
+++ b/python/mozboot/mozboot/centos.py
@@ -11,20 +11,32 @@ class CentOSBootstrapper(BaseBootstrappe
     def __init__(self, version, dist_id):
         BaseBootstrapper.__init__(self)
 
         self.version = version
         self.dist_id = dist_id
 
     def install_system_packages(self):
         kern = platform.uname()
-        os.system("sudo yum groupinstall 'Development Tools' 'Development Libraries' 'GNOME Software Development'")
-        os.system("sudo yum install mercurial autoconf213 glibc-static libstdc++-static yasm wireless-tools-devel mesa-libGL-devel alsa-lib-devel libXt-devel")
-        os.system("sudo yum install gtk2-devel")
-        os.system("sudo yum install dbus-glib-devel")
 
-        if ('x86_64' in kern[2]):
-            os.system("sudo rpm -ivh http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.x86_64.rpm")
-        else:
-            os.system("sudo rpm -ivh http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.i686.rpm")
+        self.yum_groupinstall(
+            'Development Tools',
+            'Development Libraries',
+            'GNOME Software Development')
+        self.yum_install(
+            'alsa-lib-devel',
+            'autoconf213',
+            'curl-devel',
+            'dbus-glib-devel',
+            'glibc-static',
+            'gtk2-devel',
+            'libstdc++-static',
+            'libXt-devel',
+            'mercurial',
+            'mesa-libGL-devel',
+            'wireless-tools-devel',
+            'yasm')
 
-        os.system("sudo yum install curl-devel")
+        yasm = 'http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.i686.rpm'
+        if 'x86_64' in kern[2]:
+            yasm = 'http://pkgs.repoforge.org/yasm/yasm-1.1.0-1.el6.rf.x86_64.rpm'
 
+        self.run_as_root(['rpm', '-ivh', yasm])
--- a/python/mozboot/mozboot/fedora.py
+++ b/python/mozboot/mozboot/fedora.py
@@ -9,10 +9,23 @@ from mozboot.base import BaseBootstrappe
 class FedoraBootstrapper(BaseBootstrapper):
     def __init__(self, version, dist_id):
         BaseBootstrapper.__init__(self)
 
         self.version = version
         self.dist_id = dist_id
 
     def install_system_packages(self):
-        os.system("sudo yum groupinstall 'Development Tools' 'Development Libraries' 'GNOME Software Development'")
-        os.system("sudo yum install mercurial autoconf213 glibc-static libstdc++-static yasm wireless-tools-devel mesa-libGL-devel alsa-lib-devel libXt-devel")
+        self.yum_groupinstall(
+            'Development Tools',
+            'Development Libraries',
+            'GNOME Software Development')
+
+        self.yum_install(
+            'alsa-lib-devel',
+            'autoconf213',
+            'glibc-static',
+            'libstdc++-static',
+            'libXt-devel',
+            'mercurial',
+            'mesa-libGL-devel',
+            'wireless-tools-devel',
+            'yasm')
--- a/python/mozboot/mozboot/mint.py
+++ b/python/mozboot/mozboot/mint.py
@@ -9,10 +9,21 @@ from mozboot.base import BaseBootstrappe
 class MintBootstrapper(BaseBootstrapper):
     def __init__(self, version, dist_id):
         BaseBootstrapper.__init__(self)
 
         self.version = version
         self.dist_id = dist_id
 
     def install_system_packages(self):
-        os.system("sudo apt-get build-dep firefox")
-        os.system("sudo apt-get install mercurial libasound2-dev libcurl4-openssl-dev libnotify-dev libxt-dev libiw-dev mesa-common-dev autoconf2.13 yasm uuid")
+        self.run_as_root(['apt-get', 'build-dep', 'firefox'])
+
+        self.apt_install(
+            'autoconf2.13',
+            'mercurial',
+            'libasound2-dev',
+            'libcurl4-openssl-dev',
+            'libnotify-dev',
+            'libiw-dev',
+            'libxt-dev',
+            'mesa-common-dev',
+            'uuid',
+            'yasm')
--- a/python/mozboot/mozboot/ubuntu.py
+++ b/python/mozboot/mozboot/ubuntu.py
@@ -9,10 +9,21 @@ from mozboot.base import BaseBootstrappe
 class UbuntuBootstrapper(BaseBootstrapper):
     def __init__(self, version, dist_id):
         BaseBootstrapper.__init__(self)
 
         self.version = version
         self.dist_id = dist_id
 
     def install_system_packages(self):
-        os.system("sudo apt-get build-dep firefox")
-        os.system("sudo apt-get install mercurial libasound2-dev libcurl4-openssl-dev libnotify-dev libxt-dev libiw-dev mesa-common-dev autoconf2.13 yasm uuid")
+        self.run_as_root(['apt-get', 'build-dep', 'firefox'])
+
+        self.apt_install(
+            'autoconf2.13',
+            'libasound2-dev',
+            'libcurl4-openssl-dev',
+            'libiw-dev',
+            'libnotify-dev',
+            'libxt-dev',
+            'mercurial',
+            'mesa-common-dev',
+            'uuid',
+            'yasm')