Copy and mkdir¶
Copying a file or making a directory can be planned using the copy()
and mkdir()
functions, respectively.
These functions perform a few sanity checks and then create a step with the corresponding shell command.
The example below will also be used in the Automatic Cleaning tutorial.
Example¶
Example source files: getting_started/copy_mkdir/
Create a file plan.py
with the following contents:
#!/usr/bin/env python
from stepup.core.api import copy, mkdir, step
step("echo hello > hello.txt", out="hello.txt")
mkdir("sub/")
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
DIRECTOR │ Launched worker 0
DIRECTOR │ Launched worker 1
PHASE │ run
START │ ./plan.py
START │ echo hello > hello.txt
SUCCESS │ echo hello > hello.txt
START │ mkdir -p sub/
SUCCESS │ mkdir -p sub/
SUCCESS │ ./plan.py
START │ cp -aT hello.txt sub/hello.txt
SUCCESS │ cp -aT hello.txt sub/hello.txt
WORKFLOW │ Dumped to .stepup/workflow.mpk.xz
DIRECTOR │ Stopping workers.
DIRECTOR │ See you!
Notes¶
-
StepUp expects all directories to end with a trailing delimiter (
/
). In the example above,mkdir
andcopy
have asub/
argument, which is a directory. This imposes some clarity on theplan.py
file and improves readability. -
The second argument of
copy
can also be a file. For example, replacesub/
withsub/hello.txt
, and you will get exactly the same result. You can also use a different filename, such assub/hi.txt
.