Esempio n. 1
0
    def execute(self, cmd, root=False):
        if not root and os.geteuid() == 0:
            return execute_subprocess(['sudo', '-u', tools_user()[1]] + cmd)

        # Make it clear we're running as root. We could check os.geteuid() != 0 though.
        if root:
            cmd = ['sudo', '-n'] + cmd

        return execute_subprocess(cmd)
 def _adb_devices():
     device_list = execute_subprocess(['adb', 'devices',
                                       '-l'])[1].split()[4:]
     device_list = [
         device_list[i:i + 6] for i in range(0, len(device_list), 6)
     ]
     adb_device = namedtuple(
         'adb_device', ['adb_id', 'usb', 'product', 'model', 'device'])
     for device in device_list:
         yield adb_device(
             adb_id=device[0],
             usb=device[2].split(':')[1],
             product=device[3].split(':')[1],
             model=device[4].split(':')[1],
             device=device[5].split(':')[1],
         )
Esempio n. 3
0
    def push(self, src, dst):
        ret, stdout, stderr = execute_subprocess(['cp', '-rf', src, dst])

        if ret != 0:
            raise XVEx("Couldn't copy {} -> {}: stdout: {}, stderr: {}".format(
                src, dst, stdout, stderr))

        if os.geteuid() != 0:
            return

        # When executing locally it's entirely likely we'll be running as root. We don't want to
        # have any files owned by root unless directly specified by the user - in which case they
        # should chown via a command for now (which I think is an unlikely use case).

        L.verbose("Removing root permissions from file {} ({})".format(
            dst,
            tools_user()[0]))
        os.chown(dst, tools_user()[0], -1)
Esempio n. 4
0
 def execute(self, cmd, root=False):
     # TODO: Don't have the ability to change to/from root on Windows. Any clean way of doing
     # this?
     return execute_subprocess(cmd)
 def _run_adb_cmd(self, cmd):
     self._ensure_connected()
     cmd = ['adb', '-s', self.adb_id] + cmd
     return execute_subprocess(cmd)
 def _start_adb_server():
     ret, _, stderr = execute_subprocess(['adb', 'start-server'])
     if ret:
         raise XVEx('Could not start the ADB server: {}.'.format(stderr))