support canceling the key fetch
This commit is contained in:
parent
7df7a4c1fa
commit
8a63cc8506
|
@ -16,7 +16,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from subiquitycore.controller import BaseController
|
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
|
from subiquity.ui.views import IdentityView
|
||||||
|
|
||||||
|
@ -51,18 +51,34 @@ class IdentityController(BaseController):
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self.signal.emit_signal('prev-screen')
|
self.signal.emit_signal('prev-screen')
|
||||||
|
|
||||||
def _fetch_ssh_keys(self, result, ssh_import_id):
|
def _fetch_cancel(self):
|
||||||
status = run_command(['ssh-import-id', '-o-', ssh_import_id])
|
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']
|
result['ssh_key'] = status['output']
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _fetched_ssh_keys(self, fut):
|
def _fetched_ssh_keys(self, fut):
|
||||||
result = fut.result()
|
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):
|
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(
|
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)
|
self._fetched_ssh_keys)
|
||||||
|
|
||||||
def done(self, result):
|
def done(self, result):
|
||||||
|
|
|
@ -194,8 +194,10 @@ class FetchingSSHKeys(WidgetWrap):
|
||||||
Pile([
|
Pile([
|
||||||
('pack', Text(' ' + text)),
|
('pack', Text(' ' + text)),
|
||||||
('pack', spinner),
|
('pack', spinner),
|
||||||
|
('pack', button_pile([button])),
|
||||||
])))
|
])))
|
||||||
def cancel(self):
|
def cancel(self, sender):
|
||||||
|
self.parent.controller._fetch_cancel()
|
||||||
self.parent.remove_overlay()
|
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)
|
connect_signal(self.form.ssh_import_id.widget, 'select', self._select_ssh_import_id)
|
||||||
self.form.import_username.enabled = False
|
self.form.import_username.enabled = False
|
||||||
|
|
||||||
self.ssh_import_confirmed = True
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
screen(
|
screen(
|
||||||
self.form.as_rows(),
|
self.form.as_rows(),
|
||||||
|
|
Loading…
Reference in New Issue