Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
WindEnergyToolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
toolbox
WindEnergyToolbox
Commits
a4b3759b
There was a problem fetching the pipeline summary.
Commit
a4b3759b
authored
8 years ago
by
mads
Browse files
Options
Downloads
Patches
Plain Diff
divided into loginterpreter and logfile
parent
97a9b23c
No related branches found
No related tags found
1 merge request
!5
Clustertools
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wetb/hawc2/log_file.py
+42
-36
42 additions, 36 deletions
wetb/hawc2/log_file.py
with
42 additions
and
36 deletions
wetb/hawc2/log_file.py
+
42
−
36
View file @
a4b3759b
...
@@ -23,35 +23,13 @@ INITIALIZATION = 'Initializing simulation'
...
@@ -23,35 +23,13 @@ INITIALIZATION = 'Initializing simulation'
SIMULATING
=
"
Simulating
"
SIMULATING
=
"
Simulating
"
DONE
=
"
Simulation succeded
"
DONE
=
"
Simulation succeded
"
#def is_file_open(filename):
class
LogInterpreter
(
object
):
# try:
def
__init__
(
self
,
time_stop
):
# os.rename(filename, filename + "_")
# os.rename(filename + "_", filename)
# return False
# except OSError as e:
# if "The process cannot access the file because it is being used by another process" not in str(e):
# raise
#
# if os.path.isfile(filename + "_"):
# os.remove(filename + "_")
# return True
class
LogFile
(
object
):
def
__init__
(
self
,
log_filename
,
time_stop
):
self
.
filename
=
log_filename
self
.
time_stop
=
time_stop
self
.
time_stop
=
time_stop
self
.
hawc2version
=
"
Unknown
"
self
.
hawc2version
=
"
Unknown
"
self
.
reset
()
self
.
reset
()
self
.
update_status
()
self
.
update_status
()
@staticmethod
def
from_htcfile
(
htcfile
,
modelpath
):
logfilename
=
htcfile
.
simulation
.
logfile
[
0
]
if
not
os
.
path
.
isabs
(
logfilename
):
logfilename
=
os
.
path
.
join
(
modelpath
,
logfilename
)
return
LogFile
(
logfilename
,
htcfile
.
simulation
.
time_stop
[
0
])
def
reset
(
self
):
def
reset
(
self
):
self
.
position
=
0
self
.
position
=
0
self
.
lastline
=
""
self
.
lastline
=
""
...
@@ -66,12 +44,8 @@ class LogFile(object):
...
@@ -66,12 +44,8 @@ class LogFile(object):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
txt
return
self
.
txt
def
clear
(
self
):
def
clear
(
self
):
# exist_ok does not exist in Python27
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
self
.
filename
)):
os
.
makedirs
(
os
.
path
.
dirname
(
self
.
filename
))
#, exist_ok=True)
with
open
(
self
.
filename
,
'
w
'
,
encoding
=
'
utf-8
'
):
pass
self
.
reset
()
self
.
reset
()
def
extract_time
(
self
,
txt
):
def
extract_time
(
self
,
txt
):
...
@@ -89,17 +63,13 @@ class LogFile(object):
...
@@ -89,17 +63,13 @@ class LogFile(object):
print
(
"
Cannot extract time from #
"
+
time_line
+
"
#
"
)
print
(
"
Cannot extract time from #
"
+
time_line
+
"
#
"
)
pass
pass
def
update_status
(
self
):
def
update_status
(
self
,
new_lines
=
""
):
if
not
os
.
path
.
isfile
(
self
.
filename
)
:
if
self
.
txt
==
""
and
new_lines
==
""
:
self
.
status
=
MISSING
self
.
status
=
MISSING
else
:
else
:
if
self
.
status
==
UNKNOWN
or
self
.
status
==
MISSING
:
if
self
.
status
==
UNKNOWN
or
self
.
status
==
MISSING
:
self
.
status
=
PENDING
self
.
status
=
PENDING
with
open
(
self
.
filename
,
'
rb
'
)
as
fid
:
txt
=
new_lines
fid
.
seek
(
self
.
position
)
txt
=
fid
.
read
()
self
.
position
+=
len
(
txt
)
txt
=
txt
.
decode
(
encoding
=
'
utf_8
'
,
errors
=
'
strict
'
)
self
.
txt
+=
txt
self
.
txt
+=
txt
if
self
.
status
==
PENDING
and
self
.
position
>
0
:
if
self
.
status
==
PENDING
and
self
.
position
>
0
:
self
.
status
=
INITIALIZATION
self
.
status
=
INITIALIZATION
...
@@ -162,6 +132,42 @@ class LogFile(object):
...
@@ -162,6 +132,42 @@ class LogFile(object):
return
"
--:--
"
return
"
--:--
"
class
LogFile
(
LogInterpreter
):
def
__init__
(
self
,
log_filename
,
time_stop
):
self
.
filename
=
log_filename
LogInterpreter
.
__init__
(
self
,
time_stop
)
@staticmethod
def
from_htcfile
(
htcfile
,
modelpath
):
logfilename
=
htcfile
.
simulation
.
logfile
[
0
]
if
not
os
.
path
.
isabs
(
logfilename
):
logfilename
=
os
.
path
.
join
(
modelpath
,
logfilename
)
return
LogFile
(
logfilename
,
htcfile
.
simulation
.
time_stop
[
0
])
def
clear
(
self
):
# exist_ok does not exist in Python27
if
not
os
.
path
.
exists
(
os
.
path
.
dirname
(
self
.
filename
)):
os
.
makedirs
(
os
.
path
.
dirname
(
self
.
filename
))
#, exist_ok=True)
with
open
(
self
.
filename
,
'
w
'
,
encoding
=
'
utf-8
'
):
pass
LogInterpreter
.
clear
(
self
)
def
update_status
(
self
):
if
not
os
.
path
.
isfile
(
self
.
filename
):
self
.
status
=
MISSING
else
:
if
self
.
status
==
UNKNOWN
or
self
.
status
==
MISSING
:
self
.
status
=
PENDING
s
=
self
.
status
with
open
(
self
.
filename
,
'
rb
'
)
as
fid
:
fid
.
seek
(
self
.
position
)
txt
=
fid
.
read
()
self
.
position
+=
len
(
txt
)
txt
=
txt
.
decode
(
encoding
=
'
utf_8
'
,
errors
=
'
strict
'
)
if
txt
!=
""
:
LogInterpreter
.
update_status
(
self
,
txt
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment