Skip to content

Commit

Permalink
Merge pull request #428 from lomnido/feat_dump-manifest
Browse files Browse the repository at this point in the history
introducing 'dump-manifest' command
  • Loading branch information
lomnido authored Oct 25, 2024
2 parents bcfeeb9 + 4f8f459 commit 62a5b51
Show file tree
Hide file tree
Showing 37 changed files with 5,644 additions and 109 deletions.
87 changes: 85 additions & 2 deletions tsrc/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import cli_ui as ui

from tsrc.errors import Error
from tsrc.groups_and_constraints_data import GroupsAndConstraints
from tsrc.manifest import Manifest
from tsrc.manifest_common_data import ManifestsTypeOfData
from tsrc.repo import Repo
from tsrc.workspace import Workspace
from tsrc.workspace_config import WorkspaceConfig
Expand Down Expand Up @@ -105,6 +107,7 @@ def find_workspace_path() -> Path:
def get_workspace_with_repos(
namespace: argparse.Namespace,
ignore_if_group_not_found: bool = False,
ignore_group_item: bool = False,
) -> Workspace:
workspace = get_workspace(namespace, silent=ignore_if_group_not_found)
workspace.repos = resolve_repos(
Expand All @@ -114,6 +117,7 @@ def get_workspace_with_repos(
include_regex=namespace.include_regex,
exclude_regex=namespace.exclude_regex,
ignore_if_group_not_found=ignore_if_group_not_found,
ignore_group_item=ignore_group_item,
)
return workspace

Expand All @@ -129,6 +133,7 @@ def simulate_get_workspace_with_repos(
include_regex=namespace.include_regex,
exclude_regex=namespace.exclude_regex,
ignore_if_group_not_found=True,
ignore_group_item=True,
)


Expand All @@ -141,13 +146,17 @@ def simulate_resolve_repos(
include_regex: str = "",
exclude_regex: str = "",
ignore_if_group_not_found: bool = False,
ignore_group_item: bool = False,
) -> List[str]:
"""
just to obatin 'groups_seen'
as if we hit the exception, we may miss some groups
"""
# Handle --all-cloned and --groups
manifest = workspace.get_manifest()
if ignore_group_item is True:
manifest = workspace.get_manifest_safe_mode(ManifestsTypeOfData.LOCAL)
else:
manifest = workspace.get_manifest()

if groups:
manifest.get_repos(groups=groups, ignore_if_group_not_found=True)
Expand All @@ -165,14 +174,18 @@ def resolve_repos(
include_regex: str = "",
exclude_regex: str = "",
ignore_if_group_not_found: bool = False,
ignore_group_item: bool = False,
) -> List[Repo]:
"""
Given a workspace with its config and its local manifest,
and a collection of parsed command line arguments,
return the list of repositories to operate on.
"""
# Handle --all-cloned and --groups
manifest = workspace.get_manifest()
if ignore_group_item is True:
manifest = workspace.get_manifest_safe_mode(ManifestsTypeOfData.LOCAL)
else:
manifest = workspace.get_manifest()
repos = []

if groups:
Expand Down Expand Up @@ -210,6 +223,76 @@ def resolve_repos(
return repos


def resolve_repos_without_workspace(
manifest: Manifest,
gac: GroupsAndConstraints,
) -> List[Repo]:
"""
Use just Manifest to get Repos in regard of Groups,
include_regex, exclude_regex. Also respect 'singular_remote'
If no Groups are provided, consider all Repos there are.
Return Repos to operate on.
"""
repos = []

if gac.groups:
# due to we are working with Manifest, there is
# no reason to enforce group to exist
repos = manifest.get_repos(groups=gac.groups, ignore_if_group_not_found=True)
else:
repos = manifest.get_repos(all_=True)

if gac.singular_remote:
filtered_repos = []
for repo in repos:
remotes = [
remote
for remote in repo.remotes
if gac.singular_remote.lower() == remote.name.lower()
]
if remotes:
filtered_repos.append(repo)
repos = filtered_repos

if gac.include_regex:
repos = [repo for repo in repos if re.search(gac.include_regex, repo.dest)]

if gac.exclude_regex:
repos = [repo for repo in repos if not re.search(gac.exclude_regex, repo.dest)]

return repos


def resolve_repos_apply_constraints(
repos: List[Repo],
gac: GroupsAndConstraints,
) -> List[Repo]:
"""
Use just constraints on Repos in GroupAndConstraints class
to filter Repos. Consider:
include_regex, exclude_regex. Also respect 'singular_remote'
"""
if gac.singular_remote:
filtered_repos = []
for repo in repos:
remotes = [
remote
for remote in repo.remotes
if gac.singular_remote.lower() == remote.name.lower()
]
if remotes:
filtered_repos.append(repo)
repos = filtered_repos

if gac.include_regex:
repos = [repo for repo in repos if re.search(gac.include_regex, repo.dest)]

if gac.exclude_regex:
repos = [repo for repo in repos if not re.search(gac.exclude_regex, repo.dest)]

return repos


def repos_from_config(
manifest: Manifest,
workspace_config: WorkspaceConfig,
Expand Down
Loading

0 comments on commit 62a5b51

Please sign in to comment.