support canceling the key fetch
This commit is contained in:
parent
7df7a4c1fa
commit
8a63cc8506
|
@ -16,7 +16,7 @@
|
|||
import logging
|
||||
|
||||
from subiquitycore.controller import BaseController
|
||||
from subiquitycore.utils import run_command
|
||||
from subiquitycore.utils import run_command_start, run_command_summarize
|
||||
|
||||
from subiquity.ui.views import IdentityView
|
||||
|
||||
|
@ -51,18 +51,34 @@ class IdentityController(BaseController):
|
|||
def cancel(self):
|
||||
self.signal.emit_signal('prev-screen')
|
||||
|
||||
def _fetch_ssh_keys(self, result, ssh_import_id):
|
||||
status = run_command(['ssh-import-id', '-o-', ssh_import_id])
|
||||
def _fetch_cancel(self):
|
||||
if self._fetching_proc is None:
|
||||
return
|
||||
try:
|
||||
self._fetching_proc.terminate()
|
||||
except ProcessLookupError:
|
||||
pass # It's OK if the process has already terminated.
|
||||
self._fetching_proc = None
|
||||
|
||||
def _fetch_ssh_keys(self, result, p):
|
||||
stdout, stderr = p.communicate()
|
||||
if p != self._fetching_proc:
|
||||
log.debug("_fetch_ssh_keys cancelled")
|
||||
return None
|
||||
status = run_command_summarize(p, stdout, stderr)
|
||||
result['ssh_key'] = status['output']
|
||||
return result
|
||||
|
||||
def _fetched_ssh_keys(self, fut):
|
||||
result = fut.result()
|
||||
self.loop.set_alarm_in(0.0, lambda loop, ud: self.done(result))
|
||||
log.debug("_fetched_ssh_keys %s", result)
|
||||
if result is not None:
|
||||
self.loop.set_alarm_in(0.0, lambda loop, ud: self.done(result))
|
||||
|
||||
def fetch_ssh_keys(self, result, ssh_import_id):
|
||||
self._fetching_proc = run_command_start(['ssh-import-id', '-o-', ssh_import_id])
|
||||
self.run_in_bg(
|
||||
lambda: self._fetch_ssh_keys(result, ssh_import_id),
|
||||
lambda: self._fetch_ssh_keys(result, self._fetching_proc),
|
||||
self._fetched_ssh_keys)
|
||||
|
||||
def done(self, result):
|
||||
|
|
|
@ -194,8 +194,10 @@ class FetchingSSHKeys(WidgetWrap):
|
|||
Pile([
|
||||
('pack', Text(' ' + text)),
|
||||
('pack', spinner),
|
||||
('pack', button_pile([button])),
|
||||
])))
|
||||
def cancel(self):
|
||||
def cancel(self, sender):
|
||||
self.parent.controller._fetch_cancel()
|
||||
self.parent.remove_overlay()
|
||||
|
||||
|
||||
|
@ -213,8 +215,6 @@ class IdentityView(BaseView):
|
|||
connect_signal(self.form.ssh_import_id.widget, 'select', self._select_ssh_import_id)
|
||||
self.form.import_username.enabled = False
|
||||
|
||||
self.ssh_import_confirmed = True
|
||||
|
||||
super().__init__(
|
||||
screen(
|
||||
self.form.as_rows(),
|
||||
|
|
Loading…
Reference in New Issue