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
14e9e1d4
Commit
14e9e1d4
authored
Nov 06, 2022
by
BO ZHANG
🏀
Browse files
updated FileRecorder.__repr__()
parent
bb226846
Changes
1
Show whitespace changes
Inline
Side-by-side
csst_common/file_recorder.py
View file @
14e9e1d4
import
os
from
collections
import
namedtuple
from
collections
import
namedtuple
from
astropy
import
table
from
astropy
import
table
import
os
File
=
namedtuple
(
File
Record
=
namedtuple
(
"FileRecord"
,
"FileRecord"
,
[
"filepath"
,
"db"
,
"comment"
,
"existence"
]
[
"filepath"
,
"db"
,
"comment"
,
"existence"
]
)
)
...
@@ -10,7 +11,7 @@ File = namedtuple(
...
@@ -10,7 +11,7 @@ File = namedtuple(
class
FileRecorder
(
list
):
class
FileRecorder
(
list
):
"""
"""
File Recorder, inherited from the built-in ``list``.
File
Record
Recorder, inherited from the built-in ``list``.
This recorder is used to record files generated by functional modules.
This recorder is used to record files generated by functional modules.
In principle, a CSST pipeline module should return a status (CsstStatus)
In principle, a CSST pipeline module should return a status (CsstStatus)
...
@@ -62,22 +63,19 @@ class FileRecorder(list):
...
@@ -62,22 +63,19 @@ class FileRecorder(list):
super
(
FileRecorder
,
self
).
__init__
(
*
args
,
**
kwargs
)
super
(
FileRecorder
,
self
).
__init__
(
*
args
,
**
kwargs
)
@
staticmethod
@
staticmethod
def
Record
(
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
def
File
Record
(
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
return
File
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
os
.
path
.
exists
(
filepath
))
return
File
Record
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
os
.
path
.
exists
(
filepath
))
def
add_record
(
self
,
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
def
add_record
(
self
,
filepath
:
str
=
""
,
db
:
bool
=
False
,
comment
:
str
=
""
):
existence
=
os
.
path
.
exists
(
filepath
)
existence
=
os
.
path
.
exists
(
filepath
)
assert
isinstance
(
filepath
,
str
)
assert
isinstance
(
filepath
,
str
)
assert
isinstance
(
db
,
bool
)
assert
isinstance
(
db
,
bool
)
assert
isinstance
(
comment
,
str
)
assert
isinstance
(
comment
,
str
)
super
().
append
(
File
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
existence
))
super
().
append
(
File
Record
(
filepath
=
filepath
,
db
=
db
,
comment
=
comment
,
existence
=
existence
))
def
to_table
(
self
):
def
to_table
(
self
):
return
table
.
Table
([
_
.
_asdict
()
for
_
in
self
])
return
table
.
Table
([
_
.
_asdict
()
for
_
in
self
])
def
__repr__
(
self
):
return
self
.
to_table
().
__repr__
()
def
pprint
(
self
,
*
args
,
**
kwargs
):
def
pprint
(
self
,
*
args
,
**
kwargs
):
print
(
"<FileRecorder length={}>"
.
format
(
len
(
self
)))
print
(
"<FileRecorder length={}>"
.
format
(
len
(
self
)))
return
self
.
to_table
().
pprint
(
*
args
,
**
kwargs
)
return
self
.
to_table
().
pprint
(
*
args
,
**
kwargs
)
...
@@ -85,3 +83,11 @@ class FileRecorder(list):
...
@@ -85,3 +83,11 @@ class FileRecorder(list):
def
pprint_all
(
self
,
*
args
,
**
kwargs
):
def
pprint_all
(
self
,
*
args
,
**
kwargs
):
print
(
"<FileRecorder length={}>"
.
format
(
len
(
self
)))
print
(
"<FileRecorder length={}>"
.
format
(
len
(
self
)))
return
self
.
to_table
().
pprint_all
(
*
args
,
**
kwargs
)
return
self
.
to_table
().
pprint_all
(
*
args
,
**
kwargs
)
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
=
None
)
if
outs
[
'show_length'
]:
lines
.
append
(
f
'Length =
{
len
(
self
)
}
rows'
)
return
"
\n
"
.
join
(
lines
)
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