Skip to content

Commit

Permalink
Merge pull request #2 from dobraczka/inform-if-not-exists
Browse files Browse the repository at this point in the history
Add more user feedback
  • Loading branch information
dobraczka committed Sep 13, 2023
2 parents 6262240 + 93b3ddc commit f80772d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added `ls` command for cli
- Response in cli if file does not exist


## [0.1.0] - 2023-08-07
Expand Down
2 changes: 2 additions & 0 deletions src/nephelai/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ def download(remote_path: str, local_path: Optional[str] = None) -> Optional[boo
if not remote_path.startswith("/"):
remote_path = "/" + remote_path
file_state, file_info = _check_file_state(oc=oc, remote_path=remote_path)
if file_state == FileStateDoesNotExist:
return None
if file_state == FileStateIsDirUnchunked:
assert file_info # for mypy
remote_dir_name = pathlib.Path(file_info.path).name
Expand Down
23 changes: 19 additions & 4 deletions src/nephelai/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from typing import Optional

import owncloud
import typer
from typing_extensions import Annotated

Expand Down Expand Up @@ -28,12 +29,14 @@ def upload(
chunk_size: str = "100MiB",
debug: bool = False,
):
nephelai_upload(
res = nephelai_upload(
file_to_upload=file_to_upload,
nc_path=nc_path,
chunk_size=chunk_size,
debug=debug,
)
if res is not None:
typer.echo("Successfully uploaded '{file_to_upload}'!")


@app.command()
Expand All @@ -57,14 +60,26 @@ def upload_with_fs(

@app.command()
def download(remote_path: str, local_path: Optional[str] = None):
nephelai_download(remote_path=remote_path, local_path=local_path)
res = nephelai_download(remote_path=remote_path, local_path=local_path)
if res is None:
typer.echo(f"Path '{remote_path}' does not exist...")
else:
typer.echo(f"Successfully downloaded '{remote_path}'!")


@app.command()
def ls(remote_path: str):
oc = get_oc()
for file in oc.list(remote_path):
typer.echo(file.path)
try:
file_list = oc.list(remote_path)
typer.echo(f"Listing files in '{remote_path}':")
for file in file_list:
typer.echo(file.path)
except owncloud.owncloud.HTTPResponseError as err:
if err.status_code == 404:
typer.echo(f"Path '{remote_path}' does not exist...")
else:
raise err


if __name__ == "__main__":
Expand Down

0 comments on commit f80772d

Please sign in to comment.