Skip to content

repo_on_fire.application

Repo on fire main application.

Application

The repo-on-fire application.

Source code in repo_on_fire/application.py
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class Application:
    """The repo-on-fire application."""

    def __init__(self, configuration: Optional[Configuration] = None) -> None:
        """Create a new instance of the app.

        Args:
            configuration: The configuration to use. If not given, load from
                           default settings files.
        """
        if configuration is not None:
            self._configuration = configuration
        else:
            self._configuration = load_configuration()
        self._git = Git(self._configuration)
        self._repo = Repo(self._configuration, self._git)
        self._workspace = Workspace(self._repo)

    @property
    def workspace(self) -> Workspace:
        """Utilities to manipulate a repo workspace."""
        return self._workspace

    def run_native_repo_command(self, command: str, args: List[str], cwd: Optional[Path] = None):
        """Runs a native repo command.

        This runs the repo tool with the given command and arguments.

        Args:
            command: The command to run (e.g. init, sync, ...).
            args: A list of additional options to pass to repo.
            cwd: The directory where to run repo. If omitted, run in the current
                working directory.
        """
        additional_args = []
        if self._configuration.native_command_additional_arguments is not None:
            additional_args = self._configuration.native_command_additional_arguments.get(
                command, []
            )
        result = self._repo.call([command, *additional_args, *args], cwd=cwd)
        sys.exit(result)

    def run_repo(self, args: List[str], cwd: Optional[Path] = None):
        """Run the repo tool.

        This runs repo passing it the given arguments. Note that injection of
        additional arguments does not work with this method!

        Args:
            args: The arguments to pass to repo, including the sub-command (if any).
            cwd: The directory where to run. If omitted, run in the current directory.
        """
        result = self._repo.call(args, cwd=cwd)
        sys.exit(result)

    def init_workspace_from_cache(
        self,
        manifest_url: str,
        manifest_name: Optional[str],
        manifest_branch: Optional[str],
        args: List[str],
        workspace_path: Optional[Path] = None,
    ):
        """Initialize a workspace from the cache.

        This runs a "special" init command, which will create a workspace from
        a mirror workspace in the app's cache. If the mirror workspace does not
        exist, it will be created first. On top, the cache entry will be kept
        up to date by running a sync on it every time the init command is run.

        Args:
            manifest_url: The URL of the repository where the repo manifest is stored.
            manifest_name: The name of the manifest file within the repository.
            manifest_branch: The branch in the manifest repository to use.
            args: Additional arguments to be passed to the init command
                run in the target workspace.
            workspace_path: The path to where the workspace shall be created.
                If omitted, the current working directory will be used.
        """
        self._repo.create_or_update_cache_entry(manifest_url, manifest_name, manifest_branch)
        self._repo.init_from_cache_entry(
            manifest_url, manifest_name, manifest_branch, args, workspace_path=workspace_path
        )

    def show_config_file_path(self, print_as_json: bool = False):
        """Print the path to the configuration file."""
        if print_as_json:
            data = {"path": str(get_user_config_file_path())}
            print(json.dumps(data, indent="  "))
        else:
            print(get_user_config_file_path())

    def list_config(self, print_as_json: bool = False):
        """Print the configuration settings used by the app."""
        if print_as_json:
            print(self._configuration.model_dump_json(indent=2))
        else:
            config_dict = self._configuration.model_dump()
            for key, value in config_dict.items():
                print(f"{key} = {value}")

workspace property

Utilities to manipulate a repo workspace.

__init__(configuration=None)

Create a new instance of the app.

Parameters:

Name Type Description Default
configuration Optional[Configuration]

The configuration to use. If not given, load from default settings files.

None
Source code in repo_on_fire/application.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def __init__(self, configuration: Optional[Configuration] = None) -> None:
    """Create a new instance of the app.

    Args:
        configuration: The configuration to use. If not given, load from
                       default settings files.
    """
    if configuration is not None:
        self._configuration = configuration
    else:
        self._configuration = load_configuration()
    self._git = Git(self._configuration)
    self._repo = Repo(self._configuration, self._git)
    self._workspace = Workspace(self._repo)

init_workspace_from_cache(manifest_url, manifest_name, manifest_branch, args, workspace_path=None)

Initialize a workspace from the cache.

This runs a "special" init command, which will create a workspace from a mirror workspace in the app's cache. If the mirror workspace does not exist, it will be created first. On top, the cache entry will be kept up to date by running a sync on it every time the init command is run.

Parameters:

Name Type Description Default
manifest_url str

The URL of the repository where the repo manifest is stored.

required
manifest_name Optional[str]

The name of the manifest file within the repository.

required
manifest_branch Optional[str]

The branch in the manifest repository to use.

required
args List[str]

Additional arguments to be passed to the init command run in the target workspace.

required
workspace_path Optional[Path]

The path to where the workspace shall be created. If omitted, the current working directory will be used.

None
Source code in repo_on_fire/application.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
def init_workspace_from_cache(
    self,
    manifest_url: str,
    manifest_name: Optional[str],
    manifest_branch: Optional[str],
    args: List[str],
    workspace_path: Optional[Path] = None,
):
    """Initialize a workspace from the cache.

    This runs a "special" init command, which will create a workspace from
    a mirror workspace in the app's cache. If the mirror workspace does not
    exist, it will be created first. On top, the cache entry will be kept
    up to date by running a sync on it every time the init command is run.

    Args:
        manifest_url: The URL of the repository where the repo manifest is stored.
        manifest_name: The name of the manifest file within the repository.
        manifest_branch: The branch in the manifest repository to use.
        args: Additional arguments to be passed to the init command
            run in the target workspace.
        workspace_path: The path to where the workspace shall be created.
            If omitted, the current working directory will be used.
    """
    self._repo.create_or_update_cache_entry(manifest_url, manifest_name, manifest_branch)
    self._repo.init_from_cache_entry(
        manifest_url, manifest_name, manifest_branch, args, workspace_path=workspace_path
    )

list_config(print_as_json=False)

Print the configuration settings used by the app.

Source code in repo_on_fire/application.py
106
107
108
109
110
111
112
113
def list_config(self, print_as_json: bool = False):
    """Print the configuration settings used by the app."""
    if print_as_json:
        print(self._configuration.model_dump_json(indent=2))
    else:
        config_dict = self._configuration.model_dump()
        for key, value in config_dict.items():
            print(f"{key} = {value}")

run_native_repo_command(command, args, cwd=None)

Runs a native repo command.

This runs the repo tool with the given command and arguments.

Parameters:

Name Type Description Default
command str

The command to run (e.g. init, sync, ...).

required
args List[str]

A list of additional options to pass to repo.

required
cwd Optional[Path]

The directory where to run repo. If omitted, run in the current working directory.

None
Source code in repo_on_fire/application.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def run_native_repo_command(self, command: str, args: List[str], cwd: Optional[Path] = None):
    """Runs a native repo command.

    This runs the repo tool with the given command and arguments.

    Args:
        command: The command to run (e.g. init, sync, ...).
        args: A list of additional options to pass to repo.
        cwd: The directory where to run repo. If omitted, run in the current
            working directory.
    """
    additional_args = []
    if self._configuration.native_command_additional_arguments is not None:
        additional_args = self._configuration.native_command_additional_arguments.get(
            command, []
        )
    result = self._repo.call([command, *additional_args, *args], cwd=cwd)
    sys.exit(result)

run_repo(args, cwd=None)

Run the repo tool.

This runs repo passing it the given arguments. Note that injection of additional arguments does not work with this method!

Parameters:

Name Type Description Default
args List[str]

The arguments to pass to repo, including the sub-command (if any).

required
cwd Optional[Path]

The directory where to run. If omitted, run in the current directory.

None
Source code in repo_on_fire/application.py
56
57
58
59
60
61
62
63
64
65
66
67
def run_repo(self, args: List[str], cwd: Optional[Path] = None):
    """Run the repo tool.

    This runs repo passing it the given arguments. Note that injection of
    additional arguments does not work with this method!

    Args:
        args: The arguments to pass to repo, including the sub-command (if any).
        cwd: The directory where to run. If omitted, run in the current directory.
    """
    result = self._repo.call(args, cwd=cwd)
    sys.exit(result)

show_config_file_path(print_as_json=False)

Print the path to the configuration file.

Source code in repo_on_fire/application.py
 98
 99
100
101
102
103
104
def show_config_file_path(self, print_as_json: bool = False):
    """Print the path to the configuration file."""
    if print_as_json:
        data = {"path": str(get_user_config_file_path())}
        print(json.dumps(data, indent="  "))
    else:
        print(get_user_config_file_path())