Commit 2470bf960ee10d2d6bdee3f1fa0c7333db000ca1

Authored by Charles Oliveira
1 parent 188e1d3d

Adding multi-distribuition support

Showing 1 changed file with 28 additions and 8 deletions   Show diff stats
fabfile.py
... ... @@ -9,6 +9,16 @@ from fabric.api import env, run, sudo, local
9 9 from fabric.contrib.files import exists
10 10 from fabric.context_managers import prefix, cd, settings, shell_env
11 11  
  12 +LINUX_DISTRO = 'Debian'
  13 +DISTRO_CMD = {'Debian': {
  14 + 'install': 'apt-get install',
  15 + 'update': 'apt-get update',
  16 + },
  17 + 'CentOS': {
  18 + 'install': 'yum install',
  19 + 'install': 'yum update -y',
  20 + }
  21 + }
12 22  
13 23 APP_USER = APP_NAME = VENV_NAME = 'colab'
14 24 REPO_URL = 'git@github.com:colab-community/colab.git'
... ... @@ -35,6 +45,15 @@ MANAGE_PATH = os.path.join(REPO_PATH, 'src')
35 45 SETTINGS_PATH = os.path.join(MANAGE_PATH, APP_NAME)
36 46  
37 47  
  48 +def get_distro():
  49 + global LINUX_DISTRO
  50 + linux_name = run('python -c "import platform; print platform.dist()[0]"')
  51 +
  52 + if 'Ubuntu' in linux_name or 'Debian' in linux_name:
  53 + LINUX_DISTRO = 'Debian'
  54 + elif 'centos' in linux_name:
  55 + LINUX_DISTRO = 'CentOS'
  56 +
38 57 @task
39 58 def environment(name=DEFAULT_ENVIRONMENT):
40 59 """Set the environment where the tasks will be executed"""
... ... @@ -53,12 +72,9 @@ def environment(name=DEFAULT_ENVIRONMENT):
53 72  
54 73 env.update(environments[name])
55 74 env.environment = name
56   -environment()
57   -
58   -
59   -def aptget_install(pkg):
60   - sudo('DEBIAN_FRONTEND=noninteractive apt-get install -y -q {}'.format(pkg))
61 75  
  76 +def package_install(pkg):
  77 + sudo(DISTRO_CMD[LINUX_DISTRO]['install'] + ' ' + pkg + ' -y -q')
62 78  
63 79 def install_requirements():
64 80 with cd(REPO_PATH), prefix(WORKON_ENV):
... ... @@ -130,11 +146,12 @@ def update_code():
130 146 @task
131 147 def bootstrap():
132 148 """Bootstrap machine to run fabric tasks"""
133   -
134 149 with settings(user=env.superuser):
135 150  
136   - if not exists('/usr/bin/git'):
137   - aptget_install('git')
  151 + sudo(DISTRO_CMD[LINUX_DISTRO]['update'])
  152 +
  153 + if not exists('/usr/bin/git'):
  154 + package_install('git-core')
138 155  
139 156 if env.is_vagrant:
140 157 groups = 'sudo,vagrant'
... ... @@ -222,3 +239,6 @@ def deploy(noprovision=False):
222 239 migrate()
223 240  
224 241 sudo('supervisorctl start all')
  242 +
  243 +# Main
  244 +environment()
... ...