-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_webdav.py
More file actions
80 lines (70 loc) · 2.54 KB
/
run_webdav.py
File metadata and controls
80 lines (70 loc) · 2.54 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import os
from cheroot import wsgi
from wsgidav import util
from wsgidav.wsgidav_app import WsgiDAVApp
from src.virtual_disk.config import Config
from src.virtual_disk.disk import InFileChaCha20EncryptedDisk, InFileDisk, InMemoryDisk
from src.virtual_disk.path import Directory
from webdav.config import get_config
def format_size(size_bytes):
for unit in ["B", "KB", "MB", "GB", "TB", "PB"]:
if size_bytes < 1024:
return f"{size_bytes:.2f} {unit}"
size_bytes /= 1024
return f"{size_bytes:.2f} PB"
def main(
root: Directory, readonly: bool = False, host: str = "0.0.0.0", port: int = 8081
) -> None:
config = get_config(root=root, readonly=readonly)
config["host"] = host
config["port"] = port
config["verbose"] = 3
app = WsgiDAVApp(config)
version = (
f"{util.public_wsgidav_info} {wsgi.Server.version} {util.public_python_info}"
)
server = wsgi.Server(
bind_addr=(config["host"], config["port"]),
wsgi_app=app,
server_name=version,
numthreads=1,
# numthreads = 50, # NOTE/TODO: MY LIB IS NOT COMPATABLE YET
)
app.logger.info(f"Running {version}")
app.logger.info(f"Serving on http://{config['host']}:{config['port']}/ ...")
try:
server.start()
except KeyboardInterrupt:
app.logger.info("Received Ctrl-C: stopping...")
finally:
server.stop()
if __name__ == "__main__":
basedir = os.path.dirname(os.path.abspath(__file__))
instance = os.path.join(basedir, "instance")
if not os.path.exists(instance):
os.mkdir(instance)
filepath = os.path.join(instance, "large_disk.bin.enc")
if not os.path.exists(filepath):
config = Config(
block_size=4096, inode_size=64, num_blocks=1024 * 64, num_inodes=1024 * 16
)
disk = InFileChaCha20EncryptedDisk.new_disk(
filepath=filepath, config=config, password=b"very secure password :->"
)
# filepath=filepath,
# config=config
# )
# disk = InFileDisk.new_disk(
else:
# disk = InFileDisk(
# filepath=filepath
# )
disk = InFileChaCha20EncryptedDisk(
filepath=filepath, password=b"very secure password :->"
)
with disk:
print("TOTAL SPACE: ", format_size(disk.total_space()))
print("RESERVED SPACE: ", format_size(disk.reserved_space()))
print("USED SPACE: ", format_size(disk.used_space()))
print("FREE SPACE: ", format_size(disk.free_space()))
main(root=disk.root)