当前位置: 首页>>代码示例>>Python>>正文


Python Library.maybe_create_with_kind方法代码示例

本文整理汇总了Python中datamodel.Library.maybe_create_with_kind方法的典型用法代码示例。如果您正苦于以下问题:Python Library.maybe_create_with_kind方法的具体用法?Python Library.maybe_create_with_kind怎么用?Python Library.maybe_create_with_kind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datamodel.Library的用法示例。


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

示例1: init_library

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import maybe_create_with_kind [as 别名]
 def init_library(self, owner, repo, kind=None, create=True):
   self.owner = owner.lower()
   self.repo = repo.lower()
   if create:
     assert kind is not None
     self.library = Library.maybe_create_with_kind(self.owner, self.repo, kind)
   else:
     self.library = Library.get_by_id('%s/%s' % (owner, repo))
开发者ID:samuelli,项目名称:v2,代码行数:10,代码来源:manage.py

示例2: get

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import maybe_create_with_kind [as 别名]
  def get(self, owner, repo, kind):
    if not (kind == 'element' or kind == 'collection'):
      self.response.set_status(400)
      return
    owner = owner.lower()
    repo = repo.lower()
    library = Library.maybe_create_with_kind(owner, repo, kind)
    library_dirty = False
    if library.error is not None:
      library_dirty = True
      library.error = None

    logging.info('created library')

    github = quota.GitHub()
    if not github.reserve(3):
      self.response.set_status(500)
      return

    response = github.github_resource('repos', owner, repo, etag=library.metadata_etag)
    if response.status_code != 304:
      if response.status_code == 200:
        library.metadata = response.content
        library.metadata_etag = response.headers.get('ETag', None)
        library_dirty = True
      else:
        library.error = 'repo metadata not found (%d)' % response.status_code
        github.release()
        library.put()
        return

    response = github.github_resource('repos', owner, repo, 'contributors', etag=library.contributors_etag)
    if response.status_code != 304:
      if response.status_code == 200:
        library.contributors = response.content
        library.contributors_etag = response.headers.get('ETag', None)
        library.contributor_count = len(json.loads(response.content))
        library_dirty = True
      else:
        library.error = 'repo contributors not found (%d)' % response.status_code
        github.release()
        library.put()
        return


    response = github.github_resource('repos', owner, repo, 'git/refs/tags', etag=library.tags_etag)
    if response.status_code != 304:
      if response.status_code == 200:
        library.tags = response.content
        library.tags_etag = response.headers.get('ETag', None)
        library_dirty = True

        data = json.loads(response.content)
        if not isinstance(data, object):
          library.error = 'repo contains no valid version tags'
          github.release()
          library.put()
          return
        for version in data:
          tag = version['ref'][10:]
          if not versiontag.is_valid(tag):
            continue
          sha = version['object']['sha']
          version_object = Version(parent=library.key, id=tag, sha=sha)
          version_object.put()
          task_url = util.ingest_version_task(owner, repo, tag)
          util.new_task(task_url)
          util.publish_analysis_request(owner, repo, tag)
      else:
        library.error = 'repo tags not found (%d)' % response.status_code
        github.release()
        library.put()
        return

    if library_dirty:
      library.put()
    github.release()
开发者ID:shans,项目名称:v2,代码行数:79,代码来源:manage.py

示例3: get

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import maybe_create_with_kind [as 别名]
  def get(self, owner, repo, kind):
    if not (kind == 'element' or kind == 'collection'):
      self.response.set_status(400)
      return
    owner = owner.lower()
    repo = repo.lower()
    library = Library.maybe_create_with_kind(owner, repo, kind)

    logging.info('created library')

    github = quota.GitHub()
    if not github.reserve(3):
      self.response.set_status(500)
      return

    response = github.github_resource('repos', owner, repo)

    if not response.status_code == 200:
      library.error = 'repo metadata not found'
      github.release()
      library.put()
      return

    library.metadata = response.content

    response = github.github_resource('repos', owner, repo, 'contributors')
    if not response.status_code == 200:
      library.error = 'repo contributors not found'
      github.release()
      library.put()
      return

    library.contributors = response.content
    library.contributor_count = len(json.loads(response.content))

    response = github.github_resource('repos', owner, repo, 'git/refs/tags')
    if not response.status_code == 200:
      library.error = 'repo tags not found'
      github.release()
      library.put()
      return

    data = json.loads(response.content)
    if not isinstance(data, object):
      library.error = 'repo contians no valid version tags'
      github.release()
      library.put()
      return

    library.put()

    for version in data:
      tag = version['ref'][10:]
      if not versiontag.is_valid(tag):
        continue
      sha = version['object']['sha']
      version_object = Version(parent=library.key, id=tag, sha=sha)
      version_object.put()
      util.new_task('ingest/version', owner, repo, detail=tag)
      util.publish_hydrolyze_pending(
          '/task/ingest/hydrolyzer/%s/%s/%s' % (owner, repo, tag),
          owner,
          repo,
          tag)
开发者ID:keanulee,项目名称:v2,代码行数:66,代码来源:manage.py


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