@@ -94,12 +94,12 @@ def check_newline_in_file_field(component):
94
94
if k in file_fields :
95
95
try :
96
96
if '\n ' in component [k ]:
97
- if k == u'about_resource' :
98
- msg = (
99
- "Multiple lines detected in 'about_resource' for '%s' which is not supported." ) % component ['about_resource' ]
100
- else :
101
- msg = ("New line character detected in '%s' for '%s' which is not supported."
102
- "\n Please use ',' to declare multiple files." ) % (k , component ['about_resource' ])
97
+ # if k == u'about_resource':
98
+ # msg = (
99
+ # "Multiple lines detected in 'about_resource' for '%s' which is not supported.") % component['about_resource']
100
+ # else:
101
+ msg = ("New line character detected in '%s' for '%s' which is not supported."
102
+ "\n Please use ',' to declare multiple files." ) % (k , component ['about_resource' ])
103
103
errors .append (Error (CRITICAL , msg ))
104
104
except :
105
105
pass
@@ -123,9 +123,6 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
123
123
Load the inventory file at `location` for ABOUT and LICENSE files stored in
124
124
the `base_dir`. Return a list of errors and a list of About objects
125
125
validated against the `base_dir`.
126
-
127
- Optionally use `reference_dir` as the directory location of extra reference
128
- license and notice files to reuse.
129
126
"""
130
127
errors = []
131
128
abouts = []
@@ -164,21 +161,37 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
164
161
for component in stripped_inv :
165
162
if not from_attrib :
166
163
if 'about_resource' in component :
167
- arp = component ['about_resource' ]
168
- dup_err = check_duplicated_about_resource (arp , arp_list )
169
- if dup_err :
170
- if not dup_err in errors :
171
- errors .append (dup_err )
172
- else :
173
- arp_list .append (arp )
174
-
175
- invalid_about_filename = check_about_resource_filename (arp )
176
- if invalid_about_filename and not invalid_about_filename in errors :
177
- errors .append (invalid_about_filename )
164
+ if isinstance (component ['about_resource' ], str ):
165
+ arp = component ['about_resource' ]
166
+ dup_err = check_duplicated_about_resource (arp , arp_list )
167
+ if dup_err :
168
+ if dup_err not in errors :
169
+ errors .append (dup_err )
170
+ else :
171
+ arp_list .append (arp )
178
172
173
+ invalid_about_filename = check_about_resource_filename (arp )
174
+ if invalid_about_filename and invalid_about_filename not in errors :
175
+ errors .append (invalid_about_filename )
176
+ else :
177
+ for arp in component ['about_resource' ]:
178
+ dup_err = check_duplicated_about_resource (
179
+ arp , arp_list )
180
+ if dup_err :
181
+ if dup_err not in errors :
182
+ errors .append (dup_err )
183
+ else :
184
+ arp_list .append (arp )
185
+
186
+ invalid_about_filename = check_about_resource_filename (
187
+ arp )
188
+ if invalid_about_filename and invalid_about_filename not in errors :
189
+ errors .append (invalid_about_filename )
190
+ """
179
191
newline_in_file_err = check_newline_in_file_field(component)
180
192
if newline_in_file_err:
181
193
errors.extend(newline_in_file_err)
194
+ """
182
195
183
196
if errors :
184
197
return errors , abouts
@@ -197,50 +210,27 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
197
210
)
198
211
errors .append (Error (CRITICAL , msg ))
199
212
return errors , abouts
213
+
200
214
# Set about file path to '' if no 'about_resource' is provided from
201
215
# the input
202
216
if 'about_resource' not in fields :
203
217
afp = ''
218
+ about , custom_fields_list , process_errors = process_inventory (afp , fields ,
219
+ from_attrib , base_dir , scancode , reference_dir )
220
+ abouts .append (about )
204
221
else :
205
- afp = fields .get (model .About .ABOUT_RESOURCE_ATTR )
206
-
207
- afp = util .to_posix (afp )
208
- if base_dir :
209
- loc = join (base_dir , afp )
210
- else :
211
- loc = afp
212
- about = model .About (about_file_path = afp )
213
- about .location = loc
214
-
215
- # Update value for 'about_resource'
216
- # keep only the filename or '.' if it's a directory
217
- if 'about_resource' in fields :
218
- updated_resource_value = u''
219
- resource_path = fields ['about_resource' ]
220
- if resource_path .endswith (u'/' ):
221
- updated_resource_value = u'.'
222
- else :
223
- updated_resource_value = basename (resource_path )
224
- fields ['about_resource' ] = updated_resource_value
225
-
226
- ld_errors = about .load_dict (
227
- fields ,
228
- base_dir ,
229
- scancode = scancode ,
230
- from_attrib = from_attrib ,
231
- running_inventory = False ,
232
- reference_dir = reference_dir ,
233
- )
234
-
235
- for severity , message in ld_errors :
236
- if 'Custom Field' in message :
237
- field_name = message .replace ('Custom Field: ' , '' ).strip ()
238
- if not field_name in custom_fields_list :
239
- custom_fields_list .append (field_name )
222
+ if scancode :
223
+ afp_list = [fields .get (model .About .ABOUT_RESOURCE_ATTR )]
240
224
else :
241
- errors .append (Error (severity , message ))
225
+ afp_list = fields .get (model .About .ABOUT_RESOURCE_ATTR )
226
+ for afp in afp_list :
227
+ about , custom_fields_list , process_errors = process_inventory (afp , fields ,
228
+ from_attrib , base_dir , scancode , reference_dir )
229
+ abouts .append (about )
230
+
231
+ for err in process_errors :
232
+ errors .append (err )
242
233
243
- abouts .append (about )
244
234
if custom_fields_list :
245
235
custom_fields_err_msg = 'Field ' + \
246
236
str (custom_fields_list ) + ' is a custom field.'
@@ -249,6 +239,66 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
249
239
return errors , abouts
250
240
251
241
242
+ def process_inventory (about_file_path , fields , from_attrib , base_dir , scancode , reference_dir ):
243
+ """
244
+ Return About object, a list of custom fields and a list of errors and
245
+ validated against the `base_dir`.
246
+
247
+ Optionally use `reference_dir` as the directory location of extra reference
248
+ license and notice files to reuse.
249
+ """
250
+ custom_fields_list = []
251
+ errors = []
252
+ afp = util .to_posix (about_file_path )
253
+ if base_dir :
254
+ loc = join (base_dir , afp )
255
+ else :
256
+ loc = afp
257
+ about = model .About (about_file_path = afp )
258
+ about .location = loc
259
+
260
+ """
261
+ # Update value for 'about_resource'
262
+ # keep only the filename or '.' if it's a directory
263
+ if 'about_resource' in fields:
264
+ updated_resource_list = []
265
+ resource_path_list = fields['about_resource']
266
+ for resource_path in resource_path_list:
267
+ if resource_path.endswith(u'/'):
268
+ updated_resource_list.append('.')
269
+ else:
270
+ updated_resource_list.append(basename(resource_path))
271
+ fields['about_resource'] = updated_resource_list
272
+ """
273
+ if 'about_resource' in fields :
274
+ updated_resource_value = u''
275
+ resource_path = about .about_file_path
276
+ if resource_path .endswith (u'/' ):
277
+ updated_resource_value = u'.'
278
+ else :
279
+ updated_resource_value = basename (resource_path )
280
+ fields ['about_resource' ] = updated_resource_value
281
+
282
+ ld_errors = about .load_dict (
283
+ fields ,
284
+ base_dir ,
285
+ scancode = scancode ,
286
+ from_attrib = from_attrib ,
287
+ running_inventory = False ,
288
+ reference_dir = reference_dir ,
289
+ )
290
+
291
+ for severity , message in ld_errors :
292
+ if 'Custom Field' in message :
293
+ field_name = message .replace ('Custom Field: ' , '' ).strip ()
294
+ if field_name not in custom_fields_list :
295
+ custom_fields_list .append (field_name )
296
+ else :
297
+ errors .append (Error (severity , message ))
298
+
299
+ return about , custom_fields_list , errors
300
+
301
+
252
302
def update_about_resource (self ):
253
303
pass
254
304
@@ -283,6 +333,7 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
283
333
scancode = scancode ,
284
334
worksheet = worksheet
285
335
)
336
+
286
337
if gen_license :
287
338
license_dict , err = model .pre_process_and_fetch_license_dict (
288
339
abouts , api_url = api_url , api_key = api_key )
@@ -297,7 +348,7 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
297
348
about .about_file_path = about .about_file_path .strip ()
298
349
if about .about_file_path .startswith ('/' ):
299
350
about .about_file_path = about .about_file_path .lstrip ('/' )
300
- # Use the name as the ABOUT file name if about_resource is empty
351
+ # Use the name as the ABOUT file name if about_file_path field is empty
301
352
if not about .about_file_path :
302
353
about .about_file_path = about .name .value
303
354
dump_loc = join (bdir , about .about_file_path .lstrip ('/' ))
@@ -319,7 +370,6 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
319
370
continue
320
371
321
372
try :
322
-
323
373
licenses_dict = {}
324
374
if gen_license :
325
375
# Write generated LICENSE file
@@ -344,9 +394,7 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
344
394
about .license_url .present = True
345
395
if about .spdx_license_key .value :
346
396
about .spdx_license_key .present = True
347
-
348
397
about .dump (dump_loc , licenses_dict )
349
-
350
398
if android :
351
399
"""
352
400
Create MODULE_LICENSE_XXX and get context to create NOTICE file
0 commit comments