views:

46

answers:

2
run("if [ -d data.bak ];then mv data.bak data;fi;")
sudo('....')
sudo('')

i use fabric deploy my project to web,and i want to find a way to didn't do the left command,if didn't find data.bak directory,so is there some way to achieve this on fabric

A: 

You can use the os module to check for its existence:

import os
if os.path.exists('data.bak'):
    run('mv data.bak data')
claytron
A: 

there is a contribute api

from fabric.contrib.files import exists

i found in fabric

mlzboy