Skip to content

Commit 3406714

Browse files
committed
Create a 'check' command #281
The 'check' command will only print the following severities errors: 'CRITICAL', 'ERROR', 'WARNING'. It is using the same approach as user run the 'inventroy'. Instead of creating the generated CSV file and an error.log, this command will not create any files but just print the error on the screen. Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 41f4a60 commit 3406714

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/attributecode/cmd.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545

4646
__copyright__ = """
47-
Copyright (c) 2013-2016 nexB Inc. All rights reserved.
47+
Copyright (c) 2013-2017 nexB Inc. All rights reserved.
4848
Licensed under the Apache License, Version 2.0 (the "License");
4949
you may not use this file except in compliance with the License.
5050
You may obtain a copy of the License at
@@ -63,6 +63,7 @@
6363
%(__copyright__)s
6464
''' % locals()
6565

66+
important_errors = [u'CRITICAL', u'ERROR', u'WARNING']
6667

6768
class AboutCommand(click.Command):
6869
def main(self, args=None, prog_name=None, complete_var=None,
@@ -210,6 +211,26 @@ def attrib(location, output, template, mapping, inventory, quiet):
210211
click.echo('Finished.')
211212

212213

214+
@cli.command(cls=AboutCommand, short_help='LOCATION: directory')
215+
@click.argument('location', nargs=1, required=True, type=click.Path(exists=True, readable=True, resolve_path=True))
216+
def check(location):
217+
"""
218+
Validating ABOUT files at LOCATION.
219+
220+
LOCATION: Path to an ABOUT file or a directory containing ABOUT files.
221+
"""
222+
click.echo('Running attributecode version ' + __version__)
223+
click.echo('Checking ABOUT files...')
224+
225+
errors, abouts = attributecode.model.collect_inventory(location)
226+
227+
msg_format = '%(sever)s: %(message)s'
228+
for severity, message in errors:
229+
sever = severities[severity]
230+
if sever in important_errors:
231+
print(msg_format % locals())
232+
233+
213234
def log_errors(errors, quiet, base_dir=False):
214235
"""
215236
Iterate of sequence of Error objects and print and log errors with a severity

0 commit comments

Comments
 (0)