python - In Fabric, how can I check if a Debian or Ubuntu package exists and install it if it does not? -



python - In Fabric, how can I check if a Debian or Ubuntu package exists and install it if it does not? -

i required install memcached part of fabric script setting test servers. figured i'd record here future reference.

pieced superuser comment , stackoverflow answer. (note: i'm running root rather using sudo):

def package_installed(pkg_name): """ref: http:superuser.com/questions/427318/#comment490784_427339""" cmd_f = 'dpkg-query -l "%s" | grep -q ^.i' cmd = cmd_f % (pkg_name) settings(warn_only=true): result = run(cmd) homecoming result.succeeded def yes_install(pkg_name): """ref: http://stackoverflow.com/a/10439058/1093087""" run('apt-get --force-yes --yes install %s' % (pkg_name)) def make_sure_memcached_is_installed_and_running(): if not package_installed('memcached'): yes_install('memcached') settings(warn_only=true): run('/etc/init.d/memcached restart', pty=false)

python ubuntu debian fabric

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -