sshmitm.appimage module

Module for initializing applications within an AppImage via AppRun.

This module is designed to be invoked by the AppRun script of an AppImage and is not intended for direct execution. The module includes the AppStarter class, which orchestrates the application startup process based on configurations defined in a .ini file, controlling environment variables, interpreter access, entry point restrictions, and default commands.

The .ini configuration file must be named ‘appimage.ini’ and located within the root firectory of an AppImage next to the AppRun.

The provided AppRun bash script sets up the necessary environment and invokes the application using this module. It should be located at the root of the AppImage filesystem.

Configuration File Format:

[appimage] entry_point = sshmitm.cli:main # entry point which uses the module function syntax

or

[appimage] entry_point = ssh-mitm # entry point is set by entrypoint name

Intended Usage:

This module is used within an AppImage environment, with the AppRun entry point calling the start_entry_point function provided by this module. AppStarter reads the configurations, determines the appropriate entry point, and initiates the application.

exception sshmitm.appimage.AppStartException

Bases: Exception

Base exception class for errors during the app start process.

class sshmitm.appimage.AppStarter

Bases: object

Class responsible for managing the application start process, including reading the configuration, determining the correct entry point, and executing the application.

property appdir: str

Get the application directory from the ‘APPDIR’ environment variable. If ‘APPDIR’ is not set in the environment, it defaults to the directory containing the current file (__file__).

Returns:

str: The path to the application directory.

create_venv(venv_dir)
Parameters:

venv_dir (str)

Return type:

None

property entry_points: Dict[str, EntryPoint]
get_entry_point(*, ignore_default=False)
Parameters:

ignore_default (bool, default: False)

Return type:

Optional[EntryPoint]

parse_python_args()
Return type:

None

start()

Determine the entry point and start it. If an interpreter is requested via environment variables, or if no entry point is found, it starts an interpreter. Otherwise, it starts the determined entry point.

Return type:

None

start_entry_point()

Load a module and execute the function specified by the entry point. The entry point is a string in the ‘module:function’ format.

Return type:

None

Raises:

InvalidEntryPoint: If the entry point does not exist.

start_interpreter()

Start an interactive Python interpreter using the current Python executable.

It passes any additional arguments provided in the command line to the interpreter.

Return type:

None

exception sshmitm.appimage.InvalidEntryPoint

Bases: AppStartException

Exception raised for invalid entry point.

sshmitm.appimage.patch_appimage_venv(context)
Parameters:

context (SimpleNamespace)

Return type:

None

sshmitm.appimage.setup_python_patched(self, context)
Parameters:
  • self (EnvBuilder)

  • context (SimpleNamespace)

Return type:

None

sshmitm.appimage.start_entry_point()

Initiates the application start process by creating an instance of the AppStarter class and calling its start method. This function acts as an entry point to begin the application’s execution flow.

The start method of the AppStarter instance will determine the appropriate entry point from the available configurations and proceed to execute it. If the start method encounters any issues that it cannot handle (such as configuration errors, missing entry points, etc.), it will raise an AppStartException.

Return type:

None