• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.format_path函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中util.format_path函数的典型用法代码示例。如果您正苦于以下问题:Python format_path函数的具体用法?Python format_path怎么用?Python format_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了format_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: put

  def put(self, path, content):
    """
    Args:
      path: string
      content: string

    Returns:
      None
    """
    path = util.format_path(path)
    name = os.path.basename(path)
    parent_folder = os.path.dirname(path)

    if parent_folder == '/':
      parent_id = BoxAPI.ROOT_FOLDER_ID
    else:
      parent = self._path_to_metadata(parent_folder, isfolder=True)
      if not parent:
        # if the parent folder doesn't exist, then create one
        self.putdir(parent_folder)
        parent = self._path_to_metadata(parent_folder, isfolder=True)
      parent_id = parent['id']

    url = BoxAPI.UPLOAD_URL + '/files/content'
    form = {"parent_id": parent_id}
    strobj = StringIO(content)

    resp = self._request('POST', url, data=form, files={name: strobj})

    metadata = resp['entries'][0]
    self._cache_metadata(path, metadata)
    return True 
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:32,代码来源:box_api.py


示例2: get_logs

  def get_logs(self, path, last_clock):

    beg = time.time()

    path = '/Public' + util.format_path(path)
    length = 5
    offset = 0

    # latest comment comes first
    comments = self.get_comments(path, length, offset)
    if not comments:
      return [], None
    
    new_logs = []
    new_clock = comments[0]['id']
    end = False

    while True:
      for comment in comments:
        if last_clock and comment['id'] == last_clock:
          end = True
          break
        new_logs.insert(0, comment['message'])
      if end: break
      if len(comments) < length: break
      # if haven't reached to end, read next batch
      offset += length
      comments = self.get_comments(path, length, offset)

    end = time.time()
    dbg.paxos_time("get_log %s", end-beg)
    return new_logs, new_clock
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:32,代码来源:onedrive_api.py


示例3: listdir

  def listdir(self, path):
    """
    Args:
      path: string

    Returns:
      list of file/dir names
    """
    path = util.format_path(path)

    if path == '/':
      folder_id = BoxAPI.ROOT_FOLDER_ID
    else:
      folder = self.search(path)
      folder_id = folder['id']

    result = []
    offset = 0
    while True:
      metalist = self._listdir(folder_id, offset)
    
      for metadata in metalist:
        self._cache_metadata(os.path.join(path, metadata['name']), metadata)
        result.append(metadata['name'])

      if(len(metalist) < 1000): break
      offset += 1000
      
    return result
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:29,代码来源:box_api.py


示例4: listdir

  def listdir(self, path):
    result = []
    path = util.format_path(path)
    if path == '/':
      folder_id = 'root'
    else:
      folder_id = self._path_to_metadata(path)['id']

    param = {}
    param['q'] = '"%s" in parents and trashed=false' % (folder_id)
    param['maxResults'] = 500
    page_token = None

    while True:
      try:
        if page_token:
          param['pageToken'] = page_token
        files = self.service.files().list(**param).execute()
        result.extend(map(lambda x: x['title'], files['items']))

        page_token = files.get('nextPageToken', None)
        if not page_token:
          break
      except errors.HttpError, error:
        print 'An error occurred: %s' % error
        return None
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:26,代码来源:google_api.py


示例5: putdir

  def putdir(self, path):
    """
    Args:
      path: string

    Returns:
      None
    """
    path = util.format_path(path)
    name = os.path.basename(path)
    parent_folder = os.path.dirname(path)

    if parent_folder == '/':
      parent_id = BoxAPI.ROOT_FOLDER_ID
    else:
      parent = self._path_to_metadata(parent_folder, isfolder=True)
      if not parent:
        # if the parent folder doesn't exist, then create one
        self.putdir(parent_folder)
        parent = self._path_to_metadata(parent_folder, isfolder=True)
      parent_id = parent['id']

    url = BoxAPI.BASE_URL + '/folders'
    data = '{"name":"%s", "parent":{"id":"%s"}}' % (name, parent_id)
    resp = self._request('POST', url, data=data)

    self._cache_metadata(path, resp)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:27,代码来源:box_api.py


示例6: rmdir

  def rmdir(self, path):
    path = util.format_path(path)
    metadata = self._path_to_metadata(path, isfolder=True)
    file_id = metadata['id']

    url = OneDriveAPI.BASE_URL + '/%s' % file_id
    self._request('DELETE', url, raw=True)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:7,代码来源:onedrive_api.py


示例7: metadata

 def metadata(self, path):
   path = util.format_path(path)
   _md = self.search(path)
   md = {}
   md['size'] = _md['size']
   md['mtime'] = util.convert_time(_md['updated_time'])
   return md
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:7,代码来源:onedrive_api.py


示例8: putdir

  def putdir(self, path):
    """
    Args:
      path: string

    Returns:
      None
    """
    path = util.format_path(path)
    name = os.path.basename(path)
    parent_folder = os.path.dirname(path)

    parent = self._path_to_metadata(parent_folder, isfolder=True)
    if not parent:
      # if the parent folder doesn't exist, then create one
      self.putdir(parent_folder)
      parent = self._path_to_metadata(parent_folder, isfolder=True)

    parent_id = parent['id']
    url = OneDriveAPI.BASE_URL + '/%s' % parent_id
    headers = {
      "Authorization": "Bearer " + self.token.access_token,
      "Content-Type": "application/json"
    }
    data = '{"name": "%s"}' % name
    resp = self._request('POST', url, headers=headers, data=data)
    self._cache_metadata(path, resp)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:27,代码来源:onedrive_api.py


示例9: put

  def put(self, path, content):
    """
    Args:
      path: string
      content: string

    Returns:
      None
    """
    path = util.format_path(path)
    name = os.path.basename(path)
    parent_folder = os.path.dirname(path)

    parent = self._path_to_metadata(parent_folder, isfolder=True)
    if not parent:
      # if the parent folder doesn't exist, then create one
      self.putdir(parent_folder)
      parent = self._path_to_metadata(parent_folder, isfolder=True)

    parent_id = parent['id']
    url = OneDriveAPI.BASE_URL + '/%s/files/%s' % (parent_id, name)
    strobj = StringIO(content)
    params = { 'overwrite': 'false' }
    metadata = self._request('PUT', url, params=params, data=strobj)

    metadata[u'type'] = u'file'
    self._cache_metadata(path, metadata)
    return True
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:28,代码来源:onedrive_api.py


示例10: update

  def update(self, path, content):
    """Update the file
    Args and returns same as put
    """
    dbg.dbg(path)
    path = util.format_path(path)
    metadata = self._path_to_metadata(path)
    file_id = metadata['id']

    uri = GoogleAPI.UPLOAD_URL + '/files/%s?uploadType=media' % file_id

    headers = {
      'Content-Type': 'text/plain',
      'Content-Length': len(content),
	 	}

    for retry_num in xrange(self._num_retries + 1):
      resp, data = self.service._http.request(uri, method='PUT',
        body=content, headers=headers)
      if resp.status < 500:
        break

    if resp.status >= 300:
      raise errors.HttpError(resp, data, uri=uri)
    if resp.status == 200:
      drive_file = json.loads(data)
      self._cache_metadata(path, drive_file)
      return True
    else:
      return False
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:30,代码来源:google_api.py


示例11: putdir

  def putdir(self, path):

    uri = GoogleAPI.UPLOAD_URL + '/files?uploadType=multipart&alt=json'

    path = util.format_path(path)
    name = os.path.basename(path)
    folder = os.path.dirname(path)

    parent_id = None
    if folder != '/':
      # if it's not at the root folder, find out the parent id
      parent = self._path_to_metadata(folder, isfolder=True)
      if not parent:
        # if the parent folder doesn't exist, then create one
        self.putdir(folder)
        parent = self._path_to_metadata(folder, isfolder=True)
      parent_id = parent['id']

    body = {
      'title': name,
      'mimeType': 'application/vnd.google-apps.folder'
    }
    if parent_id:
      # if not at root folder
      body['parents'] = [{'id': parent_id}]

    try:
      drive_file = self.service.files().insert(body=body).execute()
      self._cache_metadata(path, drive_file)
      return True
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
      return False
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:33,代码来源:google_api.py


示例12: rmdir

  def rmdir(self, path):
    path = util.format_path(path)
    metadata = self._path_to_metadata(path, isfolder=True)
    file_id = metadata['id']

    self.service.files().delete(fileId=file_id).execute()
    self._decache_metadata(path, metadata)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:7,代码来源:google_api.py


示例13: metadata

 def metadata(self, path):
   path = util.format_path(path)
   _md = self.search(path)
   md = {}
   md['size'] = eval(_md['fileSize'])
   md['mtime'] = util.convert_time(_md['modifiedDate'])
   return md
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:7,代码来源:google_api.py


示例14: get_logs

  def get_logs(self, path, last_clock):
    path = util.format_path(path)
    file_id = self._path_to_metadata(path)['id']

    # latest comment comes first
    comments = self.service.comments().list(fileId=file_id, maxResults=5).execute()
    if not comments['items']:
      return [], None
    
    new_logs = []
    new_clock = comments['items'][0]['commentId']
    end = False

    while True:
      for comment in comments['items']:
        if last_clock and comment['commentId'] == last_clock:
          end = True
          break
        new_logs.insert(0, comment['content'])
      if end: break
      if 'nextPageToken' not in comments: break
      # get a new batch (5) comments
      comments = self.service.comments().list(fileId=file_id, maxResults=5, pageToken=comments['nextPageToken']).execute()

    return new_logs, new_clock
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:25,代码来源:google_api.py


示例15: listdir_old

  def listdir_old(self, path):
    result = []
    page_token = None

    path = util.format_path(path)
    folder_metadata = self.search(path)
    if folder_metadata:
      folder_id = folder_metadata['id']
    else:
      folder_id = 'root'

    while True:
      try:
        param = {}
        if page_token:
          param['pageToken'] = page_token

        children = self.service.children().list(folderId=folder_id, **param).execute()

        for child in children.get('items', []):
          request = self.service.files().get(fileId=child['id'])
          metadata = request.execute()
          self._cache_metadata(os.path.join(path, metadata['title']), metadata)
          result.append(metadata['title'])

        page_token = children.get('nextPageToken')

        if not page_token:
          break
      except errors.HttpError, error:
        print 'An error occurred: %s' % error
        break
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:32,代码来源:google_api.py


示例16: rmdir

  def rmdir(self, path):
    # remove directory only
    path = util.format_path(path)
    metadata = self._path_to_metadata(path, isfolder=True)
    dir_id = metadata['id']

    url = BoxAPI.BASE_URL + '/folders/%s?recursive=true' % dir_id
    self._request('DELETE', url, raw=True)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:8,代码来源:box_api.py


示例17: rm

  def rm(self, path):
    # remove file only
    path = util.format_path(path)
    metadata = self._path_to_metadata(path)
    file_id = metadata['id']

    url = BoxAPI.BASE_URL + '/files/%s' % file_id
    self._request('DELETE', url, raw=True)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:8,代码来源:box_api.py


示例18: putdir

  def putdir(self, path):
    path = BaiduAPI.ROOT_DIR + util.format_path(path)
    url = BaiduAPI.BASE_URL + '/file'
    params = {
      'method': 'mkdir',
      'path': path
    }

    resp = self._request('POST', url, params=params)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:9,代码来源:baidu_api.py


示例19: rm

  def rm(self, path):
    path = BaiduAPI.ROOT_DIR + util.format_path(path)
    url = BaiduAPI.BASE_URL + '/file'
    params = {
      'method': 'delete',
      'path': path
    }

    self._request('POST', url, params=params)
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:9,代码来源:baidu_api.py


示例20: get_comments

  def get_comments(self, path):

    path = util.format_path(path)
    metadata = self._path_to_metadata(path)
    file_id = metadata['id']

    url = BoxAPI.BASE_URL + '/files/%s/comments' % file_id
    resp = self._request('GET', url);
    return resp['entries']
开发者ID:UWNetworksLab,项目名称:metasync,代码行数:9,代码来源:box_api.py



注:本文中的util.format_path函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.format_satoshis函数代码示例发布时间:2022-05-27
下一篇:
Python util.flipCoin函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap