Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHELPLAN-59755 - Collection - script - not include symlinks in the co… #33

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions lsr_role2collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ def copy_tree_with_replace(
transformer_args,
isrole=True,
ignoreme=None,
symlinks=False,
symlinks=True,
):
"""
1. Copy files and dirs in the dir to
Expand Down Expand Up @@ -659,11 +659,23 @@ def copy_tree_with_replace(
lsrxfrm.run()


def cleanup_roles_dir(path):
def cleanup_symlinks(path, role, rmlist):
"""
Clean up symlinks in tests/roles
"""
if path.exists():
nodes = sorted(list(path.rglob("*")), reverse=True)
for node in nodes:
for item in rmlist:
if item == node.name:
if node.is_symlink():
node.unlink()
if (
node.is_dir()
and r"linux-system-roles." + role == node.name
and not any(node.iterdir())
):
node.rmdir()
roles_dir = path / "roles"
if roles_dir.exists() and not any(roles_dir.iterdir()):
roles_dir.rmdir()
Expand Down Expand Up @@ -1071,11 +1083,11 @@ def role2collection():
transformer_args,
isrole=False,
ignoreme=["artifacts", "linux-system-roles.*", "__pycache__"],
symlinks=False,
)

# remove "roles" directory if empty.
cleanup_roles_dir(tests_dir / role)
# remove symlinks in the tests/role.
removeme = ["library", "modules", "module_utils", "roles"]
cleanup_symlinks(tests_dir / role, role, removeme)

# ==============================================================================

Expand Down Expand Up @@ -1180,8 +1192,9 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
elif src.is_file():
process_readme(src_path, doc, role)

# remove "roles" directory if empty.
cleanup_roles_dir(dest)
# Remove symlinks in the docs/role (e.g., in the examples).
removeme = ["library", "modules", "module_utils", "roles"]
cleanup_symlinks(dest, role, removeme)

# ==============================================================================

Expand Down Expand Up @@ -1275,10 +1288,10 @@ def process_readme(src_path, filename, rolename, original=None, issubrole=False)
transformer_args,
isrole=False,
ignoreme=["artifacts", "linux-system-roles.*", "__pycache__"],
symlinks=False,
)
# remove "roles" directory if empty.
cleanup_roles_dir(tests_dir / dr)
# remove symlinks in the tests/role.
removeme = ["library", "modules", "module_utils", "roles"]
cleanup_symlinks(tests_dir / dr, dr, removeme)
# copy README.md to dest_path/roles/sr.name
readme = sr / "README.md"
if readme.is_file():
Expand Down