def _ssh_ls(self, uri): """Helper for ls(); obeys globbing""" m = SSH_URI_RE.match(uri) try: addr = m.group('hostname') if not addr: raise ValueError if '!' in addr and self.ssh_key_name is None: raise ValueError('ssh_key_name must not be None') output = ssh_ls( self._ssh_bin, addr, self._ec2_key_pair_file, m.group('filesystem_path'), self.ssh_key_name, ) for line in output: # skip directories, we only want to return downloadable files if line and not line.endswith('/'): yield SSH_PREFIX + addr + line except SSHException, e: raise IOError(e)
def _cat_file(self, filename): ssh_match = SSH_URI_RE.match(filename) addr = ssh_match.group('hostname') or self._address_of_master() if '!' in addr and self.ssh_key_name is None: raise ValueError('ssh_key_name must not be None') output = ssh_cat( self._ssh_bin, addr, self._ec2_key_pair_file, ssh_match.group('filesystem_path'), self.ssh_key_name, ) return read_file(filename, fileobj=StringIO(output))
def _cat_file(self, filename): ssh_match = SSH_URI_RE.match(filename) addr = ssh_match.group('hostname') or self._address_of_master() keyfile = self._key_filename_for(addr) output = ssh_cat( self._ssh_bin, addr, self._ec2_key_pair_file, ssh_match.group('filesystem_path'), keyfile, ) return read_file(filename, fileobj=BytesIO(output))
def _ssh_ls(self, uri): """Helper for ls(); obeys globbing""" m = SSH_URI_RE.match(uri) addr = m.group('hostname') if not addr: raise ValueError keyfile = self._key_filename_for(addr) output = ssh_ls( self._ssh_bin, addr, self._ec2_key_pair_file, m.group('filesystem_path'), keyfile, ) for line in output: # skip directories, we only want to return downloadable files if line and not line.endswith('/'): yield SSH_PREFIX + addr + line
def ls(self, path_glob): if SSH_URI_RE.match(path_glob): for item in self._ssh_ls(path_glob): yield item return
def can_handle_path(self, path): return SSH_URI_RE.match(path) is not None