#!/usr/bin/env python3

import argparse
import datetime
import os
import uuid

TRASHDIR="/tmp/trash"

def run():
    go(parse_args())

def parse_args():
    a = argparse.ArgumentParser("move-to-trash", description="Move items to {} instead of deleting them".format(TRASHDIR))
    a.add_argument("-v", "--verbose", action="store_true", help="Print information about actions taken")
    a.add_argument("FILE", nargs="*", help="File to trash")
    return a.parse_args()

def go(args):
    os.makedirs(TRASHDIR, exist_ok=True)
    for f in args.FILE:
        f = os.path.abspath(f)
        target_dir_name = "{}--{}".format(
            datetime.datetime.now(),
            uuid.uuid4())

        target_path = os.path.join(TRASHDIR, target_dir_name, os.path.basename(f))

        if args.verbose:
            print("{} ==> {}".format(f, target_path))

        os.mkdir(os.path.join(TRASHDIR, target_dir_name))
        os.rename(f, target_path)

if __name__ == "__main__":
    run()
