2012-03-29 7 views
0

Lassen Sie uns diese fabfileStoff - Projektpfadumgebung

betrachten
def syncdb(): 
    print(green("Database Synchronization ...")) 
    with cd('/var/www/project'): 
    sudo('python manage.py syncdb', user='www-data') 

def colstat(): 
    print(green("Collecting Static Files...")) 
    with cd('/var/www/project'): 
    sudo('python manage.py collectstatic --noinput', user='www-data') 

def httpdrst(): 
    print(green("Restarting Apache...")) 
    sudo('apachectl restart') 

def srefresh(): 
    colstat() 
    syncdb() 
    httpdrst() 

Die srefresh Richtlinie fordert alle anderen, von denen einige with cd(...)

Was wäre der beste Weg, um dieses ‚cd Pfad‘ haben in einer Variablen?

def colstat(): 
    with cd(env.remote['path']): 

def srefresh(): 
    env.remote['path'] = '/var/www/project' 
    colstat() 
    syncdb() 
    httpdrst() 

So ähnlich?

Antwort

2

Ich würde nur die Variable an die Funktionen als Argument übergeben.

def syncdb(path): 
    print(green("Database Synchronization ...")) 
    with cd(path): 
    sudo('python manage.py syncdb', user='www-data') 

def colstat(path): 
    print(green("Collecting Static Files...")) 
    with cd(path): 
    sudo('python manage.py collectstatic --noinput', user='www-data') 

def httpdrst(): 
    print(green("Restarting Apache...")) 
    sudo('apachectl restart') 

def srefresh(): 
    path = '/var/www/project' 
    colstat(path) 
    syncdb(path) 
    httpdrst() 
+0

die Arbeit zu tun könnte allerdings nicht auf Stoff anwendbar sein ... – enderskill

+0

Dies sollte auf Stoff gut funktionieren. Wenn Sie sie immer noch mit 'fab command' aufrufen möchten, ohne die Argumente angeben zu müssen, geben Sie ihnen einfach einen Standardwert. – Wilduck

+0

Funktioniert, aber das Problem ist, dass ich 'syncdb',' colstat' nicht mehr unabhängig aufrufen kann –

0

nicht sicher, dass es eine gute Praxis, aber es scheint, mit diesen

env.remote_path = '/var/www/project' 

def colstat(): 
    with cd(env.remote_path): 

#... 

def srefresh(): 
    env.remote_path = '/var/www/other_project' 
    pushpull() 
    colstat() 
#...