#!/usr/bin/env python3
#
#  Upload to and replace the given documents in $WWWHOST/WWWDIR.
#
import sys, os

host = os.environ['WWWHOST']
dir = os.environ['WWWDIR']

# Don't try to copy straight on to the file,
# this may fail if it's write-locked.  Besides, moves are atomic.
scp_cmd   = "scp -q ~/HTML/%s '"+host+":"+dir+"/%s.new' && ssh -q esr@"+host+" 'cd "+dir+"/%s && rm -f %s; mv %s.new %s'"

for file in sys.argv[1:]:
    os.system(scp_cmd % (file, file, os.path.dirname(file), os.path.basename(file), os.path.basename(file), os.path.basename(file)))

# upload ends here

