Skip to content

Commit 5d5a1fc

Browse files
committed
#364 Removed the 'about_file_path' column from the inventory output.
Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 289dc8c commit 5d5a1fc

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/attributecode/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
__copyright__ = """
49-
Copyright (c) 2013-2018 nexB Inc and others. All rights reserved.
49+
Copyright (c) 2013-2019 nexB Inc and others. All rights reserved.
5050
Licensed under the Apache License, Version 2.0 (the "License");
5151
you may not use this file except in compliance with the License.
5252
You may obtain a copy of the License at

src/attributecode/model.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ def _validate(self, *args, **kwargs):
428428

429429
name = self.name
430430

431-
# FIXME: Why is the PathField an ordered dict?
431+
# Why is the PathField an ordered dict?
432+
# Ans: The reason why the PathField use an ordered dict is because
433+
# for the FileTextField, the key is used as the path to the file and
434+
# the value is used as the context of the file
432435
# dict of normalized paths to a location or None
433436
paths = OrderedDict()
434437

@@ -692,7 +695,7 @@ class About(object):
692695
about_resource_path_attr = 'about_resource_path'
693696

694697
# Required fields
695-
required_fields = [ABOUT_FILE_PATH_ATTR, 'name']
698+
required_fields = ['name']
696699

697700
def get_required_fields(self):
698701
return [f for f in self.fields if f.required]
@@ -1137,7 +1140,7 @@ def get_field_names(abouts):
11371140
in any object, including custom fields.
11381141
"""
11391142
fields = []
1140-
fields.append(About.ABOUT_FILE_PATH_ATTR)
1143+
# fields.append(About.ABOUT_FILE_PATH_ATTR)
11411144

11421145
standard_fields = About().fields.keys()
11431146
standards = []
@@ -1179,10 +1182,17 @@ def about_object_to_list_of_dictionary(abouts):
11791182
for about in abouts:
11801183
# TODO: this wholeblock should be under sd_dict()
11811184
ad = about.as_dict()
1185+
# Update the 'about_resource' field with the relative path
1186+
# from the output location
11821187
if 'about_file_path' in ad.keys():
11831188
afp = ad['about_file_path']
1184-
afp = '/' + afp if not afp.startswith('/') else afp
1185-
ad['about_file_path'] = afp
1189+
afp_parent = posixpath.dirname(afp)
1190+
afp_parent = '/' + afp_parent if not afp_parent.startswith('/') else afp_parent
1191+
about_resource = ad['about_resource']
1192+
for resource in about_resource:
1193+
updated_about_resource = posixpath.join(afp_parent, resource)
1194+
ad['about_resource'] = OrderedDict([(updated_about_resource, None)])
1195+
del ad['about_file_path']
11861196
serialized.append(ad)
11871197
return serialized
11881198

0 commit comments

Comments
 (0)