def test_categorize(self):
        self.assertEqual(versiontag.categorize('v1.0.0', []), 'unknown')
        self.assertEqual(versiontag.categorize('v2.0.0', ['v1.0.0']), 'major')
        self.assertEqual(versiontag.categorize('v1.1.0', ['v1.0.0']), 'minor')
        self.assertEqual(versiontag.categorize('v1.1.1', ['v1.0.0']), 'minor')
        self.assertEqual(versiontag.categorize('v1.0.1', ['v1.0.0']), 'patch')
        self.assertEqual(versiontag.categorize('1.0.1', ['v1.0.0']), 'patch')

        self.assertEqual(versiontag.categorize('bestversionever', ['v1.0.0']),
                         'unknown')

        self.assertEqual(versiontag.categorize('v2.0.0', ['v1.0.0', 'v3.0.0']),
                         'major')
        self.assertEqual(versiontag.categorize('v2.1.0', ['v1.0.0', 'v3.0.0']),
                         'major')
        self.assertEqual(
            versiontag.categorize('v2.1.1', ['v1.0.0', 'v2.1.0', 'v3.0.0']),
            'patch')
Exemple #2
0
    def update_versions(self):
        if self.library.shallow_ingestion:
            return

        if self.library.kind == 'collection':
            new_tag_map = self.update_collection_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)
Exemple #3
0
  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)
Exemple #4
0
  def test_categorize(self):
    self.assertEqual(versiontag.categorize('v1.0.0', []), 'unknown')
    self.assertEqual(versiontag.categorize('v2.0.0', ['v1.0.0']), 'major')
    self.assertEqual(versiontag.categorize('v1.1.0', ['v1.0.0']), 'minor')
    self.assertEqual(versiontag.categorize('v1.1.1', ['v1.0.0']), 'minor')
    self.assertEqual(versiontag.categorize('v1.0.1', ['v1.0.0']), 'patch')
    self.assertEqual(versiontag.categorize('1.0.1', ['v1.0.0']), 'patch')
    self.assertEqual(versiontag.categorize('1.0.1-pre', ['v1.0.0']), 'pre-release')

    self.assertEqual(versiontag.categorize('bestversionever', ['v1.0.0']), 'unknown')

    self.assertEqual(versiontag.categorize('v2.0.0', ['v1.0.0', 'v3.0.0']), 'major')
    self.assertEqual(versiontag.categorize('v2.1.0', ['v1.0.0', 'v3.0.0']), 'major')
    self.assertEqual(versiontag.categorize('v2.1.1', ['v1.0.0', 'v2.1.0', 'v3.0.0']), 'patch')