Can't get simple python script to copy file

Probably a very simple solution. I’m trying to copy a binary after compile. Everything works except the actual file copy.

Import("env")

def post_program_action(source, target, env):
    src = target[0].get_abspath()
    dest = env["PROJECT_DIR"]+env.GetProjectOption("renameToFile")
    print("dest:"+dest)
    print("source:"+src)
    # Copy(dest, src)
    Command(dest, src, Copy("$TARGET", "$SOURCE"))

env.AddPostAction("$BUILD_DIR/firmware.hex", post_program_action)

The source and destination paths are correct and exist. The file just doesn’t get copied.

Okay, I solved it with env.Execute.

env.Execute("cp %s %s" % (src, dest))

Probably not the correct way, because it’s not portable, but for me, this is good enough.

Weird. Something like

import shutil
import os
Import("env")

def post_program_action(source, target, env):
    src = target[0].get_abspath()
    dest = os.path.join(env["PROJECT_DIR"], env.GetProjectOption("renameToFile"))
    print("dest:"+dest)
    print("source:"+src)
    shutil.copy(src, dest)

env.AddPostAction("$BUILD_DIR/firmware.hex", post_program_action)

didn’t work?

I didn’t know about shutil.copy(). I’m pretty sure that will work. Thanks!