Skip to content

Commit 9637fa0

Browse files
committed
Fixed #486 - Add option to save error log in check command.
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent d73982d commit 9637fa0

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Add ability to transform Excel formatted file
1616
* Support Excel file format for `inventory`, `gen` and `attrib`
1717
* Add 'spdx_license_key' support
18+
* Add option to save error log in `check` command
1819

1920
2021-04-02
2021
Release 6.0.0

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
# This pattern also affects html_static_path and html_extra_path.
3939
exclude_patterns = []
4040

41+
master_doc = 'index'
4142

4243
# -- Options for HTML output -------------------------------------------------
4344

docs/source/reference.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ Details
141141
Users can use the following in the template to get the vartext:
142142
{{ vartext['title'] }}
143143
{{ vartext['header'] }}
144-
144+
145145
--verbose
146-
146+
147147
This option tells the tool to show all errors found.
148148
The default behavior will only show 'CRITICAL', 'ERROR', and 'WARNING'
149149
@@ -170,9 +170,10 @@ Options
170170
.. code-block:: none
171171
172172
--djc api_url api_key Validate license_expression from a DejaCode License
173-
Library API URL using the API KEY.
174-
--verbose Show all the errors and warning
175-
-h, --help Show this message and exit.
173+
Library API URL using the API KEY.
174+
--log FILE Path to a file to save the error messages if any.
175+
--verbose Show all error and warning messages.
176+
-h, --help Show this message and exit.
176177
177178
Purpose
178179
-------
@@ -184,11 +185,17 @@ Details
184185

185186
.. code-block:: none
186187
188+
--log
189+
190+
This option save the error log to the defined location
191+
192+
$ about check --log /home/project/error.log /home/project/about_files/
193+
187194
--verbose
188-
195+
189196
This option tells the tool to show all errors found.
190197
The default behavior will only show 'CRITICAL', 'ERROR', and 'WARNING'
191-
198+
192199
$ about check --verbose /home/project/about_files/
193200
194201
Special Notes

src/attributecode/cmd.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,18 +592,30 @@ def collect_redist_src(location, output, from_inventory, with_structures, zip, q
592592
help='Validate license_expression from a DejaCode License Library '
593593
'API URL using the API KEY.')
594594

595+
@click.option('--log',
596+
nargs=1,
597+
metavar='FILE',
598+
help='Path to a file to save the error messages if any.')
599+
595600
@click.option('--verbose',
596601
is_flag=True,
597602
help='Show all error and warning messages.')
598603

599604
@click.help_option('-h', '--help')
600-
def check(location, djc, verbose):
605+
def check(location, djc, log, verbose):
601606
"""
602607
Check .ABOUT file(s) at LOCATION for validity and print error messages.
603608
604609
LOCATION: Path to an ABOUT file or a directory with ABOUT files.
605610
"""
606611
print_version()
612+
613+
if log:
614+
# Check if the error log location exist and create the parent directory if not
615+
parent = os.path.dirname(log)
616+
if not parent:
617+
os.makedirs(parent)
618+
607619
api_url = ''
608620
api_key = ''
609621
if djc:
@@ -613,14 +625,13 @@ def check(location, djc, verbose):
613625
click.echo('Checking ABOUT files...')
614626
errors, abouts = collect_inventory(location)
615627

616-
617628
# Validate license_expression
618-
key_text_dict, errs = pre_process_and_fetch_license_dict(abouts, api_url, api_key)
629+
_key_text_dict, errs = pre_process_and_fetch_license_dict(abouts, api_url, api_key)
619630
for e in errs:
620631
errors.append(e)
621632

622633
errors = unique(errors)
623-
severe_errors_count = report_errors(errors, quiet=False, verbose=verbose)
634+
severe_errors_count = report_errors(errors, quiet=False, verbose=verbose, log_file_loc=log)
624635
sys.exit(severe_errors_count)
625636

626637
######################################################################

src/attributecode/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,6 @@ def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scanc
16071607
license_data, errs = api.get_license_details_from_api(url, api_key, lic_key)
16081608
license_name = license_data.get('short_name', '')
16091609
license_text = license_data.get('full_text', '')
1610-
license_key = license_data.get('key', '')
16111610
spdx_license_key = license_data.get('spdx_license_key', '')
16121611
for severity, message in errs:
16131612
msg = (about.about_file_path + ": " + message)

tests/testdata/test_cmd/help/about_check_help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ Usage: about check [OPTIONS] LOCATION
77
Options:
88
--djc api_url api_key Validate license_expression from a DejaCode License
99
Library API URL using the API KEY.
10+
--log FILE Path to a file to save the error messages if any.
1011
--verbose Show all error and warning messages.
1112
-h, --help Show this message and exit.

0 commit comments

Comments
 (0)