Skip to content

Commit

Permalink
Add is_key_file as a file flag #1180
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Nov 8, 2018
1 parent 940f096 commit 0eaf1aa
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/summarycode/classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ class FileClassifier(PreScanPlugin):
"""
resource_attributes = OrderedDict([
('is_legal',
Boolean(help='True if this file is likely a "legal"-related file such '
'as a COPYING or LICENSE file.')),
Boolean(help='True if this file is likely a "legal", license-related'
'file such as a COPYING or LICENSE file.')),

('is_manifest',
Boolean(help='True if this file is likely a package manifest file such '
Expand All @@ -80,6 +80,10 @@ class FileClassifier(PreScanPlugin):
Boolean(help='True if this file is "top-level" file located either at '
'the root of a package or in a well-known common location.')),

('is_key_file',
Boolean(help='True if this file is "top-level" file and either a '
'legal, readme or manifest file.')),

# ('is_doc',
# Boolean(help='True if this file is likely a documentation file.')),
#
Expand Down Expand Up @@ -183,8 +187,10 @@ def process_codebase(self, codebase, classify, **kwargs):
'/meta-inf/manifest.mf': 'maven',
}


MANIFEST_ENDS = tuple(_MANIFEST_ENDS)


README_STARTS_ENDS = (
'readme',
)
Expand All @@ -200,8 +206,9 @@ def set_classification_flags(resource,
name = resource.name.lower()
path = resource.path.lower()

resource.is_legal = name.startswith(_LEGAL) or name.endswith(_LEGAL)
resource.is_readme = name.startswith(_README) or name.endswith(_README)
resource.is_manifest = path.endswith(_MANIF)

resource.is_legal = is_legal = name.startswith(_LEGAL) or name.endswith(_LEGAL)
resource.is_readme = is_readme = name.startswith(_README) or name.endswith(_README)
resource.is_manifest = is_manifest = path.endswith(_MANIF)
resource.is_key_file = (resource.is_top_level
and (is_readme or is_legal or is_manifest))
return resource
10 changes: 10 additions & 0 deletions tests/summarycode/data/classify/cli.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 8,
"dirs_count": 1,
"size_count": 0,
Expand Down Expand Up @@ -57,6 +58,7 @@
"is_manifest": false,
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -84,6 +86,7 @@
"is_manifest": false,
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -111,6 +114,7 @@
"is_manifest": true,
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -138,6 +142,7 @@
"is_manifest": true,
"is_readme": false,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -165,6 +170,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -192,6 +198,7 @@
"is_manifest": true,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -219,6 +226,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -246,6 +254,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -273,6 +282,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 24,
"dirs_count": 9,
"size_count": 14310,
Expand Down Expand Up @@ -234,6 +235,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 7,
"dirs_count": 1,
"size_count": 4227,
Expand Down Expand Up @@ -264,6 +266,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 7,
"dirs_count": 0,
"size_count": 4227,
Expand Down Expand Up @@ -306,6 +309,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -354,6 +358,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -396,6 +401,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -432,6 +438,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -468,6 +475,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -510,6 +518,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -546,6 +555,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -576,6 +586,7 @@
"is_manifest": false,
"is_readme": true,
"is_top_level": true,
"is_key_file": true,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -606,6 +617,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 3,
"dirs_count": 0,
"size_count": 1896,
Expand Down Expand Up @@ -648,6 +660,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -690,6 +703,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -732,6 +746,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -762,6 +777,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": true,
"is_key_file": false,
"files_count": 13,
"dirs_count": 5,
"size_count": 7951,
Expand Down Expand Up @@ -792,6 +808,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 1,
"dirs_count": 0,
"size_count": 2054,
Expand Down Expand Up @@ -834,6 +851,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -876,6 +894,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -918,6 +937,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -960,6 +980,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -990,6 +1011,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 863,
Expand Down Expand Up @@ -1032,6 +1054,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1074,6 +1097,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1104,6 +1128,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 1,
"dirs_count": 0,
"size_count": 1774,
Expand Down Expand Up @@ -1152,6 +1177,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1182,6 +1208,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 2,
"dirs_count": 0,
"size_count": 353,
Expand Down Expand Up @@ -1224,6 +1251,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1266,6 +1294,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1296,6 +1325,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 1,
"dirs_count": 0,
"size_count": 649,
Expand Down Expand Up @@ -1338,6 +1368,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1380,6 +1411,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1422,6 +1454,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down Expand Up @@ -1464,6 +1497,7 @@
"is_manifest": false,
"is_readme": false,
"is_top_level": false,
"is_key_file": false,
"files_count": 0,
"dirs_count": 0,
"size_count": 0,
Expand Down
Loading

0 comments on commit 0eaf1aa

Please sign in to comment.