Skip to content

deltacode doesn't support the new json format of scancode over 3.0 #122

Description

@macrovve

When I used the json file generate by scancode 3.0.2, It raise an exception.

$ ./deltacode -n samples/samples.json -o samples/samples-of-scancode-3.0.json -j output.json
Traceback (most recent call last):
  File "/Users/macrovve/Workspace/deltacode-1.0.0/bin/deltacode", line 11, in <module>
    load_entry_point('deltacode', 'console_scripts', 'deltacode')()
  File "/Users/macrovve/Workspace/deltacode-1.0.0/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/src/deltacode/cli.py", line 89, in cli
    deltacode = DeltaCode(new, old, options)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/src/deltacode/__init__.py", line 51, in __init__
    self.old = Scan(old_path)
  File "/Users/macrovve/Workspace/deltacode-1.0.0/src/deltacode/models.py", line 46, in __init__
    if not self.is_valid_scan(path):
  File "/Users/macrovve/Workspace/deltacode-1.0.0/src/deltacode/models.py", line 90, in is_valid_scan
    raise ScanException(msg)
deltacode.models.ScanException: JSON file 'samples/samples-of-scancode-3.0.json' is missing the 'scancode_version' attribute.

And here are the head of two sample file:

# the sample json provide by deltacode
{
  "scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
  "scancode_version": "2.2.1.post259.4c5233dcb",
  "scancode_options": {
    "input": "samples/",
    "--copyright": true,
    "--info": true,
    "--json-pp": "/Users/sesser/Desktop/samples.json",
    "--license": true,
    "--package": true,
    "--processes": "3"
  },
  "files_count": 33,
# new sample json generated by scancode 3.0.2
{
  "headers": [
    {
      "tool_name": "scancode-toolkit",
      "tool_version": "3.0.2",
      "options": {
        "input": "samples/zlib/",
        "--copyright": true,
        "--info": true,
        "--json-pp": "-",
        "--license": true,
        "--package": true,
        "--processes": "3"
      },
      "notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
      "start_timestamp": "2019-04-07T024626.059587",
      "end_timestamp": "2019-04-07T024635.259788",
      "message": null,
      "errors": [],
      "extra_data": {
        "files_count": 16
      }
    }
  ],

And here are the source code. The reason why raise exception is the scancode_version has been change to tool_version in scancode 3.0+.

def is_valid_scan(self, location):
        """
        In conjunction with test_deltacode.py, test the incoming files to
        ensure that they are well-formed JSON and otherwise satisfy the
        requirements to be run in DeltaCode (e.g., ScanCode version, proper
        ScanCode options etc.).
        """
        # TODO: handle this exception during #171
        try:
            scan = json.loads(open(location).read())
        except IOError:
            return

        scan = json.loads(open(location).read())

        if not scan.get('scancode_version'):
            msg = ('JSON file \'' + location + '\' is missing the \'scancode_version\' attribute.')
            raise ScanException(msg)

        if int(scan.get('scancode_version').split('.').pop(0)) < 2:
            msg = ('JSON file \'' + location + '\' was created with an old version of ScanCode.')
            raise ScanException(msg)

        if not scan.get('scancode_options').get('--info'):
            msg = ('JSON file \'' + location + '\' is missing the \'scancode_options/--info\' attribute.')
            raise ScanException(msg)

        return True

but I cannot find #171 information in TODO. it seems easy to fix. Can I work on it?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions