Skip to content
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
10 changes: 10 additions & 0 deletions licomp_toolkit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ def supported_provisionings(self, args):
provisioning_names.sort()
return provisioning_names, ReturnCodes.LICOMP_OK.value, None

def simplify(self, args):
formatter = LicompToolkitFormatter.formatter(args.output_format)
normalized = self.__normalize_license(args.license)
simplified = self.licomp_toolkit.simplify(normalized)
return formatter.format_licomp_licenses(simplified), ReturnCodes.LICOMP_OK.value, None

def supported_resources(self, args):
formatter = LicompToolkitFormatter.formatter(args.output_format)
return formatter.format_licomp_resources([f'{x.name()}:{x.version()}' for x in self.licomp_toolkit.licomp_resources().values()]), ReturnCodes.LICOMP_OK.value, False
Expand Down Expand Up @@ -159,6 +165,10 @@ def main():
default=[])

# Command: list supported
parser_si = subparsers.add_parser('simplify', help='Normalize and simplify a license expression')
parser_si.set_defaults(which="simplify", func=lct_parser.simplify)
parser_si.add_argument("license")

parser_sr = subparsers.add_parser('supported-resources', help='List all supported Licomp resources')
parser_sr.set_defaults(which="supported_resources", func=lct_parser.supported_resources)

Expand Down
5 changes: 2 additions & 3 deletions licomp_toolkit/expr_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import logging

from license_expression import get_spdx_licensing
from license_expression import Licensing
from licomp.interface import LicompException
from licomp.return_codes import ReturnCodes

Expand All @@ -18,7 +18,7 @@
class LicenseExpressionParser():

def __init__(self):
self.licensing = get_spdx_licensing()
self.licensing = Licensing([])

self.CLOSE_PARENTHESIS = ")"
self.LICENSE_SYMBOL = "LicenseSymbol"
Expand All @@ -27,7 +27,6 @@ def __init__(self):
def parse_license_expression(self, expression):
if not expression:
raise LicompException("No license provided: " + str(expression), ReturnCodes.LICOMP_PARSE_ERROR)

p = self.__parse_expression(self.licensing.parse(expression).pretty().replace('\n', ' '))
return p

Expand Down
4 changes: 4 additions & 0 deletions licomp_toolkit/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later

import logging
from license_expression import Licensing

from licomp.interface import Licomp
from licomp.interface import UseCase
Expand Down Expand Up @@ -142,6 +143,9 @@ def outbound_inbound_compatibility(self, outbound, inbound, usecase, provisionin

return compatibilities

def simplify(self, lic):
return str(Licensing([]).parse(lic).simplify())

def supported_licenses(self):
licenses = set()
for resource in self.licomp_resources().values():
Expand Down