def getLog(self):
     """ 
     Returns the (full) logcat output
     """
     args = ['shell', 'logcat', '-d', '-v', 'thread', '&&',
             '%sadb' % Utils.getAdbPath(self.sdkPath), '-s', 'emulator-%s' % str(self.port), 'shell', 'logcat', '-b', 'events', '-d', '-v', 'thread', '&&',
             '%sadb' % Utils.getAdbPath(self.sdkPath), '-s', 'emulator-%s' % str(self.port), 'shell', 'logcat', '-b', 'radio', '-d', '-v', 'thread']
     logcat = self.runAdbCommand(args)[0]
     return logcat
 def getLog(self):
     """ 
     Returns the (full) logcat output
     """
     args = [
         'shell', 'logcat', '-d', '-v', 'thread', '&&',
         '%sadb' % Utils.getAdbPath(self.sdkPath), '-s',
         'emulator-%s' % str(self.port), 'shell', 'logcat', '-b', 'events',
         '-d', '-v', 'thread', '&&',
         '%sadb' % Utils.getAdbPath(self.sdkPath), '-s',
         'emulator-%s' % str(self.port), 'shell', 'logcat', '-b', 'radio',
         '-d', '-v', 'thread'
     ]
     logcat = self.runAdbCommand(args)[0]
     return logcat
    def startLogcatRedirect(self, theFile='/mnt/sdcard/logcat.log', theMaxSize=4096):
        """
        Start logcat redirection.
        """
        self.log.debug('Start logcat redirect, file: %s, size: %dkBytes' % (theFile, theMaxSize))
        if not self.logcatRedirectProcess is None:
            self.endLogcatRedirect()
        if not self.logcatRedirectProcess is None:
            raise EmulatorClientError('Logcat redirect is already running', EmulatorClientError.LOGCAT_REDIRECT_RUNNING)
        
        try:
            args = ['%sadb' % Utils.getAdbPath(self.sdkPath), '-s', 'emulator-%s' % str(self.port),
                    'shell', 'logcat', '-v', 'thread', '-f', theFile, '-r', str(theMaxSize)]
            self.logcatRedirectProcess = subprocess.Popen(args,
                                                          stdout=subprocess.PIPE,
                                                          stdin=subprocess.PIPE,
                                                          stderr=subprocess.PIPE)

            #if self.verbose:
            #    print self.logcatRedirectProcess.communicate()
        except OSError, osErr:
            print osErr
            raise EmulatorClientError('Failed to run adb command \'%s\': %s' % (args, osErr.strerror),
                                      theCode=EmulatorClientError.ADB_RUN_ERROR,
                                      theBaseError=osErr)
 def runAdbCommand(self, theArgs):
     """
     Runs a simple adb command
     """
     args = ['%sadb' % Utils.getAdbPath(self.sdkPath), '-s', 'emulator-%s' % str(self.port)]
     args.extend(theArgs)
     self.log.debug('Exec adb command: %s' % args)
     try:
         self.adbProcess = subprocess.Popen(args,
                                            stdout=subprocess.PIPE,
                                            stdin=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
     except OSError, osErr:
         raise EmulatorClientError('Failed to run adb command \'%s\': %s' % (args, osErr.strerror),
                                   theCode=EmulatorClientError.ADB_RUN_ERROR,
                                   theBaseError=osErr)
 def runAdbCommand(self, theArgs):
     """
     Runs a simple adb command
     """
     args = [
         '%sadb' % Utils.getAdbPath(self.sdkPath), '-s',
         'emulator-%s' % str(self.port)
     ]
     args.extend(theArgs)
     self.log.debug('Exec adb command: %s' % args)
     try:
         self.adbProcess = subprocess.Popen(args,
                                            stdout=subprocess.PIPE,
                                            stdin=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
     except OSError, osErr:
         raise EmulatorClientError(
             'Failed to run adb command \'%s\': %s' %
             (args, osErr.strerror),
             theCode=EmulatorClientError.ADB_RUN_ERROR,
             theBaseError=osErr)
    def startLogcatRedirect(self,
                            theFile='/mnt/sdcard/logcat.log',
                            theMaxSize=4096):
        """
        Start logcat redirection.
        """
        self.log.debug('Start logcat redirect, file: %s, size: %dkBytes' %
                       (theFile, theMaxSize))
        if not self.logcatRedirectProcess is None:
            self.endLogcatRedirect()
        if not self.logcatRedirectProcess is None:
            raise EmulatorClientError(
                'Logcat redirect is already running',
                EmulatorClientError.LOGCAT_REDIRECT_RUNNING)

        try:
            args = [
                '%sadb' % Utils.getAdbPath(self.sdkPath), '-s',
                'emulator-%s' % str(self.port), 'shell', 'logcat', '-v',
                'thread', '-f', theFile, '-r',
                str(theMaxSize)
            ]
            self.logcatRedirectProcess = subprocess.Popen(
                args,
                stdout=subprocess.PIPE,
                stdin=subprocess.PIPE,
                stderr=subprocess.PIPE)

            #if self.verbose:
            #    print self.logcatRedirectProcess.communicate()
        except OSError, osErr:
            print osErr
            raise EmulatorClientError(
                'Failed to run adb command \'%s\': %s' %
                (args, osErr.strerror),
                theCode=EmulatorClientError.ADB_RUN_ERROR,
                theBaseError=osErr)