⚲
Project
General
Profile
Sign in
Home
Projects
Help
Search
:
openQA Project
All Projects
QA
»
openQA Project
Overview
Activity
Roadmap
Issues
Wiki
Download (1.73 KB)
action #94531
» scan_details.py
MDoucha
, 2021-06-30 11:24
#!/usr/bin/python3
import
json
import
os
import
os.path
import
re
import
sys
def
scan_result
(
path
):
pattern
=
re
.
compile
(
r
'
\Adetails-([^.]+)\.json\Z
'
)
with
os
.
scandir
(
path
)
as
fileiter
:
for
file
in
fileiter
:
modname
=
pattern
.
match
(
file
.
name
)
if
not
modname
:
continue
try
:
with
open
(
file
.
path
,
'
r
'
)
as
fr
:
data
=
json
.
load
(
fr
)
if
'
details
'
not
in
data
:
continue
for
module
in
data
[
'
details
'
]:
if
(
'
text
'
in
module
and
'
text_data
'
not
in
module
and
not
os
.
path
.
isfile
(
os
.
path
.
join
(
path
,
module
[
'
text
'
]))):
job_id
=
path
.
name
.
partition
(
'
-
'
)[
0
]
print
(
"
%d %s
"
%
(
int
(
job_id
),
modname
.
group
(
1
)))
return
True
except
KeyboardInterrupt
:
raise
except
:
print
(
'
Error reading file %s
'
%
file
.
path
,
file
=
sys
.
stderr
)
continue
return
False
def
scan_path
(
basepath
):
with
os
.
scandir
(
basepath
)
as
groupiter
:
dirlist
=
sorted
((
x
for
x
in
groupiter
if
x
.
name
.
isnumeric
()
and
x
.
is_dir
()),
key
=
lambda
x
:
x
.
name
,
reverse
=
True
)
for
groupdir
in
dirlist
:
print
(
groupdir
.
name
,
end
=
'
\r
'
,
file
=
sys
.
stderr
)
with
os
.
scandir
(
groupdir
)
as
testiter
:
if
not
groupdir
.
is_dir
():
continue
for
testdir
in
testiter
:
scan_result
(
testdir
)
if
__name__
==
'
__main__
'
:
pathlist
=
sys
.
argv
[
1
:]
or
[
'
/var/lib/openqa/testresults/
'
]
for
item
in
pathlist
:
try
:
scan_path
(
item
)
except
KeyboardInterrupt
:
break
« Previous
1
2
3
…
6
Next »
(1-1/6)
Loading...