-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from fossology/feat/nirjas/update-interface
feat(nirjas): Update interface with Nirjas 0.0.5 Reviewed-By: [email protected] Tested-By: [email protected]
- Loading branch information
Showing
4 changed files
with
58 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,65 +20,69 @@ | |
""" | ||
|
||
import argparse | ||
from nirjas import extract | ||
import json | ||
import os | ||
import sys | ||
import re | ||
import string | ||
import tempfile | ||
|
||
from nirjas import extract as commentExtract, LanguageMapper | ||
|
||
__author__ = "Aman Jain" | ||
__email__ = "[email protected]" | ||
|
||
args = None | ||
|
||
def licenseComment(data): | ||
list = ['source', 'free', 'under','use', 'copyright', 'grant', 'software', 'license','licence', 'agreement', 'distribute', 'redistribution', 'liability', 'rights', 'reserved', 'general', 'public', 'modify', 'modified', 'modification', 'permission','permitted' 'granted', 'distributed', 'notice', 'distribution', 'terms', 'freely', 'licensed', 'merchantibility','redistributed', 'see', 'read', '(c)', 'copying', 'legal', 'licensing', 'spdx'] | ||
|
||
MLmapCount, CSLmapCount, SLmapCount = [], [], [] | ||
comment = "" | ||
tempCount = 0 | ||
for id, item in enumerate(data[0]["multi_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
|
||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
if "cont_single_line_comment" in data[0]: | ||
for id, item in enumerate(data[0]["cont_single_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
if "single_line_comment" in data[0]: | ||
for id, item in enumerate(data[0]["single_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
return comment | ||
match_list = ['source', 'free', 'under','use', 'copyright', 'grant', 'software', 'license','licence', 'agreement', 'distribute', 'redistribution', 'liability', 'rights', 'reserved', 'general', 'public', 'modify', 'modified', 'modification', 'permission','permitted' 'granted', 'distributed', 'notice', 'distribution', 'terms', 'freely', 'licensed', 'merchantibility','redistributed', 'see', 'read', '(c)', 'copying', 'legal', 'licensing', 'spdx'] | ||
|
||
MLmapCount, CSLmapCount, SLmapCount = [], [], [] | ||
comment = "" | ||
tempCount = 0 | ||
if "multi_line_comment" in data: | ||
for id, item in enumerate(data["multi_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in match_list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
|
||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
if "cont_single_line_comment" in data: | ||
for id, item in enumerate(data["cont_single_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in match_list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
|
||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
if "single_line_comment" in data: | ||
for id, item in enumerate(data["single_line_comment"]): | ||
count = 0 | ||
if 'spdx-license-identifier' in item['comment'].lower(): | ||
return item['comment'] | ||
|
||
for i in match_list: | ||
if i in item['comment'].lower(): | ||
count+=1 | ||
|
||
if count > tempCount: | ||
tempCount = count | ||
comment = item['comment'] | ||
|
||
return comment | ||
|
||
|
||
class CommentPreprocessor(object): | ||
|
@@ -114,17 +118,15 @@ def extract(inputFile): | |
:return: Temp file path from the OS | ||
''' | ||
|
||
supportedFileExtensions = ['.py','.m4','.nsi','.c','.h','.cs','.cpp','.sep','.hxx','.cc','.css','.go','.hs','.html', | ||
'.xml','.java','.js','.kt','.kts','.ktm','.m','.php','.pl','.r','.R','.rb','.rs','.sh','.swift','.scala', | ||
'.sc','.txt','.lic','.install','.OSS','.gl'] | ||
|
||
supportedFileExtensions = list(LanguageMapper.LANG_MAP.keys()) | ||
|
||
fd, outputFile = tempfile.mkstemp() | ||
fileType = os.path.splitext(inputFile)[1] | ||
|
||
with open(outputFile, 'w') as outFile: | ||
# if the file extension is supported | ||
if fileType in supportedFileExtensions: | ||
data_file = extract(inputFile) | ||
data_file = commentExtract(inputFile) | ||
data = json.loads(data_file) | ||
data1 = licenseComment(data) | ||
outFile.write(data1) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters