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
vidjil
vidjil
Commits
1ced3f8f
Commit
1ced3f8f
authored
Apr 13, 2015
by
Mikaël Salson
Committed by
Vidjil Team
Apr 13, 2015
Browse files
vidjil_utils: Move regex search in vidjil_utils
parent
ee8ad6a6
Changes
2
Hide whitespace changes
Inline
Side-by-side
server/web2py/applications/vidjil/controllers/patient.py
View file @
1ced3f8f
...
...
@@ -198,23 +198,12 @@ def stats():
d
[
'stats'
]
=
keys
for
row
in
d
[
'query'
]:
results_f
=
defs
.
DIR_RESULTS
+
row
.
results_file
.
data_file
try
:
results
=
open
(
results_f
).
readlines
(
STATS_READLINES
)
except
IOError
:
results
=
[]
results_f
=
row
.
results_file
.
data_file
row_result
=
vidjil_utils
.
search_first_regex_in_file
(
regex
,
defs
.
DIR_RESULTS
+
results_f
,
STATS_READLINES
)
for
key
in
keys
:
row
[
key
]
=
''
for
r
in
regex
:
for
line
in
results
:
m
=
r
.
search
(
line
)
if
m
:
for
(
key
,
val
)
in
m
.
groupdict
().
items
():
row
[
key
]
=
val
.
replace
(
'
\\
'
,
''
)
break
log
.
debug
(
"patient/stats (%.3fs)"
%
(
time
.
time
()
-
start
))
return
d
...
...
server/web2py/applications/vidjil/modules/vidjil_utils.py
View file @
1ced3f8f
...
...
@@ -116,6 +116,26 @@ def filter(str, filter_str):
return
True
#### Utilities on regex
def
search_first_regex_in_file
(
regex
,
filename
,
max_nb_line
=
None
):
try
:
if
max_nb_line
is
None
:
results
=
open
(
filename
).
readlines
()
else
:
results
=
open
(
filename
).
readlines
(
max_nb_line
)
except
IOError
as
e
:
results
=
[]
matched_keys
=
{}
for
r
in
regex
:
for
line
in
results
:
m
=
r
.
search
(
line
)
if
m
:
for
(
key
,
val
)
in
m
.
groupdict
().
items
():
matched_keys
[
key
]
=
val
.
replace
(
'
\\
'
,
''
)
break
return
matched_keys
log_patient
=
re
.
compile
(
'\((\d+)\)'
)
log_config
=
re
.
compile
(
' c(\d+)'
)
log_task
=
re
.
compile
(
'\[(\d+)\]'
)
...
...
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