Skip to content

Commit bff1878

Browse files
committed
Merge branch 'develop' into pep8
2 parents 79d789e + a6a939b commit bff1878

File tree

5 files changed

+193
-38
lines changed

5 files changed

+193
-38
lines changed

about_code_tool/MAPPING.CONFIG

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,15 @@
2121
# Assuming your input have columns "Resource", "Component", "file_name", "file_version"
2222
# One should do:
2323
#
24-
# about_resource: file_name
2524
# about_file: Resource
2625
# name: Component
2726
# version: file_version
2827
#
2928
# See http://www.dejacode.org/about_spec_v0.8.1.html for more information
3029

3130
# Essential Fields
32-
about_resource: file_name
3331
about_file: Directory/Filename
3432

35-
3633
# Mandatory Fields
3734
name: Component
3835
version: Confirmed Version

about_code_tool/about.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,16 @@ def repr_problem(obj):
9393

9494

9595
MANDATORY_FIELDS = (
96-
'about_resource',
96+
#'about_resource',
97+
#'about_file',
9798
'name',
9899
'version',
99100
)
100101

101102

102103
BASIC_FIELDS = (
104+
'about_resource',
105+
'about_resource_path', # Need to update spec
103106
'spec_version',
104107
'date',
105108
'description',

about_code_tool/genabout.py

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from collections import namedtuple
2525
from os import makedirs
26-
from os.path import exists, dirname, join, abspath, isdir, normpath
26+
from os.path import exists, dirname, join, abspath, isdir, normpath, basename
2727

2828
import about
2929

@@ -54,7 +54,7 @@
5454
logger.addHandler(handler)
5555
file_logger = logging.getLogger(__name__+'_file')
5656

57-
ESSENTIAL_FIELDS = ('about_file', 'about_resource',)
57+
ESSENTIAL_FIELDS = ('about_file',)
5858

5959
# The 'dje_license_key' will be removed and will use the 'dje_license' instead.
6060
SUPPORTED_FIELDS = about.OPTIONAL_FIELDS + about.MANDATORY_FIELDS + \
@@ -172,7 +172,7 @@ def validate_value_in_essential_fields(input_list):
172172
def validate_duplication(input_list):
173173
check_duplication = []
174174
for line in input_list:
175-
component = line['about_file'] + line['about_resource']
175+
component = line['about_file']
176176
if component in check_duplication:
177177
return True
178178
check_duplication.append(component)
@@ -453,27 +453,44 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
453453
for line in input_list:
454454
component_list = []
455455
file_location = line['about_file']
456+
# TODO: The following few line of code seems to change the value
457+
# without checking the action num which is incorrect.
458+
# Get the filename from the file_location and put it as the
459+
# value for 'about_resource'
460+
456461
if file_location.startswith('/'):
457462
file_location = file_location.partition('/')[2]
458463
if not file_location.endswith('.ABOUT'):
459464
if file_location.endswith('/'):
460465
file_location = dirname(file_location)
461-
file_location = join(file_location, os.path.basename(file_location))
466+
file_location = join(file_location, basename(file_location))
467+
file_location += '.ABOUT'
468+
469+
"""line['about_resource'] = basename(file_location)
470+
if not file_location.startswith('/'):
471+
line['about_resource_path'] = '/' + file_location
472+
else:
473+
line['about_resource_path'] = file_location
474+
# Strip the first '/' for the later 'join'
475+
file_location = file_location.partition('/')[2]
476+
if not file_location.endswith('.ABOUT'):
477+
if file_location.endswith('/'):
478+
file_location = dirname(file_location)
479+
file_location = join(file_location, basename(file_location))
462480
# Since this is referencing everything in the current directory,
463481
# we will use a '.' period to reference it.
464482
line['about_resource'] = '.'
465-
file_location += '.ABOUT'
483+
file_location += '.ABOUT'"""
466484
if all_in_one:
467485
# This is to get the filename instead of the file path
468486
file_location = file_location.rpartition('/')[2]
469487
about_file_location = join(gen_location, file_location)
470-
if not file_location.startswith('/'):
471-
line['about_resource_path'] = '/'
472-
line['about_resource_path'] += file_location
473488
dir = dirname(about_file_location)
474489
if not _exists(dir):
475490
makedirs(dir)
491+
about_file_exist = False
476492
if _exists(about_file_location):
493+
about_file_exist = True
477494
if action_num == 0:
478495
about_exist = "ABOUT file already existed. Generation is skipped."
479496
self.warnings.append(Warn('about_file', about_file_location, about_exist))
@@ -491,13 +508,54 @@ def pre_generation(self, gen_location, input_list, action_num, all_in_one):
491508
for field_name, value in about_object.parsed.items():
492509
field_name = field_name.lower()
493510
line[field_name] = value
494-
# We don't need to do anything for the action_num = 3 as
495-
# the original ABOUT file will be replaced in the write_output()
511+
# We do not need to do anything if action_num is 3 as the
512+
# original ABOUT file will be replaced in the write_output()
513+
elif action_num == 3:
514+
pass
515+
# The following is to ensure the 'about_resource' and
516+
# 'about_resource_path' present. If those are existed already,
517+
# the code will not touch it.
518+
self.update_about_resource(line, about_file_exist)
519+
self.update_about_resource_path(line, about_file_exist)
520+
496521
component_list.append(about_file_location)
497522
component_list.append(line)
498523
output_list.append(component_list)
499524
return output_list
500525

526+
def update_about_resource(self, line, about_file_exist):
527+
# Check is 'about_resource' exist
528+
try:
529+
if line['about_resource']:
530+
if not about_file_exist:
531+
about_resource = line['about_file']
532+
if about_resource.endswith('/'):
533+
line['about_resource'] = '.'
534+
except:
535+
# Add the 'about_resource' field
536+
about_resource = line['about_file']
537+
if about_resource.endswith('/'):
538+
line['about_resource'] = '.'
539+
else:
540+
line['about_resource'] = basename(about_resource)
541+
542+
def update_about_resource_path(self, line, about_file_exist):
543+
# Check is 'about_resource_path' exist
544+
try:
545+
if line['about_resoure_path']:
546+
if not about_file_exist:
547+
file_path = line['about_file']
548+
if not file_path.startswith('/'):
549+
line['about_resource_path'] = '/' + file_path
550+
else:
551+
line['about_resource_path'] = file_path
552+
except:
553+
file_path = line['about_file']
554+
if not file_path.startswith('/'):
555+
line['about_resource_path'] = '/' + file_path
556+
else:
557+
line['about_resource_path'] = file_path
558+
501559
@staticmethod
502560
def gen_license_list(line):
503561
dje_license_name = line['dje_license_name']
@@ -527,7 +585,8 @@ def format_output(input_list):
527585
# The purpose of the replace('\n', '\n ') is used to
528586
# format the continuation strings
529587
value = about_dict_list[item].replace('\n', '\n ')
530-
if (value or item in about.MANDATORY_FIELDS) and not item in about.ERROR_WARN_FIELDS:
588+
if (value or item in about.MANDATORY_FIELDS) and not item\
589+
in about.ERROR_WARN_FIELDS and not item == 'about_resource':
531590
context += item + ': ' + value + '\n'
532591

533592
component.append(about_file_location)

about_code_tool/tests/test_about.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ def test_return_path_is_not_abspath_and_contains_subdirs_on_dir(self):
8484
self.assertTrue(f.read().partition('\n')[2].startswith(expected))
8585

8686
def test_header_row_in_csv_output(self):
87-
expected_header = 'about_file,about_resource,name,version,' \
88-
'spec_version,date,description,description_file,home_url,' \
89-
'download_url,readme,readme_file,install,install_file,changelog,' \
90-
'changelog_file,news,news_file,news_url,notes,notes_file,contact,' \
91-
'owner,author,author_file,copyright,copyright_file,notice,' \
92-
'notice_file,notice_url,license_text,license_text_file,license_url,' \
93-
'license_spdx,redistribute,attribute,track_changes,vcs_tool,' \
94-
'vcs_repository,vcs_path,vcs_tag,vcs_branch,vcs_revision,' \
95-
'checksum_sha1,checksum_md5,checksum_sha256,dje_component,' \
87+
expected_header = 'about_file,name,version,about_resource,'\
88+
'about_resource_path,spec_version,date,description,description_file,'\
89+
'home_url,download_url,readme,readme_file,install,install_file,changelog,'\
90+
'changelog_file,news,news_file,news_url,notes,notes_file,contact,'\
91+
'owner,author,author_file,copyright,copyright_file,notice,'\
92+
'notice_file,notice_url,license_text,license_text_file,license_url,'\
93+
'license_spdx,redistribute,attribute,track_changes,vcs_tool,'\
94+
'vcs_repository,vcs_path,vcs_tag,vcs_branch,vcs_revision,'\
95+
'checksum_sha1,checksum_md5,checksum_sha256,dje_component,'\
9696
'dje_license,dje_organization,dje_license_name,warnings,errors'
9797

9898
input = "about_code_tool/tests/testdata/basic"
@@ -323,11 +323,12 @@ def test_validate_about_ref_testing_the_about_resource_field_is_present(self):
323323

324324
def test_validate_about_ref_no_about_ref_key(self):
325325
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/.ABOUT'))
326-
expected_errors = [about.VALUE, 'about_resource']
327-
self.assertTrue(len(about_file.errors) == 1, "This should throw 1 error")
328-
for w in about_file.errors:
326+
# We do not need 'about_resource' now, so no error should be thrown.
327+
# expected_errors = [about.VALUE, 'about_resource']
328+
self.assertTrue(len(about_file.errors) == 0, "No error should be thrown.")
329+
"""for w in about_file.errors:
329330
self.assertEqual(expected_errors[0], w.code)
330-
self.assertEqual(expected_errors[1], w.field_name)
331+
self.assertEqual(expected_errors[1], w.field_name)"""
331332

332333
def test_validate_about_resource_error_thrown_when_file_referenced_by_about_file_does_not_exist(self):
333334
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/missing_about_ref.ABOUT'))
@@ -339,19 +340,17 @@ def test_validate_about_resource_error_thrown_when_file_referenced_by_about_file
339340

340341
def test_validate_mand_fields_name_and_version_and_about_resource_present(self):
341342
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/missing_mand.ABOUT'))
342-
expected_errors = [(about.VALUE, 'about_resource'),
343-
(about.VALUE, 'name'),
343+
expected_errors = [(about.VALUE, 'name'),
344344
(about.VALUE, 'version'), ]
345-
self.assertTrue(len(about_file.errors) == 3, "This should throw 3 errors")
345+
self.assertTrue(len(about_file.errors) == 2, "This should throw 2 errors.")
346346
for i, w in enumerate(about_file.errors):
347347
self.assertEqual(expected_errors[i][0], w.code)
348348
self.assertEqual(expected_errors[i][1], w.field_name)
349349

350350
about_file = about.AboutFile(join(TESTDATA_PATH, 'parser_tests/missing_mand_values.ABOUT'))
351351
expected_errors = [(about.VALUE, 'name'),
352-
(about.VALUE, 'version'),
353-
(about.VALUE, 'about_resource')]
354-
self.assertTrue(len(about_file.errors) == 3, "This should throw 3 errors")
352+
(about.VALUE, 'version')]
353+
self.assertTrue(len(about_file.errors) == 2, "This should throw 2 errors.")
355354
for i, w in enumerate(about_file.errors):
356355
self.assertEqual(expected_errors[i][0], w.code)
357356
self.assertEqual(expected_errors[i][1], w.field_name)

about_code_tool/tests/test_genabout.py

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def test_get_mapping_list(self):
6363
gen = genabout.GenAbout()
6464
expected_list = {'about_file': 'directory/filename',
6565
'version': 'confirmed version',
66-
'about_resource': 'file_name',
6766
'name': 'component',
6867
'copyright': 'confirmed copyright'}
6968
output = gen.get_mapping_list()
@@ -93,7 +92,9 @@ def test_validate_value_in_essential_missing_about_resource(self):
9392
gen = genabout.GenAbout()
9493
input = [{'about_file': '/about.ABOUT', 'about_resource': '',
9594
'name': 'ABOUT tool', 'version': '0.8.1'}]
96-
self.assertFalse(gen.validate_value_in_essential_fields(input))
95+
#self.assertFalse(gen.validate_value_in_essential_fields(input))
96+
# This is now true as it doesn't depends on about_resource now
97+
self.assertTrue(gen.validate_value_in_essential_fields(input))
9798

9899
def test_validate_value_in_essential_missing_all(self):
99100
gen = genabout.GenAbout()
@@ -151,7 +152,9 @@ def test_validate_mandatory_fields_missing_about_resource(self):
151152
gen = genabout.GenAbout()
152153
input_list = [{'about_file': '/about.ABOUT', 'name': 'ABOUT tool',
153154
'version': '0.8.1'}]
154-
self.assertFalse(gen.validate_mandatory_fields(input_list))
155+
#self.assertFalse(gen.validate_mandatory_fields(input_list))
156+
# This is now True as it doesn't need about_resource
157+
self.assertTrue(gen.validate_mandatory_fields(input_list))
155158

156159
def test_get_non_supported_fields(self):
157160
gen = genabout.GenAbout()
@@ -299,7 +302,7 @@ def test_pre_generation_about_is_dir_exists_action_0(self):
299302
'about_resource': '.', 'name': 'ABOUT tool'}]
300303
expected_output_list = [[join(TESTDATA_PATH, 'test_files_for_genabout/TESTCASE', 'TESTCASE.ABOUT'),
301304
{'about_file': '/TESTCASE/', 'version': '0.8.1',
302-
'about_resource_path' : '/TESTCASE/TESTCASE.ABOUT',
305+
'about_resource_path' : '/TESTCASE/',
303306
'about_resource': '.', 'name': 'ABOUT tool'}]]
304307
output_list = gen.pre_generation(gen_location, input_list, action_num, False)
305308
self.assertTrue(expected_output_list == output_list)
@@ -525,3 +528,97 @@ def test_process_dje_licenses(self):
525528
expected_output = [[join(u'/test', 'test_key.LICENSE'), 'This is a test license.']]
526529
output = gen.process_dje_licenses(test_license_list, test_license_dict, test_path)
527530
self.assertTrue(output == expected_output)
531+
532+
def test_update_about_resource_about_file_and_field_exist(self):
533+
gen = genabout.GenAbout()
534+
input_dict = {'about_resource': 'test.c', 'about_file': '/tmp/test.c'}
535+
about_file_exist = True
536+
gen.update_about_resource(input_dict, about_file_exist)
537+
self.assertTrue(input_dict == input_dict, "The dict should not be changed.")
538+
539+
def test_update_about_resource_about_file_and_field_not_exist_isFile(self):
540+
gen = genabout.GenAbout()
541+
input_dict = {'about_file': '/tmp/test.c'}
542+
expected_output = {'about_file': '/tmp/test.c', 'about_resource': 'test.c'}
543+
about_file_exist = True
544+
gen.update_about_resource(input_dict, about_file_exist)
545+
self.assertTrue(input_dict == expected_output)
546+
547+
def test_update_about_resource_about_file_and_field_not_exist_isdir(self):
548+
gen = genabout.GenAbout()
549+
input_dict = {'about_file': '/tmp/test/'}
550+
expected_output = {'about_file': '/tmp/test/', 'about_resource': '.'}
551+
about_file_exist = True
552+
gen.update_about_resource(input_dict, about_file_exist)
553+
self.assertTrue(input_dict == expected_output)
554+
555+
def test_update_about_resource_no_about_file_field_exist(self):
556+
gen = genabout.GenAbout()
557+
input_dict = {'about_resource': 'test.c', 'about_file': '/tmp/test.c'}
558+
about_file_exist = False
559+
gen.update_about_resource(input_dict, about_file_exist)
560+
self.assertTrue(input_dict == input_dict, "The dict should not be changed.")
561+
562+
def test_update_about_resource_no_about_file_no_field_isFile(self):
563+
gen = genabout.GenAbout()
564+
input_dict = {'about_file': '/tmp/test.c'}
565+
expected_output = {'about_file': '/tmp/test.c', 'about_resource': 'test.c'}
566+
about_file_exist = False
567+
gen.update_about_resource(input_dict, about_file_exist)
568+
self.assertTrue(input_dict == expected_output)
569+
570+
def test_update_about_resource_no_about_file_no_field_isdir(self):
571+
gen = genabout.GenAbout()
572+
input_dict = {'about_file': '/tmp/test/'}
573+
expected_output = {'about_file': '/tmp/test/', 'about_resource': '.'}
574+
about_file_exist = False
575+
gen.update_about_resource(input_dict, about_file_exist)
576+
self.assertTrue(input_dict == expected_output)
577+
578+
def test_update_about_resource_path_about_file_field_exist(self):
579+
gen = genabout.GenAbout()
580+
input_dict = {'about_resource_path': '/tmp/test.c', 'about_file': '/tmp/test.c'}
581+
about_file_exist = True
582+
gen.update_about_resource_path(input_dict, about_file_exist)
583+
self.assertTrue(input_dict == input_dict, "The dict should not be changed.")
584+
585+
def test_update_about_resource_path_about_file_field_not_exist_isFile(self):
586+
gen = genabout.GenAbout()
587+
input_dict = {'about_file': '/tmp/test.c'}
588+
expected_output = {'about_file': '/tmp/test.c', 'about_resource_path': '/tmp/test.c'}
589+
about_file_exist = True
590+
gen.update_about_resource_path(input_dict, about_file_exist)
591+
self.assertTrue(input_dict == expected_output)
592+
593+
def test_update_about_resource_path_about_file_field_not_exist_isDir(self):
594+
gen = genabout.GenAbout()
595+
input_dict = {'about_file': '/tmp/test/'}
596+
expected_output = {'about_file': '/tmp/test/', 'about_resource_path': '/tmp/test/'}
597+
about_file_exist = True
598+
gen.update_about_resource_path(input_dict, about_file_exist)
599+
self.assertTrue(input_dict == expected_output)
600+
601+
def test_update_about_resource_path_no_about_file_field_exist(self):
602+
gen = genabout.GenAbout()
603+
input_dict = {'about_resource_path': '/tmp/test.c', 'about_file': '/tmp/test.c'}
604+
about_file_exist = False
605+
gen.update_about_resource_path(input_dict, about_file_exist)
606+
self.assertTrue(input_dict == input_dict, "The dict should not be changed.")
607+
608+
def test_update_about_resource_path_no_about_file_field_not_exist_isFile(self):
609+
gen = genabout.GenAbout()
610+
input_dict = {'about_file': '/tmp/test.c'}
611+
expected_output = {'about_file': '/tmp/test.c', 'about_resource_path': '/tmp/test.c'}
612+
about_file_exist = False
613+
gen.update_about_resource_path(input_dict, about_file_exist)
614+
self.assertTrue(input_dict == expected_output)
615+
616+
def test_update_about_resource_path_no_about_file_field_not_exist_isDir(self):
617+
gen = genabout.GenAbout()
618+
input_dict = {'about_file': '/tmp/test/'}
619+
expected_output = {'about_file': '/tmp/test/', 'about_resource_path': '/tmp/test/'}
620+
about_file_exist = False
621+
gen.update_about_resource_path(input_dict, about_file_exist)
622+
self.assertTrue(input_dict == expected_output)
623+
624+

0 commit comments

Comments
 (0)