-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoc_share.py
32 lines (24 loc) · 1.05 KB
/
oc_share.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import owncloud
import typer
from owncloud import Client
from rich.progress import track
def oc_share(
url: str = typer.Argument(..., help="OwnCloud instance url."),
username: str = typer.Argument(..., help="OwnCloud username to connect as."),
folder: str = typer.Argument(..., help="OwnCloud folder name, like '/ToBeShared'."),
password: str = typer.Option(..., prompt=True, hide_input=True,
help="OwnCloud password, leave empty to get a prompt.")
):
"""This will generate public links for all the content in the given OwnCloud resource."""
oc = owncloud.Client(url)
oc.login(username, password)
share_all_in_folder(oc, folder)
def share_all_in_folder(oc: Client, folder: str):
"""Share all files in a given folder"""
for item in track(oc.list(folder), description="Creating links..."):
link_info = oc.share_file_with_link(item)
print(f"{link_info.get_path()}: {link_info.get_link()}")
def main():
typer.run(oc_share)
if __name__ == '__main__':
main()