Skip to content

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: docs/getting_started/copy_mkdir/

Create a file plan.py with the following contents:

#!/usr/bin/env python3
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:

chmod +x plan.py
stepup -n 1

You should get the following output:

  DIRECTOR │ Listening on /tmp/stepup-########/director (StepUp 2.0.4)
   STARTUP │ (Re)initialized boot script
  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
  DIRECTOR │ Trying to delete 0 outdated output(s).
  DIRECTOR │ Stopping workers.
  DIRECTOR │ See you!

Notes

  • StepUp expects all directories to end with a trailing delimiter (/). In the example above, mkdir() and copy() have a sub/ argument, which is a directory. This imposes some clarity on the plan.py file and improves readability.

  • The second argument of copy() can also be a file. For example, replace sub/ with sub/hello.txt, and you will get exactly the same result. You can also use a different filename, such as sub/hi.txt.