title: calling rsync from python subprocess.call
body: <p>I'm trying to execute rsync over ssh from a subprocess in a python script to copy images from one server to another.  I have a function defined as:</p>
  
  <pre><code>def rsyncBookContent(bookIds, serverEnv):
      bookPaths = ""
      if len(bookIds) &gt; 1:
          bookPaths = "{" + ",".join(("book_"+str(x)) for x in bookIds) + "}"
      else:
          bookPaths = "book_" + str(bookIds[0])
  
      for host in serverEnv['content.hosts']:
          args = ["rsync", "-avz", "--include='*/'", "--include='*.jpg'", "--exclude='*'", "-e", "ssh", options.bookDestDir + "/" + bookPaths, "jill@" + host + ":/home/jill/web/public/static/"]
          print "executing " + ' '.join(args)
          subprocess.call(args)
  </code></pre>
  
  <p>What I'm ultimately trying to do is have Python execute this (which works from a bash shell):</p>
  
  <pre><code>rsync -avz --include='*/' --include='*.jpg' --exclude='*' -e ssh /shared/books/{book_482,book_347} jill@10.12.27.20:/home/jill/web/public/static/
  </code></pre>
  
  <p>And indeed my print statement outputs:</p>
  
  <pre><code>executing rsync -avz --include='*/' --include='*.jpg' --exclude='*' -e ssh /shared/books/{book_482,book_347} jill@10.12.27.20:/home/jill/web/public/static/
  </code></pre>
  
  <p>But when executed from within this python script, there are two problems:</p>
  
  <ol>
  <li>if len(bookIds) > 1, the list of sub-directories under /shared/books/ is somehow misinterpreted by bash or rsync.  The error message is:
  <ul>
  <li>rsync: link_stat "/shared/books/{book_482,book_347}" failed: No such file or directory (2))</li>
  </ul></li>
  <li>if len(bookIds) == 1, <em>all</em> files under the source directory are rsynced (not just *.jpg, as is my intention)</li>
  </ol>
  
  <p>Seems as if the subprocess.call function requires some characters to be escaped or something, no?</p>