diff --git a/.vscode/settings.json b/.vscode/settings.json index a3e2455d..cb779e0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -37,7 +37,7 @@ "python.linting.banditEnabled": true, "python.linting.flake8Args": [ "--max-line-length=120", - "--ignore=E722,F405,E203,W503,W293", + "--ignore=E722,F405,E203,W503,W293,E402", ], "python.linting.banditArgs": [ "--ignore=B104" @@ -55,6 +55,6 @@ // // things you may wanna edit: // - "python.pythonPath": ".venv/bin/python", + "python.pythonPath": "/usr/bin/python3", //"python.linting.enabled": true, } \ No newline at end of file diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 9facd25e..fe356d14 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -137,6 +137,8 @@ def main(): ap.add_argument("-q", action="store_true", help="quiet") ap.add_argument("-ed", action="store_true", help="enable ?dots") ap.add_argument("-nw", action="store_true", help="disable writes (benchmark)") + ap.add_argument("-nih", action="store_true", help="no info hostname") + ap.add_argument("-nid", action="store_true", help="no info disk-usage") al = ap.parse_args() SvcHub(al).run() diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 5225371b..7d65926a 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -6,6 +6,7 @@ import stat import gzip import time import json +import socket from datetime import datetime import calendar @@ -1076,6 +1077,27 @@ class HttpCli(object): break + srv_info = [] + + try: + if not self.args.nih: + srv_info.append(str(socket.gethostname()).split('.')[0]) + except: + self.log("#wow #whoa") + pass + + try: + # some fuses misbehave + if not self.args.nid: + sv = os.statvfs(abspath) + free = humansize(sv.f_frsize * sv.f_bfree, True) + total = humansize(sv.f_frsize * sv.f_blocks, True) + + srv_info.append(free + " free") + srv_info.append(total) + except: + pass + ts = "" # ts = "?{}".format(time.time()) @@ -1090,6 +1112,7 @@ class HttpCli(object): prologue=logues[0], epilogue=logues[1], title=html_escape(self.vpath, quote=False), + srv_info=' /// '.join(srv_info) ) self.reply(html.encode("utf-8", "replace")) return True diff --git a/copyparty/util.py b/copyparty/util.py index 0474d96f..ea47c489 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -334,6 +334,21 @@ def read_header(sr): return ret[:ofs].decode("utf-8", "surrogateescape").split("\r\n") +def humansize(sz, terse=False): + for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB']: + if sz < 1024: + break + + sz /= 1024 + + ret = ' '.join([str(sz)[:4].rstrip('.'), unit]) + + if not terse: + return ret + + return ret.replace('iB', '').replace(' ', '') + + def undot(path): ret = [] for node in path.split("/"): diff --git a/copyparty/web/browser.css b/copyparty/web/browser.css index 9c69480b..bdc8ca57 100644 --- a/copyparty/web/browser.css +++ b/copyparty/web/browser.css @@ -131,6 +131,17 @@ a { .logue { padding: .2em 1.5em; } +#srv_info { + opacity: .5; + font-size: .8em; + color: #fc5; + position: absolute; + top: .5em; + left: 2em; +} +#srv_info span { + color: #fff; +} a.play { color: #e70; } diff --git a/copyparty/web/browser.html b/copyparty/web/browser.html index b49598a6..6235dcac 100644 --- a/copyparty/web/browser.html +++ b/copyparty/web/browser.html @@ -53,6 +53,10 @@

control-panel

+ {%- if srv_info %} +
{{ srv_info }}
+ {%- endif %} +