33
33
34
34
NOMOS = 'nomos'
35
35
SCANCODE = 'scancode'
36
+ SCANCODE_CLI = 'scancode_cli'
36
37
37
38
CATEGORY_COLIC_NOMOS = 'code_license_' + NOMOS
38
39
CATEGORY_COLIC_SCANCODE = 'code_license_' + SCANCODE
40
+ CATEGORY_COLIC_SCANCODE_CLI = 'code_license_' + SCANCODE_CLI
39
41
40
42
logger = logging .getLogger (__name__ )
41
43
@@ -44,7 +46,7 @@ class CoLic(Graal):
44
46
"""CoLic backend.
45
47
46
48
This class extends the Graal backend. It gathers license information
47
- using Nomos
49
+ using Nomos, Scancode or Scancode-cli
48
50
49
51
:param uri: URI of the Git repository
50
52
:param git_path: path to the repository or to the log file
@@ -59,9 +61,9 @@ class CoLic(Graal):
59
61
:raises RepositoryError: raised when there was an error cloning or
60
62
updating the repository.
61
63
"""
62
- version = '0.4 .0'
64
+ version = '0.5 .0'
63
65
64
- CATEGORIES = [CATEGORY_COLIC_NOMOS , CATEGORY_COLIC_SCANCODE ]
66
+ CATEGORIES = [CATEGORY_COLIC_NOMOS , CATEGORY_COLIC_SCANCODE , CATEGORY_COLIC_SCANCODE_CLI ]
65
67
66
68
def __init__ (self , uri , git_path , exec_path , worktreepath = DEFAULT_WORKTREE_PATH ,
67
69
entrypoint = None , in_paths = None , out_paths = None ,
@@ -84,6 +86,8 @@ def fetch(self, category=CATEGORY_COLIC_NOMOS, paths=None,
84
86
85
87
if category == CATEGORY_COLIC_SCANCODE :
86
88
self .analyzer_kind = SCANCODE
89
+ elif category == CATEGORY_COLIC_SCANCODE_CLI :
90
+ self .analyzer_kind = SCANCODE_CLI
87
91
elif category == CATEGORY_COLIC_NOMOS :
88
92
self .analyzer_kind = NOMOS
89
93
else :
@@ -101,13 +105,15 @@ def fetch(self, category=CATEGORY_COLIC_NOMOS, paths=None,
101
105
def metadata_category (item ):
102
106
"""Extracts the category from a Code item.
103
107
104
- This backend generates two types of item which can be :
105
- 'code_license_nomos' or 'code_license_scancode'.
108
+ This backend generates the following types of item:
109
+ 'code_license_nomos', 'code_license_scancode' or 'code_license_scancode_cli .
106
110
"""
107
111
if item ['analyzer' ] == NOMOS :
108
112
return CATEGORY_COLIC_NOMOS
109
113
elif item ['analyzer' ] == SCANCODE :
110
114
return CATEGORY_COLIC_SCANCODE
115
+ elif item ['analyzer' ] == SCANCODE_CLI :
116
+ return CATEGORY_COLIC_SCANCODE_CLI
111
117
else :
112
118
raise GraalError (cause = "Unknown analyzer %s" % item ['analyzer' ])
113
119
@@ -135,6 +141,7 @@ def _analyze(self, commit):
135
141
:param commit: a Perceval commit item
136
142
"""
137
143
analysis = []
144
+ files_to_process = []
138
145
139
146
for committed_file in commit ['files' ]:
140
147
@@ -148,9 +155,18 @@ def _analyze(self, commit):
148
155
if not GraalRepository .exists (local_path ):
149
156
continue
150
157
151
- license_info = self .analyzer .analyze (local_path )
152
- license_info .update ({'file_path' : file_path })
153
- analysis .append (license_info )
158
+ if self .analyzer_kind == NOMOS or self .analyzer_kind == SCANCODE :
159
+ license_info = self .analyzer .analyze (local_path )
160
+ license_info .update ({'file_path' : file_path })
161
+ analysis .append (license_info )
162
+ elif self .analyzer_kind == SCANCODE_CLI :
163
+ files_to_process .append ((file_path , local_path ))
164
+
165
+ if files_to_process :
166
+ local_paths = [path [1 ] for path in files_to_process ]
167
+ analysis = self .analyzer .analyze (local_paths )
168
+ for i in range (len (analysis ['files' ])):
169
+ analysis ['files' ][i ]['file_path' ] = files_to_process [i ][0 ]
154
170
155
171
return analysis
156
172
@@ -170,17 +186,20 @@ class LicenseAnalyzer:
170
186
"""Class to analyse the content of files
171
187
172
188
:param exec_path: path of the license analyzer executable
173
- :param kind: the analyzer kind (e.g., NOMOS, SCANCODE)
189
+ :param kind: the analyzer kind (e.g., NOMOS, SCANCODE, SCANCODE_CLI )
174
190
"""
175
191
176
192
def __init__ (self , exec_path , kind = NOMOS ):
193
+ self .kind = kind
177
194
if kind == SCANCODE :
178
195
self .analyzer = ScanCode (exec_path )
196
+ elif kind == SCANCODE_CLI :
197
+ self .analyzer = ScanCode (exec_path , cli = True )
179
198
else :
180
199
self .analyzer = Nomos (exec_path )
181
200
182
201
def analyze (self , file_path ):
183
- """Analyze the content of a file using Nomos
202
+ """Analyze the content of a file using Nomos/Scancode
184
203
185
204
:param file_path: file path
186
205
@@ -189,7 +208,11 @@ def analyze(self, file_path):
189
208
'licenses': [..]
190
209
}
191
210
"""
192
- kwargs = {'file_path' : file_path }
211
+ if self .kind == SCANCODE_CLI :
212
+ kwargs = {'file_paths' : file_path }
213
+ else :
214
+ kwargs = {'file_path' : file_path }
215
+
193
216
analysis = self .analyzer .analyze (** kwargs )
194
217
195
218
return analysis
0 commit comments