-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy path__init__.py
More file actions
45 lines (34 loc) · 1.21 KB
/
__init__.py
File metadata and controls
45 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from functools import wraps
from fabric.api import sudo
from patchwork.info import distro_family
def package(*packages):
"""
Installs one or more ``packages`` using the system package manager.
Specifically, this function calls a package manager like ``apt-get`` or
``yum`` once per package given.
"""
# Try to suppress interactive prompts, assume 'yes' to all questions
apt = "DEBIAN_FRONTEND=noninteractive apt-get install -y %s"
# Run from cache vs updating package lists every time; assume 'yes'.
yum = "yum install -y %s"
manager = apt if distro_family() == "debian" else yum
sudo(manager % " ".join(packages))
def rubygem(gem):
"""
Install a Rubygem
"""
return sudo("gem install -b --no-rdoc --no-ri %s" % gem)
class requires_packages(object):
"""
A decorator that ensures the listed packages are installed. Example:
@task
@requires_packages('python-dev', 'redis-server', 'nginx')
def my_task(): ...
"""
def __init__(self, *args):
self.packages = args
def __call__(self, fn, *args, **kwargs):
def wrapper():
package(*self.packages)
fn(*args, **kwargs)
return wraps(fn)(wrapper)