Skip to content

Commit 8bb8468

Browse files
committed
#354 Remove the 'about_resource_path' field
* The key 'about_resource_path' is removed * Updated the required fields to be 'about_resource' and 'name' * Removed some non-use code Signed-off-by: Chin Yeung Li <[email protected]>
1 parent b597273 commit 8bb8468

File tree

23 files changed

+124
-151
lines changed

23 files changed

+124
-151
lines changed

docs/CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* The owner is now a StringField instead of ListField
99
* Format the ordering of the genreated ABOUT file (See https://github.com/nexB/aboutcode-toolkit/issues/349#issuecomment-438871444)
1010
* '+' and '(' and ')' is now supported in license_expression
11+
* The key 'about_resource_path' is removed
12+
* The 2 required fields are 'about_resource' and 'name'
1113

1214
2018-10-23
1315

src/attributecode/cmd.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from attributecode import model
3636
from attributecode import severities
3737
from attributecode.util import extract_zip
38-
from attributecode.util import update_severity_level_about_resource_path_not_exist_error
3938
from attributecode.util import to_posix
4039
from attributecode.util import inventory_filter
4140

@@ -199,14 +198,13 @@ def inventory(location, output, mapping, mapping_file, mapping_output, filter, q
199198
print(msg)
200199

201200
error_count = 0
202-
finalized_errors = update_severity_level_about_resource_path_not_exist_error(errors)
203201

204-
for e in finalized_errors:
202+
for e in errors:
205203
# Only count as warning/error if CRITICAL, ERROR and WARNING
206204
if e.severity > 20:
207205
error_count = error_count + 1
208206

209-
log_errors(finalized_errors, error_count, quiet, verbose, os.path.dirname(output))
207+
log_errors(errors, error_count, quiet, verbose, os.path.dirname(output))
210208
click.echo(' %(error_count)d errors or warnings detected.' % locals())
211209
sys.exit(0)
212210

@@ -283,13 +281,12 @@ def gen(location, output, mapping, mapping_file, license_notice_text_location, f
283281

284282
about_count = len(abouts)
285283
error_count = 0
286-
finalized_errors = update_severity_level_about_resource_path_not_exist_error(errors)
287284

288-
for e in finalized_errors:
285+
for e in errors:
289286
# Only count as warning/error if CRITICAL, ERROR and WARNING
290287
if e.severity > 20:
291288
error_count = error_count + 1
292-
log_errors(finalized_errors, error_count, quiet, verbose, output)
289+
log_errors(errors, error_count, quiet, verbose, output)
293290
click.echo('Generated %(about_count)d .ABOUT files with %(error_count)d errors or warnings' % locals())
294291
sys.exit(0)
295292

@@ -372,14 +369,13 @@ def attrib(location, output, template, mapping, mapping_file, inventory, vartext
372369
inv_errors.append(no_match_error)
373370

374371
error_count = 0
375-
finalized_errors = update_severity_level_about_resource_path_not_exist_error(inv_errors)
376372

377-
for e in finalized_errors:
373+
for e in inv_errors:
378374
# Only count as warning/error if CRITICAL, ERROR and WARNING
379375
if e.severity > 20:
380376
error_count = error_count + 1
381377

382-
log_errors(finalized_errors, error_count, quiet, verbose, os.path.dirname(output))
378+
log_errors(inv_errors, error_count, quiet, verbose, os.path.dirname(output))
383379
click.echo(' %(error_count)d errors or warnings detected.' % locals())
384380
click.echo('Finished.')
385381
sys.exit(0)

src/attributecode/gen.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
from attributecode import ERROR
3535
from attributecode import CRITICAL
36+
from attributecode import INFO
3637
from attributecode import Error
3738
from attributecode import model
3839
from attributecode import util
@@ -244,40 +245,29 @@ def generate(location, base_dir, license_notice_text_location=None,
244245

245246
try:
246247
# Generate value for 'about_resource' if it does not exist
247-
# Note: The `about_resource` is in ListField class
248-
# and `about_resource_path` is in AboutResourceField class
249248
if not about.about_resource.value:
250-
#about.about_resource.value = OrderedDict()
249+
about.about_resource.value = OrderedDict()
250+
about_resource_value = ''
251251
if about.about_file_path.endswith('/'):
252-
about.about_resource.value.append(u'.')
253-
about.about_resource.original_value = u'.'
252+
about_resource_value = u'.'
254253
else:
255-
about.about_resource.value.append(basename(about.about_file_path))
256-
about.about_resource.original_value = basename(about.about_file_path)
254+
about_resource_value = basename(about.about_file_path)
255+
about.about_resource.value[about_resource_value] = None
257256
about.about_resource.present = True
258-
259-
# Generate value for 'about_resource_path' if it does not exist
260-
# Basically, this should be the same as the 'about_resource'
261-
if not about.about_resource_path.value:
262-
about.about_resource_path.value = OrderedDict()
263-
for about_resource_value in about.about_resource.value:
264-
about.about_resource_path.value[about_resource_value] = None
265-
about.about_resource_path.present = True
266-
# Check for the existence of the about_resource
267-
# If the input already have the about_resource_path field, it will
257+
# Check for the existence of the 'about_resource'
258+
# If the input already have the 'about_resource' field, it will
268259
# be validated when creating the about object
269260
loc = util.to_posix(dump_loc)
270261
about_file_loc = loc
271-
for about_resource_value in about.about_resource_path.value:
272-
path = join(dirname(util.to_posix(about_file_loc)),
273-
about_resource_value)
274-
if not exists(path):
275-
path = util.to_posix(path.strip(UNC_PREFIX_POSIX))
276-
path = normpath(path)
277-
msg = (u'Field about_resource_path: '
278-
u'%(path)s '
279-
u'does not exist' % locals())
280-
not_exist_errors.append(msg)
262+
path = join(dirname(util.to_posix(about_file_loc)), about_resource_value)
263+
if not exists(path):
264+
path = util.to_posix(path.strip(UNC_PREFIX_POSIX))
265+
path = normpath(path)
266+
msg = (u'Field about_resource: '
267+
u'%(path)s '
268+
u'does not exist' % locals())
269+
not_exist_errors.append(msg)
270+
281271
if gen_license:
282272
# Write generated LICENSE file
283273
license_key_name_context_url_list = about.dump_lic(dump_loc, license_dict)
@@ -304,7 +294,7 @@ def generate(location, base_dir, license_notice_text_location=None,
304294
# Write the ABOUT files
305295
about.dump(dump_loc, use_mapping=use_mapping, mapping_file=mapping_file, with_empty=with_empty, with_absent=with_absent)
306296
for e in not_exist_errors:
307-
errors.append(Error(ERROR, e))
297+
errors.append(Error(INFO, e))
308298
except Exception as e:
309299
# only keep the first 100 char of the exception
310300
emsg = repr(e)[:100]

src/attributecode/model.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,15 @@ def _validate(self, *args, **kwargs):
455455
if self.license_notice_text_location:
456456
location = posixpath.join(self.license_notice_text_location, path)
457457
else:
458-
# The 'about_resource_path' should be a joined path with
458+
# The 'about_resource' should be a joined path with
459459
# the 'about_file_path' and the 'base_dir
460460
if not self.running_inventory and self.about_file_path:
461461
# Get the parent directory of the 'about_file_path'
462462
afp_parent = posixpath.dirname(self.about_file_path)
463463

464-
# Create a relative 'about_resource_path' by joining the
464+
# Create a relative 'about_resource' path by joining the
465465
# parent of the 'about_file_path' with the value of the
466-
# 'about_resource_path'
466+
# 'about_resource'
467467
arp = posixpath.join(afp_parent, path)
468468
normalized_arp = posixpath.normpath(arp).strip(posixpath.sep)
469469
location = posixpath.join(self.base_dir, normalized_arp)
@@ -480,7 +480,11 @@ def _validate(self, *args, **kwargs):
480480
location = util.to_posix(location.strip(UNC_PREFIX))
481481
msg = (u'Field %(name)s: Path %(location)s not found'
482482
% locals())
483-
errors.append(Error(CRITICAL, msg))
483+
# We want to show INFO error for 'about_resource'
484+
if name == u'about_resource':
485+
errors.append(Error(INFO, msg))
486+
else:
487+
errors.append(Error(CRITICAL, msg))
484488
location = None
485489

486490
paths[path] = location
@@ -702,10 +706,10 @@ def create_fields(self):
702706
is simpler.
703707
"""
704708
self.fields = OrderedDict([
705-
('about_resource', ListField(required=True)),
709+
#('about_resource', ListField(required=True)),
706710
# ('about_resource', AboutResourceField(required=True)),
707-
('name', SingleLineField()),
708-
('about_resource_path', AboutResourceField()),
711+
('about_resource', AboutResourceField(required=True)),
712+
('name', SingleLineField(required=True)),
709713

710714
('version', SingleLineField()),
711715
('download_url', UrlField()),
@@ -870,6 +874,7 @@ def as_dict(self, with_paths=False, with_absent=True, with_empty=True):
870874
afpa = self.about_file_path_attr
871875
as_dict[afpa] = self.about_file_path
872876
arpa = self.about_resource_path_attr
877+
"""
873878
if self.about_resource_path.present:
874879
as_dict[arpa] = self.resolved_resources_paths()
875880
else:
@@ -890,6 +895,7 @@ def as_dict(self, with_paths=False, with_absent=True, with_empty=True):
890895
key = u''
891896
arp[key] = None
892897
as_dict[arpa] = arp
898+
"""
893899

894900
for field in self.all_fields(with_absent=with_absent,
895901
with_empty=with_empty):
@@ -1035,12 +1041,12 @@ def load(self, location, use_mapping=False, mapping_file=None):
10351041
yaml.load(input_text, Loader=util.NoDuplicateLoader)
10361042
"""
10371043
The running_inventory defines if the current process is 'inventory' or not.
1038-
This is used for the validation of the about_resource_path.
1044+
This is used for the validation of the path of the 'about_resource'.
10391045
In the 'inventory' command, the code will use the parent of the about_file_path
1040-
location and join with the 'about_resource_path' for the validation.
1046+
location and join with the 'about_resource' for the validation.
10411047
On the other hand, in the 'gen' command, the code will use the
10421048
generated location (aka base_dir) along with the parent of the about_file_path
1043-
and then join with the 'about_resource_path'
1049+
and then join with the 'about_resource'
10441050
"""
10451051
running_inventory = True
10461052
# wrap the value of the boolean field in quote to avoid
@@ -1103,7 +1109,7 @@ def dumps(self, use_mapping=False, mapping_file=False, with_absent=False, with_e
11031109
license_name = []
11041110
license_file = []
11051111
license_url = []
1106-
file_fields = ['about_resource_path', 'notice_file', 'changelog_file', 'author_file']
1112+
file_fields = ['about_resource', 'notice_file', 'changelog_file', 'author_file']
11071113
bool_fields = ['redistribute', 'attribute', 'track_changes', 'modified']
11081114
for field in self.all_fields(with_absent, with_empty):
11091115
if field.name == 'license_key' and field.value:
@@ -1114,11 +1120,9 @@ def dumps(self, use_mapping=False, mapping_file=False, with_absent=False, with_e
11141120
license_file = field.value.keys()
11151121
elif field.name == 'license_url' and field.value:
11161122
license_url = field.value
1117-
# No multiple 'about_resource' and 'about_resource_path' reference supported.
1123+
# No multiple 'about_resource' reference supported.
11181124
# Take the first element (should only be one) in the list for the
1119-
# value of 'about_resource' and 'about_resource_path'
1120-
elif field.name == 'about_resource' and field.value:
1121-
about_data[field.name] = field.value[0]
1125+
# value of 'about_resource'
11221126
elif field.name in file_fields and field.value:
11231127
about_data[field.name] = list(field.value.keys())[0]
11241128
else:
@@ -1373,8 +1377,6 @@ def about_object_to_list_of_dictionary(abouts, with_absent=False, with_empty=Tru
13731377
afp = ad['about_file_path']
13741378
afp = '/' + afp if not afp.startswith('/') else afp
13751379
ad['about_file_path'] = afp
1376-
if not 'about_resource_path' in ad.keys():
1377-
arp = ad['about_resource_path']
13781380
abouts_dictionary_list.append(ad)
13791381
return abouts_dictionary_list
13801382

src/attributecode/util.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -656,19 +656,6 @@ def copy_license_notice_files(fields, base_dir, license_notice_text_location, af
656656
print(repr(e))
657657
print('Cannot copy file at %(from_lic_path)r.' % locals())
658658

659-
660-
def update_severity_level_about_resource_path_not_exist_error(errors):
661-
ignore_resource_path_check_message = u'Field about_resource_path:'
662-
updated_errors = []
663-
for err in errors:
664-
if ignore_resource_path_check_message in err.message:
665-
updated_errors.append(Error(INFO, err.message))
666-
#continue
667-
else:
668-
updated_errors.append(err)
669-
return updated_errors
670-
671-
672659
def inventory_filter(abouts, filter_dict):
673660
updated_abouts = []
674661
for key in filter_dict:
@@ -743,7 +730,7 @@ def format_about_dict_for_csv_output(about_dictionary_list):
743730
if element[key]:
744731
if isinstance(element[key], list):
745732
row_list[key] = u'\n'.join((element[key]))
746-
elif key == u'about_resource_path' or key in file_fields:
733+
elif key == u'about_resource' or key in file_fields:
747734
row_list[key] = u'\n'.join((element[key].keys()))
748735
else:
749736
row_list[key] = element[key]
@@ -763,10 +750,12 @@ def format_about_dict_for_json_output(about_dictionary_list):
763750
license_url = []
764751
for key in element:
765752
if element[key]:
753+
"""
766754
if key == u'about_resource':
767755
row_list[key] = element[key][0]
768-
# The 'about_resource_path' is an ordered dict
769-
elif key == u'about_resource_path':
756+
"""
757+
# The 'about_resource' is an ordered dict
758+
if key == u'about_resource':
770759
row_list[key] = list(element[key].keys())[0]
771760
elif key in licenses:
772761
if key == 'license_key':

0 commit comments

Comments
 (0)