コード例 #1
0
    def display(self):
        if self.setup_network and not self.do_setup_network():
            return ActionResult(False, {'goBack': True})

        file_source = {}
        accepted_chars = list(range(ord('a'), ord('z') + 1))
        accepted_chars.extend(range(ord('A'), ord('Z') + 1))
        accepted_chars.extend(range(ord('0'), ord('9') + 1))
        accepted_chars.extend(
            [ord('-'),
             ord('_'),
             ord('.'),
             ord('~'),
             ord(':'),
             ord('/')])
        result = WindowStringReader(self.maxy, self.maxx, 18, 78, 'url', None,
                                    None, accepted_chars, None, None,
                                    self.title, self.intro, 10, file_source,
                                    'https://', True).get_user_string(None)
        if not result.success:
            return result

        status_window = Window(10, 70, self.maxy, self.maxx,
                               'Installing Photon', False)
        status_window.addstr(1, 0, 'Downloading file...')
        status_window.show_window()

        fd, temp_file = tempfile.mkstemp()
        result, msg = CommandUtils.wget(
            file_source['url'],
            temp_file,
            ask_fn=self.ask_proceed_unsafe_download)
        os.close(fd)
        if not result:
            status_window.adderror('Error: ' + msg +
                                   ' Press any key to go back...')
            status_window.content_window().getch()
            status_window.clearerror()
            status_window.hide_window()
            return ActionResult(False, {'goBack': True})

        if 'additional_files' not in self.install_config:
            self.install_config['additional_files'] = []
        copy = {temp_file: self.dest}
        self.install_config['additional_files'].append(copy)

        return ActionResult(True, None)
コード例 #2
0
class SelectDisk(object):
    def __init__(self, maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) / 2
        self.win_startx = (self.maxx - self.win_width) / 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5
        self.progress_padding = 5
        self.progress_width = self.win_width - self.progress_padding
        self.progress_bar = ProgressBar(
            self.win_starty + 6, self.win_startx + self.progress_padding / 2,
            self.progress_width)

        self.window = Window(self.win_height, self.win_width, self.maxy,
                             self.maxx, 'Setup your disk', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(
            menu_height, menu_width, self.maxy, self.maxx, menu_starty,
            'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if not confirmed:
            return ActionResult(confirmed, None)

        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        self.window.clearerror()
        partitions_data = modules.commons.partition_disk(
            self.devices[device_index].path)
        if partitions_data == None:
            self.window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)

    def display(self, params):
        self.window.addstr(
            0, 0,
            'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'
            .format(len(self.devices)))

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
            self.disk_menu_items.append(
                ('{2} - {1} @ {0}'.format(device.path, device.size,
                                          device.model),
                 self.guided_partitions, index))

        self.disk_menu = Menu(self.menu_starty, self.maxx,
                              self.disk_menu_items, self.menu_height)

        self.window.set_action_panel(self.disk_menu)
        return self.window.do_action()
コード例 #3
0
ファイル: selectdisk.py プロジェクト: Andrew219/photon
class SelectDisk(object):
    def __init__(self,  maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) / 2
        self.win_startx = (self.maxx - self.win_width) / 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5

        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Setup your disk', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']
        
        if not confirmed:
            return ActionResult(confirmed, None)
        
        #self.install_config['disk'] = self.devices[device_index].path
        #return ActionResult(True, None)
        
        # Do the partitioning
        self.window.clearerror()
        json_ret = subprocess.check_output(['gpartedbin', 'defaultpartitions', self.devices[device_index].path], stderr=open(os.devnull, 'w'))
        json_dct = json.loads(json_ret)
        if json_dct['success']:
            self.install_config['disk'] = json_dct['data']
        else:
            self.window.adderror('Partitioning failed, you may try again')
        return ActionResult(json_dct['success'], None)

    def display(self, params):
        self.window.addstr(0, 0, 'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'.format(len(self.devices)))

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
                self.disk_menu_items.append(
                        (
                            '{2} - {1} MB @ {0}'.format(device.path, device.size, device.model), 
                            self.guided_partitions, 
                            index
                        )
                    )

        self.disk_menu = Menu(self.menu_starty,  self.maxx, self.disk_menu_items, self.menu_height)

        self.window.set_action_panel(self.disk_menu)

        return self.window.do_action()
コード例 #4
0
class SelectDisk(object):
    def __init__(self, maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) / 2
        self.win_startx = (self.maxx - self.win_width) / 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5

        self.window = Window(self.win_height, self.win_width, self.maxy,
                             self.maxx, 'Setup your disk', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(
            menu_height, menu_width, self.maxy, self.maxx, menu_starty,
            'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if not confirmed:
            return ActionResult(confirmed, None)

        #self.install_config['disk'] = self.devices[device_index].path
        #return ActionResult(True, None)

        # Do the partitioning
        self.window.clearerror()
        json_ret = subprocess.check_output([
            'gpartedbin', 'defaultpartitions', self.devices[device_index].path
        ],
                                           stderr=open(os.devnull, 'w'))
        json_dct = json.loads(json_ret)
        if json_dct['success']:
            self.install_config['disk'] = json_dct['data']
        else:
            self.window.adderror('Partitioning failed, you may try again')
        return ActionResult(json_dct['success'], None)

    def display(self, params):
        self.window.addstr(
            0, 0,
            'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'
            .format(len(self.devices)))

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
            self.disk_menu_items.append(
                ('{2} - {1} MB @ {0}'.format(device.path, device.size,
                                             device.model),
                 self.guided_partitions, index))

        self.disk_menu = Menu(self.menu_starty, self.maxx,
                              self.disk_menu_items, self.menu_height)

        self.window.set_action_panel(self.disk_menu)

        return self.window.do_action()
コード例 #5
0
ファイル: selectdisk.py プロジェクト: BillTheBest/photon
class SelectDisk(object):
    def __init__(self,  maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) / 2
        self.win_startx = (self.maxx - self.win_width) / 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5
        self.progress_padding = 5
        self.progress_width = self.win_width - self.progress_padding
        self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + self.progress_padding / 2, self.progress_width)

        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Setup your disk', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, device_index):
        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if not confirmed:
            return ActionResult(confirmed, None)

        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        self.window.clearerror()
        partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
        if partitions_data == None:
            self.window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)

    def display(self, params):
        self.window.addstr(0, 0, 'First, we will setup your disks.\n\nWe have detected {0} disks, choose disk to be auto-partitioned:'.format(len(self.devices)))

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
                self.disk_menu_items.append(
                        (
                            '{2} - {1} @ {0}'.format(device.path, device.size, device.model), 
                            self.guided_partitions, 
                            index
                        )
                    )

        self.disk_menu = Menu(self.menu_starty,  self.maxx, self.disk_menu_items, self.menu_height)

        self.window.set_action_panel(self.disk_menu)
        return self.window.do_action()
コード例 #6
0
ファイル: selectdisk.py プロジェクト: zhangzdb/photon
class SelectDisk(object):
    def __init__(self,  maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) // 2
        self.win_startx = (self.maxx - self.win_width) // 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5
        self.progress_padding = 5
        self.progress_width = self.win_width - self.progress_padding
        self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + (self.progress_padding // 2), self.progress_width, new_win=True)

        self.disk_buttom_items = []
        self.disk_buttom_items.append(('<Custom>', self.custom_function, False))
        self.disk_buttom_items.append(('<Auto>', self.auto_function, False))

        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select a disk', True, items = self.disk_buttom_items, menu_helper = self.save_index, position = 2, tab_enabled=False)
        self.partition_window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Partition', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, params):
        if not 'diskindex' in self.install_config:
            return ActionResult(False, None);

        device_index = self.install_config['diskindex']

        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) // 2 + 5
        self.install_config['delete_partition'] = True
        confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if confirmed == False:
            self.install_config['skipPrevs'] = True
            return ActionResult(False, {'goBack':True})

        self.install_config['skipPrevs'] = False
        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        if 'partitionsnumber' in self.install_config:
                if (int(self.install_config['partitionsnumber']) == 0):
                    partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
                else:
                    partitions = []
                    for i in range (int (self.install_config['partitionsnumber'])):
                        if len(self.install_config[str(i)+'partition_info'+str(0)])==0:
                            sizedata=0
                        else:
                            sizedata = int(self.install_config[str(i)+'partition_info'+str(0)])
                        mtdata = self.install_config[str(i)+'partition_info'+str(2)]
                        typedata = self.install_config[str(i)+'partition_info'+str(1)]

                        partitions = partitions + [
                                    {"mountpoint": mtdata, "size": sizedata, "filesystem": typedata},
                                    ]
                    partitions_data = modules.commons.partition_disk(self.devices[device_index].path, partitions)
        else: 
            partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)

        if partitions_data == None:
            self.partition_window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)

    def display(self, params):
        if 'skipPrevs' in self.install_config:
            self.install_config['skipPrevs'] = False
        self.window.addstr(0, 0, 'Please select a disk and a method how to partition it:\nAuto - single partition for /, no swap partition.\nCustom - for customized partitioning')

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
                self.disk_menu_items.append(
                        (
                            '{2} - {1} @ {0}'.format(device.path, device.size, device.model), 
                            self.save_index, 
                            index
                        )
                    )

        self.disk_menu = Menu(self.menu_starty,  self.maxx, self.disk_menu_items, self.menu_height, tab_enable=False)
        self.disk_menu.can_save_sel(True)

        self.window.set_action_panel(self.disk_menu)
        return self.window.do_action()

    def save_index(self, device_index):
        self.install_config['diskindex'] = device_index
        return ActionResult(True, None)

    def auto_function(self, params):    #default is no partition
        self.install_config['autopartition'] = True
        self.install_config['partitionsnumber'] = 0
        return ActionResult(True, None)

    def custom_function(self, params):  #custom minimize partition number is 1
        self.install_config['autopartition'] = False
        return ActionResult(True, None)
コード例 #7
0
ファイル: selectdisk.py プロジェクト: megacoder/photon
class SelectDisk(object):
    def __init__(self,  maxy, maxx, install_config):
        self.install_config = install_config
        self.menu_items = []

        self.maxx = maxx
        self.maxy = maxy
        self.win_width = 70
        self.win_height = 16

        self.win_starty = (self.maxy - self.win_height) / 2
        self.win_startx = (self.maxx - self.win_width) / 2

        self.menu_starty = self.win_starty + 6
        self.menu_height = 5
        self.progress_padding = 5
        self.progress_width = self.win_width - self.progress_padding
        self.progress_bar = ProgressBar(self.win_starty + 6, self.win_startx + self.progress_padding / 2, self.progress_width, new_win=True)

        self.disk_buttom_items = []
        self.disk_buttom_items.append(('<Custom>', self.custom_function, False))
        self.disk_buttom_items.append(('<Auto>', self.auto_function, False))

        self.window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Select a disk', True, items = self.disk_buttom_items, menu_helper = self.save_index, position = 2, tab_enabled=False)
        self.partition_window = Window(self.win_height, self.win_width, self.maxy, self.maxx, 'Partition', True)
        self.devices = Device.refresh_devices()

    def guided_partitions(self, params):
        if not 'diskindex' in self.install_config:
            return ActionResult(False, None);

        device_index = self.install_config['diskindex']

        menu_height = 9
        menu_width = 40
        menu_starty = (self.maxy - menu_height) / 2 + 5
        self.install_config['delete_partition'] = True
        confrim_window = ConfirmWindow(menu_height, menu_width, self.maxy, self.maxx, menu_starty, 'This will erase the disk.\nAre you sure?')
        confirmed = confrim_window.do_action().result['yes']

        if confirmed == False:
            self.install_config['skipPrevs'] = True
            return ActionResult(False, {'goBack':True})

        self.install_config['skipPrevs'] = False
        self.progress_bar.initialize('Partitioning...')
        self.progress_bar.show()
        self.progress_bar.show_loading('Partitioning')

        # Do the partitioning
        if 'partitionsnumber' in self.install_config:
                if (int(self.install_config['partitionsnumber']) == 0):
                    partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)
                else:
                    partitions = []
                    for i in range (int (self.install_config['partitionsnumber'])):
                        if len(self.install_config[str(i)+'partition_info'+str(0)])==0:
                            sizedata=0
                        else:
                            sizedata = int(self.install_config[str(i)+'partition_info'+str(0)])
                        mtdata = self.install_config[str(i)+'partition_info'+str(2)]
                        typedata = self.install_config[str(i)+'partition_info'+str(1)]

                        partitions = partitions + [
                                    {"mountpoint": mtdata, "size": sizedata, "filesystem": typedata},
                                    ]
                    partitions_data = modules.commons.partition_disk(self.devices[device_index].path, partitions)
        else: 
            partitions_data = modules.commons.partition_disk(self.devices[device_index].path, modules.commons.default_partitions)

        if partitions_data == None:
            self.partition_window.adderror('Partitioning failed, you may try again')
        else:
            self.install_config['disk'] = partitions_data

        self.progress_bar.hide()
        return ActionResult(partitions_data != None, None)

    def display(self, params):
        if 'skipPrevs' in self.install_config:
            self.install_config['skipPrevs'] = False
        self.window.addstr(0, 0, 'Please select a disk and a method how to partition it:\nAuto - single partition for /, no swap partition.\nCustom - for customized partitioning')

        self.disk_menu_items = []

        # Fill in the menu items
        for index, device in enumerate(self.devices):
            #if index > 0:
                self.disk_menu_items.append(
                        (
                            '{2} - {1} @ {0}'.format(device.path, device.size, device.model), 
                            self.save_index, 
                            index
                        )
                    )

        self.disk_menu = Menu(self.menu_starty,  self.maxx, self.disk_menu_items, self.menu_height, tab_enable=False)
        self.disk_menu.can_save_sel(True)

        self.window.set_action_panel(self.disk_menu)
        return self.window.do_action()

    def save_index(self, device_index):
        self.install_config['diskindex'] = device_index
        return ActionResult(True, None)

    def auto_function(self, params):    #default is no partition
        self.install_config['autopartition'] = True
        self.install_config['partitionsnumber'] = 0
        return ActionResult(True, None)

    def custom_function(self, params):  #custom minimize partition number is 1
        self.install_config['autopartition'] = False
        return ActionResult(True, None)