本文整理汇总了Python中pykickstart.version.makeVersion函数的典型用法代码示例。如果您正苦于以下问题:Python makeVersion函数的具体用法?Python makeVersion怎么用?Python makeVersion使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了makeVersion函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()
示例2: read_kickstart
def read_kickstart(path):
"""Parse a kickstart file and return a KickstartParser instance.
This is a simple utility function which takes a path to a kickstart file,
parses it and returns a pykickstart KickstartParser instance which can
be then passed to an ImageCreator constructor.
If an error occurs, a CreatorError exception is thrown.
"""
version = ksversion.makeVersion()
ks = ksparser.KickstartParser(version)
try:
if "://" not in path:
path = "file://%s" % (urllib.request.pathname2url(os.path.abspath(path)))
ksdata = urllib.request.urlopen(path).read().decode("utf-8")
ks.readKickstartFromString(ksdata, reset=False)
# Fallback to e.args[0] is a workaround for bugs in urlgragger and pykickstart.
except IOError as e:
raise errors.KickstartError("Failed to read kickstart file "
"'%s' : %s" % (path, e.strerror or
e.args[0]))
except kserrors.KickstartError as e:
raise errors.KickstartError("Failed to parse kickstart file "
"'%s' : %s" % (path, e))
return ks
示例3: 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, '')
示例4: kickstart
def kickstart(ks, path=settings.KS_DIR):
"""
return parsed pykickstart object
"""
ks = "%s%s" % (path, ks)
ksparser = KickstartParser(makeVersion())
ksparser.readKickstart(ks)
return ksparser
示例5: kickstart
def kickstart(ks, uploaded, path=settings.KS_DIR):
"""
return parsed pykickstart object
"""
if not uploaded:
ks = "%s%s" % (path, ks)
ksparser = DecoratedKickstartParser(makeVersion())
ksparser.readKickstart(ks)
return ksparser
示例6: kickstart
def kickstart(ks, path=settings.KS_DIR):
"""
return parsed pykickstart object
"""
ks = "%s%s" % (path, ks)
ksparser = KickstartParser(makeVersion())
if isinstance(ks, unicode):
ks = ks.encode('utf-8')
ksparser.readKickstart(ks)
return ksparser
示例7: process_kickstart
def process_kickstart(ksfile):
# pykickstart refs
# https://jlaska.fedorapeople.org/pykickstart-doc/pykickstart.commands.html
ksparser = KickstartParser(makeVersion())
try:
ksparser.readKickstart(ksfile)
except KickstartError as e:
sys.stderr.write(str(e))
sys.exit(1)
user_data = '#!/bin/bash'
# repo
for repo in ksparser.handler.repo.repoList:
if repo.mirrorlist:
repo_url = 'metalink=%s' % repo.mirrorlist
else:
repo_url = 'baseurl=%s' % repo.baseurl
user_data += """
cat <<"EOF" >/etc/yum.repos.d/%s.repo
[%s]
name=%s
%s
enabled=1
gpgcheck=0
EOF
""" % (repo.name,
repo.name,
repo.name,
repo_url)
# rootpw
if ksparser.handler.rootpw.isCrypted:
user_data += 'echo "root:%s" | chpasswd -e\n' % ksparser.handler.rootpw.password
else:
user_data += 'echo "root:%s" | chpasswd\n' % ksparser.handler.rootpw.password
# selinux
if ksparser.handler.selinux.selinux is 0:
selinux_status = 'disabled'
elif ksparser.handler.selinux.selinux is 2:
selinux_status = 'enforcing'
else:
selinux_status = 'enforcing'
user_data += "sed -i 's/SELINUX=.*/SELINUX=%s/' /etc/selinux/config\n" % selinux_status
# %packages
packages = []
for group in ksparser.handler.packages.groupList:
packages.append("@%s" % group.name)
for package in ksparser.handler.packages.packageList:
packages.append(package)
if packages:
user_data += "yum -y install %s\n" % ' '.join(packages)
# skip %prep
# %post
user_data += ksparser.handler.scripts[1].script
# remove cloud-init package and reboot
user_data += 'yum -y remove cloud-init\nreboot'
print user_data
示例8: __init__
def __init__(self, main_window, kickstart=False):
if kickstart:
self.ksparser = pykickstart.parser.KickstartParser(makeVersion())
self.storage = Blivet(ksdata=self.ksparser.handler)
else:
self.storage = Blivet()
self.storage.reset()
self.main_window = main_window
示例9: __init__
def __init__(self, ks_path, blacklist=None):
self.ks_path = ks_path
if blacklist is None:
self.blacklist = []
else:
self.blacklist = blacklist
# create a kickstart parser from the latest version
self.ksparser = KickstartParser(makeVersion())
self.yb = yum.YumBase()
self._repo_problems = False
示例10: kickstart
def kickstart(ks, path=settings.KS_DIR):
"""
return parsed pykickstart object
"""
ks = "%s%s" % (path, ks)
ksparser = DecoratedKickstartParser(makeVersion())
ksparser.readKickstart(ks)
# add the RIT stuff
ritPostContents = get_rit_post()
ksparser.addScript(ritPostContents, constants.KS_SCRIPT_POST)
return ksparser
示例11: split
def split(self, path):
"""Split the kickstart given by path into elements."""
self._elements = None
self._kickstart_path = path
handler = makeVersion()
ksparser = SplitKickstartParser(handler, valid_sections=VALID_SECTIONS_ANACONDA)
try:
result = ksparser.split(path)
except KickstartParseError as e:
raise SplitKickstartSectionParsingError(e)
except KickstartError as e:
raise SplitKickstartMissingIncludeError(e)
self._elements = result
示例12: __init__
def __init__(self, kickstart=False):
if kickstart:
self.ksparser = pykickstart.parser.KickstartParser(makeVersion())
self.storage = blivet.Blivet(ksdata=self.ksparser.handler)
else:
self.storage = blivet.Blivet()
blivet.formats.fs.NTFS._formattable = True
self.storage.reset()
self.storage.devicetree.populate()
self.storage.devicetree.getActiveMounts()
self.update_min_sizes_info()
示例13: runTest
def runTest(self):
for version, command_map in control.commandMap.items():
handler = makeVersion(version)
parser = KickstartParser(handler)
for command_name, command_class in command_map.items():
if not issubclass(command_class, DeprecatedCommand):
continue
with warnings.catch_warnings(record=True):
# The deprecated commands should be ignored with
# a warning when they are parsed. Make sure that
# they will not cause any errors.
parser.readKickstartFromString(command_name)
示例14: load_or_default
def load_or_default(system_ks_path):
"""load system ks or default ks"""
ksparser = KickstartParser(makeVersion())
try:
ksparser.readKickstart(system_ks_path)
except (KickstartError, IOError):
log_message("Can't read system kickstart at {0}".format(system_ks_path))
try:
ksparser.readKickstart(settings.KS_TEMPLATE)
except AttributeError:
log_message("There is no KS_TEMPLATE_POSTSCRIPT specified in settings.py")
except IOError:
log_message("Can't read kickstart template {0}".format(settings.KS_TEMPLATE))
return None
return ksparser
示例15: test_biosboot_bootloader_in_kickstart
def test_biosboot_bootloader_in_kickstart(self, mock_mountpoints, mock_devices, dbus):
"""Test that a biosboot bootloader shows up in the ks data."""
# set up biosboot partition
biosboot_device_obj = PartitionDevice("biosboot_partition_device")
biosboot_device_obj.size = Size('1MiB')
biosboot_device_obj.format = formats.get_format("biosboot")
# mountpoints must exist for updateKSData to run
mock_devices.return_value = [biosboot_device_obj]
mock_mountpoints.values.return_value = []
# initialize ksdata
biosboot_blivet_obj = InstallerStorage(makeVersion())
biosboot_blivet_obj.update_ksdata()
self.assertIn("part biosboot", str(biosboot_blivet_obj.ksdata))