code: def to_drakefile(steps, preview=True, debug=False, input_drakefile=None, bindir=None):
      
      data = get_drake_data(steps)
      drakefile = StringIO()
  
      if input_drakefile:
          drakefile.write('%context {}\n\n'.format(input_drakefile))
  
      if bindir is None:
          bindir = os.path.join(os.path.dirname(__file__), '..', 'bin')
  
      # if the step has a $OUTPUT, write drain.log to its directory
      drakefile.write("""drain()
      if [ $OUTPUT ]; then LOGFILE=$(dirname $OUTPUT)/drain.log; fi
      python %s %s/run_step.py $OUTPUT $INPUTS 2>&1 | tee $LOGFILE
  
  
  """ % ('-m pdb' if debug else '', bindir))
      for output, inputs in data.items():
          if not preview:
              output.setup_dump()
  
          drakefile.write(to_drake_step(inputs, output))
  
      return drakefile.getvalue()
docs: Args:
          steps: collection of drain.step.Step objects for which to
              generate a drakefile
          preview: boolean, when False will create directories for output
              steps.  When True do not touch filesystem.
          debug: run python with '-m pdb'
          drakefile: path to drakefile to include
          bindir: path to drake binaries, defaults to ../bin/
      Returns:
          a string representation of the drakefile