diff --git a/python/flame/__main__.py b/python/flame/__main__.py index 4f08370..4c7f895 100755 --- a/python/flame/__main__.py +++ b/python/flame/__main__.py @@ -66,6 +66,11 @@ def parse(): 'compats', help='show all compatibilities') parser_cs.set_defaults(which='compats', func=compats) + # operators + parser_os = subparsers.add_parser( + 'operators', help='show all operators') + parser_os.set_defaults(which='operators', func=operators) + # licenses parser_cs = subparsers.add_parser( 'licenses', help='show all licenses') @@ -75,6 +80,10 @@ def parse(): return args +def operators(ldb, formatter, args): + all_op = ldb.operators() + return formatter.format_operators(all_op, args.verbose) + def aliases(ldb, formatter, args): all_aliases = ldb.aliases_list() return formatter.format_identified_list(all_aliases, args.verbose) diff --git a/python/flame/format.py b/python/flame/format.py index b97ffe7..49ed6fe 100644 --- a/python/flame/format.py +++ b/python/flame/format.py @@ -47,6 +47,9 @@ def format_licenses(self, licenses, verbose): def format_compatibilities(self, compats, verbose): return None + def format_operators(self, operators, verbose): + return None + class JsonOutputFormatter(OutputFormatter): def format_compat(self, compat, verbose): @@ -73,6 +76,9 @@ def format_licenses(self, licenses, verbose): def format_compatibilities(self, compats, verbose): return json.dumps(compats) + def format_operators(self, operators, verbose): + return json.dumps(operators) + class YamlOutputFormatter(OutputFormatter): def format_compat(self, compat, verbose): @@ -99,6 +105,9 @@ def format_licenses(self, licenses, verbose): def format_compatibilities(self, compats, verbose): return yaml.dump(compats) + def format_operators(self, operators, verbose): + return yaml.dump(operators) + class TextOutputFormatter(OutputFormatter): def format_compat(self, compat, verbose): @@ -164,5 +173,8 @@ def format_licenses(self, licenses, verbose): licenses.sort() return "\n".join(licenses) + def format_operators(self, operators, verbose): + return "\n".join(operators) + def format_error(self, error, verbose): return f'Error, {error}' diff --git a/python/flame/license_db.py b/python/flame/license_db.py index b4330c1..3b4f426 100644 --- a/python/flame/license_db.py +++ b/python/flame/license_db.py @@ -180,6 +180,9 @@ def aliases(self, license_name): identified_name = self.__identify_license(license_name)[NAME_TAG] return self.license_db[LICENSES_TAG][identified_name][ALIASES_TAG] + def operators(self): + return self.license_db[LICENSE_OPERATORS_TAG] + def compatibility_as(self, license_name): # List compatibility_as for license identified = self.__identify_license(license_name) diff --git a/tests/python/test_ldb.py b/tests/python/test_ldb.py index 07bb2ab..77efbf6 100644 --- a/tests/python/test_ldb.py +++ b/tests/python/test_ldb.py @@ -70,6 +70,10 @@ def test_licenses(): licenses = ldb.licenses() assert len(licenses) == 3 +def test_operators(): + operators = ldb.operators() + assert len(operators) > 3 + def test_compat_as_bad_input(): with pytest.raises(LicenseDatabaseError) as _error: