Skip to content

Commit

Permalink
Merge pull request #22 from hesa/hesa-add-list-op
Browse files Browse the repository at this point in the history
Hesa add list op
  • Loading branch information
hesa committed Aug 28, 2023
2 parents f45c741 + 9109f2c commit 88e5c22
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
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

0 comments on commit 88e5c22

Please sign in to comment.