#!/usr/bin/env python3

import os as _os
import argparse as _argparse


def string_coin(
	template,
	arguments
):
	result = template
	for (key, value, ) in arguments.items():
		result = result.replace("{{%s}}" % key, value)
	return result
	

def execute_shell_command(
	command
):
	_os.system(command)
	

def main():
	## args
	argument_parser = _argparse.ArgumentParser(
	)
	argument_parser.add_argument(
		"target_system",
		type = str,
	)
	argument_parser.add_argument(
		"-t",
		"--target-directory",
		type = str,
		metavar = "<target-directory>",
		default = "vortraege/freie_systeme",
	)
	argument_parser.add_argument(
		"-s",
		"--source-directory",
		type = str,
		metavar = "<source-directory>",
		default = "/tmp/freie_systeme",
	)
	args = argument_parser.parse_args()
	
	## exec
	execute_shell_command(
		string_coin(
			"rsync --update --recursive --verbose {{source_directory}}/ {{target_system}}:{{target_directory}}",
			{
				"source_directory": args.source_directory,
				"target_system": args.target_system,
				"target_directory": args.target_directory,
			}
		)
	)
	

main()

