Skip to content
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

Hesa add list op #22

Merged
merged 4 commits into from
Aug 28, 2023
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
9 changes: 9 additions & 0 deletions python/flame/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions python/flame/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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}'
3 changes: 3 additions & 0 deletions python/flame/license_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/python/test_ldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down