• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python pykickstart._函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pykickstart._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: parse

    def parse(self, args):
        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        data = self.handler.BTRFSData()
        self._setToObj(self.op, opts, data)
        data.lineno = self.lineno

        if len(extra) == 0:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs must be given a mountpoint")))

        if len(extra) == 1 and not data.subvol:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs must be given a list of partitions")))
        elif len(extra) == 1:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs subvol requires specification of parent volume")))

        if data.subvol and not data.name:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("btrfs subvolume requires a name")))

        data.mountpoint = extra[0]
        data.devices = extra[1:]

        # Check for duplicates in the data list.
        if data in self.dataList():
            warnings.warn(_("A btrfs volume with the mountpoint %s has already been defined.") % data.label)

        return data
开发者ID:tradej,项目名称:pykickstart-old,代码行数:25,代码来源:btrfs.py


示例2: formatErrorMsg

def formatErrorMsg(lineno, msg=""):
    """Properly format the error message msg for inclusion in an exception."""
    if msg != "":
        mapping = {"lineno": lineno, "msg": msg}
        return _("The following problem occurred on line %(lineno)s of the kickstart file:\n\n%(msg)s\n") % mapping
    else:
        return _("There was a problem reading from line %s of the kickstart file") % lineno
开发者ID:tradej,项目名称:pykickstart-old,代码行数:7,代码来源:errors.py


示例3: _parseJoin

    def _parseJoin(self, args):
        try:
            # We only support these args
            opts, remaining = getopt.getopt(args, "", ("client-software=",
                                                       "server-software=",
                                                       "membership-software=",
                                                       "one-time-password=",
                                                       "no-password",
                                                       "computer-ou="))
        except getopt.GetoptError as ex:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
                "Invalid realm arguments: %s") % ex))

        if len(remaining) != 1:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
                "Specify only one realm to join")))

        # Parse successful, just use this as the join command
        self.join_realm = remaining[0]
        self.join_args = args

        # Build a discovery command
        self.discover_options = []
        supported_discover_options = ("--client-software",
                                      "--server-software",
                                      "--membership-software")
        for (o, a) in opts:
            if o in supported_discover_options:
                self.discover_options.append("%s=%s" % (o, a))
开发者ID:tradej,项目名称:pykickstart-old,代码行数:29,代码来源:realm.py


示例4: check_values

    def check_values (self, values, args):
        def seen(option):
            return option in self.option_seen

        def usedTooNew(option):
            return option.introduced and option.introduced > self.version

        def usedDeprecated(option):
            return option.deprecated

        def usedRemoved(option):
            return option.removed and option.removed <= self.version

        for option in [o for o in self.option_list if isinstance(o, Option)]:
            if option.required and not seen(option):
                raise KickstartValueError(formatErrorMsg(self.lineno, _("Option %s is required") % option))
            elif seen(option) and usedTooNew(option):
                mapping = {"option": option, "intro": versionToString(option.introduced),
                           "version": versionToString(self.version)}
                self.error(_("The %(option)s option was introduced in version %(intro)s, but you are using kickstart syntax version %(version)s.") % mapping)
            elif seen(option) and usedRemoved(option):
                mapping = {"option": option, "removed": versionToString(option.removed),
                           "version": versionToString(self.version)}

                if option.removed == self.version:
                    self.error(_("The %(option)s option is no longer supported.") % mapping)
                else:
                    self.error(_("The %(option)s option was removed in version %(removed)s, but you are using kickstart syntax version %(version)s.") % mapping)
            elif seen(option) and usedDeprecated(option) and self.version >= option.deprecated:
                mapping = {"lineno": self.lineno, "option": option}
                warnings.warn(_("Ignoring deprecated option on line %(lineno)s:  The %(option)s option has been deprecated and no longer has any effect.  It may be removed from future releases, which will result in a fatal error from kickstart.  Please modify your kickstart file to remove this option.") % mapping, DeprecationWarning)

        return (values, args)
开发者ID:tradej,项目名称:pykickstart-old,代码行数:33,代码来源:options.py


示例5: stringToVersion

def stringToVersion(s):
    """Convert string into one of the provided version constants.  Raises
       KickstartVersionError if string does not match anything.
    """
    # First try these short forms.
    try:
        return versionMap[s.upper()]
    except KeyError:
        pass

    # Now try the Fedora versions.
    m = re.match(r"^fedora.* (\d+)$", s, re.I)

    if m and m.group(1):
        if "FC" + m.group(1) in versionMap:
            return versionMap["FC" + m.group(1)]
        elif "F" + m.group(1) in versionMap:
            return versionMap["F" + m.group(1)]
        else:
            raise KickstartVersionError(_("Unsupported version specified: %s") % s)

    # Now try the RHEL versions.
    m = re.match(r"^red hat enterprise linux.* (\d+)([\.\d]*)$", s, re.I)

    if m and m.group(1):
        if "RHEL" + m.group(1) in versionMap:
            return versionMap["RHEL" + m.group(1)]
        else:
            raise KickstartVersionError(_("Unsupported version specified: %s") % s)

    # If nothing else worked, we're out of options.
    raise KickstartVersionError(_("Unsupported version specified: %s") % s)
开发者ID:tradej,项目名称:pykickstart-old,代码行数:32,代码来源:version.py


示例6: _preprocessStateMachine

def _preprocessStateMachine (lineIter):
    l = None
    lineno = 0

    # Now open an output kickstart file that we are going to write to one
    # line at a time.
    (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")

    while True:
        try:
            l = next(lineIter)
        except StopIteration:
            break

        # At the end of the file?
        if l == "":
            break

        lineno += 1
        url = None

        ll = l.strip()
        if not ll.startswith("%ksappend"):
            os.write(outF, l)
            continue

        # Try to pull down the remote file.
        try:
            ksurl = ll.split(' ')[1]
        except:
            raise KickstartParseError(formatErrorMsg(lineno, msg=_("Illegal url for %%ksappend: %s") % ll))

        try:
            if '://' in ksurl:
                url = urlopen(ksurl)
            else:
                url = open(ksurl, 'r')
        except (URLError, IOError) as e:
            raise KickstartError(formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file: %s") % str(e)))
        else:
            # Sanity check result.  Sometimes FTP doesn't catch a file
            # is missing.
            try:
                if url.size < 1:
                    raise KickstartError(formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file")))
            except:
                raise KickstartError(formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file")))

        # If that worked, write the remote file to the output kickstart
        # file in one burst.  Then close everything up to get ready to
        # read ahead in the input file.  This allows multiple %ksappend
        # lines to exist.
        if url is not None:
            os.write(outF, url.read())
            url.close()

    # All done - close the temp file and return its location.
    os.close(outF)
    return outName
开发者ID:tradej,项目名称:pykickstart-old,代码行数:59,代码来源:parser.py


示例7: parse

    def parse(self, args):
        retval = F14_Url.parse(self, args)

        if self.url and self.mirrorlist:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Only one of --url and --mirrorlist may be specified for url command.")))

        if not self.url and not self.mirrorlist:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("One of --url or --mirrorlist must be specified for url command.")))

        return retval
开发者ID:tradej,项目名称:pykickstart-old,代码行数:10,代码来源:url.py


示例8: parse

    def parse(self, args):
        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        self._setToSelf(self.op, opts)

        if len(extra) != 0:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "eula"))

        if not self.agreed:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command eula expects the --agreed option")))

        return self
开发者ID:tradej,项目名称:pykickstart-old,代码行数:11,代码来源:eula.py


示例9: _parseArguments

 def _parseArguments(self, string):
     if self.join_realm:
         raise KickstartParseError(formatErrorMsg(self.lineno, msg=_(
             "The realm command 'join' should only be specified once")))
     args = shlex.split(string)
     if not args:
         raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
             "Missing realm command arguments")))
     command = args.pop(0)
     if command == "join":
         self._parseJoin(args)
     else:
         raise KickstartValueError(formatErrorMsg(self.lineno, msg=_(
             "Unsupported realm '%s' command" % command)))
开发者ID:tradej,项目名称:pykickstart-old,代码行数:14,代码来源:realm.py


示例10: parse

    def parse(self, args):
        ud = self.handler.SshPwData()
        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        self._setToObj(self.op, opts, ud)
        ud.lineno = self.lineno

        if len(extra) != 1:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("A single argument is expected for the %s command") % "sshpw"))
        ud.password = extra[0]

        if ud in self.dataList():
            warnings.warn(_("An ssh user with the name %s has already been defined.") % ud.name)

        return ud
开发者ID:tradej,项目名称:pykickstart-old,代码行数:14,代码来源:sshpw.py


示例11: handleHeader

    def handleHeader(self, lineno, args):
        """Process the arguments to the %packages header and set attributes
           on the Version's Packages instance appropriate.  This method may be
           overridden in a subclass if necessary.
        """
        Section.handleHeader(self, lineno, args)
        op = KSOptionParser(version=self.version)
        op.add_option("--excludedocs", dest="excludedocs", action="store_true",
                      default=False)
        op.add_option("--ignoremissing", dest="ignoremissing",
                      action="store_true", default=False)
        op.add_option("--nobase", dest="nobase", action="store_true",
                      default=False, deprecated=F18)
        op.add_option("--nocore", dest="nocore", action="store_true",
                      default=False, introduced=F21)
        op.add_option("--ignoredeps", dest="resolveDeps", action="store_false",
                      deprecated=FC4, removed=F9)
        op.add_option("--resolvedeps", dest="resolveDeps", action="store_true",
                      deprecated=FC4, removed=F9)
        op.add_option("--default", dest="defaultPackages", action="store_true",
                      default=False, introduced=F7)
        op.add_option("--instLangs", dest="instLangs", type="string",
                      default="", introduced=F9)
        op.add_option("--multilib", dest="multiLib", action="store_true",
                      default=False, introduced=F18)

        (opts, _extra) = op.parse_args(args=args[1:], lineno=lineno)

        if opts.defaultPackages and opts.nobase:
            raise KickstartParseError(formatErrorMsg(lineno, msg=_("--default and --nobase cannot be used together")))
        elif opts.defaultPackages and opts.nocore:
            raise KickstartParseError(formatErrorMsg(lineno, msg=_("--default and --nocore cannot be used together")))

        self.handler.packages.excludeDocs = opts.excludedocs
        self.handler.packages.addBase = not opts.nobase
        if opts.ignoremissing:
            self.handler.packages.handleMissing = KS_MISSING_IGNORE
        else:
            self.handler.packages.handleMissing = KS_MISSING_PROMPT

        if opts.defaultPackages:
            self.handler.packages.default = True

        if opts.instLangs:
            self.handler.packages.instLangs = opts.instLangs

        self.handler.packages.nocore = opts.nocore
        self.handler.packages.multiLib = opts.multiLib
        self.handler.packages.seen = True
开发者ID:tradej,项目名称:pykickstart-old,代码行数:49,代码来源:sections.py


示例12: parse

    def parse(self, args):
        zd = self.handler.FcoeData()
        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        if len(extra) > 0:
            mapping = {"command": "fcoe", "options": extra}
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping))

        self._setToObj(self.op, opts, zd)
        zd.lineno = self.lineno

        # Check for duplicates in the data list.
        if zd in self.dataList():
            warnings.warn(_("A FCOE device with the name %s has already been defined.") % zd.nic)

        return zd
开发者ID:tradej,项目名称:pykickstart-old,代码行数:15,代码来源:fcoe.py


示例13: parse

    def parse(self, args):
        (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)

        if len(extra) > 0:
            raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % self.currentCmd))

        return self
开发者ID:tradej,项目名称:pykickstart-old,代码行数:7,代码来源:cdrom.py


示例14: readKickstart

    def readKickstart(self, f, reset=True):
        """Process a kickstart file, given by the filename f."""
        if reset:
            self._reset()

        # an %include might not specify a full path.  if we don't try to figure
        # out what the path should have been, then we're unable to find it
        # requiring full path specification, though, sucks.  so let's make
        # the reading "smart" by keeping track of what the path is at each
        # include depth.
        if not os.path.exists(f):
            if self._includeDepth - 1 in self.currentdir:
                if os.path.exists(os.path.join(self.currentdir[self._includeDepth - 1], f)):
                    f = os.path.join(self.currentdir[self._includeDepth - 1], f)

        cd = os.path.dirname(f)
        if not cd.startswith("/"):
            cd = os.path.abspath(cd)
        self.currentdir[self._includeDepth] = cd

        try:
            s = open(f, 'r').read()
        except IOError as e:
            raise KickstartError(formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % str(e)))

        self.readKickstartFromString(s, reset=False)
开发者ID:tradej,项目名称:pykickstart-old,代码行数:26,代码来源:parser.py


示例15: dispatcher

    def dispatcher(self, args, lineno):
        """Call the appropriate KickstartCommand handler for the current line
           in the kickstart file.  A handler for the current command should
           be registered, though a handler of None is not an error.  Returns
           the data object returned by KickstartCommand.parse.

           args    -- A list of arguments to the current command
           lineno  -- The line number in the file, for error reporting
        """
        cmd = args[0]

        if cmd not in self.commands:
            raise KickstartParseError(formatErrorMsg(lineno, msg=_("Unknown command: %s" % cmd)))
        elif self.commands[cmd] != None:
            self.commands[cmd].currentCmd = cmd
            self.commands[cmd].currentLine = self.currentLine
            self.commands[cmd].lineno = lineno
            self.commands[cmd].seen = True

            # The parser returns the data object that was modified.  This could
            # be a BaseData subclass that should be put into a list, or it
            # could be the command handler object itself.
            obj = self.commands[cmd].parse(args[1:])
            lst = self.commands[cmd].dataList()
            if lst is not None:
                lst.append(obj)

            return obj
开发者ID:tradej,项目名称:pykickstart-old,代码行数:28,代码来源:base.py


示例16: parse

    def parse(self, args):
        (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        if len(extra) != 1:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s requires one argument") % "lang"))

        self.lang = extra[0]
        return self
开发者ID:tradej,项目名称:pykickstart-old,代码行数:7,代码来源:lang.py


示例17: returnClassForVersion

def returnClassForVersion(version=DEVEL):
    """Return the class of the syntax handler for version.  version can be
       either a string or the matching constant.  Raises KickstartValueError
       if version does not match anything.
    """
    try:
        version = int(version)
        module = "%s" % versionToString(version, skipDevel=True)
    except ValueError:
        module = "%s" % version
        version = stringToVersion(version)

    module = module.lower()

    try:
        import pykickstart.handlers
        sys.path.extend(pykickstart.handlers.__path__)
        found = imp.find_module(module)
        loaded = imp.load_module(module, found[0], found[1], found[2])

        for (k, v) in loaded.__dict__.items():
            if k.lower().endswith("%shandler" % module):
                return v
    except:
        raise KickstartVersionError(_("Unsupported version specified: %s") % version)
    finally:
        if found[0]:
            found[0].close()
开发者ID:tradej,项目名称:pykickstart-old,代码行数:28,代码来源:version.py


示例18: parse

    def parse(self, args):
        (opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)

        if len(extra) != 1:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("%s command requires a single argument: %s") % ("device", "module name")))

        dd = F8_DeviceData()
        self._setToObj(self.op, opts, dd)
        dd.lineno = self.lineno
        dd.moduleName = extra[0]

        # Check for duplicates in the data list.
        if dd in self.dataList():
            warnings.warn(_("A module with the name %s has already been defined.") % dd.moduleName)

        return dd
开发者ID:tradej,项目名称:pykickstart-old,代码行数:16,代码来源:device.py


示例19: parse

    def parse(self, args):
        (_opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
        if len(extra) > 0:
            raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("Kickstart command %s does not take any arguments") % "lilocheck"))

        self.check = True
        return self
开发者ID:tradej,项目名称:pykickstart-old,代码行数:7,代码来源:lilocheck.py


示例20: _stateMachine

    def _stateMachine(self, lineIter):
        # For error reporting.
        lineno = 0

        while True:
            # Get the next line out of the file, quitting if this is the last line.
            try:
                self._line = next(lineIter)
                if self._line == "":
                    break
            except StopIteration:
                break

            lineno += 1

            # Eliminate blank lines, whitespace-only lines, and comments.
            if self._isBlankOrComment(self._line):
                self._handleSpecialComments(self._line)
                continue

            # Split the line, discarding comments.
            args = shlex.split(self._line, comments=True)

            if args[0] == "%include":
                if len(args) == 1 or not args[1]:
                    raise KickstartParseError(formatErrorMsg(lineno))

                self._handleInclude(args[1])
                continue

            # Now on to the main event.
            if self._state == STATE_COMMANDS:
                if args[0] == "%ksappend":
                    # This is handled by the preprocess* functions, so continue.
                    continue
                elif args[0][0] == '%':
                    # This is the beginning of a new section.  Handle its header
                    # here.
                    newSection = args[0]
                    if not self._validState(newSection):
                        raise KickstartParseError(formatErrorMsg(lineno, msg=_("Unknown kickstart section: %s" % newSection)))

                    self._state = newSection
                    obj = self._sections[self._state]
                    self._tryFunc(lambda: obj.handleHeader(lineno, args))

                    # This will handle all section processing, kicking us back
                    # out to STATE_COMMANDS at the end with the current line
                    # being the next section header, etc.
                    lineno = self._readSection(lineIter, lineno)
                else:
                    # This is a command in the command section.  Dispatch to it.
                    self._tryFunc(lambda: self.handleCommand(lineno, args))
            elif self._state == STATE_END:
                break
            elif self._includeDepth > 0:
                lineIter.put(self._line)
                lineno -= 1
                lineno = self._readSection(lineIter, lineno)
开发者ID:tradej,项目名称:pykickstart-old,代码行数:59,代码来源:parser.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python base.BaseData类代码示例发布时间:2022-05-25
下一篇:
Python pykeyboard.PyKeyboard类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap