Compare commits
No commits in common. "cb3433e93c266124c79a23bfaa3e2299631ec858" and "794658b1ab7bdeebb51694df9b948cbaf3fc7384" have entirely different histories.
cb3433e93c
...
794658b1ab
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,3 +0,0 @@
|
|||
build/
|
||||
dist/
|
||||
*.egg-info/
|
|
@ -48,9 +48,6 @@ class Handler(socketserver.StreamRequestHandler):
|
|||
print("Unknown type.")
|
||||
return
|
||||
|
||||
if not file_name:
|
||||
return
|
||||
|
||||
print(f"{len(data)} bytes — {header} — '{file_name}'.")
|
||||
self.request.sendall(file_name.encode())
|
||||
|
||||
|
@ -60,8 +57,7 @@ def write_text(data: bytes, title=None):
|
|||
html = HTML_TEMPLATE.format(title=title or "?", content=content)
|
||||
path = str(Path(ARGS.root) / "txt")
|
||||
if not os.path.isdir(path):
|
||||
print(f"Missing '{path}' folder.")
|
||||
return None
|
||||
os.makedirs(path)
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="wt",
|
||||
dir=path,
|
||||
|
@ -69,27 +65,19 @@ def write_text(data: bytes, title=None):
|
|||
delete=False
|
||||
) as output_file:
|
||||
output_file.write(html)
|
||||
os.chmod(output_file.name, 0o644)
|
||||
return output_file.name
|
||||
|
||||
|
||||
def main():
|
||||
argp = argparse.ArgumentParser(description="Share stuff through a socket.")
|
||||
argp = argparse.ArgumentParser()
|
||||
argp.add_argument("root", help="root path where to put files")
|
||||
argp.add_argument("-s", "--socket", help="socket path")
|
||||
global ARGS
|
||||
ARGS = argp.parse_args()
|
||||
|
||||
socket_path = ARGS.socket
|
||||
if not socket_path:
|
||||
runtime_dir = os.environ.get("RUNTIME_DIRECTORY")
|
||||
if not runtime_dir:
|
||||
exit("No socket path nor runtime directory specified.")
|
||||
socket_path = os.path.join(runtime_dir, "shr.sock")
|
||||
print("Socket path:", socket_path)
|
||||
uid = os.getuid()
|
||||
socket_path = f"/run/user/{uid}/shr.sock"
|
||||
if os.path.exists(socket_path):
|
||||
os.unlink(socket_path)
|
||||
|
||||
try:
|
||||
with socketserver.UnixStreamServer(socket_path, Handler) as server:
|
||||
server.serve_forever()
|
||||
|
|
Reference in a new issue