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_fs
Commits
4d626ab1
Commit
4d626ab1
authored
Aug 14, 2024
by
WeidenthalerMatthias
Browse files
Merge pull request !10 from WeidenthalerMatthias/feature.isfile
parents
ffdd0a96
3bdf00d1
Changes
5
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
4d626ab1
...
...
@@ -62,6 +62,15 @@ with s3_fs.open('s3://csst-prod/gaia/test/requirements.txt', s3_options=s3_optio
file
.
write
(
"CSST"
)
```
### Check if the given file path exists
```
python
from
csst_fs
import
fs
# local or on s3, depending on the given path
fs
.
isfile
(
'requirements.txt'
)
fs
.
isfile
(
's3://csst-prod/test.txt'
)
fs
.
isfile
(
's3://csst-prod/test.txt'
,
s3_options
=
s3_options
)
```
## astropy直接读写s3的写法适配
### fits.open
#### 老写法
...
...
csst_fs/__init__.py
View file @
4d626ab1
...
...
@@ -2,4 +2,5 @@ from .fits import fsspec_fits
from
.fits
import
fsspec_header
from
.fits
import
fsspec_HDUList
from
.table
import
fsspec_table
from
.
import
s3_fs
\ No newline at end of file
from
.
import
s3_fs
from
.
import
fs
\ No newline at end of file
csst_fs/fs.py
0 → 100644
View file @
4d626ab1
from
.s3_fs
import
is_s3_path
from
.s3_fs
import
isfile
as
s3_isfile
from
.local_fs
import
isfile
as
local_isfile
def
isfile
(
path
:
str
,
*
args
,
**
kwargs
)
->
bool
:
if
is_s3_path
(
path
):
return
s3_isfile
(
path
,
*
args
,
**
kwargs
)
else
:
return
local_isfile
(
path
,
*
args
,
**
kwargs
)
csst_fs/local_fs.py
0 → 100644
View file @
4d626ab1
import
os
def
isfile
(
path
:
str
)
->
bool
:
return
os
.
path
.
isfile
(
path
)
\ No newline at end of file
csst_fs/s3_fs.py
View file @
4d626ab1
...
...
@@ -15,4 +15,13 @@ def info(path, bucket=None, key=None, refresh=False, version_id=None, s3_options
return
s3_fs
.
info
(
path
,
bucket
,
key
,
refresh
,
version_id
)
def
open
(
file
:
str
,
mode
:
str
=
'r'
,
s3_options
=
load_s3_options
()):
return
open_fileobj
(
path
=
file
,
s3_options
=
s3_options
,
mode
=
mode
)
\ No newline at end of file
return
open_fileobj
(
path
=
file
,
s3_options
=
s3_options
,
mode
=
mode
)
def
isfile
(
path
:
str
,
s3_options
:
dict
=
load_s3_options
())
->
bool
:
s3_fs
=
fsspec
.
filesystem
(
's3'
,
**
s3_options
)
return
s3_fs
.
isfile
(
path
)
def
is_s3_path
(
path
:
str
):
if
(
path
.
startswith
(
"s3"
)):
return
True
return
False
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