in services/jenkins-master/scripts/jenkins_config_templating.py [0:0]
def assemble_symlink_list(symlink_file, jenkinsdir):
"""
Assemble a list of files that should be symlinked during startup, providing support for state files on EBS
:param symlink_file: File containing path expressions to describe the symlinked files and dirs
:param jenkinsdir: Jenkins configuration directory
:return: Array of SymlinkEntry
"""
symlink_config = read_symlink_entries(symlink_file)
logging.debug('Found {} symlink entries'.format(len(symlink_config)))
symlinks = []
for symlink_entry in symlink_config:
input_path_expression = os.path.join(jenkinsdir, symlink_entry.filepath)
result_paths = []
if '*' in symlink_entry.filepath:
# If path contains a wildcard, search for all results
wildcard_path_split = input_path_expression.split('*')
if len(wildcard_path_split) == 1:
result_paths = glob.glob(input_path_expression)
elif len(wildcard_path_split) == 2:
# If wildcard is in the middle and target directories don't exist, result would be empty.
# Instead, iterate manually
for partial_path in glob.glob(os.path.join(wildcard_path_split[0], '*')):
result_paths.append(os.path.join(partial_path, wildcard_path_split[1].lstrip('/')))
else:
raise ValueError('Symlink expression may only contain one wildcard')
logging.debug('Resolving {} to {}'.format(symlink_entry.filepath, result_paths))
else:
result_paths = [input_path_expression]
for abs_path in result_paths:
rel_path = os.path.relpath(abs_path, jenkinsdir)
symlinks.append(SymlinkEntry(rel_path, symlink_entry.is_dir))
return symlinks