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, runsh

runsh("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 boot -n 1

You should get the following output:

  DIRECTOR │ Listening on /tmp/stepup-########/director (StepUp 3.0.0)
   STARTUP │ (Re)initialized boot script
  DIRECTOR │ Launched worker 0
  DIRECTOR │ Launched worker 1
     PHASE │ run
     START │ runpy ./plan.py
     START │ runsh echo hello > hello.txt
   SUCCESS │ runpy ./plan.py
   SUCCESS │ runsh echo hello > hello.txt
     START │ mkdir sub/
   SUCCESS │ mkdir sub/
     START │ copy hello.txt sub/hello.txt
   SUCCESS │ copy 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.