Return resource by remote path.

        path -- remote path

        Keyword arguments:
        folder_key -- what to use as the root folder (None for root)
430964
def get_resource_by_path(self, path, folder_key=None):
        
        logger.debug("resolving %s", path)

        # remove empty path components
        path = posixpath.normpath(path)
        components = [t for t in path.split(posixpath.sep) if t != '']

        if not components:
            # request for root
            return Folder(
                self.api.folder_get_info(folder_key)['folder_info']
            )

        resource = None

        for component in components:
            exists = False
            for item in self._folder_get_content_iter(folder_key):
                name = item['name'] if 'name' in item else item['filename']

                if name == component:
                    exists = True
                    if components[-1] != component:
                        # still have components to go through
                        if 'filename' in item:
                            # found a file, expected a directory
                            raise NotAFolderError(item['filename'])
                        folder_key = item['folderkey']
                    else:
                        # found the leaf
                        resource = item
                    break

                if resource is not None:
                    break

            if not exists:
                # intermediate component does not exist - bailing out
                break

        if resource is None:
            raise ResourceNotFoundError(path)

        if "quickkey" in resource:
            file_info = self.api.file_get_info(
                resource['quickkey'])['file_info']
            result = File(file_info)
        elif "folderkey" in resource:
            folder_info = self.api.folder_get_info(
                resource['folderkey'])['folder_info']
            result = Folder(folder_info)

        return result
173911
def _context_source_file_url(path_or_url):
    
    if path_or_url.startswith('http'):
        # Remote CSV. Just return the URL
        return path_or_url

    if path_or_url.startswith('/'):
        # Absolute path
        return "file://" + path_or_url

    return "file://" + os.path.join(os.path.realpath(os.getcwd()), path_or_url)
460552
def get_key_from_request(self):
        '''
        '''

        path = "result:%s" % self.context.request.url

        if self.is_auto_webp():
            path += '/webp'

        return path
484822
def url(self, filetype, base_dir=None, sasdir='sas', **kwargs):
        

        location = self.location(filetype, **kwargs)
        return join(self.remote_base, sasdir, location) if self.remote_base and location else None
1273998
def download_from(self, buff, remote_path):
        
        urn = Urn(remote_path)
        if self.is_dir(urn.path()):
            raise OptionNotValid(name='remote_path', value=remote_path)

        if not self.check(urn.path()):
            raise RemoteResourceNotFound(urn.path())

        response = self.execute_request(action='download', path=urn.quote())
        buff.write(response.content)
497570
def file_or_folder(path):
        
        target = unicode(path)
        return Folder(target) if os.path.isdir(target) else File(target)
1228385
def directory(self, key):
    ''''''
    if key.name != 'directory':
      key = key.instance('directory')
    return self.get(key) or []
436141
def pull_folder(self, path, decode=False):
        
        driver = self._current_application()
        theFolder = driver.pull_folder(path)
        if decode:
            theFolder = base64.b64decode(theFolder)
        return theFolder
82030
def Remote(path=None, loader=Notebook, **globals):
    

    class Remote(RemoteMixin, loader):
        ...

    return Remote(path=path, **globals)
1339031
def GetSubkeyByPath(self, key_path):
    
    pyregf_key = self._pyregf_key.get_sub_key_by_path(key_path)
    if not pyregf_key:
      return None

    key_path = key_paths.JoinKeyPath([self._key_path, key_path])
    return REGFWinRegistryKey(pyregf_key, key_path=key_path)
354033
def path(self):
        '''  '''
        if isinstance(self.dir, Directory):
            return self.dir._path
        elif isinstance(self.dir, ROOT.TDirectory):
            return self.dir.GetPath()
        elif isinstance(self.dir, _FolderView):
            return self.dir.path()
        else:
            return str(self.dir)
1217367
def remote_path(self):
        
        # TODO: move this property into independent object for PG
        if len(self.book_id) > 1:
            path_parts = list(self.book_id[:-1])
        else:
            path_parts = ['0']
        path_parts.append(self.book_id)
        return os.path.join(*path_parts) + '/'
1352952
def key(base):
    
    for root, dirs, files in os.walk(base, topdown=False):
        for file in files:
            yield os.path.join(root, file)
1154601
def scp(local_path, remote_path)
      resources.active.each do |resource|
        resource.put(local_path, remote_path)
      end
      return
    end
970383
def getdir(self, section, option, raw=False, vars=None, fallback="", validate=False):
        
        v = self.get(section, option, raw=raw, vars=vars, fallback=fallback)
        v = self._convert_to_path(v)
        return v if not validate or os.path.isdir(v) else fallback
354308
def get(self, path=None, method='GET', **options):
        
        return self.route(path, method, **options)
1146860
def ReadRemoteFile(remote_file_path, hostname, ssh_key):
  
  cmd = 'sudo cat %s' % remote_file_path
  exit_code, output = RunCommandOnHost(cmd, hostname, ssh_key)
  if exit_code:
    raise IOError('Can not read remote path: %s' % (remote_file_path))
  return output