Skip to content

Commit

Permalink
Merge pull request #1 from dobraczka/add-ls-command
Browse files Browse the repository at this point in the history
Add ls command
  • Loading branch information
dobraczka committed Sep 13, 2023
2 parents d400768 + 4e0ce1e commit 6262240
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.2.0] - 2023-09-13

### Fixed

- Reading dotenv when using cli

### Added

- Added `ls` command for cli


## [0.1.0] - 2023-08-07

First release

[0.1.0]: https://github.com/dobraczka/nephelai/releases/tag/v0.1.0
[0.2.0]: https://github.com/dobraczka/nephelai/releases/tag/v0.2.0
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ This download the folder as:
└── testfile.txt
```

Using

```bash
nephelai ls tests
```
you can show the files in the `tests` directory.

You can get help for each command via the `--help` flag.

Via Python:
Expand Down
7 changes: 7 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ This download the folder as:
└── testfile.txt
```

Using

```bash
nephelai ls tests
```
you can show the files in the `tests` directory.

You can get help for each command via the `--help` flag.

Via Python:
Expand Down
26 changes: 14 additions & 12 deletions src/nephelai/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import bitmath
import owncloud
from dotenv import load_dotenv
from dotenv import find_dotenv, load_dotenv
from tqdm.auto import tqdm, trange

_DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024
Expand All @@ -29,6 +29,17 @@
]


def get_oc():
if not find_dotenv():
load_dotenv(".env")
else:
load_dotenv()
return owncloud.Client.from_public_link(
os.environ[NEXTCLOUD_FOLDER_URI_KEY],
folder_password=os.environ[NEXTCLOUD_FOLDER_PW_KEY],
)


def _remove_commonpath(full_path: str, base: str):
return os.path.relpath(full_path, os.path.commonpath([base, full_path]))

Expand Down Expand Up @@ -167,12 +178,7 @@ def upload(
chunk_size = int(chunk_size)
except ValueError:
chunk_size = int(bitmath.parse_string(chunk_size).bytes)
load_dotenv()
oc = owncloud.Client.from_public_link(
os.environ[NEXTCLOUD_FOLDER_URI_KEY],
folder_password=os.environ[NEXTCLOUD_FOLDER_PW_KEY],
debug=debug,
)
oc = get_oc()
if file_to_upload.is_dir():
create_nc_folders(file_to_upload, oc)
for subfile in file_to_upload.iterdir():
Expand Down Expand Up @@ -323,11 +329,7 @@ def download(remote_path: str, local_path: Optional[str] = None) -> Optional[boo
Returns:
True if successful, else None
"""
load_dotenv()
oc = owncloud.Client.from_public_link(
os.environ[NEXTCLOUD_FOLDER_URI_KEY],
folder_password=os.environ[NEXTCLOUD_FOLDER_PW_KEY],
)
oc = get_oc()
if local_path is None:
local_path = pathlib.Path(remote_path).name
if not remote_path.startswith("/"):
Expand Down
8 changes: 8 additions & 0 deletions src/nephelai/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing_extensions import Annotated

from .api import download as nephelai_download
from .api import get_oc
from .api import upload as nephelai_upload

app = typer.Typer()
Expand Down Expand Up @@ -59,5 +60,12 @@ def download(remote_path: str, local_path: Optional[str] = None):
nephelai_download(remote_path=remote_path, local_path=local_path)


@app.command()
def ls(remote_path: str):
oc = get_oc()
for file in oc.list(remote_path):
typer.echo(file.path)


if __name__ == "__main__":
app()

0 comments on commit 6262240

Please sign in to comment.