MCPcopy
hub / github.com/freedomofpress/dangerzone / should_skip

Method should_skip

dangerzone/startup.py:103–153  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

101 raise errors.OtherMachineRunningError(message)
102
103 def should_skip(self) -> bool:
104 if settings.Settings().custom_runtime_specified():
105 return True
106
107 if platform.system() in ["Linux", "Windows"]:
108 # * On Linux, there are no Podman machines
109 # * On Windows, WSL allows multiple VMs:
110 # https://github.com/containers/podman/issues/18415
111 # * On macOS, only one Podman machine can run:
112 # https://docs.podman.io/en/v5.2.2/markdown/podman-machine-start.1.html
113 return True
114
115 other_running_machines = PodmanMachineManager().list_other_running_machines()
116 if not other_running_machines:
117 return True
118 assert len(other_running_machines) == 1
119 machine_name = other_running_machines[0]
120 logger.info(
121 f"Dangerzone has detected that a Podman machine with name '{machine_name}'"
122 " is already running in your system. This machine needs to stop so that"
123 " Dangerzone can run."
124 )
125
126 stop_setting = settings.Settings().get("stop_other_podman_machines")
127
128 if stop_setting == "always":
129 logger.info(
130 "Stopping the Podman machine because the user has asked us to remember their choice"
131 )
132 return False
133 elif stop_setting == "never":
134 self.fail(
135 "Another Podman machine is running and Dangerzone is configured to not stop it."
136 )
137 elif stop_setting == "ask":
138 logger.debug("We need to prompt the user to stop the other Podman machine")
139 stop = self.prompt_user(machine_name)
140 if not stop:
141 self.fail(
142 f"User decided to quit Dangerzone instead of stopping Podman"
143 f" machine '{machine_name}'."
144 )
145 # NOTE: This is required only for testing. Else, we expect it will raise
146 # an exception.
147 return True
148 else:
149 return False
150
151 raise errors.StartupException(
152 "BUG: Dangerzone cannot decide how to handle running Podman machine"
153 )
154
155 def prompt_user(self, machine_name: str) -> bool:
156 """Return whether the user has accepted to stop the machine or not."""

Callers 1

Calls 6

failMethod · 0.95
prompt_userMethod · 0.95
getMethod · 0.80

Tested by 1