Skip to content

Commit 4e5ef76

Browse files
committed
#3 Update download command
1 parent a4d48d6 commit 4e5ef76

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

deshima_rawdata/cli.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
# standard library
5+
import tarfile
56
from pathlib import Path
67

78

@@ -14,23 +15,25 @@
1415

1516
# constants
1617
CHUNK_SIZE = 1024
17-
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
1818
DEFAULT_TAG = f"v{__version__}"
19+
GITHUB_URL = "https://raw.githubusercontent.com/deshima-dev/rawdata"
1920

2021

2122
def download(
2223
obsid: str,
2324
/,
2425
*,
2526
dir: Path = Path(),
26-
progress: bool = True,
27+
extract: bool = False,
28+
progress: bool = False,
2729
tag: str = DEFAULT_TAG,
2830
) -> Path:
2931
"""Download DESHIMA raw data for given observation ID.
3032
3133
Args:
3234
obsid: Observation ID (YYYYmmddHHMMSS).
3335
dir: Directory where the raw data is saved.
36+
extract: Whether to extract the raw data.
3437
progress: Whether to show a progress bar.
3538
tag: Git tag (or branch) of the raw data.
3639
@@ -56,7 +59,15 @@ def download(
5659
bar.update(len(data))
5760
f.write(data)
5861

59-
return data_path
62+
if not extract:
63+
return data_path
64+
65+
with tarfile.open(data_path, "r:gz") as tar:
66+
tar.extractall(data_path.parent)
67+
dir_name = tar.getnames()[0]
68+
69+
data_path.unlink(True)
70+
return data_path.parent / dir_name
6071

6172

6273
def main() -> None:

0 commit comments

Comments
 (0)