Skip to content

Commit 1731a88

Browse files
committed
Add support for 'about_resource_path' #287
* The 'about_resource_path' is a relative path from where the ABOUT file located. * If 'about_resource_path' is not found, the code will create a relative 'about_resource_path'. * If 'about_resource' key is not found in ABOUT files, the 'about_resource_path' will be empty. Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 0796c21 commit 1731a88

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/attributecode/model.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -793,9 +793,22 @@ def as_dict(self, with_paths=False, with_absent=True, with_empty=True):
793793
as_dict = OrderedDict()
794794
if with_paths:
795795
afpa = self.about_file_path_attr
796-
arpa = self.about_resource_path_attr
797796
as_dict[afpa] = self.about_file_path
798-
as_dict[arpa] = self.resolved_resources_paths()
797+
arpa = self.about_resource_path_attr
798+
if self.about_resource_path.present:
799+
as_dict[arpa] = self.resolved_resources_paths()
800+
else:
801+
# Create a relative 'about_resource_path' if user has not defined
802+
if self.about_resource.present:
803+
for resource_name in self.about_resource.value:
804+
if resource_name == '.':
805+
as_dict[arpa] = '.'
806+
else:
807+
as_dict[arpa] = './' + resource_name
808+
# Return an empty 'about_resource_path' if the 'about_resource'
809+
# key is not found
810+
else:
811+
as_dict[arpa] = ''
799812

800813
for field in self.all_fields(with_absent=with_absent,
801814
with_empty=with_empty):
@@ -1233,15 +1246,8 @@ def about_object_to_list_of_dictionary(abouts, with_absent=False, with_empty=Tru
12331246
afp = ad['about_file_path']
12341247
afp = '/' + afp if not afp.startswith('/') else afp
12351248
ad['about_file_path'] = afp
1236-
"""if 'about_resource_path' in ad.keys():
1249+
if not 'about_resource_path' in ad.keys():
12371250
arp = ad['about_resource_path']
1238-
arp = '/' + arp if not arp.startswith('/') else arp
1239-
ad['about_resource_path'] = arp"""
1240-
# Make the 'about_resource_path' endswith '/' if the 'about_resource'
1241-
# reference the current directory
1242-
if 'about_resource' in ad.keys() and ad['about_resource'] == '.':
1243-
if not ad['about_resource_path'].endswith('/'):
1244-
ad['about_resource_path'] += '/'
12451251
abouts_dictionary_list.append(ad)
12461252
return abouts_dictionary_list
12471253

0 commit comments

Comments
 (0)