Skip to content

Write updated licenses from SPDX directly to spdxlicenses package #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions cmd/exceptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -42,34 +41,31 @@ func extractExceptionLicenseIDs() error {
}

// create slice of exception license IDs that are not deprecated
var nonDeprecatedExceptionLicenseIDs []string
var exceptionLicenseIDs []string
for _, e := range exceptionData.Exceptions {
if !e.IsDeprecated {
nonDeprecatedExceptionLicenseIDs = append(nonDeprecatedExceptionLicenseIDs, e.LicenseID)
exceptionLicenseIDs = append(exceptionLicenseIDs, e.LicenseID)
}
}

// save non-deprecated license IDs followed by a comma with one per line in file license_ids.txt
nonDeprecatedExceptionLicenseIDsTxt := []byte{}
for _, id := range nonDeprecatedExceptionLicenseIDs {
nonDeprecatedExceptionLicenseIDsTxt = append(nonDeprecatedExceptionLicenseIDsTxt, []byte(" \"")...)
nonDeprecatedExceptionLicenseIDsTxt = append(nonDeprecatedExceptionLicenseIDsTxt, []byte(id)...)
nonDeprecatedExceptionLicenseIDsTxt = append(nonDeprecatedExceptionLicenseIDsTxt, []byte("\",")...)
nonDeprecatedExceptionLicenseIDsTxt = append(nonDeprecatedExceptionLicenseIDsTxt, []byte("\n")...)
}
err = ioutil.WriteFile("exception_ids.txt", nonDeprecatedExceptionLicenseIDsTxt, 0600)
if err != nil {
return err
}
// generate the GetExceptions() function in get_exceptions.go
getExceptionsContents := []byte(`package spdxlicenses

// save non-deprecated license IDs to json array in file exception_ids.json
nonDeprecatedExceptionLicenseIDsJSON, err := json.Marshal(nonDeprecatedExceptionLicenseIDs)
if err != nil {
return err
func GetExceptions() []string {
return []string{
`)
for _, id := range exceptionLicenseIDs {
getExceptionsContents = append(getExceptionsContents, ` "`+id+`",
`...)
}
err = ioutil.WriteFile("exception_ids.json", nonDeprecatedExceptionLicenseIDsJSON, 0600)
getExceptionsContents = append(getExceptionsContents, ` }
}
`...)

err = os.WriteFile("../spdxexp/spdxlicenses/get_exceptions.go", getExceptionsContents, 0600)
if err != nil {
return err
}

return nil
}
68 changes: 30 additions & 38 deletions cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)

Expand Down Expand Up @@ -43,61 +42,54 @@ func extractLicenseIDs() error {
return err
}

// create two slices of license IDs, one for deprecated and one for not deprecated
// create two slices of license IDs, one for deprecated and one for active
var activeLicenseIDs []string
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was nonDeprecatedLicenseIDs. Updated the var name to activeLicenseIDs` as it is a better description of what the var holds.

var deprecatedLicenseIDs []string
var nonDeprecatedLicenseIDs []string
for _, l := range licenseData.Licenses {
if l.IsDeprecated {
deprecatedLicenseIDs = append(deprecatedLicenseIDs, l.LicenseID)
} else {
nonDeprecatedLicenseIDs = append(nonDeprecatedLicenseIDs, l.LicenseID)
activeLicenseIDs = append(activeLicenseIDs, l.LicenseID)
}
}

// save deprecated license IDs followed by a comma with one per line in file deprecated_license_ids.txt
deprecatedLicenseIDsTxt := []byte{}
for _, id := range deprecatedLicenseIDs {
deprecatedLicenseIDsTxt = append(deprecatedLicenseIDsTxt, []byte(" \"")...)
deprecatedLicenseIDsTxt = append(deprecatedLicenseIDsTxt, []byte(id)...)
deprecatedLicenseIDsTxt = append(deprecatedLicenseIDsTxt, []byte("\",")...)
deprecatedLicenseIDsTxt = append(deprecatedLicenseIDsTxt, []byte("\n")...)
}
err = ioutil.WriteFile("deprecated_license_ids.txt", deprecatedLicenseIDsTxt, 0600)
if err != nil {
return err
}
// generate the GetLicenses() function in get_licenses.go
getLicensesContents := []byte(`package spdxlicenses

// save deprecated license IDs to json array in file deprecated_license_ids.json
deprecatedLicenseIDsJSON, err := json.Marshal(deprecatedLicenseIDs)
if err != nil {
return err
}
err = ioutil.WriteFile("deprecated_license_ids.json", deprecatedLicenseIDsJSON, 0600)
if err != nil {
return err
func GetLicenses() []string {
return []string{
`)
for _, id := range activeLicenseIDs {
getLicensesContents = append(getLicensesContents, ` "`+id+`",
`...)
}
getLicensesContents = append(getLicensesContents, ` }
}
`...)

// save non-deprecated license IDs followed by a comma with one per line in file license_ids.txt
nonDeprecatedLicenseIDsTxt := []byte{}
for _, id := range nonDeprecatedLicenseIDs {
nonDeprecatedLicenseIDsTxt = append(nonDeprecatedLicenseIDsTxt, []byte(" \"")...)
nonDeprecatedLicenseIDsTxt = append(nonDeprecatedLicenseIDsTxt, []byte(id)...)
nonDeprecatedLicenseIDsTxt = append(nonDeprecatedLicenseIDsTxt, []byte("\",")...)
nonDeprecatedLicenseIDsTxt = append(nonDeprecatedLicenseIDsTxt, []byte("\n")...)
}
err = ioutil.WriteFile("license_ids.txt", nonDeprecatedLicenseIDsTxt, 0600)
err = os.WriteFile("../spdxexp/spdxlicenses/get_licenses.go", getLicensesContents, 0600)
if err != nil {
return err
}

// save non-deprecated license IDs to json array in file license_ids.json
nonDeprecatedLicenseIDsJSON, err := json.Marshal(nonDeprecatedLicenseIDs)
if err != nil {
return err
// generate the GetDeprecated() function in get_deprecated.go
getDeprecatedContents := []byte(`package spdxlicenses

func GetDeprecated() []string {
return []string{
`)
for _, id := range deprecatedLicenseIDs {
getDeprecatedContents = append(getDeprecatedContents, ` "`+id+`",
`...)
}
err = ioutil.WriteFile("license_ids.json", nonDeprecatedLicenseIDsJSON, 0600)
getDeprecatedContents = append(getDeprecatedContents, ` }
}
`...)

err = os.WriteFile("../spdxexp/spdxlicenses/get_deprecated.go", getDeprecatedContents, 0600)
if err != nil {
return err
}

return nil
}