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 :
@@ -108,6 +112,8 @@ def metadata_category(item):
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,23 @@ 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 :
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 :
163
+ license_info = self .analyzer .analyze (local_path )
164
+ license_info .update ({'file_path' : file_path })
165
+ analysis .append (license_info )
166
+ else :
167
+ files_to_process .append ((file_path , local_path ))
168
+
169
+ if files_to_process :
170
+ local_paths = [f [1 ] for f in files_to_process ]
171
+ analysis = self .analyzer .analyze (local_paths )
172
+
173
+ for i in range (len (analysis ['files' ])):
174
+ analysis ['files' ][i ]['file_path' ] = files_to_process [i ][0 ]
154
175
155
176
return analysis
156
177
@@ -176,11 +197,13 @@ class LicenseAnalyzer:
176
197
def __init__ (self , exec_path , kind = NOMOS ):
177
198
if kind == SCANCODE :
178
199
self .analyzer = ScanCode (exec_path )
200
+ elif kind == SCANCODE_CLI :
201
+ self .analyzer = ScanCode (exec_path , cli = True )
179
202
else :
180
203
self .analyzer = Nomos (exec_path )
181
204
182
205
def analyze (self , file_path ):
183
- """Analyze the content of a file using Nomos
206
+ """Analyze the content of a file using Nomos/Scancode
184
207
185
208
:param file_path: file path
186
209
@@ -189,7 +212,7 @@ def analyze(self, file_path):
189
212
'licenses': [..]
190
213
}
191
214
"""
192
- kwargs = {'file_path ' : file_path }
215
+ kwargs = {'file_paths ' : file_path }
193
216
analysis = self .analyzer .analyze (** kwargs )
194
217
195
218
return analysis
0 commit comments