File copy¶
The copy() function can be used to plan file copying steps.
It automatically performs several sanity checks and generates a corresponding shell command step.
The example below will also be used in the Automatic Cleaning tutorial.
Example¶
Example source files: docs/getting_started/copy/
Create a file plan.py with the following contents:
#!/usr/bin/env python3
from stepup.core.api import copy, run
run("echo hello > hello.txt", shell=True, out="hello.txt")
copy("hello.txt", "sub/")
Make it executable and run it with StepUp as follows:
You should get the following output:
DIRECTOR │ Listening on /tmp/stepup-########/director (StepUp Core 3.2.3.post54)
STARTUP │ (Re)initialized boot script
PHASE │ build
START │ ./plan.py
SUCCESS │ ./plan.py
START │ echo hello > hello.txt
SUCCESS │ echo hello > hello.txt
START │ cp -p hello.txt sub/hello.txt
SUCCESS │ cp -p hello.txt sub/hello.txt
DIRECTOR │ Trying to delete 0 outdated output(s)
DIRECTOR │ See you!
Notes¶
-
The second argument is a directory into which the file will be copied.
-
StepUp creates subdirectories automatically if they don’t exist yet.
-
The second argument of
copy()can also be a file. For example, replacesub/withsub/hello.txt, and the file will be copied to that specific destination. You can also use a different filename, such assub/hi.txt.