本文整理汇总了Python中pykickstart.i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例2: _parse_optional
def _parse_optional(self, arg_string):
def usedTooNew(action):
return action.introduced and action.introduced > self.version
def usedRemoved(action):
return action.removed and action.removed <= self.version
option_tuple = ArgumentParser._parse_optional(self, arg_string)
if option_tuple is None or option_tuple[0] is None:
return option_tuple
action = option_tuple[0]
if usedTooNew(action):
mapping = {"option": action.option_strings[0], "intro": versionToString(action.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 usedRemoved(action):
mapping = {"option": action.option_strings[0], "removed": versionToString(action.removed),
"version": versionToString(self.version)}
if action.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 action.deprecated == True or (self.version and self.version >= action.deprecated):
mapping = {"lineno": self.lineno, "option": action.option_strings[0]}
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 option_tuple
示例3: parse
def parse(self, args):
ns = self.op.parse_args(args=args, lineno=self.lineno)
snap_data = self.dataClass() # pylint: disable=not-callable
self.set_to_obj(ns, snap_data)
snap_data.lineno = self.lineno
# Check for duplicates
if snap_data.name in [snap.name for snap in self.dataList()]:
msg = (_("Snapshot with the name %s has been already defined!") % snap_data.name)
raise KickstartParseError(msg, lineno=self.lineno)
if snap_data.when is None:
msg = _("Snapshot \"when\" parameter must be specified!")
raise KickstartParseError(msg, lineno=self.lineno)
groups = snap_data.origin.split('/')
if len(groups) != 2 or len(groups[0]) == 0 or len(groups[1]) == 0:
msg = (_("Snapshot origin %s must be specified by VG/LV!") % snap_data.origin)
raise KickstartParseError(msg, lineno=self.lineno)
# Check if value in a '--when' param is valid
if snap_data.when != "" and snap_data.when not in self.whenMap.values():
msg = (_("Snapshot when param must have one of these values %s!") %
self.whenMap.keys())
raise KickstartParseError(msg, lineno=self.lineno)
return snap_data
示例4: parse
def parse(self, args):
ns = self.op.parse_args(args=args, lineno=self.lineno)
self.set_to_self(ns)
# just "timezone" without any arguments and timezone specification doesn't really make sense,
# so throw an error when we see it (it might even be an indication of an incorrect machine generated kickstart)
if not args:
error_message = _("At least one option and/or an argument are expected for the %s command") % "timezone"
raise KickstartParseError(formatErrorMsg(self.lineno, msg=error_message))
# To be able to support the timezone command being used without
# a timezone specification:
# - we don't call the parse() method of the ancestors
# -> due to the FC3 parse() method that would be eventually called,
# which throws an exception if no timezone specification is provided
# - we implement the relevant functionality of the ancestor methods here
if len(ns.timezone) == 1:
self.timezone = ns.timezone[0]
elif len(ns.timezone) > 1:
error_message = _("One or zero arguments are expected for the %s command") % "timezone"
raise KickstartParseError(formatErrorMsg(self.lineno, msg=error_message))
if self.ntpservers and self.nontp:
msg = formatErrorMsg(self.lineno, msg=_("Options --nontp and --ntpservers are mutually exclusive"))
raise KickstartParseError(msg)
return self
示例5: parse
def parse(self, args):
# call the overridden command to do it's job first
retval = F21_Network.parse(self, args)
# validate the network interface name
error_message = validate_network_interface_name(retval.interfacename)
# something is wrong with the interface name
if error_message:
raise KickstartParseError(error_message, lineno=self.lineno)
if retval.bridgeopts:
if not retval.bridgeslaves:
msg = _("Option --bridgeopts requires --bridgeslaves to be specified")
raise KickstartParseError(msg, lineno=self.lineno)
opts = retval.bridgeopts.split(",")
for opt in opts:
_key, _sep, value = opt.partition("=")
if not value or "=" in value:
msg = _("Bad format of --bridgeopts, expecting key=value options separated by ','")
raise KickstartParseError(msg, lineno=self.lineno)
if retval.bindto == BIND_TO_MAC:
if retval.vlanid and not retval.bondopts:
msg = _("--bindto=%s is not supported for this type of device") % BIND_TO_MAC
raise KickstartParseError(msg, lineno=self.lineno)
return retval
示例6: 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)
示例7: parse
def parse(self, args):
(ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno)
if len(extra) > 1:
raise KickstartParseError(
formatErrorMsg(self.lineno, msg=_("Only one partition may be specified for driverdisk command."))
)
elif any(arg for arg in extra if arg.startswith("-")):
mapping = {"command": "driverdisk", "options": extra}
raise KickstartParseError(
formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping)
)
if len(extra) == 1 and ns.source:
raise KickstartParseError(
formatErrorMsg(
self.lineno, msg=_("Only one of --source and partition may be specified for driverdisk command.")
)
)
if not extra and not ns.source:
raise KickstartParseError(
formatErrorMsg(
self.lineno, msg=_("One of --source or partition must be specified for driverdisk command.")
)
)
ddd = self.handler.DriverDiskData()
self.set_to_obj(ns, ddd)
ddd.lineno = self.lineno
if len(extra) == 1:
ddd.partition = extra[0]
return ddd
示例8: 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)
示例9: parse
def parse(self, args):
(ns, extra) = self.op.parse_known_args(args=args, lineno=self.lineno)
if not ns.format:
ns.preexist = True
vg = self.handler.VolGroupData()
self.set_to_obj(ns, vg)
vg.lineno = self.lineno
if len(extra) == 0:
raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("volgroup must be given a VG name")))
elif any(arg for arg in extra if arg.startswith("-")):
mapping = {"command": "volgroup", "options": extra}
raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("Unexpected arguments to %(command)s command: %(options)s") % mapping))
if len(extra) == 1 and not ns.preexist:
raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("volgroup must be given a list of partitions")))
elif len(extra) > 1 and ns.preexist:
raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("Members may not be specified for preexisting volgroup")))
vg.vgname = extra[0]
if len(extra) > 1:
vg.physvols = extra[1:]
# Check for duplicates in the data list.
if vg in self.dataList():
warnings.warn(_("A volgroup with the name %s has already been defined.") % vg.vgname)
return vg
示例10: main
def main():
opts = parse_args()
if not opts.kscfg:
print(_("Need to specify a config to flatten"), file=sys.stderr)
sys.exit(1)
ksversion = makeVersion(opts.version)
ksparser = pykickstart.parser.KickstartParser(ksversion)
try:
ksparser.readKickstart(opts.kscfg)
except IOError as msg:
print(_("Failed to read kickstart file '%(filename)s' : %(error_msg)s") % {"filename": opts.kscfg, "error_msg": msg}, file=sys.stderr)
sys.exit(1)
except pykickstart.errors.KickstartError as e:
print(_("Failed to parse kickstart file '%(filename)s' : %(error_msg)s") % {"filename": opts.kscfg, "error_msg": e}, file=sys.stderr)
sys.exit(1)
if opts.output:
try:
f = open(opts.output, 'w')
except IOError as msg:
print(_("Failed to open output file '%(filename)s' : %(error_msg)s") % {"filename": opts.output, "error_msg": msg}, file=sys.stderr)
sys.exit(1)
else:
f = sys.stdout
f.write("%s" % ksparser.handler)
f.close()
示例11: parse
def parse(self, args):
(opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
vg = self.handler.VolGroupData()
self._setToObj(self.op, opts, vg)
vg.lineno = self.lineno
if len(extra) == 0:
raise KickstartParseError(formatErrorMsg(self.lineno, msg=_("volgroup must be given a VG name")))
if len(extra) == 1 and not opts.preexist:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("volgroup must be given a list of partitions")))
elif len(extra) > 1 and opts.preexist:
raise KickstartValueError(
formatErrorMsg(self.lineno, msg=_("Members may not be specified for preexisting volgroup"))
)
vg.vgname = extra[0]
if len(extra) > 1:
vg.physvols = extra[1:]
# Check for duplicates in the data list.
if vg in self.dataList():
warnings.warn(_("A volgroup with the name %s has already been defined.") % vg.vgname)
return vg
示例12: _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 KickstartParseError(formatErrorMsg(self.lineno, msg=_(
"Invalid realm arguments: %s") % ex))
if len(remaining) != 1:
raise KickstartParseError(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))
示例13: 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
示例14: main
def main(argv=None):
opts = parse_args(argv)
if not opts.kscfg:
return (1, _("Need to specify a config to flatten"))
try:
ksversion = makeVersion(opts.version)
except KickstartVersionError:
print(_("The version %s is not supported by pykickstart") % opts.version)
sys.exit(1)
ksparser = pykickstart.parser.KickstartParser(ksversion)
try:
ksparser.readKickstart(opts.kscfg)
except IOError as msg:
return (1, _("Failed to read kickstart file '%(filename)s' : %(error_msg)s") % {"filename": opts.kscfg, "error_msg": msg})
except pykickstart.errors.KickstartError as e:
return (1, _("Failed to parse kickstart file '%(filename)s' : %(error_msg)s") % {"filename": opts.kscfg, "error_msg": e})
if opts.output:
try:
f = open(opts.output, 'w')
except IOError as msg:
return (1, _("Failed to open output file '%(filename)s' : %(error_msg)s") % {"filename": opts.output, "error_msg": msg})
else:
f = sys.stdout
f.write("%s" % ksparser.handler)
if opts.output:
f.close()
return (0, '')
示例15: 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 = self._getParser()
ns = op.parse_args(args=args[1:], lineno=lineno)
if ns.defaultPackages and ns.nobase:
raise KickstartParseError(formatErrorMsg(lineno, msg=_("--default and --nobase cannot be used together")), lineno=lineno)
elif ns.defaultPackages and ns.nocore:
raise KickstartParseError(formatErrorMsg(lineno, msg=_("--default and --nocore cannot be used together")), lineno=lineno)
self.handler.packages.excludeDocs = ns.excludedocs
self.handler.packages.addBase = not ns.nobase
if ns.ignoremissing:
self.handler.packages.handleMissing = KS_MISSING_IGNORE
else:
self.handler.packages.handleMissing = KS_MISSING_PROMPT
if ns.defaultPackages:
self.handler.packages.default = True
if ns.instLangs is not None:
self.handler.packages.instLangs = ns.instLangs
self.handler.packages.nocore = ns.nocore
self.handler.packages.multiLib = ns.multiLib
self.handler.packages.excludeWeakdeps = ns.excludeWeakdeps
self.handler.packages.timeout = ns.timeout
self.handler.packages.retries = ns.retries
self.handler.packages.seen = True