Ejemplo n.º 1
0
    def get_binary(self):
        dest_parent_dir = os.path.join(os.path.expanduser('~'),
                                       '.browserstack')
        if not os.path.exists(dest_parent_dir):
            os.makedirs(dest_parent_dir)
        bsfiles = [
            f for f in os.listdir(dest_parent_dir)
            if f.startswith('BrowserStackLocal')
        ]

        if len(bsfiles) == 0:
            binary_path = self.download()
        else:
            binary_path = os.path.join(dest_parent_dir, bsfiles[0])

        valid_binary = self.__verify_binary(binary_path)
        if valid_binary:
            return binary_path
        else:
            binary_path = self.download()
            valid_binary = self.__verify_binary(binary_path)
            if valid_binary:
                return binary_path
            else:
                raise BrowserStackLocalError(
                    'BrowserStack Local binary is corrupt')
Ejemplo n.º 2
0
 def __available_dir(self):
     while self.path_index < len(self.ordered_paths):
         if self.__make_path(self.ordered_paths[self.path_index]):
             final_path = self.ordered_paths[self.path_index]
             self.path_index += 1
             return final_path
         else:
             self.path_index += 1
     raise BrowserStackLocalError(
         'Error trying to download BrowserStack Local binary')
Ejemplo n.º 3
0
    def start(self, **kwargs):
        for k, v in kwargs.items():
            self.options[k] = v

        if 'key' in self.options:
            self.key = self.options['key']
            del self.options['key']

        if 'binarypath' in self.options:
            self.binary_path = self.options['binarypath']
            del self.options['binarypath']
        else:
            self.binary_path = LocalBinary().get_binary()

        if 'logfile' in self.options:
            self.local_logfile_path = self.options['logfile']
            del self.options['logfile']

        if "onlyCommand" in kwargs and kwargs["onlyCommand"]:
            return

        self.proc = subprocess.Popen(self._generate_cmd(),
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE)
        (out, err) = self.proc.communicate()

        os.system('echo "" > "' + self.local_logfile_path + '"')
        try:
            if out:
                data = json.loads(out.decode())
            else:
                data = json.loads(err.decode())

            if data['state'] != "connected":
                raise BrowserStackLocalError(data["message"]["message"])
            else:
                self.pid = data['pid']
        except ValueError:
            raise BrowserStackLocalError(
                'Error parsing JSON output from daemon')