Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Visit https://aboutcode.org and https://github.com/nexB/ for support and downloa

To install this package use::

pip install commoncode]
pip install commoncode


To set up the development environment::
Expand Down
3 changes: 3 additions & 0 deletions src/commoncode/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,9 @@ class Resource(object):
# external data to serialize
size = attr.ib(default=0, type=int, repr=TRACE)

# fingerprint attribute of the file it may be an optional attribute
fingerprint = attr.ib(default=None)

# These attributes are re/computed for directories and files with children
# they represent are the for the full descendants of a Resource
size_count = attr.ib(default=0, type=int, repr=False)
Expand Down
98 changes: 98 additions & 0 deletions tests/data/resource/virtual_codebase/fingerprint_attribute.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"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.9.0b1.post32.fea65d35a",
"scancode_options": {
"input": "C:\\code\\nexb\\dev\\codebase01\\licenses\\apache_to_all_notable_lic\\apache_to_all_notable_lic_new",
"--copyright": true,
"--info": true,
"--json-pp": "C:\\code\\nexb\\dev\\deltacode\\tests\\data\\deltacode\\apache_to_all_notable_lic_new.json",
"--license": true,
"--package": true
},
"files_count": 2,
"files": [
{
"path": "apache_to_all_notable_lic_new",
"type": "directory",
"name": "apache_to_all_notable_lic_new",
"base_name": "apache_to_all_notable_lic_new",
"extension": "",
"size": 0,
"date": null,
"sha1": null,
"md5": null,
"mime_type": null,
"file_type": null,
"programming_language": null,
"is_binary": false,
"is_text": false,
"is_archive": false,
"is_media": false,
"is_source": false,
"is_script": false,
"licenses": [],
"copyrights": [],
"packages": [],
"files_count": 2,
"dirs_count": 0,
"size_count": 16471,
"scan_errors": []
},
{
"path": "apache_to_all_notable_lic_new/a1.py",
"type": "file",
"name": "a1.py",
"base_name": "a1",
"extension": ".py",
"size": 16271,
"date": "2018-03-16",
"sha1": "535b9966048ad50a9d5eb2f167c0a3013ee5cc6f",
"md5": "e5658fe520bbebaf6f3d4be2e2525ab6",
"fingerprint": "e30cf09443e7878dfed3288886e97542",
"mime_type": "text/plain",
"file_type": "UTF-8 Unicode text, with very long lines, with CRLF line terminators",
"programming_language": "Python",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": true,
"is_script": false,
"licenses": [],
"copyrights": [],
"packages": [],
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
},
{
"path": "apache_to_all_notable_lic_new/a2.py",
"type": "file",
"name": "a2.py",
"base_name": "a2",
"extension": ".py",
"size": 200,
"date": "2017-09-26",
"sha1": "310797523e47db8481aeb06f1634317285115091",
"md5": "19efdad483f68bc9997a5c1f7ba41b26",
"mime_type": "text/plain",
"file_type": "ASCII text, with CRLF line terminators",
"programming_language": "Python",
"is_binary": false,
"is_text": true,
"is_archive": false,
"is_media": false,
"is_source": true,
"is_script": false,
"licenses": [],
"copyrights": [],
"packages": [],
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
"scan_errors": []
}
]
}

8 changes: 8 additions & 0 deletions tests/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -1323,6 +1323,14 @@ def test_VirtualCodebase_create_from_multiple_scans(self):
]
assert expected == results

def test_VirtualCodebase_account_fingerprint_attribute(self):
test_file = self.get_test_loc("resource/virtual_codebase/fingerprint_attribute.json")
codebase = VirtualCodebase(test_file)
resources_fingerprint = [resource.fingerprint for resource in codebase.walk()]
assert "e30cf09443e7878dfed3288886e97542" in resources_fingerprint
assert None in resources_fingerprint
assert resources_fingerprint.count(None) == 2


class TestResource(FileBasedTesting):
test_data_dir = join(dirname(__file__), 'data')
Expand Down