Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-pipeline
csst_common
Commits
5d274f01
Commit
5d274f01
authored
Dec 09, 2023
by
BO ZHANG
🏀
Browse files
deprecate FileRecorder
parent
7b9bcc4a
Pipeline
#2154
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
csst_common/file_recorder.py
View file @
5d274f01
"""
Identifier: KSC-SJ4-csst_common/__init__.py
Name: __init__.py
Description: csst_common package
Author: Bo Zhang
Created: 2022-09-13
Modified-History:
2022-09-13, Bo Zhang, created
2022-09-13, Bo Zhang, fixed a bug
2023-12-39, Bo Zhang, deprecated
"""
import
os
from
collections
import
namedtuple
from
astropy
import
table
FileRecord
=
namedtuple
(
"FileRecord"
,
[
"filepath"
,
"db"
,
"comment"
,
"existence"
]
)
FileRecord
=
namedtuple
(
"FileRecord"
,
[
"filepath"
,
"db"
,
"comment"
,
"existence"
])
class
FileRecorder
(
list
):
...
...
@@ -64,14 +73,21 @@ class FileRecorder(list):
@
staticmethod
def
FileRecord
(
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
return
FileRecord
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
os
.
path
.
exists
(
filepath
))
return
FileRecord
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
os
.
path
.
exists
(
filepath
),
)
def
add_record
(
self
,
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
existence
=
os
.
path
.
exists
(
filepath
)
assert
isinstance
(
filepath
,
str
)
assert
isinstance
(
db
,
bool
)
assert
isinstance
(
comment
,
str
)
super
().
append
(
FileRecord
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
existence
))
super
().
append
(
FileRecord
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
existence
)
)
def
to_table
(
self
):
return
table
.
Table
([
_
.
_asdict
()
for
_
in
self
])
...
...
@@ -87,20 +103,29 @@ class FileRecorder(list):
def
__repr__
(
self
):
t
=
self
.
to_table
()
lines
,
outs
=
t
.
formatter
.
_pformat_table
(
t
,
max_lines
=-
1
,
max_width
=-
1
,
show_name
=
True
,
show_unit
=
None
,
show_dtype
=
False
,
align
=
"<"
)
if
outs
[
'show_length'
]:
lines
.
append
(
f
'Length =
{
len
(
self
)
}
rows'
)
t
,
max_lines
=-
1
,
max_width
=-
1
,
show_name
=
True
,
show_unit
=
None
,
show_dtype
=
False
,
align
=
"<"
,
)
if
outs
[
"show_length"
]:
lines
.
append
(
f
"Length =
{
len
(
self
)
}
rows"
)
return
"
\n
"
.
join
(
lines
)
@
property
def
summary
(
self
):
if
len
(
self
)
==
0
:
return
'
0 alleged, 0 missing, 0 to db
'
return
"
0 alleged, 0 missing, 0 to db
"
else
:
return
f
"
{
len
(
self
)
}
alleged, "
\
f
"
{
len
(
self
)
-
sum
(
self
.
to_table
()[
'existence'
])
}
missing, "
\
f
"
{
sum
(
self
.
to_table
()[
'existence'
])
}
to db"
return
(
f
"
{
len
(
self
)
}
alleged, "
f
"
{
len
(
self
)
-
sum
(
self
.
to_table
()[
'existence'
])
}
missing, "
f
"
{
sum
(
self
.
to_table
()[
'existence'
])
}
to db"
)
def
is_good
(
self
):
"""
Check if all alleged files exist.
"""
return
all
(
self
.
to_table
()[
'
existence
'
])
"""Check if all alleged files exist."""
return
all
(
self
.
to_table
()[
"
existence
"
])
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment