Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
snf-image-creator
Commits
9df74818
Commit
9df74818
authored
Jul 02, 2014
by
Nikos Skalkotos
Browse files
windows: Rewrite the INF file parsing function
Collect more detailed information about the installed VirtIO drivers
parent
d5a69ea3
Changes
1
Hide whitespace changes
Inline
Side-by-side
image_creator/os_type/windows/__init__.py
View file @
9df74818
...
...
@@ -563,36 +563,72 @@ class Windows(OSBase):
%
retries
)
def
_virtio_state
(
self
):
"""Check if the virtio drivers are install and return the
version of
the installed driver
"""Check if the virtio drivers are install and return the
information
about
the installed driver
"""
catalogfile_entry
=
re
.
compile
(
r
'^\s*CatalogFile\s*='
)
driverver_entry
=
re
.
compile
(
r
'^\s*DriverVer\s*='
)
inf_path
=
self
.
image
.
g
.
case_sensitive_path
(
"%s/inf"
%
self
.
systemroot
)
state
=
{}
for
driver
in
VIRTIO
:
state
[
driver
]
=
[]
def
examine_inf
(
filename
):
catalogFile
=
None
driverVer
=
None
state
[
driver
]
=
{}
def
parse_inf
(
filename
):
"""Parse a Windows INF file and fetch all information found in the
Version section.
"""
version
=
{}
# The 'Version' section
strings
=
{}
# The 'Strings' section
section
=
""
current
=
None
prev_line
=
""
fullpath
=
"%s/%s"
%
(
inf_path
,
filename
)
for
line
in
self
.
image
.
g
.
cat
(
fullpath
).
splitlines
():
if
catalogfile_entry
.
match
(
line
):
catalogFile
=
line
.
split
(
"="
)[
1
].
strip
().
lower
()
elif
driverver_entry
.
match
(
line
):
driverVer
=
line
.
split
(
"="
)[
1
].
strip
()
line
=
prev_line
+
line
.
strip
().
split
(
';'
)[
0
].
strip
()
prev_line
=
""
if
not
len
(
line
):
continue
if
line
[
-
1
]
==
"
\\
"
:
prev_line
=
line
continue
# Does the line denote a section?
if
line
.
startswith
(
'['
)
and
line
.
endswith
(
']'
):
section
=
line
[
1
:
-
1
].
lower
()
if
section
==
'version'
:
current
=
version
if
section
==
'strings'
:
current
=
strings
# We only care about 'version' and 'string' sections
if
section
not
in
(
'version'
,
'strings'
):
continue
# We only care about param = value lines
if
line
.
find
(
'='
)
<
0
:
continue
param
,
value
=
line
.
split
(
'='
,
1
)
current
[
param
.
strip
()]
=
value
.
strip
()
# Replace all strkey tokens with their actual value
for
k
,
v
in
version
.
items
():
if
v
.
startswith
(
'%'
)
and
v
.
endswith
(
'%'
):
strkey
=
v
[
1
:
-
1
]
if
strkey
in
strings
:
version
[
k
]
=
strings
[
strkey
]
cat
=
version
[
'CatalogFile'
]
if
'CatalogFile'
in
version
else
""
for
driver
in
VIRTIO
:
if
cat
a
lo
gFile
==
"%s.cat"
%
driver
:
state
[
driver
]
.
append
((
filename
,
driverVer
))
if
cat
.
lo
wer
()
==
"%s.cat"
%
driver
:
state
[
driver
]
[
filename
]
=
version
oem
=
re
.
compile
(
r
'^oem\d+\.inf'
,
flags
=
re
.
IGNORECASE
)
for
f
in
self
.
image
.
g
.
readdir
(
inf_path
):
if
oem
.
match
(
f
[
'name'
]):
examin
e_inf
(
f
[
'name'
])
pars
e_inf
(
f
[
'name'
])
return
state
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment