Skip to content

Commit

Permalink
Merge pull request #5 from raimon49/implement-output-html
Browse files Browse the repository at this point in the history
Implement output HTML
  • Loading branch information
raimon49 authored Feb 11, 2018
2 parents 62f1350 + a679037 commit 73398ab
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### 1.6.0

* Implement new option `--format-html`

### 1.5.0

* Implement new option `--format-rst`
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Dump the software license list of Python packages installed with pip.
* [Option: order](#option-order)
* [Option: format\-markdown](#option-format-markdown)
* [Option: format\-rst](#option-format-rst)
* [Option: format\-html](#option-format-html)
* [More Information](#more-information)
* [License](#license)
* [Dependencies](#dependencies)
Expand Down Expand Up @@ -178,6 +179,31 @@ When executed with the `--format-rst` option, you can output list in "[Grid tabl
+--------+---------+---------+
```

### Option: format-html

When executed with the `--format-html` option, you can output list in HTML table format.

```bash
(venv) $ pip-licenses --format-html
<table>
<tr>
<th>Name</th>
<th>Version</th>
<th>License</th>
</tr>
<tr>
<td>Django</td>
<td>2.0.2</td>
<td>BSD</td>
</tr>
<tr>
<td>pytz</td>
<td>2017.3</td>
<td>MIT</td>
</tr>
</table>
```

### More Information

Other, please make sure to execute the `--help` option.
Expand Down
23 changes: 18 additions & 5 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from prettytable.prettytable import HEADER as RULE_HEADER, ALL as RULE_ALL

__pkgname__ = 'pip-licenses'
__version__ = '1.5.0'
__version__ = '1.6.0'
__author__ = 'raimon'
__license__ = 'MIT License'
__summary__ = ('Dump the software license list of '
Expand Down Expand Up @@ -188,6 +188,17 @@ def get_sortby(args):
return 'Name'


def create_output_string(args):
table = create_licenses_table(args)
output_fields = get_output_fields(args)
sortby = get_sortby(args)

if args.format_html:
return table.get_html_string(fields=output_fields, sortby=sortby)
else:
return table.get_string(fields=output_fields, sortby=sortby)


def create_parser():
parser = argparse.ArgumentParser(
description=__summary__)
Expand Down Expand Up @@ -229,6 +240,10 @@ def create_parser():
action='store_true',
default=False,
help='dump as reST style')
parser.add_argument('--format-html',
action='store_true',
default=False,
help='dump as html style')

return parser

Expand All @@ -237,10 +252,8 @@ def main(): # pragma: no cover
parser = create_parser()
args = parser.parse_args()

table = create_licenses_table(args)
output_fields = get_output_fields(args)
sortby = get_sortby(args)
print(table.get_string(fields=output_fields, sortby=sortby))
output_string = create_output_string(args)
print(output_string)


if __name__ == '__main__': # pragma: no cover
Expand Down
12 changes: 11 additions & 1 deletion test_piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from piplicenses import (__pkgname__, create_parser,
create_licenses_table, get_output_fields, get_sortby,
factory_styled_table_with_args,
find_license_from_classifier,
find_license_from_classifier, create_output_string,
DEFAULT_OUTPUT_FIELDS, SYSTEM_PACKAGES,
LICENSE_UNKNOWN)

Expand Down Expand Up @@ -70,6 +70,9 @@ def test_with_empty_args(self):
sortby = get_sortby(args)
self.assertEquals('Name', sortby)

output_string = create_output_string(args)
self.assertNotIn('<table>', output_string)

def test_from_classifier(self):
from_classifier_args = ['--from-classifier']
args = self.parser.parse_args(from_classifier_args)
Expand Down Expand Up @@ -192,5 +195,12 @@ def test_format_rst(self):
self.assertEquals('+', table.junction_char)
self.assertEquals(RULE_ALL, table.hrules)

def test_format_html(self):
format_html_args = ['--format-html']
args = self.parser.parse_args(format_html_args)
output_string = create_output_string(args)

self.assertIn('<table>', output_string)

def tearDown(self):
pass

0 comments on commit 73398ab

Please sign in to comment.