summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/wic/3rdparty/pykickstart/parser.py87
-rw-r--r--scripts/lib/wic/3rdparty/pykickstart/version.py29
2 files changed, 2 insertions, 114 deletions
diff --git a/scripts/lib/wic/3rdparty/pykickstart/parser.py b/scripts/lib/wic/3rdparty/pykickstart/parser.py
index 840a448673..9c9674bf73 100644
--- a/scripts/lib/wic/3rdparty/pykickstart/parser.py
+++ b/scripts/lib/wic/3rdparty/pykickstart/parser.py
@@ -38,8 +38,6 @@ import sys
38import tempfile 38import tempfile
39from copy import copy 39from copy import copy
40from optparse import * 40from optparse import *
41from urlgrabber import urlread
42import urlgrabber.grabber as grabber
43 41
44import constants 42import constants
45from errors import KickstartError, KickstartParseError, KickstartValueError, formatErrorMsg 43from errors import KickstartError, KickstartParseError, KickstartValueError, formatErrorMsg
@@ -55,87 +53,6 @@ STATE_COMMANDS = "commands"
55 53
56ver = version.DEVEL 54ver = version.DEVEL
57 55
58def _preprocessStateMachine (lineIter):
59 l = None
60 lineno = 0
61
62 # Now open an output kickstart file that we are going to write to one
63 # line at a time.
64 (outF, outName) = tempfile.mkstemp("-ks.cfg", "", "/tmp")
65
66 while True:
67 try:
68 l = lineIter.next()
69 except StopIteration:
70 break
71
72 # At the end of the file?
73 if l == "":
74 break
75
76 lineno += 1
77 url = None
78
79 ll = l.strip()
80 if not ll.startswith("%ksappend"):
81 os.write(outF, l)
82 continue
83
84 # Try to pull down the remote file.
85 try:
86 ksurl = ll.split(' ')[1]
87 except:
88 raise KickstartParseError, formatErrorMsg(lineno, msg=_("Illegal url for %%ksappend: %s") % ll)
89
90 try:
91 url = grabber.urlopen(ksurl)
92 except grabber.URLGrabError, e:
93 raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file: %s") % e.strerror)
94 else:
95 # Sanity check result. Sometimes FTP doesn't catch a file
96 # is missing.
97 try:
98 if url.size < 1:
99 raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file"))
100 except:
101 raise KickstartError, formatErrorMsg(lineno, msg=_("Unable to open %%ksappend file"))
102
103 # If that worked, write the remote file to the output kickstart
104 # file in one burst. Then close everything up to get ready to
105 # read ahead in the input file. This allows multiple %ksappend
106 # lines to exist.
107 if url is not None:
108 os.write(outF, url.read())
109 url.close()
110
111 # All done - close the temp file and return its location.
112 os.close(outF)
113 return outName
114
115def preprocessFromString (s):
116 """Preprocess the kickstart file, provided as the string str. This
117 method is currently only useful for handling %ksappend lines,
118 which need to be fetched before the real kickstart parser can be
119 run. Returns the location of the complete kickstart file.
120 """
121 i = iter(s.splitlines(True) + [""])
122 rc = _preprocessStateMachine (i.next)
123 return rc
124
125def preprocessKickstart (f):
126 """Preprocess the kickstart file, given by the filename file. This
127 method is currently only useful for handling %ksappend lines,
128 which need to be fetched before the real kickstart parser can be
129 run. Returns the location of the complete kickstart file.
130 """
131 try:
132 fh = urlopen(f)
133 except grabber.URLGrabError, e:
134 raise KickstartError, formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % e.strerror)
135
136 rc = _preprocessStateMachine (iter(fh.readlines()))
137 fh.close()
138 return rc
139 56
140class PutBackIterator(Iterator): 57class PutBackIterator(Iterator):
141 def __init__(self, iterable): 58 def __init__(self, iterable):
@@ -682,8 +599,8 @@ class KickstartParser:
682 self.currentdir[self._includeDepth] = cd 599 self.currentdir[self._includeDepth] = cd
683 600
684 try: 601 try:
685 s = urlread(f) 602 s = file(f).read()
686 except grabber.URLGrabError, e: 603 except IOError, e:
687 raise KickstartError, formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % e.strerror) 604 raise KickstartError, formatErrorMsg(0, msg=_("Unable to open input kickstart file: %s") % e.strerror)
688 605
689 self.readKickstartFromString(s, reset=False) 606 self.readKickstartFromString(s, reset=False)
diff --git a/scripts/lib/wic/3rdparty/pykickstart/version.py b/scripts/lib/wic/3rdparty/pykickstart/version.py
index 102cc37d80..8a8e6aad22 100644
--- a/scripts/lib/wic/3rdparty/pykickstart/version.py
+++ b/scripts/lib/wic/3rdparty/pykickstart/version.py
@@ -44,7 +44,6 @@ This module also exports several functions:
44 have a version= comment in it. 44 have a version= comment in it.
45""" 45"""
46import imputil, re, sys 46import imputil, re, sys
47from urlgrabber import urlopen
48 47
49import gettext 48import gettext
50_ = lambda x: gettext.ldgettext("pykickstart", x) 49_ = lambda x: gettext.ldgettext("pykickstart", x)
@@ -132,34 +131,6 @@ def versionToString(version, skipDevel=False):
132 131
133 raise KickstartVersionError(_("Unsupported version specified: %s") % version) 132 raise KickstartVersionError(_("Unsupported version specified: %s") % version)
134 133
135def versionFromFile(f):
136 """Given a file or URL, look for a line starting with #version= and
137 return the version number. If no version is found, return DEVEL.
138 """
139 v = DEVEL
140
141 fh = urlopen(f)
142
143 while True:
144 try:
145 l = fh.readline()
146 except StopIteration:
147 break
148
149 # At the end of the file?
150 if l == "":
151 break
152
153 if l.isspace() or l.strip() == "":
154 continue
155
156 if l[:9] == "#version=":
157 v = stringToVersion(l[9:].rstrip())
158 break
159
160 fh.close()
161 return v
162
163def returnClassForVersion(version=DEVEL): 134def returnClassForVersion(version=DEVEL):
164 """Return the class of the syntax handler for version. version can be 135 """Return the class of the syntax handler for version. version can be
165 either a string or the matching constant. Raises KickstartValueError 136 either a string or the matching constant. Raises KickstartValueError