return childnode.firstChild.data
+def _remove_duplicates_and_sort(lst):
+ # Remove duplicates from list, and sort it
+ no_dups_lst = list(dict.fromkeys(lst))
+ no_dups_lst.sort()
+
+ duplicated_list = []
+ for i in range(len(no_dups_lst)):
+ if (lst.count(no_dups_lst[i]) > 1):
+ duplicated_list.append(no_dups_lst[i])
+ log.debug("duplicates : {}".format(duplicated_list))
+
+ return no_dups_lst
+
+
def copy_archives(workspace, pattern=None):
"""Copy files matching PATTERN in a WORKSPACE to the current directory.
if pattern is None:
return
+ no_dups_pattern = _remove_duplicates_and_sort(pattern)
+
paths = []
- for p in pattern:
+ for p in no_dups_pattern:
if p == '': # Skip empty patterns as they are invalid
continue
paths.extend(glob2.glob(search, recursive=True))
log.debug('Files found: {}'.format(paths))
- for src in paths:
+ no_dups_paths = _remove_duplicates_and_sort(paths)
+
+ for src in no_dups_paths:
if len(os.path.basename(src)) > 255:
log.warn('Filename {} is over 255 characters. Skipping...'.format(
os.path.basename(src)))
try:
shutil.move(src, dest)
except IOError as e: # Switch to FileNotFoundError when Python 2 support is dropped.
- log.debug(e)
+ log.debug("Missing path, will create it {}".format(os.path.dirname(dest)))
os.makedirs(os.path.dirname(dest))
shutil.move(src, dest)
assert workspace_dir in str(excinfo.value)
+@pytest.mark.datafiles(
+ os.path.join(FIXTURE_DIR, 'deploy'),
+ )
+def test_deploy_archive4(cli_runner, datafiles, responses):
+ """Test deploy_archives() command when using duplicated patterns."""
+ os.chdir(str(datafiles))
+ workspace_dir = os.path.join(str(datafiles), 'workspace-patternfile')
+ pattern=["**/*.log", "**/hs_err_*.log", "**/target/**/feature.xml", "**/target/failsafe-reports/failsafe-summary.xml", "**/target/surefire-reports/*-output.txt", "**/target/surefire-reports/*-output.txt", "**/target/failsafe-reports/failsafe-summary.xml"]
+ result = deploy_sys.copy_archives(workspace_dir, pattern)
+ assert result is None
+
+
+def test_remove_duplicates_and_sort():
+ test_lst = [[["file1"],
+ ["file1"]],
+
+ [["file1", "file2"],
+ ["file1", "file2"]],
+
+ [["file2", "file3", "file5", "file1", "file4"],
+ ["file1", "file2", "file3", "file4", "file5"]],
+
+ [["file2", "file3", "file2", "file3", "file4"],
+ ["file2", "file3", "file4"]],
+
+
+ [["**/*.log",
+ "**/hs_err_*.log",
+ "**/target/**/feature.xml",
+ "**/target/failsafe-reports/failsafe-summary.xml",
+ "**/target/surefire-reports/*-output.txt",
+ "**/target/surefire-reports/*-output.txt",
+ "**/target/failsafe-reports/failsafe-summary.xml"],
+
+ ["**/*.log",
+ "**/hs_err_*.log",
+ "**/target/**/feature.xml",
+ "**/target/failsafe-reports/failsafe-summary.xml",
+ "**/target/surefire-reports/*-output.txt"]],
+
+ [['/workspace-patternfile/abc.log',
+ '/workspace-patternfile/dir1/hs_err_13.log',
+ '/workspace-patternfile/dir1/hs_err_12.log',
+ '/workspace-patternfile/dir1/abc.log',
+ '/workspace-patternfile/dir2/hs_err_13.log',
+ '/workspace-patternfile/dir2/hs_err_12.log',
+ '/workspace-patternfile/dir2/abc.log',
+ '/workspace-patternfile/dir1/hs_err_13.log',
+ '/workspace-patternfile/dir1/hs_err_12.log',
+ '/workspace-patternfile/dir2/hs_err_13.log',
+ '/workspace-patternfile/dir2/hs_err_12.log',
+ '/workspace-patternfile/target/dir1/feature.xml',
+ '/workspace-patternfile/target/dir2/feature.xml',
+ '/workspace-patternfile/target/surefire-reports/abc1-output.txt',
+ '/workspace-patternfile/target/surefire-reports/abc2-output.txt',
+ '/workspace-patternfile/target/surefire-reports/abc1-output.txt',
+ '/workspace-patternfile/target/surefire-reports/abc2-output.txt'],
+
+ ['/workspace-patternfile/abc.log',
+ '/workspace-patternfile/dir1/abc.log',
+ '/workspace-patternfile/dir1/hs_err_12.log',
+ '/workspace-patternfile/dir1/hs_err_13.log',
+ '/workspace-patternfile/dir2/abc.log',
+ '/workspace-patternfile/dir2/hs_err_12.log',
+ '/workspace-patternfile/dir2/hs_err_13.log',
+ '/workspace-patternfile/target/dir1/feature.xml',
+ '/workspace-patternfile/target/dir2/feature.xml',
+ '/workspace-patternfile/target/surefire-reports/abc1-output.txt',
+ '/workspace-patternfile/target/surefire-reports/abc2-output.txt']]
+
+ ]
+
+ for tst in test_lst:
+ assert deploy_sys._remove_duplicates_and_sort(tst[0]) == tst[1]
+
+
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, 'deploy'),
)