Exemple #1
0
  def update_license_and_kind(self):
    metadata = json.loads(self.library.metadata)
    kind = 'element'
    bower_json = None
    default_branch = metadata.get('default_branch', 'master')

    if not self.scope.startswith('@'):
      response = urlfetch.fetch(util.content_url(self.owner, self.repo, default_branch, 'bower.json'), validate_certificate=True)
      if response.status_code == 200:
        try:
          bower_json = json.loads(response.content)
        except ValueError:
          return self.error("Could not parse master/bower.json", ErrorCodes.Library_parse_bower)
      elif response.status_code == 404:
        bower_json = None
      else:
        return self.retry('error fetching master/bower.json (%d)' % response.status_code)

      if bower_json is not None and 'element-collection' in bower_json.get('keywords', []):
        kind = 'collection'

    if self.library.kind != kind:
      self.library.kind = kind
      self.library_dirty = True

    spdx_identifier = None
    github_license = metadata.get('license')

    # GitHub may now return as a license object instead.
    if isinstance(github_license, dict):
      github_license = github_license.get('spdx_id', 'MISSING')

    if github_license is not None:
      spdx_identifier = licenses.validate_spdx(github_license)

    if spdx_identifier is None and bower_json is not None:
      license_name = bower_json.get('license')
      if license_name is not None:
        spdx_identifier = licenses.validate_spdx(license_name)

    if spdx_identifier is None and self.scope.startswith('@'):
      registry_metadata = json.loads(self.library.registry_metadata)
      spdx_identifier = licenses.validate_spdx(registry_metadata.get('license', ''))

    if self.library.spdx_identifier != spdx_identifier:
      self.library.spdx_identifier = spdx_identifier
      self.library_dirty = True

    if self.library.spdx_identifier is None:
      if self.scope.startswith('@'):
        return self.error('Could not detect an OSI approved license on GitHub or in package info', ErrorCodes.Library_license)
      return self.error('Could not detect an OSI approved license on GitHub or in %s/bower.json' % default_branch, ErrorCodes.Library_license)
Exemple #2
0
  def update_license_and_kind(self):
    metadata = json.loads(self.library.metadata)
    kind = 'element'
    bower_json = None
    default_branch = metadata.get('default_branch', 'master')

    if not self.scope.startswith('@'):
      response = urlfetch.fetch(util.content_url(self.owner, self.repo, default_branch, 'bower.json'), validate_certificate=True)
      if response.status_code == 200:
        try:
          bower_json = json.loads(response.content)
        except ValueError:
          return self.error("Could not parse master/bower.json", ErrorCodes.Library_parse_bower)
      elif response.status_code == 404:
        bower_json = None
      else:
        return self.retry('error fetching master/bower.json (%d)' % response.status_code)

      if bower_json is not None and 'element-collection' in bower_json.get('keywords', []):
        kind = 'collection'

    if self.library.kind != kind:
      self.library.kind = kind
      self.library_dirty = True

    spdx_identifier = None
    github_license = metadata.get('license')

    # GitHub may now return as a license object instead.
    if isinstance(github_license, dict):
      github_license = github_license.get('spdx_id', 'MISSING')

    if github_license is not None:
      spdx_identifier = licenses.validate_spdx(github_license)

    if spdx_identifier is None and bower_json is not None:
      license_name = bower_json.get('license')
      if license_name is not None:
        spdx_identifier = licenses.validate_spdx(license_name)

    if spdx_identifier is None and self.scope.startswith('@'):
      registry_metadata = json.loads(self.library.registry_metadata)
      spdx_identifier = licenses.validate_spdx(registry_metadata.get('license', ''))

    if self.library.spdx_identifier != spdx_identifier:
      self.library.spdx_identifier = spdx_identifier
      self.library_dirty = True

    if self.library.spdx_identifier is None:
      if self.scope.startswith('@'):
        return self.error('Could not detect an OSI approved license on GitHub or in package info', ErrorCodes.Library_license)
      return self.error('Could not detect an OSI approved license on GitHub or in %s/bower.json' % default_branch, ErrorCodes.Library_license)
Exemple #3
0
    def update_license_and_kind(self):
        metadata = json.loads(self.library.metadata)
        default_branch = metadata.get('default_branch', 'master')
        response = urlfetch.fetch(util.content_url(self.owner, self.repo,
                                                   default_branch,
                                                   'bower.json'),
                                  validate_certificate=True)
        bower_json = None
        if response.status_code == 200:
            try:
                bower_json = json.loads(response.content)
            except ValueError:
                return self.error("Could not parse master/bower.json")
        elif response.status_code == 404:
            bower_json = None
        else:
            return self.retry('error fetching master/bower.json' %
                              response.status_code)

        kind = 'element'
        if bower_json is not None and 'element-collection' in bower_json.get(
                'keywords', []):
            kind = 'collection'

        if self.library.kind != kind:
            self.library.kind = kind
            self.library_dirty = True

        spdx_identifier = None
        github_license = metadata.get('license')
        if github_license is not None:
            spdx_identifier = licenses.validate_spdx(
                github_license.get('key', 'MISSING'))

        if spdx_identifier is None and bower_json is not None:
            license_name = bower_json.get('license')
            if license_name is not None:
                spdx_identifier = licenses.validate_spdx(license_name)

        if self.library.spdx_identifier != spdx_identifier:
            self.library.spdx_identifier = spdx_identifier
            self.library_dirty = True

        if self.library.spdx_identifier is None:
            return self.error(
                'Could not detect an OSI approved license on GitHub or in %s/bower.json'
                % default_branch)
Exemple #4
0
  def update_license_and_kind(self):
    metadata = json.loads(self.library.metadata)
    default_branch = metadata.get('default_branch', 'master')
    response = urlfetch.fetch(util.content_url(self.owner, self.repo, default_branch, 'bower.json'), validate_certificate=True)
    bower_json = None
    if response.status_code == 200:
      try:
        bower_json = json.loads(response.content)
      except ValueError:
        return self.error("Could not parse master/bower.json")
    elif response.status_code == 404:
      bower_json = None
    else:
      return self.retry('error fetching master/bower.json' % response.status_code)

    kind = 'element'
    if bower_json is not None and 'element-collection' in bower_json.get('keywords', []):
      kind = 'collection'

    if self.library.kind != kind:
      self.library.kind = kind
      self.library_dirty = True

    spdx_identifier = None
    github_license = metadata.get('license')
    if github_license is not None:
      spdx_identifier = licenses.validate_spdx(github_license.get('key', 'MISSING'))

    if spdx_identifier is None and bower_json is not None:
      license_name = bower_json.get('license')
      if license_name is not None:
        spdx_identifier = licenses.validate_spdx(license_name)

    if self.library.spdx_identifier != spdx_identifier:
      self.library.spdx_identifier = spdx_identifier
      self.library_dirty = True

    if self.library.spdx_identifier is None:
      return self.error('Could not detect an OSI approved license on GitHub or in %s/bower.json' % default_branch)