@@ -152,18 +152,18 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
152152 else :
153153 inventory = load_json (location )
154154
155- try :
156- arp_list = []
157- errors = []
155+ arp_list = []
156+ errors = []
158157
159- if is_spreadsheet :
160- # Only the .csv and .xlsx may have newline issue
161- stripped_inv = strip_inventory_value (inventory )
162- else :
163- stripped_inv = inventory
158+ if is_spreadsheet :
159+ # Only the .csv and .xlsx may have newline issue
160+ stripped_inv = strip_inventory_value (inventory )
161+ else :
162+ stripped_inv = inventory
164163
165- for component in stripped_inv :
166- if not from_attrib :
164+ for component in stripped_inv :
165+ if not from_attrib :
166+ if 'about_resource' in component :
167167 arp = component ['about_resource' ]
168168 dup_err = check_duplicated_about_resource (arp , arp_list )
169169 if dup_err :
@@ -176,16 +176,11 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
176176 if invalid_about_filename and not invalid_about_filename in errors :
177177 errors .append (invalid_about_filename )
178178
179- newline_in_file_err = check_newline_in_file_field (component )
180- if newline_in_file_err :
181- errors .extend (newline_in_file_err )
179+ newline_in_file_err = check_newline_in_file_field (component )
180+ if newline_in_file_err :
181+ errors .extend (newline_in_file_err )
182182
183- if errors :
184- return errors , abouts
185- except Exception as e :
186- # TODO: why catch ALL Exception
187- msg = "The essential field 'about_resource' is not found in the <input>"
188- errors .append (Error (CRITICAL , msg ))
183+ if errors :
189184 return errors , abouts
190185
191186 custom_fields_list = []
@@ -203,8 +198,8 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
203198 errors .append (Error (CRITICAL , msg ))
204199 return errors , abouts
205200 # Set about file path to '' if no 'about_resource' is provided from
206- # the input for `attrib`
207- if not 'about_resource' in fields :
201+ # the input
202+ if 'about_resource' not in fields :
208203 afp = ''
209204 else :
210205 afp = fields .get (model .About .ABOUT_RESOURCE_ATTR )
@@ -228,11 +223,6 @@ def load_inventory(location, from_attrib=False, base_dir=None, scancode=False, r
228223 updated_resource_value = basename (resource_path )
229224 fields ['about_resource' ] = updated_resource_value
230225
231- # Set 'about_resource' to '.' if no 'about_resource' is provided from
232- # the input for `attrib`
233- elif not 'about_resource' in fields and from_attrib :
234- fields ['about_resource' ] = u'.'
235-
236226 ld_errors = about .load_dict (
237227 fields ,
238228 base_dir ,
@@ -268,7 +258,6 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
268258 Load ABOUT data from a CSV inventory at `location`. Write ABOUT files to
269259 base_dir. Return errors and about objects.
270260 """
271- not_exist_errors = []
272261 notice_dict = {}
273262 api_url = ''
274263 api_key = ''
@@ -294,7 +283,6 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
294283 scancode = scancode ,
295284 worksheet = worksheet
296285 )
297-
298286 if gen_license :
299287 license_dict , err = model .pre_process_and_fetch_license_dict (
300288 abouts , api_url = api_url , api_key = api_key )
@@ -309,6 +297,9 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
309297 about .about_file_path = about .about_file_path .strip ()
310298 if about .about_file_path .startswith ('/' ):
311299 about .about_file_path = about .about_file_path .lstrip ('/' )
300+ # Use the name as the ABOUT file name if about_resource is empty
301+ if not about .about_file_path :
302+ about .about_file_path = about .name .value
312303 dump_loc = join (bdir , about .about_file_path .lstrip ('/' ))
313304
314305 # The following code is to check if there is any directory ends with spaces
@@ -328,30 +319,6 @@ def generate(location, base_dir, android=None, reference_dir=None, fetch_license
328319 continue
329320
330321 try :
331- # Generate value for 'about_resource' if it does not exist
332- if not about .about_resource .value :
333- about .about_resource .value = dict ()
334- about_resource_value = ''
335- if about .about_file_path .endswith ('/' ):
336- about_resource_value = u'.'
337- else :
338- about_resource_value = basename (about .about_file_path )
339- about .about_resource .value [about_resource_value ] = None
340- about .about_resource .present = True
341- # Check for the existence of the 'about_resource'
342- # If the input already have the 'about_resource' field, it will
343- # be validated when creating the about object
344- loc = util .to_posix (dump_loc )
345- about_file_loc = loc
346- path = join (dirname (util .to_posix (about_file_loc )),
347- about_resource_value )
348- if not exists (path ):
349- path = util .to_posix (path .strip (UNC_PREFIX_POSIX ))
350- path = normpath (path )
351- msg = (u'Field about_resource: '
352- u'%(path)s '
353- u'does not exist' % locals ())
354- errors .append (Error (INFO , msg ))
355322
356323 licenses_dict = {}
357324 if gen_license :
0 commit comments