Beispiel #1
0
    def __init__(self, controller):
        self.controller = controller

        found_disk = False
        found_ok_disk = False
        for disk in controller.model.all_disks():
            found_disk = True
            if disk.size > 6 * (2**30):
                found_ok_disk = True
                break

        if found_ok_disk:
            self.form = GuidedForm(model=controller.model)

            connect_signal(self.form, 'submit', self.done)
            connect_signal(self.form, 'cancel', self.cancel)

            super().__init__(
                self.form.as_screen(focus_buttons=False, excerpt=_(subtitle)))
        elif found_disk:
            super().__init__(
                screen([Text(rewrap(_(no_big_disks)))],
                       [other_btn(_("OK"), on_press=self.manual)]))
        else:
            super().__init__(screen([Text(rewrap(_(no_disks)))], []))
Beispiel #2
0
    def make_language_choices(self):
        btns = []
        current_index = None
        langs = get_languages()
        cur = self.cur_lang
        if cur in ["C.UTF-8", None]:
            cur = "en_US.UTF-8"
        for i, (code, native) in enumerate(langs):
            log.debug("%s", (code, cur))
            if code == cur:
                current_index = i
            btns.append(
                forward_btn(
                    label=native,
                    on_press=self.choose_language,
                    user_arg=code))

        lb = ListBox(btns)
        back = None
        if self.serial:
            back = other_btn(_("Back"), on_press=self.controller.cancel)
        if current_index is not None:
            lb.base_widget.focus_position = current_index
        return screen(
            lb, focus_buttons=False, narrow_rows=True,
            buttons=[back] if back else None,
            excerpt=_("Use UP, DOWN and ENTER keys to select your language."))
Beispiel #3
0
 def make_serial_choices(self):
     ssh_password = get_installer_password(self.controller.opts.dry_run)
     ips = get_global_addresses(self.controller.app)
     btns = [
         other_btn(label="Switch to rich mode", on_press=self.enable_rich),
         forward_btn(label="Continue in basic mode",
                     on_press=self.choose_language,
                     user_arg='C'),
     ]
     widgets = [
         Text(""),
         Text(rewrap(SERIAL_TEXT)),
         Text(""),
     ]
     if ssh_password and ips:
         widgets.append(Text(rewrap(SSH_TEXT)))
         widgets.append(Text(""))
         btns.insert(
             1,
             other_btn(label="View SSH instructions",
                       on_press=self.ssh_help,
                       user_arg=ssh_password))
     widgets.extend([
         button_pile(btns),
     ])
     lb = ListBox(widgets)
     return screen(lb, buttons=None)
Beispiel #4
0
    def __init__(self, model, controller, opts):
        self.model = model
        self.controller = controller
        self.signal = controller.signal
        self.opts = opts
        self.items = []

        reserved_usernames_path = (os.path.join(os.environ.get("SNAP", "."),
                                                "reserved-usernames"))
        reserved_usernames = set()
        if os.path.exists(reserved_usernames_path):
            with open(reserved_usernames_path) as fp:
                for line in fp:
                    line = line.strip()
                    if line.startswith('#') or not line:
                        continue
                    reserved_usernames.add(line)
        else:
            reserved_usernames.add('root')

        self.form = IdentityForm(reserved_usernames)

        connect_signal(self.form, 'submit', self.done)
        connect_signal(self.form.confirm_password.widget, 'change',
                       self._check_password)
        connect_signal(self.form.ssh_import_id.widget, 'select',
                       self._select_ssh_import_id)
        self.form.import_username.enabled = False

        self.form_rows = ListBox(self.form.as_rows())
        super().__init__(
            screen(self.form_rows, [self.form.done_btn],
                   excerpt=_(self.excerpt),
                   focus_buttons=False))
Beispiel #5
0
    def __init__(self, controller):
        self.controller = controller
        user_name = ""
        with open('/var/lib/ubuntu-wsl/assigned_account', 'r') as f:
            user_name = f.read()
        complete_text = _(
            "Hi {username},\n"
            "You have complete the setup!\n\n"
            "It is suggested to run the following command to update your Ubuntu "
            "to the latest version:\n\n\n"
            "  $ sudo apt update\n  $ sudo apt upgrade\n\n\n"
            "You can use the builtin `ubuntuwsl` command to manage your WSL settings:\n\n\n"
            "  $ sudo ubuntuwsl ...\n\n\n"
            "* All settings will take effect after first restart of Ubuntu."
        ).format(username=user_name)

        super().__init__(
            screen(
                rows=[],
                buttons=button_pile([
                    done_btn(_("Done"), on_press=self.confirm),
                ]),
                focus_buttons=True,
                excerpt=complete_text,
            ))
Beispiel #6
0
    def check_state_available(self, sender=None):
        self.spinner.stop()

        rows = [
            Text(_("You can read the release notes for each version at:")),
            Text(""),
            Text("https://github.com/CanonicalLtd/subiquity/releases",
                 align='center'),
            Text(""),
            Text(
                _("If you choose to update, the update will be downloaded "
                  "and the installation will continue from here."), ),
        ]

        buttons = button_pile([
            done_btn(_("Update to the new installer"), on_press=self.update),
            done_btn(_("Continue without updating"), on_press=self.done),
            other_btn(_("Back"), on_press=self.cancel),
        ])
        buttons.base_widget.focus_position = 1

        excerpt = _(self.available_excerpt).format(
            current=self.controller.status.current_snap_version,
            new=self.controller.status.new_snap_version)

        self.title = self.available_title
        self.controller.ui.set_header(self.available_title)
        self._w = screen(rows, buttons, excerpt=excerpt)
        if 'update' in self.controller.answers:
            if self.controller.answers['update']:
                self.update()
            else:
                self.controller.app.aio_loop.call_soon(self.controller.done)
Beispiel #7
0
 def make_main_screen(self, snap_list):
     self.snap_boxes = {}
     body = []
     for snap in snap_list:
         box = self.snap_boxes[snap.name] = SnapCheckBox(self, snap)
         row = [
             box,
             Text(snap.publisher),
             Text(snap.summary, wrap='clip'),
         ]
         body.append(Color.menu_button(TableRow(row)))
     table = NoTabCyclingTableListBox(body,
                                      colspecs={
                                          1: ColSpec(omittable=True),
                                          2: ColSpec(pack=False,
                                                     min_width=40),
                                      })
     ok = ok_btn(label=_("Done"), on_press=self.done)
     self._main_screen = screen(
         table, [ok],
         focus_buttons=False,
         excerpt=_(
             "These are popular snaps in server environments. Select or "
             "deselect with SPACE, press ENTER to see more details of the "
             "package, publisher and versions available."))
    def __init__(self, model, controller):
        self.model = model
        self.controller = controller
        self.signal = controller.signal

        reserved_usernames_path = '/usr/share/ubuntu-wsl-oobe/reserved-usernames'
        build_reserved_usernames_path = os.path.realpath(
            __file__ + '/../../../../reserved-usernames')
        if os.path.isfile(build_reserved_usernames_path):
            reserved_usernames_path = build_reserved_usernames_path
        reserved_usernames = set()
        if os.path.exists(reserved_usernames_path):
            with open(reserved_usernames_path) as fp:
                for line in fp:
                    line = line.strip()
                    if line.startswith('#') or not line:
                        continue
                    reserved_usernames.add(line)
        else:
            reserved_usernames.add('root')

        if model.user:
            initial = {'username': model.user.username}
        else:
            initial = {}

        self.form = IdentityForm(reserved_usernames, initial)

        connect_signal(self.form, 'submit', self.done)
        setup_password_validation(self.form, _("passwords"))

        super().__init__(
            screen(self.form.as_rows(), [self.form.done_btn],
                   excerpt=_(self.excerpt),
                   focus_buttons=False))
Beispiel #9
0
    def __init__(self, model, controller, opts):
        self.model = model
        self.controller = controller
        self.opts = opts

        self.form = KeyboardForm()
        opts = []
        for layout, desc in model.layouts.items():
            opts.append(Option((desc, True, layout)))
        opts.sort(key=lambda o: o.label)
        connect_signal(self.form, 'submit', self.done)
        connect_signal(self.form, 'cancel', self.cancel)
        connect_signal(self.form.layout.widget, "select", self.select_layout)
        self.form.layout.widget._options = opts
        setting = model.setting.for_ui()
        try:
            self.form.layout.widget.value = setting.layout
            self.form.variant.widget.value = setting.variant
        except AttributeError:
            # Don't crash on pre-existing invalid config.
            pass

        lb_contents = self.form.as_rows(self)
        if not self.opts.run_on_serial:
            lb_contents.extend([
                Text(""),
                button_pile([
                    other_btn(label=_("Identify keyboard"),
                              on_press=self.detect)
                ]),
            ])
        super().__init__(screen(lb_contents, self.form.buttons))
Beispiel #10
0
    def make_language_choices(self):
        btns = []
        current_index = None
        langs = self.model.get_languages(self.is_linux_tty)
        cur = self.model.selected_language
        log.debug("_build_model_inputs selected_language=%s", cur)
        if cur in ["C", None]:
            cur = "en_US"
        for i, (code, native) in enumerate(langs):
            log.debug("%s", (code, self.model.selected_language))
            if code == cur:
                current_index = i
            btns.append(
                forward_btn(label=native,
                            on_press=self.choose_language,
                            user_arg=code))

        lb = ListBox(btns)
        if current_index is not None:
            lb.base_widget.focus_position = current_index
        return screen(
            lb,
            buttons=None,
            narrow_rows=True,
            excerpt=_("Use UP, DOWN and ENTER keys to select your language."))
Beispiel #11
0
 def offer_retry(self):
     self._w = screen(
         [Text(_("Sorry, loading snaps from the store failed."))],
         [
             other_btn(label=_("Try again"), on_press=self.load),
             ok_btn(label=_("Continue"), on_press=self.done),
         ])
Beispiel #12
0
    def __init__(self, model, controller):
        self.model = model
        self.controller = controller

        initial = {
            "install_server": self.model.install_server,
            "pwauth": self.model.pwauth,
        }
        if self.model.ssh_import_id:
            prefix, username = self.model.ssh_import_id.split(':', 1)
            initial['ssh_import_id'] = prefix
            initial['import_username'] = username

        self.form = SSHForm(initial=initial)

        connect_signal(self.form.ssh_import_id.widget, 'select',
                       self._select_ssh_import_id)

        connect_signal(self.form, 'submit', self.done)
        connect_signal(self.form, 'cancel', self.cancel)

        self.form_rows = ListBox(self.form.as_rows())
        super().__init__(
            screen(self.form_rows,
                   self.form.buttons,
                   excerpt=_(self.excerpt),
                   focus_buttons=False))
Beispiel #13
0
    def __init__(self, model, controller):
        log.debug('FileSystemView init start()')
        self.model = model
        self.controller = controller

        self.mount_list = MountList(self)
        self.avail_list = DeviceList(self, True)
        self.used_list = DeviceList(self, False)
        self.avail_list.table.bind(self.used_list.table)

        body = [
            Text(_("FILE SYSTEM SUMMARY")),
            Text(""),
            Padding.push_2(self.mount_list),
            Text(""),
            Text(""),
            Text(_("AVAILABLE DEVICES")),
            Text(""),
            Padding.push_2(self.avail_list),
            Text(""),
            Text(""),
            Text(_("USED DEVICES")),
            Text(""),
            Padding.push_2(self.used_list),
            Text(""),
        ]

        self.lb = ListBox(body)
        frame = screen(self.lb,
                       self._build_buttons(),
                       focus_buttons=self.model.can_install())
        frame.width = ('relative', 95)
        super().__init__(frame)
        log.debug('FileSystemView init complete()')
Beispiel #14
0
 def wait_load(self):
     spinner = Spinner(self.controller.app.aio_loop, style='dots')
     spinner.start()
     self._w = screen(
         [spinner], [ok_btn(label=_("Continue"), on_press=self.done)],
         excerpt=_("Loading server snaps from store, please wait..."))
     schedule_task(self._wait_load(spinner))
Beispiel #15
0
    def __init__(self, size, existing, initial, back, focus_buttons=False):

        mountpoint_to_devpath_mapping = (
            self.model.get_mountpoint_to_devpath_mapping())
        if existing is not None:
            fs = existing.fs()
            if fs is not None:
                if getattr(existing, 'flag', None) != "boot":
                    initial['fstype'] = self.model.fs_by_name[fs.fstype]
                mount = fs.mount()
                if mount is not None:
                    initial['mount'] = mount.path
                    if mount.path in mountpoint_to_devpath_mapping:
                        del mountpoint_to_devpath_mapping[mount.path]
            else:
                initial['fstype'] = self.model.fs_by_name[None]
        self.form = self.form_cls(mountpoint_to_devpath_mapping, size, initial)
        self.back = back

        connect_signal(self.form, 'submit', self.done)
        connect_signal(self.form, 'cancel', self.cancel)

        super().__init__(
            screen(self.make_body(),
                   self.form.buttons,
                   focus_buttons=focus_buttons))
Beispiel #16
0
 def __init__(self, controller):
     self.controller = controller
     super().__init__(screen(
         rows=[],
         buttons=button_pile([done_btn("OK", on_press=self.confirm)]),
         focus_buttons=True,
         excerpt=self.excerpt))
Beispiel #17
0
 def __init__(self, model, controller, method):
     self.model = model
     self.controller = controller
     self.method = method
     cancel = cancel_btn(_("Cancel"), on_press=self.cancel)
     rows = []
     for disk in self.model.all_disks():
         if disk.size >= dehumanize_size("6G"):
             disk_btn = ClickableIcon(disk.label)
             connect_signal(
                 disk_btn, 'click', self.choose_disk, disk)
             attr = Color.done_button
         else:
             disk_btn = Text("  "+disk.label)
             attr = Color.info_minor
         rows.append(attr(TableRow([
             Text('['),
             disk_btn,
             Text(humanize_size(disk.size), align='right'),
             Text('\N{BLACK RIGHT-POINTING SMALL TRIANGLE}'),
             Text(']'),
             ])))
     super().__init__(screen(
         TableListBox(rows, spacing=1, colspecs={
             1: ColSpec(can_shrink=True, min_width=20, rpad=2),
             2: ColSpec(min_width=9),
             }),
         button_pile([cancel]),
         focus_buttons=False,
         excerpt=(
             excerpts[method]
             + "\n\n"
             + _("Choose the disk to install to:"))))
Beispiel #18
0
    def __init__(self, controller, identity_data):
        self.controller = controller

        reserved_usernames_path = (os.path.join(os.environ.get("SNAP", "."),
                                                "reserved-usernames"))
        reserved_usernames = set()
        if os.path.exists(reserved_usernames_path):
            with open(reserved_usernames_path) as fp:
                for line in fp:
                    line = line.strip()
                    if line.startswith('#') or not line:
                        continue
                    reserved_usernames.add(line)
        else:
            reserved_usernames.add('root')

        initial = {
            'realname': identity_data.realname,
            'username': identity_data.username,
            'hostname': identity_data.hostname,
        }

        self.form = IdentityForm(reserved_usernames, initial)

        connect_signal(self.form, 'submit', self.done)
        setup_password_validation(self.form, _("passwords"))

        super().__init__(
            screen(self.form.as_rows(), [self.form.done_btn],
                   excerpt=_(self.excerpt),
                   focus_buttons=False))
Beispiel #19
0
 def __init__(self, model, controller):
     self.model = model
     self.controller = controller
     super().__init__(screen(
         self._build_model_inputs(),
         buttons=None,
         narrow_rows=True,
         excerpt=_("Use UP, DOWN and ENTER keys to select your language.")))
Beispiel #20
0
 def __init__(self, model, controller):
     self.model = model
     self.controller = controller
     super().__init__(screen(
         self._build_model_inputs(),
         buttons=None,
         narrow_rows=True,
         excerpt=_("Please choose your preferred language.")))
Beispiel #21
0
    def __init__(self, controller, netdev_infos):
        self.controller = controller
        self.dev_name_to_table = {}
        self.cur_netdev_names = []
        self.error = Text("", align='center')

        self.device_colspecs = {
            0: ColSpec(rpad=1),
            3: ColSpec(min_width=15),
            4: ColSpec(can_shrink=True, rpad=1),
        }

        self.heading_table = TablePile([
            TableRow([
                Color.info_minor(Text(header)) for header in [
                    "",
                    "NAME",
                    "TYPE",
                    "NOTES",
                    "",
                ]
            ])
        ],
                                       spacing=2,
                                       colspecs=self.device_colspecs)

        self.device_pile = Pile([self.heading_table])

        for dev_info in netdev_infos:
            self.new_link(dev_info)

        self._create_bond_btn = menu_btn(_("Create bond"),
                                         on_press=self._create_bond)
        bp = button_pile([self._create_bond_btn])
        bp.align = 'left'

        rows = [
            self.device_pile,
            bp,
        ]

        self.buttons = button_pile([
            done_btn("TBD", on_press=self.done),  # See _route_watcher
            back_btn(_("Back"), on_press=self.cancel),
        ])
        self.bottom = Pile([
            ('pack', self.buttons),
        ])

        self.error_showing = False

        super().__init__(
            screen(rows=rows,
                   buttons=self.bottom,
                   focus_buttons=True,
                   excerpt=_(self.excerpt)))
Beispiel #22
0
 def __init__(self, controller):
     self.controller = controller
     super().__init__(
         screen([
             Text(_(fail_text)),
             Text(""),
             button_pile([
                 other_btn(_("Show Error Report"), on_press=self.show_error)
             ]),
         ], [other_btn(_("Back"), on_press=self.cancel)]))
Beispiel #23
0
    def __init__(self, controller, disks):
        self.controller = controller

        if disks:
            if any(disk.ok_for_guided for disk in disks):
                self.form = GuidedForm(disks=disks)

                connect_signal(self.form, 'submit', self.done)
                connect_signal(self.form, 'cancel', self.cancel)

                super().__init__(
                    self.form.as_screen(focus_buttons=False,
                                        excerpt=_(subtitle)))
            else:
                super().__init__(
                    screen([Text(rewrap(_(no_big_disks)))],
                           [other_btn(_("OK"), on_press=self.manual)]))
        else:
            super().__init__(screen([Text(rewrap(_(no_disks)))], []))
Beispiel #24
0
 def load(self, sender=None):
     t = self.controller.get_snap_list_task()
     if t.done():
         self.loaded()
         return
     spinner = Spinner(self.controller.app.aio_loop, style='dots')
     spinner.start()
     self._w = screen(
         [spinner], [ok_btn(label=_("Continue"), on_press=self.done)],
         excerpt=_("Loading server snaps from store, please wait..."))
     schedule_task(self._wait(t, spinner))
Beispiel #25
0
 def __init__(self, model, controller):
     self.title = self.title.format(lsb_release().get(
         'release', 'Unknown Release'))
     self.model = model
     self.controller = controller
     self.items = []
     back = back_btn(_("Back"), on_press=self.cancel)
     super().__init__(
         screen(self._build_choices(), [back],
                focus_buttons=False,
                excerpt=_(self.excerpt)))
Beispiel #26
0
 def __init__(self, model, controller):
     self.title = self.title.format(
         lsb_release.get_distro_information()['RELEASE'])
     self.model = model
     self.controller = controller
     self.items = []
     back = back_btn(_("Back"), on_press=self.cancel)
     super().__init__(
         screen(self._build_choices(), [back],
                focus_buttons=False,
                excerpt=_(self.excerpt)))
Beispiel #27
0
 def __init__(self, controller):
     self.controller = controller
     self.spinner = Spinner(aio_loop=controller.app.aio_loop, style="dots")
     self.spinner.start()
     super().__init__(
         screen([
             Text(
                 _("The installer is probing for block devices to install "
                   "to. Please wait until it completes.")),
             Text(""),
             self.spinner,
         ], [other_btn(_("Back"), on_press=self.cancel)]))
Beispiel #28
0
 def __init__(self, controller):
     self.controller = controller
     self.spinner = Spinner(loop=controller.loop, style="dots")
     self.spinner.start()
     super().__init__(
         screen([
             Text(
                 _("The installer is probing for block devices to install "
                   "to. Please wait until it completes.")),
             Text(""),
             self.spinner,
         ]))
Beispiel #29
0
    def __init__(self, controller, systems):
        self.controller = controller

        heading_table = TablePile([
            TableRow([
                Color.info_minor(Text(header))
                for header in ["LABEL", "MODEL", "PUBLISHER", ""]
            ])
        ],
                                  spacing=2)

        trows = []
        systems = sorted(
            systems,
            key=lambda s:
            (s.brand.display_name, s.model.display_name, s.current, s.label))
        for s in systems:
            actions = []
            log.debug('actions: %s', s.actions)
            for act in sorted(s.actions, key=by_preferred_action_type):
                actions.append(
                    Action(label=act.title.capitalize(),
                           value=act,
                           enabled=True))
            menu = ActionMenu(actions)
            connect_signal(menu, 'action', self._system_action, s)
            srow = make_action_menu_row([
                Text(s.label),
                Text(s.model.display_name),
                Text(s.brand.display_name),
                Text("(installed)" if s.current else ""),
                menu,
            ], menu)
            trows.append(srow)

        systems_table = TablePile(trows, spacing=2)
        systems_table.bind(heading_table)
        rows = [
            Pile([heading_table, systems_table]),
        ]

        buttons = []
        if controller.model.current is not None:
            # back to options of current system
            buttons.append(back_btn("BACK", on_press=self.back))

        super().__init__(
            controller.model.current,
            screen(rows=rows,
                   buttons=button_pile(buttons),
                   focus_buttons=False,
                   excerpt=self.excerpt))
Beispiel #30
0
    def __init__(self, controller, zdevinfos):
        log.debug('FileSystemView init start()')
        self.controller = controller
        self.zdev_list = ZdevList(self)
        self.zdev_list.update(zdevinfos)

        frame = screen(
            self.zdev_list, self._build_buttons(),
            focus_buttons=False)
        super().__init__(frame)
        # Prevent urwid from putting the first focused widget at the
        # very top of the display (obscuring the headings)
        self.zdev_list._w._w.base_widget.set_focus_valign("bottom")