Skip to content

Commit 17e060e

Browse files
committed
Fixed #137 - remove the 'about_resource_path' in the generated ABOUT file and keep it in the generated CSV file.
1 parent 2d041b4 commit 17e060e

File tree

5 files changed

+17
-99
lines changed

5 files changed

+17
-99
lines changed

about_code_tool/about.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import csv
3333
from datetime import datetime
3434
from email.parser import HeaderParser
35-
from os.path import basename, dirname, join, realpath
35+
from os.path import basename, dirname, join, normpath, realpath
3636
import errno
3737
import httplib
3838
import logging
@@ -948,6 +948,14 @@ def get_row_data(self, updated_path, custom_keys):
948948
for field in MANDATORY_FIELDS + OPTIONAL_FIELDS:
949949
if field in self.validated_fields:
950950
row += [self.validated_fields[field]]
951+
elif field == 'about_resource_path':
952+
about = self.validated_fields['about_resource']
953+
if about.endswith('.'):
954+
about_resource_path = dirname(updated_path) + '/'
955+
else:
956+
about_resource_path = normpath(join(dirname(updated_path),
957+
about))
958+
row += [about_resource_path]
951959
else:
952960
row += ['']
953961

about_code_tool/genabout.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,6 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
512512
file_location = join(file_location, basename(file_location))
513513
file_location += '.ABOUT'
514514

515-
"""line['about_resource'] = basename(file_location)
516-
if not file_location.startswith('/'):
517-
line['about_resource_path'] = '/' + file_location
518-
else:
519-
line['about_resource_path'] = file_location
520-
# Strip the first '/' for the later 'join'
521-
file_location = file_location.partition('/')[2]
522-
if not file_location.endswith('.ABOUT'):
523-
if file_location.endswith('/'):
524-
file_location = dirname(file_location)
525-
file_location = join(file_location, basename(file_location))
526-
# Since this is referencing everything in the current directory,
527-
# we will use a '.' period to reference it.
528-
line['about_resource'] = '.'
529-
file_location += '.ABOUT'"""
530515
if all_in_one:
531516
# This is to get the filename instead of the file path
532517
file_location = file_location.rpartition('/')[2]
@@ -560,11 +545,9 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
560545
elif action_num == ACTION_REPLACE_THE_ABOUT_FILE_WITH_THE_CURRENT_GENERATED_FILE:
561546
pass
562547

563-
# The following is to ensure about_resource and
564-
# about_resource_path fields are present. If they exist already,
565-
# the code will not changes these.
548+
# The following is to ensure about_resource is present.
549+
# If they exist already, the code will not changes these.
566550
self.update_about_resource(line, about_file_exist)
567-
self.update_about_resource_path(line, about_file_exist)
568551

569552
component_list.append(about_file_location)
570553
component_list.append(line)
@@ -587,23 +570,6 @@ def update_about_resource(self, line, about_file_exist):
587570
else:
588571
line['about_resource'] = basename(about_resource)
589572

590-
def update_about_resource_path(self, line, about_file_exist):
591-
# Check if 'about_resource_path' exist
592-
try:
593-
if line['about_resoure_path']:
594-
if not about_file_exist:
595-
file_path = line['about_file']
596-
if not file_path.startswith('/'):
597-
line['about_resource_path'] = '/' + file_path
598-
else:
599-
line['about_resource_path'] = file_path
600-
except:
601-
file_path = line['about_file']
602-
if not file_path.startswith('/'):
603-
line['about_resource_path'] = '/' + file_path
604-
else:
605-
line['about_resource_path'] = file_path
606-
607573
@staticmethod
608574
def gen_license_list(line):
609575
dje_license_name = line['dje_license_name']

about_code_tool/tests/test_about.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def test_header_row_in_csv_output(self):
115115
'checksum_sha1,checksum_md5,checksum_sha256,dje_component,'
116116
'dje_license,dje_organization,dje_license_name,scm_branch,'
117117
'scm_repository,signature_gpg_file,redistribute_sources,about_format,'
118-
'usage,scm_tool,scm_path,scm_tag,scm_rev,organization,'
118+
'usage,scm_path,scm_tool,scm_rev,scm_tag,organization,'
119119
'warnings,errors')
120120

121121
test_file = 'about_code_tool/tests/testdata/basic'
@@ -678,9 +678,10 @@ def test_get_custom_field_keys(self):
678678
about_file = about.AboutFile(join(TESTDATA_DIR, 'basic/basic.about'))
679679
result = about_file.get_custom_field_keys()
680680
expected = ['scm_branch', 'scm_repository', 'signature_gpg_file',
681-
'redistribute_sources', 'about_format', 'usage',
682-
'scm_tool', 'scm_path', 'scm_tag', 'scm_rev',
683-
'organization']
681+
'redistribute_sources', 'about_format', 'usage',
682+
'scm_path', 'scm_tool', 'scm_rev', 'scm_tag',
683+
'organization']
684+
print(result)
684685
self.assertEqual(result, expected)
685686

686687

about_code_tool/tests/test_genabout.py

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ def test_pre_generation_about_is_dir_exists_action_0(self):
441441
'TESTCASE.ABOUT'),
442442
{'about_file': '/TESTCASE/',
443443
'version': '0.8.1',
444-
'about_resource_path' : '/TESTCASE/',
445444
'about_resource': '.',
446445
'name': 'ABOUT tool'}]]
447446

@@ -479,7 +478,6 @@ def test_pre_generation_about_exists_action_1(self):
479478
expected = [[join(TESTDATA_DIR, 'test_files_for_genabout',
480479
'about.py.ABOUT'),
481480
{'about_file': '/about.py.ABOUT',
482-
'about_resource_path': '/about.py.ABOUT',
483481
'version': '0.8.2',
484482
'about_resource': '.',
485483
'name': 'ABOUT tool'}]]
@@ -503,7 +501,6 @@ def test_pre_generation_about_exists_action_2(self):
503501
'about.py.ABOUT'),
504502
{'about_file': 'about.py.ABOUT',
505503
'name': 'ABOUT tool',
506-
'about_resource_path': '/about.py.ABOUT',
507504
'version': '0.8.1',
508505
'test': 'test sample',
509506
'about_resource': '.'}]]
@@ -527,7 +524,6 @@ def test_pre_generation_about_exists_action_3(self):
527524
'about.py.ABOUT'),
528525
{'about_file': '/about.py.ABOUT',
529526
'version': '0.8.2',
530-
'about_resource_path': '/about.py.ABOUT',
531527
'about_resource': '.',
532528
'name': '',
533529
'test': 'test sample'}]]
@@ -787,57 +783,3 @@ def test_update_about_resource_no_about_file_no_field_isdir(self):
787783
about_file_exist = False
788784
gen.update_about_resource(test_fields, about_file_exist)
789785
self.assertEqual(test_fields, expected)
790-
791-
def test_update_about_resource_path_about_file_field_exist(self):
792-
gen = genabout.GenAbout()
793-
test_fields = {'about_resource_path': '/tmp/test.c',
794-
'about_file': '/tmp/test.c'}
795-
about_file_exist = True
796-
gen.update_about_resource_path(test_fields, about_file_exist)
797-
# FIXME: this will always be true: the test is incorrect
798-
self.assertTrue(test_fields == test_fields, 'The dict should not be changed.')
799-
800-
def test_update_about_resource_path_about_file_field_not_exist_isFile(self):
801-
gen = genabout.GenAbout()
802-
test_fields = {'about_file': '/tmp/test.c'}
803-
expected = {'about_file': '/tmp/test.c',
804-
'about_resource_path': '/tmp/test.c'}
805-
about_file_exist = True
806-
gen.update_about_resource_path(test_fields, about_file_exist)
807-
self.assertEqual(test_fields, expected)
808-
809-
def test_update_about_resource_path_about_file_field_not_exist_isDir(self):
810-
gen = genabout.GenAbout()
811-
test_fields = {'about_file': '/tmp/test/'}
812-
expected = {'about_file': '/tmp/test/',
813-
'about_resource_path': '/tmp/test/'}
814-
about_file_exist = True
815-
gen.update_about_resource_path(test_fields, about_file_exist)
816-
self.assertEqual(test_fields, expected)
817-
818-
def test_update_about_resource_path_no_about_file_field_exist(self):
819-
gen = genabout.GenAbout()
820-
test_fields = {'about_resource_path': '/tmp/test.c',
821-
'about_file': '/tmp/test.c'}
822-
about_file_exist = False
823-
gen.update_about_resource_path(test_fields, about_file_exist)
824-
# FIXME: this will always be true: the test is incorrect
825-
self.assertTrue(test_fields == test_fields, 'The dict should not be changed.')
826-
827-
def test_update_about_resource_path_no_about_file_field_not_exist_isFile(self):
828-
gen = genabout.GenAbout()
829-
test_fields = {'about_file': '/tmp/test.c'}
830-
expected = {'about_file': '/tmp/test.c',
831-
'about_resource_path': '/tmp/test.c'}
832-
about_file_exist = False
833-
gen.update_about_resource_path(test_fields, about_file_exist)
834-
self.assertEqual(test_fields, expected)
835-
836-
def test_update_about_resource_path_no_about_file_field_not_exist_isDir(self):
837-
gen = genabout.GenAbout()
838-
test_fields = {'about_file': '/tmp/test/'}
839-
expected = {'about_file': '/tmp/test/',
840-
'about_resource_path': '/tmp/test/'}
841-
about_file_exist = False
842-
gen.update_about_resource_path(test_fields, about_file_exist)
843-
self.assertEqual(test_fields, expected)

about_code_tool/tests/testdata/basic/basic.about

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
about_resource: .
12
name: optional
23
version: 2.2
34
about_format: 2.0

0 commit comments

Comments
 (0)