I need to run an rsync command from Python. Is this possible and if so, how do I do it?
rsync -Ccavz --delete DJStatic username@website
You can call a subprocess from python using the following snippet
import subprocess
subprocess.call(["ls", "-l"])
In your case, it would be something like this
subprocess.call(["rsync", "-Ccavz", "--delete","DJStatic", "username@website"])
See here for more details.
subprocess.call("rsync -Ccavz --delete DJStatic username@website".split()) is slightly more readable and practical to type.shlex.split(s) instead of regular s.split() to split arguments up as a normal (POSIX) shell would.shlex.split() instead of split(), as mentioned by Chris L. Barnes. I think it's fine to use that solution if you do so cautiously. Unless...is there some other specific issue this causes?
fabricprovides a nice api that wraps many comman shell commands docs.fabfile.org/en/1.4.0/index.html