Example #1
0
    def push(self, src, dst, timeout=0):
        if os.path.basename(src).startswith('tmp'):
            msg = '''
            temp-files generated by the workspace are not possible to track
            after the test execution and thus the possibility to push these
            files to the handset has been restricted.

            In order to push a generated file, it must first be secured that
            the file can be resurrected during post mortem analysis.

            AVE offers two ways to do this: Either during write_tempfile()
            or with the specific workspace method promote(). Please refer to
            the API description for details.
            '''
            raise Exception(msg)
        if os.path.islink(src):
            src = os.readlink(src)
        cmds = ['-s', self.profile['serial'], 'push', src, dst]
        s,o = run_adb(cmds, timeout)
        if s != 0:
            message = 'Failed to execute: %s' % cmds
            state,sysfs = HandsetLister.get_handset_power_state(self.profile)
            if state == 'offline':
                raise Offline('Handset is offline. %s' % message)
            else:
                raise Exception(message)
        return o
Example #2
0
 def list_forwarded_ports(self, all_adb=False):
     try:
         return self._list_forwarded_ports(all_adb)
     except Exception, e:
         state,sysfs = HandsetLister.get_handset_power_state(self.profile)
         if state == 'offline':
             raise Offline('Handset is offline. %s' % e.message)
         else:
             raise
Example #3
0
 def close_forwarded_port(self, entry):
     try:
         return self._close_forwarded_port(entry)
     except Exception, e:
         state,sysfs = HandsetLister.get_handset_power_state(self.profile)
         if state == 'offline':
             raise Offline('Handset is offline. %s' % e.message)
         else:
             raise
Example #4
0
 def pull(self, src, dst, timeout=0):
     dst  = os.path.abspath(dst) # makes exception msg easier to understand
     cmds = ['-s', self.profile['serial'], 'pull', src, dst]
     s,o = run_adb(cmds, timeout)
     if s != 0:
         message = 'Failed to execute %s: %s' % (cmds, o)
         state,sysfs = HandsetLister.get_handset_power_state(self.profile)
         if state == 'offline':
             raise Offline('Handset is offline. %s' % message)
         else:
             raise Exception(message)
     return o
Example #5
0
 def remount(self):
     self.root()
     s,o = run_adb(['-s', self.profile['serial'], 'remount'])
     if s != 0:
         message = 'Failed to execute remount: %s' % o
         state,sysfs = HandsetLister.get_handset_power_state(self.profile)
         if state == 'offline':
             raise Offline('Handset is offline. %s' % message)
         else:
             raise Exception(message)
     # if remount failed the exit code of the adb call still is 0, therefore
     # the output must be controlled as well.
     if 'remount failed' in o:
         raise Exception(o)
     return o
Example #6
0
    def take_screenshot(self, dst, timeout=20):
        if '/' in dst[-1:]:
            raise Exception('Destination must not be a folder: %s' %dst)

        if not dst:
            raise Exception('Destination must not be empty: %s' %dst)

        if dst.count('/') < 2:
            raise Exception('Destination must not be root: %s' %dst)

        cmds = ['-s', self.profile['serial'], 'shell', 'screencap', '-p', dst]
        s,o = run_adb(cmds,timeout)
        if s != 0:
            message = 'Failed to execute: %s' %cmds
            state,sysfs = HandsetLister.get_handset_power_state(self.profile)
            if state == 'offline':
                raise Offline('Handset is offline. %s' % message)
            else:
                raise Exception(message)

        return 0
Example #7
0
 def shell(self, args, timeout=0, bg = False):
     orig_args = args
     if type(args) in [str, unicode]:
         args = [a for a in args.split() if a != '']
     # Empty value was ignore when passing to some shell tool
     # We force change the empty value as ""
     if type(args) == list:
         temp = []
         for s in args:
             if s.strip() == '':
                 s = '\"%s\"' % s
             temp.append(s)
         args = temp
     cmds = ['-s', self.profile['serial'], 'shell']
     cmds.extend(args)
     #if the cmd run in background the return values are the child_pid and child_fd
     #else the the return value are the exit code of child process, and the content of
     # the stdout and stderr
     s,o = run_adb(cmds, timeout, bg=bg)
     if not bg:
         if s != 0: # only the case if host-side adb could not be executed at all
             message = 'Failed to execute: %s' % cmds
             state,sysfs = HandsetLister.get_handset_power_state(self.profile)
             if state == 'offline':
                 raise Offline('Handset is offline. %s' % message)
             else:
                 raise Exception(message)
         lines = o.splitlines()
         if (lines
         and lines[0].startswith('/system/')
         and lines[0].endswith('not found')):
             raise Exception('no such executable: %s' % orig_args)
         return o
     else:
         self.bgpids.append((s, o))
         return s, o
Example #8
0
    def root(self):
        s,o = run_adb(['-s', self.serial, 'root'])
        if s != 0: # adb may be shaky; retry once on failure
            time.sleep(0.25)
            s,o = run_adb(['-s', self.serial, 'root'])
            if s != 0:
                message = 'could not become root: %s' % o
                state,sysfs=HandsetLister.get_handset_power_state(self.profile)
                if state == 'offline':
                    raise Offline('Handset is offline. %s' % message)
                else:
                    raise Exception(message)
            else:
                if o.strip().startswith('adbd cannot run as root'):
                    raise Exception(str(o))

        else:
            if o.strip().startswith('adbd cannot run as root'):
                raise Exception(str(o))

        while True:
            if self.has_adb():
                break
            time.sleep(0.5)