Skip to content

Commit 1091fca

Browse files
author
Li
committed
Add the command to support tracecode scan and add test case #1
Signed-off-by: Li <[email protected]>
1 parent 1b29416 commit 1091fca

8 files changed

Lines changed: 86 additions & 21 deletions

File tree

src/tracecode/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,23 @@
3333
# package is not installed ??
3434
__version__ = '1.0.0'
3535

36+
37+
class TraceCode(object):
38+
"""
39+
Handle the basic operations on a pair of incoming ScanCode scans (in JSON
40+
format) and return the same paths from a comparison of the paths in both input
41+
jsons.
42+
"""
43+
def __init__(self, deploy, develop, options):
44+
self.deploy = deploy
45+
self.develop = develop
46+
self.options = options
47+
self.errors = []
48+
self.results = []
49+
self._parse()
50+
51+
def _parse(self):
52+
"""
53+
Parse the deploy and develop json and return a set of same paths.
54+
"""
55+
pass

src/tracecode/cli.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
import simplejson
3232

3333
from tracecode import __version__
34+
from tracecode import TraceCode
35+
from tracecode.utils import get_notice
3436

3537

36-
def write_json(tracecode, outfile, all_delta_types=False):
38+
def write_json(tracecode, outfile, all_paths=False):
3739
"""
3840
Using the TraceCode object, create a .json file containing the primary
3941
information from the Delta objects. Through a call to utils.deltas(), omit
@@ -44,10 +46,11 @@ def write_json(tracecode, outfile, all_delta_types=False):
4446
('tracecode_notice', get_notice()),
4547
('tracecode_options', tracecode.options),
4648
('tracecode_version', __version__),
47-
('tracecode_errors',[]),
49+
('tracecode_errors',tracecode.errors),
50+
('tracecode_resulst',tracecode.results),
51+
4852
])
4953

50-
# TODO: add toggle for pretty printing
5154
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
5255
outfile.write('\n')
5356

@@ -60,20 +63,19 @@ def print_version(ctx, param, value):
6063

6164

6265
@click.command()
63-
@click.option('--deploy',
64-
required=True, prompt=False, type=click.Path(exists=True, readable=True),
65-
help='Identify the path to the "deployed" codebase scan file')
66-
@click.option('--devel',
67-
required=True, prompt=False, type=click.Path(exists=True, readable=True),
68-
help='Path to the "development" codebase scan file')
69-
@click.option('-j', '--json',
70-
prompt=False, default='-', type=click.File(mode='wb', lazy=False),
71-
help='Path to the .json output file. Use "-" for on screen display.')
66+
@click.option('--deploy',required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Identify the path to the "deployed" codebase scan file')
67+
@click.option('--develop', required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Path to the "development" codebase scan file')
68+
@click.option('-j', '--json', prompt=False, default='-', type=click.File(mode='wb', lazy=False), help='Path to the .json output file. Use "-" for on screen display.')
7269
@click.help_option('-h', '--help')
73-
@click.option('--version', is_flag=True, is_eager=True, expose_value=False,
74-
callback=print_version, help='Show the version and exit.')
75-
def cli(new, old, json_file):
70+
@click.option('--version', is_flag=True, is_eager=True, expose_value=False, callback=print_version, help='Show the version and exit.')
71+
def cli(deploy, develop, json):
7672
"""
77-
lorem ipsum...
73+
Command to accept location of deploy and develop json, run the tracecode scan and return the expected same paths set.
7874
"""
79-
pass
75+
options = OrderedDict([
76+
('--deploy', deploy),
77+
('--develop', develop),
78+
])
79+
tracecode= TraceCode(deploy, develop, options)
80+
write_json(tracecode, json)
81+

src/tracecode/tracecode.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# http://nexb.com and https://github.com/nexB/tracecode-toolkit/
4+
# The TraceCode software is licensed under the Apache License version 2.0.
5+
# Data generated with TraceCode require an acknowledgment.
6+
# TraceCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# When you publish or redistribute any data created with TraceCode or any TraceCode
16+
# derivative work, you must accompany this data with the following acknowledgment:
17+
#
18+
# Generated with TraceCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
19+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
20+
# TraceCode should be considered or used as legal advice. Consult an Attorney
21+
# for any legal advice.
22+
# TraceCode is a free and open source software analysis tool from nexB Inc. and others.
23+
# Visit https://github.com/nexB/tracecode-toolkit/ for support and download.
24+
#
25+
from __future__ import absolute_import
26+
from __future__ import division

tests/data/cli/empty_develop.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tests/data/cli/expected_empty.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"tracecode_notice": "Generated with TraceCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nTraceCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nTraceCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/tracecode-toolkit/ for support and download.",
3+
"tracecode_errors": [],
4+
"tracecode_result": []
5+
}

tests/test_cli.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,24 @@
3434
import unicodecsv
3535

3636
from commoncode.testcase import FileBasedTesting
37+
from testing_utils import check_json_scan
38+
from testing_utils import run_scan_click
3739

40+
from tracecode import cli
3841

3942
class TestCLI(FileBasedTesting):
4043

4144
test_data_dir = os.path.join(os.path.dirname(__file__), 'data')
4245

43-
def test_cli(self):
44-
pass
46+
def test_cli_with_empty_json(self):
47+
deploy_json = self.get_test_loc('cli/empty_deploy.json')
48+
develop_json = self.get_test_loc('cli/empty_develop.json')
49+
expected_json = self.get_test_loc('cli/expected_empty.json')
50+
51+
result_file = self.get_temp_file('json')
52+
53+
args = ['--deploy', deploy_json, '--develop', develop_json, '-j', result_file]
54+
run_scan_click(args)
55+
56+
check_json_scan(expected_json, result_file, regen=True)
57+

tests/testing_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ def load_json_result_from_string(string, remove_file_date=False):
143143
# clean new headers attributes
144144
streamline_headers(scan_results)
145145

146-
scan_results['deltas'].sort(key=lambda x: x['factors'], reverse=False)
147-
scan_results['deltas'].sort(key=lambda x: x['score'], reverse=True)
148146
return scan_results
149147

150148

0 commit comments

Comments
 (0)