#!/usr/bin/env python3

import argparse
import fileinput
import os
import socket
import sys
import tempfile

parser = argparse.ArgumentParser()
parser.add_argument('files', nargs='*')
args = parser.parse_args()

if args.files:
    files = args.files
else:
    files = []
    for line in fileinput.input():
        files.append(line.strip())

tmp_dir = tempfile.mkdtemp()
for f in files:
    if not os.path.exists(f):
        print(f"Error: path '{f}' does not exist", file=sys.stderr)
        exit(1)
    f = os.path.realpath(f)
    if os.path.isabs(f):
        target = os.path.join(tmp_dir, os.path.basename(f))
    else:
        target = os.path.join(tmp_dir, f)
        os.makedirs(os.path.dirname(target), exist_ok=True)
    os.symlink(os.path.abspath(f), target)

print(f"rtransfer {socket.gethostname()} '{tmp_dir}'")
