forked from aboutcode-org/tracecode-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
94 lines (81 loc) · 3.72 KB
/
Copy pathcli.py
File metadata and controls
94 lines (81 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#
# Copyright (c) nexB Inc. and others. All rights reserved.
# http://nexb.com and https://github.com/nexB/tracecode-toolkit/
# The TraceCode software is licensed under the Apache License version 2.0.
# Data generated with TraceCode require an acknowledgment.
# TraceCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# When you publish or redistribute any data created with TraceCode or any TraceCode
# derivative work, you must accompany this data with the following acknowledgment:
#
# Generated with TraceCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# TraceCode should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
# TraceCode is a free and open source software analysis tool from nexB Inc. and others.
# Visit https://github.com/nexB/tracecode-toolkit/ for support and download.
#
from __future__ import absolute_import
from collections import OrderedDict
import click
click.disable_unicode_literals_warning = True
import simplejson
from tracecode import __version__
from tracecode import matchers
from tracecode.utils import get_notice
from tracecode.utils import is_json_path
def write_json(analysis, outfile):
"""
Write the data from the `analysis` DeploymentAnalysis as JSON to `outfile`.
"""
results = OrderedDict([
('tracecode_notice', get_notice()),
('tracecode_options', analysis.options),
('tracecode_version', __version__),
('tracecode_errors', analysis.errors),
('tracecode_results', analysis.analysed_result.values()),
])
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
outfile.write('\n')
def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
click.echo('TraceCode version ' + __version__)
ctx.exit()
@click.command()
@click.option('--develop', required=True, prompt=False,
type=click.Path(exists=True, readable=True),
help='Path to the "development" codebase scan file')
@click.option('--deploy', required=True, prompt=False,
type=click.Path(exists=True, readable=True),
help='Path to the "deployed" codebase scan file')
@click.option('-j', '--json', prompt=False, default='-',
type=click.File(mode='wb', lazy=False),
help='Path of the .json output file. Use "-" for on screen display.')
@click.help_option('-h', '--help')
@click.option('--version', is_flag=True, is_eager=True, expose_value=False, callback=print_version, help='Show the version and exit.')
def cli(develop, deploy, json):
"""
Command to accept location of deploy and develop json inputs, run the
tracecode scan and return the expected same paths set by comparison of paths.
"""
options = OrderedDict([
('--develop', develop),
('--deploy', deploy),
])
if not is_json_path(develop):
click.echo('Develop path is not a json file:' + develop)
return
if not is_json_path(deploy):
click.echo('Deploy path is not a json file: ' + deploy)
return
analysis = matchers.DeploymentAnalysis(
develop_json_location=develop, deploy_json_location=deploy, options=options)
write_json(analysis=analysis, outfile=json)