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
3a8729c4
Commit
3a8729c4
authored
Dec 14, 2023
by
BO ZHANG
🏀
Browse files
update File
parent
f9060028
Pipeline
#2308
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
csst_common/file.py
View file @
3a8729c4
import
os
import
os
from
typing
import
Optional
class
File
:
class
File
:
def
__init__
(
self
,
file_path
:
str
=
"/path/to/file.fits"
):
def
__init__
(
self
,
file_path
:
str
=
"/path/to/file.fits"
,
new_dir
=
None
):
self
.
file_path
=
file_path
self
.
file_path
=
file_path
self
.
file_path_prefix
,
self
.
file_path_ext
=
os
.
path
.
splitext
(
file_path
)
self
.
dirname
=
os
.
path
.
dirname
(
self
.
file_path
)
self
.
file_name
=
os
.
path
.
basename
(
self
.
file_path
)
self
.
prefix
,
self
.
ext
=
os
.
path
.
splitext
(
self
.
file_name
)
self
.
new_dir
=
new_dir
if
new_dir
is
not
None
else
self
.
dirname
def
replace_ext
(
self
,
ext
=
"wht.fits"
)
->
str
:
def
replace_ext
(
if
ext
.
startswith
(
"."
):
self
,
new_ext
:
str
=
"wht.fits"
,
new_dir
:
Optional
[
str
]
=
None
return
self
.
file_path_prefix
+
ext
)
->
str
:
if
new_dir
is
None
:
new_dir
=
self
.
new_dir
if
new_ext
.
startswith
(
"."
):
return
os
.
path
.
join
(
new_dir
if
new_dir
is
not
None
else
self
.
dirname
,
self
.
prefix
+
new_ext
,
)
else
:
else
:
return
self
.
file_path_prefix
+
"_"
+
ext
return
os
.
path
.
join
(
new_dir
if
new_dir
is
not
None
else
self
.
dirname
,
self
.
prefix
+
"_"
+
new_ext
,
)
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