Skip to content

Commit 5b20508

Browse files
committed
Add gitconfig, add Fabric test task, speed up Debian package check
1 parent 95a2a01 commit 5b20508

File tree

3 files changed

+80
-52
lines changed

3 files changed

+80
-52
lines changed

fabfile.py

+73-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import with_statement
22
from fabric.api import *
3-
from fabric.colors import green
3+
from fabric.colors import green, red
44
from fabric.contrib.console import confirm
55
from fabric.contrib.files import exists
6+
from fabric.operations import reboot
67
from package_lists import *
78
import os
89

@@ -20,6 +21,7 @@ def deploy():
2021
install_config_files()
2122
allow_uwsgi_to_control_supervisor()
2223
set_zsh_as_default_shell()
24+
reboot()
2325

2426
def set_hostname():
2527
prompt('Enter hostname: ', 'hostname', default='rascal2')
@@ -34,13 +36,22 @@ def install_python_modules():
3436
print(green('\nInstalling Python module: {0}'.format(module)))
3537
run('pip install ' + module)
3638

39+
def package_installed(package):
40+
cmd = 'dpkg-query -l "{0}" | grep -q ^.i'.format(package)
41+
with settings(warn_only=True):
42+
result = run(cmd)
43+
return result.succeeded
44+
3745
def install_debian_packages():
3846
print(green('\nUpdating package repository lists'))
3947
run('apt-get update -y', pty=False)
4048

4149
for package in DEBIAN_PACKAGES_TO_INSTALL:
42-
print(green('\nInstalling package: {0}'.format(package)))
43-
run('apt-get install -y ' + package, pty=False)
50+
if not package_installed(package):
51+
print(green('\nInstalling package: {0}'.format(package)))
52+
run('apt-get install -y ' + package, pty=False)
53+
else:
54+
print(green('Package ' + package + ' already installed'))
4455

4556
print(green('\nRemoving unneeded package remnants'))
4657
run('apt-get autoremove -y', pty=False)
@@ -52,8 +63,11 @@ def disable_bonescript():
5263

5364
def remove_unneeded_debian_packages():
5465
for package in DEBIAN_PACKAGES_TO_REMOVE:
55-
print(green('\nRemoving package: {0}'.format(package)))
56-
run('apt-get remove -y ' + package, pty=False)
66+
if package_installed(package):
67+
print(green('\nRemoving package: {0}'.format(package)))
68+
run('apt-get remove -y ' + package, pty=False)
69+
else:
70+
print(green('Package ' + package + ' already removed.'))
5771

5872
def install_rascal_software():
5973
print(green('Installing Rascal editor . . .'))
@@ -87,6 +101,7 @@ def install_config_files():
87101
put('uwsgi.service', '/etc/systemd/system/uwsgi.service')
88102
run('systemctl enable uwsgi.service')
89103
put('vimrc', '/root/.vimrc')
104+
put('gitconfig', '/root/.gitconfig')
90105

91106
def allow_uwsgi_to_control_supervisor():
92107
run('echo "chmod=0770 ; socket file mode (default 0700)" >> /etc/supervisor/supervisor.conf')
@@ -99,3 +114,56 @@ def set_zsh_as_default_shell():
99114
# Enter the new value, or press ENTER for the default
100115
# Login Shell [/bin/bash]: /bin/zsh
101116
# curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
117+
118+
### END DEPLOY SECTION ###
119+
120+
### START TEST SECTION ###
121+
122+
@task
123+
def test():
124+
check_debian_packages()
125+
check_programs()
126+
check_python_modules()
127+
128+
PROGRAMS_TO_TEST = {
129+
'nginx': '/usr/sbin/nginx',
130+
'uwsgi': '/usr/local/bin/uwsgi',
131+
'zsh': '/usr/bin/zsh',
132+
}
133+
134+
PYTHON_MODULES_TO_TEST_IMPORT = [
135+
'gevent',
136+
'geventwebsocket',
137+
'flask.ext.uwsgi_websocket',
138+
'redis',
139+
# uwsgi omitted; not a Python module, though installed with pip
140+
'pytronics',
141+
'bitstring',
142+
'webcolors',
143+
'flask_login'
144+
]
145+
146+
def check_debian_packages():
147+
for package in sorted(DEBIAN_PACKAGES_TO_INSTALL):
148+
if package_installed(package):
149+
print(green('Package {0} found.'.format(package)))
150+
else:
151+
print(red('Package {0} missing!'.format(package)))
152+
153+
def check_programs():
154+
for program in sorted(PROGRAMS_TO_TEST.keys()):
155+
try:
156+
run('which ' + program) == PROGRAMS_TO_TEST[program]
157+
except:
158+
print(red('Binary for {0} not at {1}.'.format(program, PROGRAMS_TO_TEST[program])))
159+
else:
160+
print(green('Binary for {0} found at {1}'.format(program, PROGRAMS_TO_TEST[program])))
161+
162+
def check_python_modules():
163+
for module in PYTHON_MODULES_TO_TEST_IMPORT:
164+
try:
165+
run('python -c "__import__(\'' + module + '\')"')
166+
except:
167+
print(red('Module {0} not installed.'.format(module)))
168+
else:
169+
print(green('Successfully imported module {0}.'.format(module)))

gitconfig

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[color]
2+
diff = auto
3+
interactive = auto
4+
status = auto
5+
branch = auto
6+
[core]
7+
quotepath = false

test-rascal2.py

-47
This file was deleted.

0 commit comments

Comments
 (0)