def on_preset_button_clicked(self, widget): def on_ok(preset_name): if preset_name == '': return preset = {} for name in self.plugin.config_default_values: if name == 'presets': continue if name == 'preview_provider': preset[name] = self.xml.get_object(name).get_active() continue widget = self.xml.get_object(name) preset[name] = widget.get_text() preset = {preset_name: preset} presets = dict(self.plugin.config['presets'].items() + preset.items()) if preset_name not in self.plugin.config['presets'].keys(): iter_ = self.preset_liststore.append((preset_name, )) self.plugin.config['presets'] = presets self.set_modal(False) InputDialog(_('Save as Preset'), _('Please type a name for this preset'), is_modal=True, ok_handler=on_ok)
def inputs(self, widget): if not self.inputdialog: self.inputdialog = InputDialog(self.mainwin) self.inputdialog.run(self.hatari)
def __init__(self, partition): assert partition.type not in (parted.PARTITION_METADATA, parted.PARTITION_EXTENDED) self.format_as = '' self.mount_as = '' self.label = '' self.encrypt = False self.enc_passphrase = '' # Initiate encryption status dictionary (even for non-encrypted partitions) self.enc_status = get_status(partition.path) self.grub = False self.disk_type = '' self.partition = partition self.path = partition.path self.length = partition.getLength() self.size_percent = max( 1, round(80 * self.length / partition.disk.device.getLength(), 1)) self.size_mb = int(partition.getLength('B') / 1024 / 1024) self.size = to_human_readable(partition.getLength('B')) try: # This will crash on USB sticks self.flags = partition.getFlagsAsString().split(', ') except: self.flags = [] # if not normal partition with /dev/sdXN path, set its name to '' and discard it from model self.name = self.path if partition.number != -1 else '' encrypted = is_encrypted(self.path) try: if encrypted: self.type = 'luks' else: self.type = partition.fileSystem.type for fs in ( 'swap', 'hfs', 'ufs' ): # normalize fs variations (parted.filesystem.fileSystemType.keys()) if fs in self.type: self.type = fs self.style = self.type except AttributeError: # non-formatted partitions self.type = { parted.PARTITION_LVM: 'LVM', parted.PARTITION_SWAP: 'swap', parted.PARTITION_RAID: 'RAID', # Empty space on Extended partition is recognized as this parted.PARTITION_PALO: 'PALO', parted.PARTITION_PREP: 'PReP', parted.PARTITION_LOGICAL: _('Logical partition'), parted.PARTITION_EXTENDED: _('Extended partition'), parted.PARTITION_FREESPACE: _('Free space'), parted.PARTITION_HPSERVICE: 'HP Service', parted.PARTITION_MSFT_RESERVED: 'MSFT Reserved', }.get(partition.type, _('Unknown')) self.style = { parted.PARTITION_SWAP: 'swap', parted.PARTITION_FREESPACE: 'freespace', }.get(partition.type, '') if "swap" in self.type: self.mount_as = SWAP_MOUNT_POINT if "fat" in self.type and installer.setup.gptonefi: if has_efi_installed(self.path): self.mount_as = EFI_MOUNT_POINT installer.setup.efi_partition = self.path else: if installer.setup.efi_partition is None: if 'boot' in self.flags: self.mount_as = EFI_MOUNT_POINT elif 'boot' in self.flags: self.mount_as = BOOT_MOUNT_POINT # identify partition's label and used space mount_point = '' try: if encrypted: if not is_connected(self): # Ask for password for encrypted partition and save it in enc_password pwd = InputDialog( title=_("Encryption password"), text="{}\n\n{}".format( _("Password for the encrypted partition:"), self.path), is_password=True) enc_passphrase = pwd.show() self.enc_passphrase = enc_passphrase mapped_drv = connect_block_device(self) if is_connected(self): self.enc_status = get_status(mapped_drv) self.path = mapped_drv self.name = mapped_drv part_label = get_partition_label(mapped_drv) self.mount_device(mapped_drv) else: part_label = get_partition_label(self.path) if not "swap" in self.type: self.mount_device(self.path) # Get size and other info size, free, self.used_percent, mount_point = getoutput( "df {0} | grep '^{0}' | awk '{{print $2,$4,$5,$6}}' | tail -1". format(self.path)).split() except ValueError: print('WARNING: Partition {} or type {} failed to mount!'.format( self.path, self.type)) self.os_fs_info, self.label, self.free_space, self.used_percent = ': ' + self.type, '', '', 0 else: self.size_mb = int(int(size) / 1024) self.size = to_human_readable( int(size) * 1024 ) # for mountable partitions, more accurate than the getLength size above self.free_space = to_human_readable( int(free) * 1024) # df returns values in 1024B-blocks by default self.used_percent = self.used_percent.strip('%') or 0 # Had to rewrite label: multiple user errors label = '' if path_exists(mount_point, 'etc/'): try: label = get_release_name(mount_point) if label == '': label = getoutput('uname -s') set_home = False if installer.setup.oem_setup: # OEM setup: check if this partition is mounted as root #print((">> %s" % get_mount_point(self.path))) if get_mount_point(self.path) == '/': installer.setup.root_partition = self.path set_home = True else: # Save this partition as a partition to mount as root if installer.setup.root_partition is None: installer.setup.root_partition = self.path set_home = True else: # Empty the root_partition and home_partition variables to show that this # is a multi-boot system and no root or home partition may be pre-mounted installer.setup.root_partition = '' installer.setup.home_partition = '' # Get home partition from fstab if set_home: fstab = join(mount_point, 'etc/fstab') if path_exists(fstab): fstab_cont = '' with open(fstab, 'r') as f: fstab_cont = f.read() fstab_str = re.search( "([a-z0-9-/]+)\s+%s" % HOME_MOUNT_POINT, fstab_cont).group(1) installer.setup.home_partition = get_partition_path_from_string( fstab_str) except: label = 'Unix' elif path_exists(mount_point, 'Windows/servicing/Version'): label = 'Windows ' + { '6.4': '10', '6.3': '8.1', '6.2': '8', '6.1': '7', '6.0': 'Vista', '5.2': 'XP Pro x64', '5.1': 'XP', '5.0': '2000', '4.9': 'ME', '4.1': '98', '4.0': '95', }.get( getoutput('ls {}/Windows/servicing/Version'.format( mount_point))[:3], '') elif path_exists(mount_point, 'Boot/BCD'): label = 'Windows recovery' elif path_exists(mount_point, 'Windows/System32'): label = 'Windows' elif path_exists( mount_point, 'System/Library/CoreServices/SystemVersion.plist'): label = 'Mac OS X' elif self.mount_as == EFI_MOUNT_POINT: # Label on fat cannot be longer than 11 characters label = 'EFI' if part_label == '': self.label = label else: self.label = part_label self.os_fs_info = ': {0.label} ({0.type}; {0.size}; {0.free_space})'.format( self) if self.label else ': ' + self.type finally: if TMP_MOUNTPOINT in mount_point: shell_exec("umount -f %s" % self.path) self.html_name = self.name.split('/')[-1] self.html_description = self.label if (self.size_percent < 10 and len(self.label) > 5): self.html_description = "%s..." % self.label[0:5] if (self.size_percent < 5): #Not enough space, don't write the name self.html_name = "" self.html_description = "" self.color = { # colors approximately from gparted (find matching set in usr/share/disk-partitions.html) 'btrfs': '#636363', 'exfat': '#47872a', 'ext2': '#2582a0', 'ext3': '#2582a0', 'ext4': '#21619e', 'fat16': '#47872a', 'fat32': '#47872a', 'hfs': '#636363', 'jfs': '#636363', 'swap': '#be3a37', 'ntfs': '#66a6a8', 'reiserfs': '#636363', 'ufs': '#636363', 'xfs': '#636363', 'zfs': '#636363', 'luks': '#3E3B4D', parted.PARTITION_EXTENDED: '#a9a9a9', }.get(self.type, '#a9a9a9')