当前位置: 首页>>代码示例>>Python>>正文


Python PartedServer.disks方法代码示例

本文整理汇总了Python中ubiquity.parted_server.PartedServer.disks方法的典型用法代码示例。如果您正苦于以下问题:Python PartedServer.disks方法的具体用法?Python PartedServer.disks怎么用?Python PartedServer.disks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ubiquity.parted_server.PartedServer的用法示例。


在下文中一共展示了PartedServer.disks方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: filter_parts

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
    def filter_parts(self):
        question = 'migration-assistant/partitions'
        from ubiquity.parted_server import PartedServer
        with raised_privileges():
            parted = PartedServer()

            parts = []
            for disk in parted.disks():
                parted.select_disk(disk)
                for partition in parted.partitions():
                    # We check to see if the partition is scheduled to be
                    # formatted and if not add it to the list of post-commit
                    # available partitions.
                    filename = '/var/lib/partman/devices/%s/%s/format' % \
                        (disk, partition[1])
                    if os.path.exists(filename):
                        syslog.syslog('filtering out %s as it is to be formatted.' % partition[5])
                    else:
                        parts.append(partition[5])

        ret = []
        for choice in self.choices(question):
            if choice[choice.rfind('(')+1:choice.rfind(')')] in parts:
                ret.append(choice)

        self.preseed(question, ", ".join(ret))
开发者ID:cjenkin2,项目名称:ubiquity,代码行数:28,代码来源:ubi-migrationassistant.py

示例2: find_grub_target

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
def find_grub_target():
    # This needs to be somewhat duplicated from grub-installer here because we
    # need to be able to show the user what device GRUB will be installed to
    # well before grub-installer is run.
    try:
        boot = ""
        root = ""
        regain_privileges()
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            for part in p.partitions():
                part = part[1]
                if p.has_part_entry(part, "mountpoint"):
                    mp = p.readline_part_entry(part, "mountpoint")
                    if mp == "/boot":
                        boot = disk.replace("=", "/")
                    elif mp == "/":
                        root = disk.replace("=", "/")
        drop_privileges()
        if boot:
            return boot
        elif root:
            return root
        return "(hd0)"
    except Exception, e:
        drop_privileges()
        import syslog

        syslog.syslog("Exception in find_grub_target: " + str(e))
        return "(hd0)"
开发者ID:ericpaulbishop,项目名称:salamander,代码行数:33,代码来源:summary.py

示例3: boot_device

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
def boot_device():
    from ubiquity.parted_server import PartedServer

    boot = None
    root = None
    try:
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            for part in p.partitions():
                part = part[1]
                if p.has_part_entry(part, 'mountpoint'):
                    mp = p.readline_part_entry(part, 'mountpoint')
                    if mp == '/boot':
                        boot = disk.replace('=', '/')
                    elif mp == '/':
                        root = disk.replace('=', '/')
    except Exception:
        import traceback

        for line in traceback.format_exc().split('\n'):
            syslog.syslog(syslog.LOG_ERR, line)
    if boot:
        return boot
    return root
开发者ID:cesarcifmetal,项目名称:Cnchi,代码行数:27,代码来源:misc.py

示例4: filter_parts

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
    def filter_parts(self):
        question = 'migration-assistant/partitions'
        from ubiquity.parted_server import PartedServer
        os.seteuid(0)
        parted = PartedServer()

        parts = []
        for disk in parted.disks():
            parted.select_disk(disk)
            for partition in parted.partitions():
                # We check to see if the partition is scheduled to be
                # formatted and if not add it to the list of post-commit
                # available partitions.
                filename = '/var/lib/partman/devices/%s/%s/view' % \
                    (disk, partition[1])
                fd = open(filename)
                pieces = fd.readline().rstrip('\n').split(None, 8)
                fd.close()
                line = [''] * 8
                line[0:len(pieces)] = pieces
                formatted = ['F', 'f', 'swap']
                if not (set(line) & set(formatted)):
                    parts.append(partition[5])
                else:
                    syslog.syslog('filtering out %s as it is to be formatted.' % partition[5])

        drop_privileges()
        ret = []
        for choice in self.choices(question):
            if choice[choice.rfind('(')+1:choice.rfind(')')] in parts:
                ret.append(choice)

        self.preseed(question, ", ".join(ret))
开发者ID:guadalinex-archive,项目名称:guadalinex-v5,代码行数:35,代码来源:migrationassistant.py

示例5: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    from ubiquity.parted_server import PartedServer

    l = []
    try:
        oslist = {}
        subp = subprocess.Popen(['os-prober'], stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
        result = subp.communicate()[0].splitlines()
        for res in result:
            res = res.split(':')
            oslist[res[0]] = res[1]
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            dev = ''
            mod = ''
            size = ''
            try:
                fp = open(p.device_entry('model'))
                mod = fp.readline()
                fp.close()
                fp = open(p.device_entry('device'))
                dev = fp.readline()
                fp.close()
                fp = open(p.device_entry('size'))
                size = fp.readline()
                fp.close()
            finally:
                if fp:
                    fp.close()
            if dev and mod:
                if size.isdigit():
                    size = format_size(int(size))
                    l.append([dev, '%s (%s)' % (mod, size)])
                else:
                    l.append([dev, mod])
            for part in p.partitions():
                ostype = ''
                if part[4] == 'linux-swap':
                    continue
                if part[4] == 'free':
                    continue
                if os.path.exists(p.part_entry(part[1], 'format')):
                    # Don't bother looking for an OS type.
                    pass
                elif part[5] in oslist.keys():
                    ostype = oslist[part[5]]
                l.append([part[5], ostype])
    except:
        import traceback
        for line in traceback.format_exc().split('\n'):
            syslog.syslog(syslog.LOG_ERR, line)
    return l
开发者ID:guadalinexv9-team,项目名称:guadalinexv9-ubiquity-conf,代码行数:58,代码来源:misc.py

示例6: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    from ubiquity.parted_server import PartedServer

    l = []
    try:
        oslist = {}
        subp = subprocess.Popen(["os-prober"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
        result = subp.communicate()[0].splitlines()
        for res in result:
            res = res.split(":")
            oslist[res[0]] = res[1]
        p = PartedServer()
        for disk in p.disks():
            p.select_disk(disk)
            with open(p.device_entry("model")) as fp:
                mod = fp.readline()
            with open(p.device_entry("device")) as fp:
                dev = fp.readline()
            with open(p.device_entry("size")) as fp:
                size = fp.readline()
            if dev and mod:
                if size.isdigit():
                    size = format_size(int(size))
                    l.append([dev, "%s (%s)" % (mod, size)])
                else:
                    l.append([dev, mod])
            for part in p.partitions():
                ostype = ""
                if part[4] == "linux-swap":
                    continue
                if part[4] == "free":
                    continue
                if os.path.exists(p.part_entry(part[1], "format")):
                    # Don't bother looking for an OS type.
                    pass
                elif part[5] in oslist.keys():
                    ostype = oslist[part[5]]
                l.append([part[5], ostype])
    except:
        import traceback

        for line in traceback.format_exc().split("\n"):
            syslog.syslog(syslog.LOG_ERR, line)
    return l
开发者ID:Astalaseven,项目名称:Cnchi,代码行数:48,代码来源:misc.py

示例7: grub_options

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
def grub_options():
    """ Generates a list of suitable targets for grub-installer
        @return empty list or a list of ['/dev/sda1','Ubuntu Hardy 8.04'] """
    os.seteuid(0)
    l = []
    oslist = {}
    subp = subprocess.Popen(['os-prober'], stdout=subprocess.PIPE,
        stderr=subprocess.PIPE)
    result = subp.communicate()[0].splitlines()
    for res in result:
        res = res.split(':')
        oslist[res[0]] = res[1]
    p = PartedServer()
    for disk in p.disks():
        p.select_disk(disk)
        dev = ''
        mod = ''
        size = ''
        try:
            fp = open(p.device_entry('model'))
            mod = fp.readline()
            fp.close()
            fp = open(p.device_entry('device'))
            dev = fp.readline()
            fp = open(p.device_entry('size'))
            size = fp.readline()
        finally:
            fp.close()
        if dev and mod:
            if size.isdigit():
                size = format_size(int(size))
                l.append([dev, '%s (%s)' % (mod, size)])
            else:
                l.append([dev, mod])
        for part in p.partitions():
            ostype = ''
            if part[4] == 'xfs' or part[4] == 'linux-swap':
                continue
            if os.path.exists(p.part_entry(part[1], 'format')):
                pass
            elif part[5] in oslist.keys():
                ostype = oslist[part[5]]
            l.append([part[5], ostype])
    drop_privileges()
    return l
开发者ID:guadalinex-archive,项目名称:guadalinex-v5,代码行数:47,代码来源:summary.py

示例8: run

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
    def run(self, priority, question):
        if self.stashed_auto_mountpoints is None:
            # We need to extract the automatic mountpoints calculated by
            # partman at some point while parted_server is running, so that
            # they can be used later if manual partitioning is selected.
            # This hack is only necessary because the manual partitioner is
            # NIHed rather than being based on partman.
            self.stashed_auto_mountpoints = {}
            parted = PartedServer()
            for disk in parted.disks():
                parted.select_disk(disk)
                for part in parted.partitions():
                    (p_num, p_id, p_size, p_type, p_fs, p_path, p_name) = part
                    if p_fs == 'free':
                        continue
                    if not parted.has_part_entry(p_id, 'method'):
                        continue
                    method = parted.readline_part_entry(p_id, 'method')
                    if method == 'swap':
                        continue
                    elif p_fs == 'hfs' and method == 'newworld':
                        self.stashed_auto_mountpoints[p_path] = 'newworld'
                    elif parted.has_part_entry(p_id, 'acting_filesystem'):
                        mountpoint = parted.readline_part_entry(p_id,
                                                                'mountpoint')
                        self.stashed_auto_mountpoints[p_path] = mountpoint
            self.frontend.set_auto_mountpoints(self.stashed_auto_mountpoints)

        if self.done:
            # user answered confirmation question or selected manual
            # partitioning
            return self.succeeded

        self.current_question = question

        try:
            qtype = self.db.metaget(question, 'Type')
        except debconf.DebconfError:
            qtype = ''

        if question == 'partman-auto/select_disk':
            self.resize_allowed = True
            self.manual_desc = \
                self.description('partman-auto/text/custom_partitioning')
            self.do_nothing_desc = \
                self.description('partman-auto/text/do_nothing_partitioning')
            self.use_biggest_free_desc = \
                self.description('partman-auto/text/use_biggest_free')
            if not self.frontend.set_disk_choices(self.choices(question),
                                                  self.manual_desc):
                # disk selector not implemented; just use first disk
                return self.succeeded

        elif question.endswith('automatically_partition'):
            if self.backup_from_new_size is not None:
                # We backed up from the resize question and now need to
                # carry on down a different (preseeded) path.
                self.preseed(question, self.backup_from_new_size)
                self.backup_from_new_size = None
                self.succeeded = True
                return True

            self.autopartition_question = question
            self.resize_desc = \
                self.description('partman-auto/text/resize_use_free')
            self.manual_desc = \
                self.description('partman-auto/text/custom_partitioning')
            self.do_nothing_desc = \
                self.description('partman-auto/text/do_nothing_partitioning')
            self.use_biggest_free_desc = \
                self.description('partman-auto/text/use_biggest_free')
            choices = self.choices(question)
            if not self.resize_allowed:
                try:
                    del choices[choices.index(self.resize_desc)]
                except ValueError:
                    pass
            self.frontend.set_autopartition_choices(
                choices, self.resize_desc, self.manual_desc, self.do_nothing_desc, self.use_biggest_free_desc)
            if self.resize_desc in choices:
                # The resize option is available, so we need to present the
                # user with an accurate resize slider before passing control
                # to the UI.
                # Don't preseed_as_c, because Perl debconf is buggy in that
                # it doesn't expand variables in the result of METAGET
                # choices-c. All locales have the same variables anyway so
                # it doesn't matter.
                self.preseed(question, self.resize_desc)
                return True

        elif question == 'partman-partitioning/new_size':
            self.backup_from_new_size = None
            self.frontend.set_autopartition_resize_bounds(self.resize_min_size,
                                                          self.resize_max_size)

        elif question.startswith('partman/confirm'):
            if question == 'partman/confirm':
                self.db.set('ubiquity/partman-made-changes', 'true')
            else:
                self.db.set('ubiquity/partman-made-changes', 'false')
#.........这里部分代码省略.........
开发者ID:guadalinex-archive,项目名称:guadalinex-v4,代码行数:103,代码来源:partman_auto.py

示例9: progress_stop

# 需要导入模块: from ubiquity.parted_server import PartedServer [as 别名]
# 或者: from ubiquity.parted_server.PartedServer import disks [as 别名]
    def progress_stop(self, progress_title):
        ret = super(PartmanCommit, self).progress_stop(progress_title)

        if (progress_title == 'partman/progress/init/title' and
            self.manual_input):
            partitions = {}
            parted = PartedServer()
            for disk in parted.disks():
                parted.select_disk(disk)
                for part in parted.partitions():
                    (p_num, p_id, p_size, p_type, p_fs, p_path, p_name) = part
                    partitions[p_path] = (disk, p_id)

            mountpoints = self.frontend.get_mountpoints()
            for device in partitions:
                (disk, p_id) = partitions[device]
                parted.select_disk(disk)
                if device in mountpoints:
                    (path, format, fstype, flags) = mountpoints[device]
                    if path == 'swap':
                        parted.write_part_entry(p_id, 'method', 'swap\n')
                        if format:
                            parted.write_part_entry(p_id, 'format', '')
                        else:
                            parted.remove_part_entry(p_id, 'format')
                        parted.remove_part_entry(p_id, 'use_filesystem')
                    else:
                        if (fstype == 'hfs' and
                            flags is not None and 'boot' in flags):
                            parted.write_part_entry(
                                p_id, 'method', 'newworld\n')
                            parted.write_part_entry(
                                p_id, 'filesystem', 'newworld')
                            parted.remove_part_entry(p_id, 'format')
                            path = None
                        elif format:
                            parted.write_part_entry(p_id, 'method', 'format\n')
                            parted.write_part_entry(p_id, 'format', '')
                            if fstype is None:
                                if parted.has_part_entry(
                                        p_id, 'detected_filesystem'):
                                    fstype = parted.readline_part_entry(
                                        p_id, 'detected_filesystem')
                                else:
                                    # TODO cjwatson 2006-09-27: Why don't we
                                    # know the filesystem type? Fortunately,
                                    # we have an explicit indication from
                                    # the user that it's OK to format this
                                    # filesystem.
                                    fstype = 'ext3'
                            parted.write_part_entry(p_id, 'filesystem', fstype)
                            parted.remove_part_entry(p_id, 'options')
                            parted.mkdir_part_entry(p_id, 'options')
                        else:
                            parted.write_part_entry(p_id, 'method', 'keep\n')
                            parted.remove_part_entry(p_id, 'format')
                            if fstype is not None:
                                parted.write_part_entry(
                                    p_id, 'detected_filesystem', fstype)
                        parted.write_part_entry(p_id, 'use_filesystem', '')
                        if path is not None:
                            parted.write_part_entry(p_id, 'mountpoint', path)
                        else:
                            parted.remove_part_entry(p_id, 'mountpoint')
                elif (parted.has_part_entry(p_id, 'method') and
                      parted.readline_part_entry(p_id, 'method') == 'newworld'):
                    # Leave existing newworld boot partitions alone.
                    pass
                else:
                    parted.remove_part_entry(p_id, 'method')
                    parted.remove_part_entry(p_id, 'format')
                    parted.remove_part_entry(p_id, 'use_filesystem')

        return ret
开发者ID:guadalinex-archive,项目名称:guadalinex-v4,代码行数:76,代码来源:partman_commit.py


注:本文中的ubiquity.parted_server.PartedServer.disks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。