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


Python Library.versions_for_key_async方法代码示例

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


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

示例1: test_ingest_version

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import versions_for_key_async [as 别名]
  def test_ingest_version(self):
    library_key = Library(id='org/repo', metadata='{"full_name": "NSS Bob", "stargazers_count": 420, "subscribers_count": 419, "forks": 418, "updated_at": "2011-8-10T13:47:12Z"}').put()
    Version(id='v1.0.0', parent=library_key, sha='sha').put()

    self.respond_to_github(r'https://api.github.com/repos/org/repo/readme\?ref=sha', '{"content":"%s"}' % b64encode('README'))
    self.respond_to('https://raw.githubusercontent.com/org/repo/sha/bower.json', '{}')
    self.respond_to_github('https://api.github.com/markdown', '<html>README</html>')

    response = self.app.get(util.ingest_version_task('org', 'repo', 'v1.0.0'), headers={'X-AppEngine-QueueName': 'default'})
    self.assertEqual(response.status_int, 200)

    version = Version.get_by_id('v1.0.0', parent=library_key)
    self.assertIsNone(version.error)
    self.assertEqual(version.status, Status.ready)
    self.assertFalse(version.preview)

    versions = Library.versions_for_key_async(library_key).get_result()
    self.assertEqual(['v1.0.0'], versions)

    readme = ndb.Key(Library, 'org/repo', Version, 'v1.0.0', Content, 'readme').get()
    self.assertEqual(readme.content, 'README')
    readme_html = ndb.Key(Library, 'org/repo', Version, 'v1.0.0', Content, 'readme.html').get()
    self.assertEqual(readme_html.content, '<html>README</html>')
    bower = ndb.Key(Library, 'org/repo', Version, 'v1.0.0', Content, 'bower').get()
    self.assertEqual(bower.content, '{}')
开发者ID:andymutton,项目名称:v2,代码行数:27,代码来源:manage_test.py

示例2: test_delete_version

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import versions_for_key_async [as 别名]
  def test_delete_version(self):
    library_key = ndb.Key(Library, 'owner/repo')
    version_key = Version(id='v1.0.0', parent=library_key, sha='1', status=Status.ready).put()
    VersionCache.update(library_key)

    response = self.app.get('/task/delete/owner/repo/v1.0.0', headers={'X-AppEngine-QueueName': 'default'})
    self.assertEqual(response.status_int, 200)
    version = version_key.get()
    self.assertIsNone(version)
    self.assertEqual(Library.versions_for_key_async(library_key).get_result(), [])
开发者ID:andymutton,项目名称:v2,代码行数:12,代码来源:manage_test.py

示例3: test_version_cache

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import versions_for_key_async [as 别名]
  def test_version_cache(self):
    library_key = ndb.Key(Library, 'a/b')
    Version(id='v2.0.0', sha='x', status=Status.ready, parent=library_key).put()
    Version(id='v1.0.0', sha='x', status=Status.ready, parent=library_key).put()
    Version(id='v3.0.0', sha='x', status=Status.ready, parent=library_key).put()
    Version(id='v3.0.X', sha='x', status=Status.ready, parent=library_key).put()
    Version(id='v4.0.0', sha='x', status=Status.error, parent=library_key).put()
    Version(id='v5.0.0', sha='x', status=Status.pending, parent=library_key).put()
    Version(id='xxx', sha='x', status=Status.ready, parent=library_key).put()
    versions = yield Library.versions_for_key_async(library_key)
    self.assertEqual(versions, [])

    latest_changed = VersionCache.update(library_key)
    self.assertTrue(latest_changed)
    versions = yield Library.versions_for_key_async(library_key)
    self.assertEqual(versions, ['v1.0.0', 'v2.0.0', 'v3.0.0', 'v4.0.0'])

    Version(id='v6.0.0', sha='x', status=Status.ready, parent=library_key).put()
    latest_changed = VersionCache.update(library_key)
    self.assertTrue(latest_changed)
    versions = yield Library.versions_for_key_async(library_key)
    self.assertEqual(versions, ['v1.0.0', 'v2.0.0', 'v3.0.0', 'v4.0.0', 'v6.0.0'])
开发者ID:andymutton,项目名称:v2,代码行数:24,代码来源:datamodel_test.py

示例4: update_versions

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import versions_for_key_async [as 别名]
  def update_versions(self):
    if self.library.shallow_ingestion:
      return

    if self.library.kind == 'collection':
      new_tag_map = self.update_collection_tags()
    elif self.scope.startswith('@'):
      assert self.library.kind == 'element'
      new_tag_map = self.update_package_tags()
    else:
      assert self.library.kind == 'element'
      new_tag_map = self.update_element_tags()

    new_tags = new_tag_map.keys()

    ingested_tags = Library.versions_for_key_async(self.library.key).get_result()
    logging.info('%d of %d tags ingested', len(ingested_tags), len(new_tags))

    tags_to_add = list(set(new_tags) - set(ingested_tags))
    tags_to_add.sort(versiontag.compare)

    if ingested_tags == [] and len(tags_to_add) > 0:
      # Only ingest the default version if we're doing ingestion for the first time.
      tags_to_add = [versiontag.default_version(tags_to_add)]
    else:
      tags_to_add = [tag for tag in tags_to_add if versiontag.compare(tag, versiontag.default_version(ingested_tags)) > 0]

    tags_to_delete = list(set(ingested_tags) - set(new_tags))
    logging.info('%d adds and %d deletes pending', len(tags_to_add), len(tags_to_delete))

    # To avoid running into limits on the number of tasks (5) that can be spawned transactionally
    # only ingest (2 tasks) or delete (1 task) one version per update.
    if len(tags_to_add) > 0:
      # Ingest from newest to oldest.
      tag = tags_to_add[-1]
      if self.trigger_version_ingestion(tag, new_tag_map[tag]):
        if self.library.kind == 'collection':
          logging.info('ingesting new collection version (%s)', tag)
        else:
          logging.info('ingesting new %s version (%s)', versiontag.categorize(tag, ingested_tags), tag)
    elif len(tags_to_delete) > 0:
      tag = tags_to_delete[0]
      self.trigger_version_deletion(tags_to_delete[0])

    if len(new_tags) is 0:
      return self.error("couldn't find any tagged versions", ErrorCodes.Library_no_version)
开发者ID:customelements,项目名称:v2,代码行数:48,代码来源:manage.py

示例5: get

# 需要导入模块: from datamodel import Library [as 别名]
# 或者: from datamodel.Library import versions_for_key_async [as 别名]
 def get(self, owner, repo, ver=None):
   owner = owner.lower()
   repo = repo.lower()
   library = Library.get_by_id('%s/%s' % (owner, repo), read_policy=ndb.EVENTUAL_CONSISTENCY)
   if library is None or library.error is not None:
     self.response.write(str(library))
     self.response.set_status(404)
     return
   versions = library.versions()
   if ver is None:
     ver = versions[-1]
   version = Version.get_by_id(ver, parent=library.key, read_policy=ndb.EVENTUAL_CONSISTENCY)
   if version is None or version.error is not None:
     self.response.write(str(version))
     self.response.set_status(404)
     return
   metadata = json.loads(library.metadata)
   dependencies = []
   bower = Content.get_by_id('bower', parent=version.key, read_policy=ndb.EVENTUAL_CONSISTENCY)
   if bower is not None:
     try:
       bower_json = json.loads(bower.content)
     # TODO: Which exception is this for?
     # pylint: disable=bare-except
     except:
       bower_json = {}
   readme = Content.get_by_id('readme.html', parent=version.key, read_policy=ndb.EVENTUAL_CONSISTENCY)
   full_name_match = re.match(r'(.*)/(.*)', metadata['full_name'])
   result = {
       'version': ver,
       'versions': versions,
       'readme': None if readme is None else readme.content,
       'subscribers': metadata['subscribers_count'],
       'stars': metadata['stargazers_count'],
       'forks': metadata['forks'],
       'contributors': library.contributor_count,
       'open_issues': metadata['open_issues'],
       'updated_at': metadata['updated_at'],
       'owner': full_name_match.groups()[0],
       'repo': full_name_match.groups()[1],
       'bower': None if bower is None else {
           'description': bower_json.get('description', ''),
           'license': bower_json.get('license', ''),
           'dependencies': bower_json.get('dependencies', []),
           'keywords': bower_json.get('keywords', []),
       },
       'collections': []
   }
   for collection in library.collections:
     if not versiontag.match(ver, collection.semver):
       continue
     collection_version = collection.version.id()
     collection_library = collection.version.parent().get()
     collection_metadata = json.loads(collection_library.metadata)
     collection_name_match = re.match(r'(.*)/(.*)', collection_metadata['full_name'])
     result['collections'].append({
         'owner': collection_name_match.groups()[0],
         'repo': collection_name_match.groups()[1],
         'version': collection_version
     })
   if library.kind == 'collection':
     dependencies = []
     version_futures = []
     for dep in version.dependencies:
       parsed_dep = Dependency.fromString(dep)
       dep_key = ndb.Key(Library, "%s/%s" % (parsed_dep.owner.lower(), parsed_dep.repo.lower()))
       version_futures.append(Library.versions_for_key_async(dep_key))
     for i, dep in enumerate(version.dependencies):
       parsed_dep = Dependency.fromString(dep)
       versions = version_futures[i].get_result()
       versions.reverse()
       while len(versions) > 0 and not versiontag.match(versions[0], parsed_dep.version):
         versions.pop()
       if len(versions) == 0:
         dependencies.append({
             'error': 'unsatisfyable dependency',
             'owner': parsed_dep.owner,
             'repo': parsed_dep.repo,
             'versionSpec': parsed_dep.version
         })
       else:
         dependencies.append(brief_metadata_from_datastore(parsed_dep.owner, parsed_dep.repo, versions[0]))
     result['dependencies'] = dependencies
   self.response.headers['Access-Control-Allow-Origin'] = '*'
   self.response.headers['Content-Type'] = 'application/json'
   self.response.write(json.dumps(result))
开发者ID:keanulee,项目名称:v2,代码行数:88,代码来源:api.py


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