Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial commit

  • Loading branch information...
commit d68561fbcffabe98725ee6828a9b6475df45bee6 1 parent 4be05ed
@saxix authored
View
0  .gitignore
No changes.
View
9 MANIFEST.in
@@ -0,0 +1,9 @@
+include README
+include MANIFEST.in
+include setup.py
+exclude manage.py
+exclude **/conf/settings/active.py
+
+recursive-include cashvoucher *.py
+recursive-include requirements *.*
+
View
38 bh/__init__.py
@@ -0,0 +1,38 @@
+import bh
+NAME = 'bh'
+VERSION = __version__ = (0, 0, 1, 'alpha', 0)
+__author__ = 'sax'
+
+def get_version(version=None):
+ """Derives a PEP386-compliant version number from VERSION."""
+ if version is None:
+ version = VERSION
+ assert len(version) == 5
+ assert version[3] in ('alpha', 'beta', 'rc', 'final')
+
+ # Now build the two parts of the version number:
+ # main = X.Y[.Z]
+ # sub = .devN - for pre-alpha releases
+ # | {a|b|c}N - for alpha, beta and rc releases
+
+ parts = 2 if version[2] == 0 else 3
+ main = '.'.join(str(x) for x in version[:parts])
+
+ sub = ''
+ if version[3] == 'alpha' and version[4] == 0:
+ path = bh.__path__[0]
+ head_path = '%s/../../.git/logs/HEAD' % path
+ try:
+ for line in open(head_path): pass
+ revision = line.split()[0]
+ except IOError, e:
+ print e
+ revision = '.unknown'
+ # raise Exception('Alpha version is are only allowed as git clone')
+ sub = '.dev%s' % revision
+
+ elif version[3] != 'final':
+ mapping = {'alpha': 'a', 'beta': 'b', 'rc': 'c'}
+ sub = mapping[version[3]] + str(version[4])
+
+ return main + sub
View
3  bh/api.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from django.utils.translation import gettext as _
View
17 bh/buildbot.py
@@ -0,0 +1,17 @@
+from fabric.api import *
+from fabric.contrib.files import contains, upload_template, sed, exists
+#from root import *
+from user import setup_env_for_user
+
+from fabfile import usudo, _bool
+from fabric.colors import green, red
+import os
+
+
+@task
+def install():
+ run('pip install buildbot buildbot-slave')
+ with cd('~'):
+ run('buildbot create-master master')
+ run('mv master/master.cfg.sample master/master.cfg')
+# run('buildslave create-slave slave localhost:9989 example-slave pass')
View
21 bh/checkpypi.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+import xmlrpclib
+import pip
+
+pypi = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
+for dist in pip.get_installed_distributions():
+ available = pypi.package_releases(dist.project_name)
+ if not available:
+ # Try to capitalize pkg name
+ available = pypi.package_releases(dist.project_name.capitalize())
+
+ if not available:
+ msg = 'no releases at pypi'
+ elif available[0] != dist.version:
+ msg = '{} available'.format(available[0])
+ else:
+ msg = 'up to date'
+ pkg_info = '{dist.project_name} {dist.version}'.format(dist=dist)
+ print '{pkg_info:40} {msg}'.format(pkg_info=pkg_info, msg=msg)
+
View
3  bh/defaults.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from django.utils.translation import gettext as _
View
6 bh/local.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+
+from django.utils.translation import gettext as _
+
+
+dev download
View
160 bh/root.py
@@ -0,0 +1,160 @@
+import crypt
+from fabric.api import *
+from fabric.contrib.files import contains, upload_template, exists, sed
+import re
+from utils import setup_env_for_user
+import os
+
+#TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'tpls', 'profiles')
+
+
+@task
+def init_env():
+ """ create common artifacts on the target host
+
+ - create pip cache directory
+ - copy source tarballs
+ - create 'pasport' group
+ - install all required libraries/sources
+
+ """
+# print 11111, contains("/etc/group", r"^%(group)s:" % env, escape=False )
+# print r"^%(group)s:x" % env
+
+ if not contains("/etc/group", r"^%(group)s:x" % env, escape=False ):
+ sudo('groupadd %(group)s' % env)
+
+ sudo('mkdir -p %(pip_cache)s' % env)
+ sudo('mkdir -p %(packages_cache)s' % env)
+ sudo('mkdir -p %(PREFIX)s/sbin' % env)
+
+ sudo('chown %(user)s:%(group)s %(PREFIX)s' % env)
+ sudo('chown %(user)s:%(group)s %(packages_cache)s' % env)
+ sudo('chown %(user)s:%(group)s %(pip_cache)s' % env)
+
+ sudo('chmod g+rw,o-rw %(PREFIX)s' % env)
+ sudo('chmod g+rw,o-rw %(pip_cache)s' % env)
+ sudo('chmod g+rw,o-rw %(packages_cache)s' % env)
+
+ copy_packages()
+ install_libraries()
+ upload_common_task()
+
+
+@task
+def install_libraries():
+ """ install OS specific package via apt-get or yum
+ """
+ if exists('/etc/redhat-release'):
+ redhat_prereq()
+ else:
+ ubuntu_prereq()
+
+@task
+def list_instances():
+ """ list available pasport instances
+ """
+ run('for x in `ls %(PREFIX)s`;do test -e "%(PREFIX)s/$x/.bashrc" && echo $x; done' % env)
+
+@task
+def reset_host():
+ """ remove ALL artifacts/instances ad users
+ """
+ out = sudo('ls -ld %(PREFIX)s' % env)
+ perms, _, owner, group, _, _, _, _, name = out.split()
+ if (group != env.group) or not 'pasport' in name: # simple check to avoi mistakes
+ print "Error"
+ return
+ sudo('getent group pasport')
+ #sudo('rm -fr %(PREFIX)s/*' % env)
+
+@task
+def create_user(admin, password='123'):
+ """ create a user
+
+ """
+
+ if not contains("/etc/passwd", "^%s:" % admin):
+ sudo('useradd -g pasport %s -M -g pasport' % admin)
+ else:
+ out = sudo('groups %s' % admin)
+ assert re.search(r"\%(group)s\b" % env, out) # check the user in pasport group
+
+ setup_env_for_user(admin)
+
+ with settings(pwd=crypt.crypt(password, ".sax/")):
+ sudo('mkdir %(admin_home_dir)s' % env)
+ sudo('touch %(admin_home_dir)s/.scout' % env)
+ sudo('usermod -p "%(pwd)s" -d %(admin_home_dir)s -m -s /bin/bash %(admin)s' % env)
+ chown()
+
+@task
+def reset_user(admin, password='123'):
+ """ reinitialize user environment
+ """
+ setup_env_for_user(admin)
+ with settings(pwd=crypt.crypt(password, ".sax/")):
+ sudo('usermod -p "%(pwd)s" -d %(admin_home_dir)s -s /bin/bash %(admin)s' % env)
+ sudo('touch %(admin_home_dir)s/.scout' % env)
+ chown()
+
+
+def chown():
+ """ setup right permission on the install dir
+ """
+ require('admin', provided_by=setup_env_for_user)
+ sudo('chown -R :%(group)s %(PREFIX)s' % env)
+ sudo('chmod g+rwx %(PREFIX)s' % env)
+
+ sudo('chown -R %(admin)s:%(group)s %(base)s' % env)
+ sudo('chmod -R ug+rwx %(base)s ' % env)
+
+
+def ubuntu_prereq():
+ reqs = ['gcc', 'build-essential', 'libaio-dev', 'libxml2-dev', 'libxslt1-dev', 'libsqlite-dev', 'curl', 'sqlite3',
+ 'libssl-dev', 'libcurl4-openssl-dev', 'libsqlite3-dev', 'postgresql-server-dev-9.1']
+ with settings(reqs=" ".join(reqs)):
+ sudo('apt-get -y --force-yes install %(reqs)s' % env)
+
+
+def redhat_prereq():
+ """ install redhat/centos packages required to compile """
+ reqs = ['autoconf', 'bzip2-devel', 'db4-devel', 'expat-devel', 'findutils', 'gcc-c++', 'gdbm-devel', 'glibc-devel',
+ 'gmp-devel', 'libGL-devel', 'libX11-devel', 'libtermcap-devel', 'ncurses-devel', 'openssl-devel',
+ 'pkgconfig', 'readline-devel', 'sqlite-devel', 'tar', 'tix-devel', 'tk-devel', 'zlib-devel', 'rpm-build',
+ 'make', 'libxml2-devel', 'curl', 'libxslt-devel', 'postgresql-libs']
+ with settings(reqs=" ".join(reqs)):
+ sudo('yum -y install %(reqs)s' % env)
+
+
+def _redhat_prereq():
+ sudo('yum remove gcc cpp kernel-headers glibc-headers glibc-devel libreadline5-dev')
+
+
+@task
+def copy_packages():
+ """ copy local source code tarball to remote machine
+ """
+# for source, dest in [(env.local_tarball , env.packages_cache), ('pip_cache', env.pip_cache)]:
+ for source, dest in [(env.local_tarball , env.packages_cache), ]:
+ with lcd(source):
+ packages = local('ls *', True)
+ for p in packages.split('\n'):
+ target = '%s/%s' % (dest, p)
+ if not exists(target):
+ with settings(p=os.path.abspath("%s/%s" % (source, p)), dest=dest):
+ local('scp %(p)s %(user)s@%(host)s:%(dest)s/' % env)
+
+
+
+@task
+def upload_common_task():
+ upload_template("all_env_command.sh", "%(PREFIX)s/sbin/all_env_command.sh" % env, env, use_jinja=True, template_dir=TEMPLATE_DIR)
+ upload_template("pending_records.sh", "%(PREFIX)s/sbin/pending_records.sh" % env, env, use_jinja=True,template_dir=TEMPLATE_DIR)
+ upload_template("payroll.sh", "%(PREFIX)s/sbin/payroll.sh" % env, env, use_jinja=True, template_dir=TEMPLATE_DIR)
+ run('chmod ugo+x-rw %(PREFIX)s/sbin' % env)
+ run('chmod ugo-rw,o-rw+x %(PREFIX)s/sbin/*' % env)
+
+
+
+
View
231 bh/system.py
@@ -0,0 +1,231 @@
+from fabric.api import *
+from fabric.contrib.files import contains, upload_template, sed, exists
+from user import setup_env_for_user
+
+from fabfile import usudo, _bool
+from fabric.colors import green, red
+import os
+
+@task
+def python():
+ """ compile and install python
+ """
+ setup_env_for_user(env.user)
+ version = env.PYTHON.replace('Python-', '')
+ run('mkdir -p %(admin_home_dir)s/~build' % env)
+ with cd(env.build):
+ run('tar -xzf %(packages_cache)s/%(PYTHON)s.tgz' % env)
+ with cd(env.PYTHON):
+ run('./configure --prefix=%(base)s --enable-shared --with-threads' % env)
+ run('make clean')
+ run('make')
+ run('make install')
+
+ # check local install
+ out = run('python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"')
+ assert out.startswith("%(base)s/" % env), 'Error: `%s` ' % out
+
+ # checl ssl support
+ out = run('python -c "import socket;print socket.ssl"')
+ assert out.startswith("<function ssl at "), out
+
+ run('python %(packages_cache)s/distribute_setup.py && easy_install pip' % env)
+ run('rm -f %(base)s/distribute-*' % env)
+ run('pip install ipython')
+
+@task
+def apache():
+ """ compile and install apache
+ """
+ setup_env_for_user(env.user)
+
+ run('mkdir -p %(admin_home_dir)s/~build' % env)
+ run('mkdir -p %(admin_home_dir)s/etc/httpd/conf.d' % env )
+ with cd(env.build):
+ run('tar -xzf %(packages_cache)s/%(APACHE)s.tar.gz' % env)
+ with cd(env.APACHE):
+ run('./configure '\
+ ' --prefix=%(base)s'\
+ ' --exec_prefix=%(base)s'\
+ ' --bindir=%(base)s/bin'\
+ ' --sbindir=%(base)s/bin'\
+ ' --libexecdir=%(base)s/lib/apache'\
+ ' --mandir=%(base)s/man'\
+ ' --sysconfdir=%(base)s/etc/httpd/conf'\
+ ' --datadir=%(base)s/var/www'\
+ ' --includedir=%(base)s/lib/include/apache'\
+ ' --localstatedir=%(base)s/var/run'\
+ ' --enable-rewrite'\
+# ' --enable-rewrite=shared'\
+# ' --enable-mods-shared=most'\
+ ' --with-included-apr'\
+ ' --enable-ssl'
+ % env)
+ run('make clean')
+ run('make')
+ run('make install')
+
+
+@task
+def uwsgi():
+ """ compile and install uwsgi
+ """
+ setup_env_for_user(env.user)
+ run('mkdir -p %(admin_home_dir)s/~build' % env)
+ with cd(env.build):
+ run('tar -xzf %(packages_cache)s/%(UWSGI)s.tar.gz' % env)
+ with cd(env.UWSGI):
+ run('python uwsgiconfig.py --build' % env)
+ run("cp uwsgi %(base)s/bin/uwsgi" % env)
+
+
+@task
+def modwsgi():
+ """ compile and install modwsgi
+ """
+ setup_env_for_user(env.user)
+ run('mkdir -p %(admin_home_dir)s/~build' % env)
+ with cd(env.build):
+ run('tar xvfz %(packages_cache)s/%(MOD_WSGI)s.tar.gz' % env)
+ with cd(env.MOD_WSGI):
+ run('./configure --with-apxs=%(base)s/bin/apxs --with-python=%(base)s/bin/python' % env)
+ run('make clean')
+ run('make')
+ run('make install')
+
+
+@task
+def oracle():
+ """ compile and install oracle drivers
+ """
+ setup_env_for_user(env.user)
+ run('mkdir -p %(admin_home_dir)s/~build' % env)
+ with cd(env.base):
+ run('rm -fr oracle*')
+ run('mkdir -p oracle')
+ with cd('oracle'):
+ arch = run('uname -i')
+ if arch == 'x86_64':
+ run('find %(packages_cache)s -name "instantclient*86-64*" -exec unzip "{}" \;' % env)
+ elif arch== 'i386':
+ run('find %(packages_cache)s -name "instantclient*" -name "*86-64*" -exec unzip "{}" \;' % env)
+ with cd('instantclient_*'):
+ env.oracle_home = '%(base)s/oracle/instantclient_11_2' % env
+ run('ln -sf libclntsh.so.11.1 libclntsh.so')
+
+ assert exists('%(oracle_home)s/libclntsh.so' % env )
+ run('pip install cx_Oracle')
+ run('mkdir ~/logs/oracle')
+ run('ln -s ~/logs/oracle %(base)s/oracle/instantclient_11_2/log' % env)
+ # test
+ out = run('python -c "import cx_Oracle;print(222)"')
+ assert out.startswith("222")
+
+
+@task
+def ngnix(recover=False, configure=True, make=True, install=True):
+ """ compile and install nginx
+ """
+ setup_env_for_user()
+ _recover = _bool(recover, False)
+ _configure = _bool(configure, True)
+ _make = _bool(make, True)
+ _install = _bool(install, True)
+ with cd(env.build):
+ if not _recover:
+ run("tar -xzf %(packages_cache)s/%(NGINX)s.tar.gz" % env)
+ run("tar -xzf %(packages_cache)s/pcre-%(PCRE)s.tar.gz" % env)
+ run("tar -xzf %(packages_cache)s/%(UWSGI)s.tar.gz" % env)
+
+ with cd(env.NGINX):
+ if _configure:
+ run("./configure --prefix=%(base)s"\
+ " --sbin-path=%(base)s/bin"\
+ " --pid-path=%(base)s/run/nginx.pid"\
+ " --lock-path=%(base)s/run/nginx.lck"\
+ " --user=nginx"\
+ " --group=%(group)s"\
+ " --with-debug "\
+ # " --with-google_perftools_module"\
+ " --with-select_module"\
+ " --with-http_ssl_module"\
+ " --with-http_gzip_static_module"\
+ " --with-http_stub_status_module"\
+ " --with-http_realip_module"\
+ " --with-http_ssl_module"\
+ " --with-http_sub_module"\
+ " --with-http_addition_module"\
+ " --with-http_flv_module"\
+ " --with-http_addition_module"\
+ " --with-file-aio"\
+ " --with-sha1-asm"\
+ " --http-proxy-temp-path=%(base)s/tmp/proxy/"\
+ " --http-client-body-temp-path=%(base)s/tmp/client/"\
+ " --http-fastcgi-temp-path=%(base)s/tmp/fcgi/"\
+ " --http-uwsgi-temp-path=%(base)s/tmp/uwsgi/"\
+ " --http-scgi-temp-path=%(base)s/tmp/scgi/"\
+ " --http-log-path=%(base)s/logs/nginx/access.log"\
+ " --error-log-path=%(base)s/logs/nginx/error.log"\
+ " --with-pcre=../pcre-8.20" % env
+ )
+ if _make:
+ run("make")
+ if _install:
+ run("make install")
+
+
+@task
+def check():
+ """ check installation of the servers/appliance
+ """
+ setup_env_for_user()
+
+ def _test(cmd, where):
+ print 'Checking `%s`..' % cmd,
+ with settings(warn_only=True):
+ out = run(cmd)
+ if out.startswith(where):
+ print green('Ok')
+ else:
+ print red("FAIL!!"), out
+
+ puts('Checking installation...')
+
+ with hide('everything'):
+ _test('which httpd', '%(base)s/bin/httpd' % env)
+ _test('which nginx', '%(base)s/bin/nginx' % env)
+ _test('which uwsgi', '%(base)s/bin/uwsgi' % env)
+ _test('which python', '%(base)s/bin/python' % env)
+ _test('which pip', '%(base)s/bin/pip' % env)
+
+ _test('python -V', 'Python 2.7.2')
+ _test('python -c "import cx_Oracle;print(\'cx_Oracle imported\')"', 'cx_Oracle imported')
+ _test('python -c "import socket;print socket.ssl"', '<function ssl at')
+
+ print 'Checking $PATH..',
+ out = run('echo $PATH')
+ assert out.startswith("%(base)s/bin:%(base)s/apache/bin" % env), out
+ print green('Ok (%s)' % out)
+
+@task
+def copy_cmds():
+ """ initalize remote admin home directory
+ """
+ upload_template("tpls/sbin/all_env_command.sh", "%(PREFIX)s/sbin" % env, env, use_jinja=True)
+ run('chmod +x %(PREFIX)s/sbin/*.sh' % env)
+
+
+@task
+def install():
+ """ install all required servers/appliance
+
+ this command
+ """
+ setup_env_for_user(env.user)
+
+ execute(python)
+ execute(apache)
+ execute(oracle)
+ execute(modwsgi)
+ execute(uwsgi)
+ execute(ngnix)
View
90 bh/tpls/bin/activate
@@ -0,0 +1,90 @@
+# This file must be used with "source bin/activate" *from bash*
+# you cannot run it directly
+
+deactivate () {
+ # reset old environment variables
+ if [ -n "$_OLD_VIRTUAL_PATH" ] ; then
+ PATH="$_OLD_VIRTUAL_PATH"
+ export PATH
+ unset _OLD_VIRTUAL_PATH
+ fi
+ if [ -n "_OLD_LD_LIBRARY_PATH" ] ; then
+ LD_LIBRARY_PATH="_OLD_LD_LIBRARY_PATH"
+ export LD_LIBRARY_PATH
+ unset _OLD_LD_LIBRARY_PATH
+ fi
+
+
+ if [ -n "$_OLD_VIRTUAL_PYTHONHOME" ] ; then
+ PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
+ export PYTHONHOME
+ unset _OLD_VIRTUAL_PYTHONHOME
+ fi
+
+ # This should detect bash and zsh, which have a hash command that must
+ # be called to get it to forget past commands. Without forgetting
+ # past commands the $PATH changes we made may not be respected
+ if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
+ hash -r
+ fi
+
+ if [ -n "$_OLD_VIRTUAL_PS1" ] ; then
+ PS1="$_OLD_VIRTUAL_PS1"
+ export PS1
+ unset _OLD_VIRTUAL_PS1
+ fi
+
+ unset PASPORT_ENV
+ if [ ! "$1" = "nondestructive" ] ; then
+ # Self destruct!
+ unset -f deactivate
+ fi
+}
+
+# unset irrelavent variables
+deactivate nondestructive
+
+PASPORT_ENV="{{base}}"
+export PASPORT_ENV
+
+_OLD_VIRTUAL_PATH="$PATH"
+_OLD_LD_LIBRARY_PATH=LD_LIBRARY_PATH
+PATH="$PASPORT_ENV/bin:$PASPORT_ENV/apache/bin:$PATH"
+export PATH
+export LD_LIBRARY_PATH=$PASPORT_ENV/lib:$PASPORT_ENV/oracle/instantclient_11_2
+export ORACLE_HOME=$PASPORT_ENV/oracle/instantclient_11_2
+export PASPORT_LOGDIR=$PASPORT_ENV/logs/pasport
+export PYTHONPATH=$PASPORT_ENV/etc/:$PYTHONPATH
+export DJANGO_SETTINGS_MODULE=pasport_settings
+export HTTP_LISTEN_PORT={{http_port}}
+
+# unset PYTHONHOME if set
+# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
+# could use `if (set -u; : $PYTHONHOME) ;` in bash
+if [ -n "$PYTHONHOME" ] ; then
+ _OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
+ unset PYTHONHOME
+fi
+
+if [ -z "$PASPORT_ENV_DISABLE_PROMPT" ] ; then
+ _OLD_VIRTUAL_PS1="$PS1"
+ if [ "x" != x ] ; then
+ PS1="$PS1"
+ else
+ if [ "`basename \"$PASPORT_ENV\"`" = "__" ] ; then
+ # special case for Aspen magic directories
+ # see http://www.zetadev.com/software/aspen/
+ PS1="[`basename \`dirname \"$PASPORT_ENV\"\``] $PS1"
+ else
+ PS1="(`basename \"$PASPORT_ENV\"`)$PS1"
+ fi
+ fi
+ export PS1
+fi
+
+# This should detect bash and zsh, which have a hash command that must
+# be called to get it to forget past commands. Without forgetting
+# past commands the $PATH changes we made may not be respected
+if [ -n "$BASH" -o -n "$ZSH_VERSION" ] ; then
+ hash -r
+fi
View
3  bh/tpls/bin/taillog.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+BASE={{ base }}
+tail -f $BASE/logs/* $BASE/logs/*/*
View
23 bh/tpls/bin/upgrade.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+f_yesno(){
+ echo -n "Do you want to exit ? (y/N)"
+ read ans
+ [ $ans == "y" ] && return 0 || return 1
+}
+
+VERSION=`python -c "import pasportng as p;print p.get_version()"`
+echo "This will upgrade the PASport NG ($VERSION) instance on '{{base}}'"
+echo -n "Please confirm (y/N) "
+read ans
+
+if [ "$ans" == "y" ];then
+ pasport_admin.py offline activate
+ pip install Wfp-PASPortNG --upgrade -f {{pypi}}
+ pasport_admin.py collectstatic --noinput
+ pasport_admin.py syncdb --noinput
+ apachectl reload
+ pasport_admin.py offline deactivate
+
+else
+ echo "Aborted"
+fi
View
13 bh/tpls/home/bash_profile
@@ -0,0 +1,13 @@
+# .bash_profile
+
+# Get the aliases and functions
+if [ -f ~/.bashrc ]; then
+ . ~/.bashrc
+fi
+
+# User specific environment and startup programs
+
+PATH=$PATH:$HOME/bin
+
+export PATH
+unset USERNAME
View
24 bh/tpls/home/bashrc
@@ -0,0 +1,24 @@
+# .bashrc
+
+# User specific aliases and functions
+
+alias rm="/bin/rm -i"
+alias cp="cp -i"
+alias mv="mv -i"
+alias ll="ls -al"
+alias env="env | sort"
+alias checklog='tail -f logs/* logs/pasport/* logs/oracle/*'
+
+
+# Source global definitions
+if [ -f /etc/bashrc ]; then
+ . /etc/bashrc
+fi
+
+export PATH=$HOME/bin:$HOME/apache/bin:$PATH
+export PIP_DOWNLOAD_CACHE={{pip_cache}}
+export PS1="[\u@\h \W]\$ "
+
+[[ -e $HOME/bin/activate ]] && source $HOME/bin/activate
+[[ -e $HOME/.django_bash_completion ]] && source $HOME/.django_bash_completion
+
View
72 bh/tpls/home/django_bash_completion
@@ -0,0 +1,72 @@
+# #########################################################################
+# This bash script adds tab-completion feature to django-admin.py and
+# manage.py.
+#
+# Testing it out without installing
+# =================================
+#
+# To test out the completion without "installing" this, just run this file
+# directly, like so:
+#
+# . ~/path/to/django_bash_completion
+#
+# Note: There's a dot ('.') at the beginning of that command.
+#
+# After you do that, tab completion will immediately be made available in your
+# current Bash shell. But it won't be available next time you log in.
+#
+# Installing
+# ==========
+#
+# To install this, point to this file from your .bash_profile, like so:
+#
+# . ~/path/to/django_bash_completion
+#
+# Do the same in your .bashrc if .bashrc doesn't invoke .bash_profile.
+#
+# Settings will take effect the next time you log in.
+#
+# Uninstalling
+# ============
+#
+# To uninstall, just remove the line from your .bash_profile and .bashrc.
+
+_django_completion()
+{
+ COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \
+ COMP_CWORD=$COMP_CWORD \
+ DJANGO_AUTO_COMPLETE=1 $1 ) )
+}
+complete -F _django_completion -o default django-admin.py manage.py django-admin pasport_admin.py pasport_admin
+
+_python_django_completion()
+{
+ if [[ ${COMP_CWORD} -ge 2 ]]; then
+ PYTHON_EXE=$( basename -- ${COMP_WORDS[0]} )
+ echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1
+ if [[ $? == 0 ]]; then
+ PYTHON_SCRIPT=$( basename -- ${COMP_WORDS[1]} )
+ echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1
+ if [[ $? == 0 ]]; then
+ COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \
+ COMP_CWORD=$(( COMP_CWORD-1 )) \
+ DJANGO_AUTO_COMPLETE=1 ${COMP_WORDS[*]} ) )
+ fi
+ fi
+ fi
+}
+
+# Support for multiple interpreters.
+unset pythons
+if command -v whereis &>/dev/null; then
+ python_interpreters=$(whereis python | cut -d " " -f 2-)
+ for python in $python_interpreters; do
+ pythons="${pythons} $(basename -- $python)"
+ done
+ pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ")
+else
+ pythons=python
+fi
+
+complete -F _python_django_completion -o default $pythons
+
View
3  bh/tpls/profiles/base/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from django.utils.translation import gettext as _
View
445 bh/tpls/profiles/base/httpd.conf
@@ -0,0 +1,445 @@
+
+#
+# This is the main Apache HTTP server configuration file. It contains the
+# configuration directives that give the server its instructions.
+# See <URL:http://httpd.apache.org/docs/2.2> for detailed information.
+# In particular, see
+# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
+# for a discussion of each configuration directive.
+#
+# Do NOT simply read the instructions in here without understanding
+# what they do. They're here only as hints or reminders. If you are unsure
+# consult the online docs. You have been warned.
+#
+# Configuration and logfile names: If the filenames you specify for many
+# of the server's control files begin with "/" (or "drive:/" for Win32), the
+# server will use that explicit path. If the filenames do *not* begin
+# with "/", the value of ServerRoot is prepended -- so "var/run/logs/foo_log"
+# with ServerRoot set to "/opt/pasport_instances/training1" will be interpreted by the
+# server as "/opt/pasport_instances/training1/var/run/logs/foo_log".
+
+#
+# ServerRoot: The top of the directory tree under which the server's
+# configuration, error, and log files are kept.
+#
+# Do not add a slash at the end of the directory path. If you point
+# ServerRoot at a non-local disk, be sure to point the LockFile directive
+# at a local disk. If you wish to share the same ServerRoot for multiple
+# httpd daemons, you will need to change at least LockFile and PidFile.
+#
+ServerRoot "{{base}}"
+
+#
+# Listen: Allows you to bind Apache to specific IP addresses and/or
+# ports, instead of the default. See also the <VirtualHost>
+# directive.
+#
+# Change this to Listen on specific IP addresses as shown below to
+# prevent Apache from glomming onto all bound IP addresses.
+#
+#Listen 12.34.56.78:80
+Listen {{ http_port }}
+
+#
+# Dynamic Shared Object (DSO) Support
+#
+# To be able to use the functionality of a module which was built as a DSO you
+# have to place corresponding `LoadModule' lines at this location so the
+# directives contained in it are actually available _before_ they are used.
+# Statically compiled modules (those listed by `httpd -l') do not need
+# to be loaded here.
+#
+# Example:
+# LoadModule foo_module modules/mod_foo.so
+#
+
+<IfModule !mpm_netware_module>
+<IfModule !mpm_winnt_module>
+#
+# If you wish httpd to run as a different user or group, you must run
+# httpd as root initially and it will switch.
+#
+# User/Group: The name (or #number) of the user/group to run httpd as.
+# It is usually good practice to create a dedicated user and group for
+# running httpd, as with most system services.
+#
+User {{ admin }}
+Group {{ group }}
+
+</IfModule>
+</IfModule>
+
+# 'Main' server configuration
+#
+# The directives in this section set up the values used by the 'main'
+# server, which responds to any requests that aren't handled by a
+# <VirtualHost> definition. These values also provide defaults for
+# any <VirtualHost> containers you may define later in the file.
+#
+# All of these directives may appear inside <VirtualHost> containers,
+# in which case these default settings will be overridden for the
+# virtual host being defined.
+#
+
+#
+# ServerAdmin: Your address, where problems with the server should be
+# e-mailed. This address appears on some server-generated pages, such
+# as error documents. e.g. admin@your-domain.com
+#
+ServerAdmin you@example.com
+
+#
+# ServerName gives the name and port that the server uses to identify itself.
+# This can often be determined automatically, but we recommend you specify
+# it explicitly to prevent problems during startup.
+#
+# If your host doesn't have a registered DNS name, enter its IP address here.
+#
+#ServerName www.example.com:80
+
+#
+# DocumentRoot: The directory out of which you will serve your
+# documents. By default, all requests are taken from this directory, but
+# symbolic links and aliases may be used to point to other locations.
+#
+DocumentRoot "{{base}}/var/www/htdocs"
+
+#
+# Each directory to which Apache has access can be configured with respect
+# to which services and features are allowed and/or disabled in that
+# directory (and its subdirectories).
+#
+# First, we configure the "default" to be a very restrictive set of
+# features.
+#
+<Directory />
+ Options FollowSymLinks
+ AllowOverride None
+ Order deny,allow
+# Deny from all
+</Directory>
+
+#
+# Note that from this point forward you must specifically allow
+# particular features to be enabled - so if something's not working as
+# you might expect, make sure that you have specifically enabled it
+# below.
+#
+
+#
+# This should be changed to whatever you set DocumentRoot to.
+#
+<Directory "{{base}}/var/www/htdocs">
+ #
+ # Possible values for the Options directive are "None", "All",
+ # or any combination of:
+ # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
+ #
+ # Note that "MultiViews" must be named *explicitly* --- "Options All"
+ # doesn't give it to you.
+ #
+ # The Options directive is both complicated and important. Please see
+ # http://httpd.apache.org/docs/2.2/mod/core.html#options
+ # for more information.
+ #
+ Options Indexes FollowSymLinks
+
+ #
+ # AllowOverride controls what directives may be placed in .htaccess files.
+ # It can be "All", "None", or any combination of the keywords:
+ # Options FileInfo AuthConfig Limit
+ #
+ AllowOverride None
+
+ #
+ # Controls who can get stuff from this server.
+ #
+ Order allow,deny
+ Allow from all
+
+</Directory>
+
+#
+# DirectoryIndex: sets the file that Apache will serve if a directory
+# is requested.
+#
+<IfModule dir_module>
+ DirectoryIndex index.html
+</IfModule>
+
+#
+# The following lines prevent .htaccess and .htpasswd files from being
+# viewed by Web clients.
+#
+<FilesMatch "^\.ht">
+ Order allow,deny
+ Deny from all
+ Satisfy All
+</FilesMatch>
+
+#
+# ErrorLog: The location of the error log file.
+# If you do not specify an ErrorLog directive within a <VirtualHost>
+# container, error messages relating to that virtual host will be
+# logged here. If you *do* define an error logfile for a <VirtualHost>
+# container, that host's errors will be logged there and not here.
+#
+ErrorLog "logs/error.log"
+
+#
+# LogLevel: Control the number of messages logged to the error_log.
+# Possible values include: debug, info, notice, warn, error, crit,
+# alert, emerg.
+#
+LogLevel warn
+
+<IfModule log_config_module>
+ #
+ # The following directives define some format nicknames for use with
+ # a CustomLog directive (see below).
+ #
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
+ LogFormat "%h %l %u %t \"%r\" %>s %b" common
+
+ <IfModule logio_module>
+ # You need to enable mod_logio.c to use %I and %O
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
+ </IfModule>
+
+ #
+ # The location and format of the access logfile (Common Logfile Format).
+ # If you do not define any access logfiles within a <VirtualHost>
+ # container, they will be logged here. Contrariwise, if you *do*
+ # define per-<VirtualHost> access logfiles, transactions will be
+ # logged therein and *not* in this file.
+ #
+ # CustomLog "logs/access.log" common
+
+ #
+ # If you prefer a logfile with access, agent, and referer information
+ # (Combined Logfile Format) you can use the following directive.
+ #
+ CustomLog "logs/access.log" combined
+</IfModule>
+
+<IfModule alias_module>
+ #
+ # Redirect: Allows you to tell clients about documents that used to
+ # exist in your server's namespace, but do not anymore. The client
+ # will make a new request for the document at its new location.
+ # Example:
+ # Redirect permanent /foo http://www.example.com/bar
+
+ #
+ # Alias: Maps web paths into filesystem paths and is used to
+ # access content that does not live under the DocumentRoot.
+ # Example:
+ # Alias /webpath /full/filesystem/path
+ #
+ # If you include a trailing / on /webpath then the server will
+ # require it to be present in the URL. You will also likely
+ # need to provide a <Directory> section to allow access to
+ # the filesystem path.
+
+ #
+ # ScriptAlias: This controls which directories contain server scripts.
+ # ScriptAliases are essentially the same as Aliases, except that
+ # documents in the target directory are treated as applications and
+ # run by the server when requested rather than as documents sent to the
+ # client. The same rules about trailing "/" apply to ScriptAlias
+ # directives as to Alias.
+ #
+ ScriptAlias /cgi-bin/ "{{base}}/var/www/cgi-bin/"
+
+</IfModule>
+
+<IfModule cgid_module>
+ #
+ # ScriptSock: On threaded servers, designate the path to the UNIX
+ # socket used to communicate with the CGI daemon of mod_cgid.
+ #
+ #Scriptsock var/run/logs/cgisock
+</IfModule>
+
+#
+# "/opt/pasport_instances/training1/var/www//cgi-bin" should be changed to whatever your ScriptAliased
+# CGI directory exists, if you have that configured.
+#
+#<Directory "{{base}}/var/www/cgi-bin">
+# AllowOverride None
+# Options None
+# Order allow,deny
+# Allow from all
+#</Directory>
+
+#
+# DefaultType: the default MIME type the server will use for a document
+# if it cannot otherwise determine one, such as from filename extensions.
+# If your server contains mostly text or HTML documents, "text/plain" is
+# a good value. If most of your content is binary, such as applications
+# or images, you may want to use "application/octet-stream" instead to
+# keep browsers from trying to display binary files as though they are
+# text.
+#
+DefaultType text/plain
+
+<IfModule mime_module>
+ #
+ # TypesConfig points to the file containing the list of mappings from
+ # filename extension to MIME-type.
+ #
+ TypesConfig etc/httpd/conf/mime.types
+
+ #
+ # AddType allows you to add to or override the MIME configuration
+ # file specified in TypesConfig for specific file types.
+ #
+ #AddType application/x-gzip .tgz
+ #
+ # AddEncoding allows you to have certain browsers uncompress
+ # information on the fly. Note: Not all browsers support this.
+ #
+ #AddEncoding x-compress .Z
+ #AddEncoding x-gzip .gz .tgz
+ #
+ # If the AddEncoding directives above are commented-out, then you
+ # probably should define those extensions to indicate media types:
+ #
+ AddType application/x-compress .Z
+ AddType application/x-gzip .gz .tgz
+
+ #
+ # AddHandler allows you to map certain file extensions to "handlers":
+ # actions unrelated to filetype. These can be either built into the server
+ # or added with the Action directive (see below)
+ #
+ # To use CGI scripts outside of ScriptAliased directories:
+ # (You will also need to add "ExecCGI" to the "Options" directive.)
+ #
+ #AddHandler cgi-script .cgi
+
+ # For type maps (negotiated resources):
+ #AddHandler type-map var
+
+ #
+ # Filters allow you to process content before it is sent to the client.
+ #
+ # To parse .shtml files for server-side includes (SSI):
+ # (You will also need to add "Includes" to the "Options" directive.)
+ #
+ #AddType text/html .shtml
+ #AddOutputFilter INCLUDES .shtml
+</IfModule>
+
+#
+# The mod_mime_magic module allows the server to use various hints from the
+# contents of the file itself to determine its type. The MIMEMagicFile
+# directive tells the module where the hint definitions are located.
+#
+#MIMEMagicFile etc/httpd/conf/magic
+
+#
+# Customizable error responses come in three flavors:
+# 1) plain text 2) local redirects 3) external redirects
+#
+# Some examples:
+#ErrorDocument 500 "The server made a boo boo."
+#ErrorDocument 404 /missing.html
+#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
+#ErrorDocument 402 http://www.example.com/subscription_info.html
+#
+
+#
+# MaxRanges: Maximum number of Ranges in a request before
+# returning the entire resource, or one of the special
+# values 'default', 'none' or 'unlimited'.
+# Default setting is to accept 200 Ranges.
+#MaxRanges unlimited
+
+#
+# EnableMMAP and EnableSendfile: On systems that support it,
+# memory-mapping or the sendfile syscall is used to deliver
+# files. This usually improves server performance, but must
+# be turned off when serving from networked-mounted
+# filesystems or if support for these functions is otherwise
+# broken on your system.
+#
+#EnableMMAP off
+#EnableSendfile off
+
+# Supplemental configuration
+#
+# The configuration files in the etc/httpd/conf/extra/ directory can be
+# included to add extra features or to modify the default configuration of
+# the server, or you may simply copy their contents here and change as
+# necessary.
+
+# Server-pool management (MPM specific)
+#Include etc/httpd/conf/extra/httpd-mpm.conf
+
+# Multi-language error messages
+#Include etc/httpd/conf/extra/httpd-multilang-errordoc.conf
+
+# Fancy directory listings
+#Include etc/httpd/conf/extra/httpd-autoindex.conf
+
+# Language settings
+#Include etc/httpd/conf/extra/httpd-languages.conf
+
+# User home directories
+#Include etc/httpd/conf/extra/httpd-userdir.conf
+
+# Real-time info on requests and configuration
+#Include etc/httpd/conf/extra/httpd-info.conf
+
+# Virtual hosts
+#Include etc/httpd/conf/extra/httpd-vhosts.conf
+
+# Local access to the Apache HTTP Server Manual
+#Include etc/httpd/conf/extra/httpd-manual.conf
+
+# Distributed authoring and versioning (WebDAV)
+#Include etc/httpd/conf/extra/httpd-dav.conf
+
+# Various default settings
+#Include etc/httpd/conf/extra/httpd-default.conf
+
+# Secure (SSL/TLS) connections
+#Include etc/httpd/conf/extra/httpd-ssl.conf
+#
+# Note: The following must must be present to support
+# starting without SSL on platforms with no /dev/random equivalent
+# but a statically compiled-in mod_ssl.
+#
+<IfModule ssl_module>
+ SSLRandomSeed startup builtin
+ SSLRandomSeed connect builtin
+</IfModule>
+
+########### START PASPORT #######
+
+RewriteCond "{{base}}/var/run/MAINTENANCE" -f
+RewriteCond %{REQUEST_URI} !/static/pasportng/img/under-maintenance.gif
+RewriteRule ^(.+) /static/mainteinance [R,L]
+
+#AddModule mod_rewrite.c
+#LoadModule mod_rewrite lib/apache/mod_rewrite.so
+
+<IfModule !wsgi_module>
+ LoadModule wsgi_module lib/apache/mod_wsgi.so
+</IfModule>
+
+ <Location /static>
+ Order deny,allow
+ Allow from all
+ </Location>
+
+Alias /static/ {{base}}/var/www/static/
+
+WSGIProcessGroup pasport
+WSGIDaemonProcess pasport user={{admin}} group=pasport home={{base}} processes=2 threads=10 maximum-requests=1000 umask=0007
+WSGIScriptAlias / {{base}}/etc/httpd/conf/pasport_wsgi.py
+
+
+
+
View
123 bh/tpls/profiles/base/logging_conf.py
@@ -0,0 +1,123 @@
+
+import os
+
+file_handler = lambda name, level: {'level': level, 'class': 'logging.handlers.RotatingFileHandler', 'formatter': 'verbose',
+ 'filename': os.path.join(os.environ['PASPORT_LOGDIR'], '%s.log' % name),
+ }
+"""
+pendig_records
+contracts
+tracer.pasport.contract
+"""
+
+LOGGING = {
+ 'version': 1,
+ 'disable_existing_loggers': False,
+ 'formatters': {
+ 'full': {
+ 'format': '%(levelname)-8s: %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
+ },
+ 'verbose': {
+ 'format': '%(levelname)-8s: %(asctime)s %(name)20s %(message)s'
+ },
+ 'simple': {
+ 'format': '%(levelname)-8s %(asctime)s %(name)20s %(funcName)s %(message)s'
+ }
+ },
+ 'filters': {
+ 'require_debug_false': {
+ '()': 'django.utils.log.RequireDebugFalse'
+ }
+ },
+ 'handlers': {
+ 'null': {
+ 'level': 'DEBUG',
+ 'class': 'django.utils.log.NullHandler'
+ },
+ 'error': file_handler('errors', 'DEBUG'),
+ 'security': file_handler('security', 'DEBUG'),
+ 'interface': file_handler('interface', 'DEBUG'),
+ 'root': file_handler('messages', 'DEBUG'),
+ 'payroll': file_handler('payroll', 'DEBUG'),
+ 'pendig_records': file_handler('pendig_records', 'DEBUG'),
+ 'console': {
+ 'level': 'DEBUG',
+ 'class': 'logging.StreamHandler',
+ 'formatter': 'simple'
+ },
+ 'mail_admins': {
+ 'level': 'ERROR',
+ 'filters': ['require_debug_false'],
+ 'class': 'django.utils.log.AdminEmailHandler',
+ 'include_html': True
+ }
+ },
+ 'loggers': {
+ '': {
+ 'handlers': ['root', ],
+ 'propagate': True,
+ 'level': 'DEBUG'
+ },
+ 'tracer.': {
+ 'handlers': ['root'],
+ 'propagate': False,
+ 'level': 'DEBUG'
+ },
+ 'kiowa.models': {'handlers': ['root'], 'propagate': False, 'level': 'CRITICAL'},
+ 'commands.*': {'handlers': ['root'], 'propagate': False, 'level': 'CRITICAL'},
+ 'sessions.models': {
+ 'handlers': ['null'],
+ 'propagate': False,
+ 'level': 'DEBUG'
+ },
+ 'django': {
+ 'handlers': ['console'],
+ 'propagate': True,
+ 'level': 'DEBUG'
+ },
+ 'error': {
+ 'handlers': ['console'],
+ 'level': 'ERROR',
+ 'propagate': True
+ },
+ 'security_risk': {
+ 'handlers': ['mail_admins'],
+ 'level': 'DEBUG',
+ 'propagate': True
+ },
+ 'security': {
+ 'handlers': ['mail_admins'],
+ 'level': 'DEBUG',
+ 'propagate': True
+ },
+ 'django.request': {
+ 'handlers': ['mail_admins'],
+ 'level': 'ERROR',
+ 'propagate': True
+ },
+ 'django.db.backends': {
+ 'handlers': ['null'],
+ 'level': 'DEBUG',
+ 'propagate': False
+ },
+ 'root': {
+ 'handlers': ['root', 'console'],
+ 'level': 'DEBUG',
+ 'propagate': True
+ },
+ 'interface': {
+ 'handlers': ['interface'],
+ 'level': 'ERROR',
+ 'propagate': True
+ },
+ 'payroll': {
+ 'handlers': ['payroll'],
+ 'level': 'ERROR',
+ 'propagate': True
+ }
+ }
+}
+
+LOGGING_DEBUG = {'version': 1,
+ 'disable_existing_loggers': True,
+ }
View
53 bh/tpls/profiles/base/settings_local.py
@@ -0,0 +1,53 @@
+#{% block content %}
+from pasportng.ng.settings import *
+#{% block header %}#{% endblock header %}
+
+#{% block debug %}
+DEBUG = TEMPLATE_DEBUG = True
+#{% endblock debug %}
+
+MAINTENANCE_FILE="{{base}}/var/run/MAINTENANCE"
+
+#{% block email %}
+# Email config
+EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
+EMAIL_HOST = '10.11.32.71'
+EMAIL_PORT = '25'
+EMAIL_NOTIFY_CONTRACT_EMPLOYEE = False # if true updtaes to contract will be nofied to the contract's owner too
+EMAIL_SUBJECT_PREFIX = '[Pasport] Base'
+EMAIL_FAKE_RECIPIENTS= DEBUG_EMAIL_TO = [ "Praphatsorn.Lertkotchakorn@wfp.org", "isariyaporn.banlusilp@wfp.org",]
+#{% endblock email %}
+
+STATIC_ROOT="{{base}}/var/www/static"
+MEDIA_ROOT="{{base}}/var/www/media"
+
+#{% block database %}
+DATABASES = {
+ 'default': {
+ 'NAME': '{{base}}/var/PASPORT.db',
+ 'ENGINE': 'django.db.backends.sqlite3', # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'USER': '',
+ 'PASSWORD': '',
+ },
+ 'interface': {
+ 'NAME': '{{base}}/var/INTERFACE.db',
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'USER': '',
+ 'PASSWORD': '',
+ }
+}
+#{% endblock database %}
+
+PASPORT_LOGDIR = "{{base}}/logs/pasport"
+try:
+ from django.utils.dictconfig import dictConfig
+ os.environ['PASPORT_LOGDIR'] = PASPORT_LOGDIR
+ from logging_conf import LOGGING
+ dictConfig(LOGGING)
+except ValueError:
+ pass
+
+#{% endblock content %}
+
+#{% block footer %}
+#{% endblock footer %}
View
12 bh/tpls/profiles/base/uwsgi.ini
@@ -0,0 +1,12 @@
+
+[uwsgi]
+# set the http port
+http = :%(uwsgi_port)s
+# change to django project directory
+chdir = /var/www/myapp
+# add /var/www to the pythonpath, in this way we can use the project.app format
+pythonpath = /var/www
+# set the project settings name
+env = DJANGO_SETTINGS_MODULE=myapp.settings
+# load django
+module = django.core.handlers.wsgi:WSGIHandler()
View
16 bh/tpls/profiles/base/wsgi.py
@@ -0,0 +1,16 @@
+
+import os
+import sys
+sys.path.insert(0, '{{base}}/etc')
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pasport_settings")
+
+# This application object is used by any WSGI server configured to use this
+# file. This includes Django's development server, if the WSGI_APPLICATION
+# setting points here.
+from django.core.wsgi import get_wsgi_application
+application = get_wsgi_application()
+
+# Apply WSGI middleware here.
+# from helloworld.wsgi import HelloWorldApplication
+# application = HelloWorldApplication(application)
View
21 bh/tpls/sbin/all_env_command.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+BASE={{ PREFIX }}
+comand=$1
+
+if [ -z "$1" ];then
+ echo "please specify a valid django command"
+ exit 1
+fi
+
+for dir in `ls $BASE`;do
+ if [ -e $BASE/$dir/bin/activate ]; then
+ TARGET=$BASE/$dir/
+ OWNER=`stat -c %U $TARGET`
+ cd $TARGET
+ . $TARGET/bin/activate
+ echo "Running $1 on $TARGET"
+ su - $OWNER -c $BASE/$dir/bin/python $TARGET/bin/pasport_admin.py wings2pasport
+ deactivate
+ fi
+
+done
View
21 bh/tpls/sbin/all_env_shell.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+BASE={{ PREFIX }}
+comand=$1
+
+if [ -z "$1" ];then
+ echo "please specify a valid django command"
+ exit 1
+fi
+
+for dir in `ls $BASE`;do
+ if [ -e $BASE/$dir/bin/activate ]; then
+ TARGET=$BASE/$dir/
+ OWNER=`stat -c %U $TARGET`
+ cd $TARGET
+ . $TARGET/bin/activate
+ echo "Running $1 on $TARGET"
+ su - $OWNER -c $BASE/$dir/bin/python $TARGET/bin/pasport_admin.py $1
+ deactivate
+ fi
+
+done
View
30 bh/tpls/sbin/cronhandler.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+if [ -z "$1" ];then
+ echo "please specify a valid django command"
+ exit 1
+fi
+COMMAND=$1
+
+TARGET="/opt/pasport_instances/pasport"
+OWNER=`stat -c %U $TARGET/bin`
+ADMIN_HOME=`su - $OWNER -c "echo ~"`
+
+if [ -e $ADMIN_HOME/bin/activate ]; then
+
+ . $ADMIN_HOME/bin/activate
+ echo "Running '$COMMAND' on $ADMIN_HOME as $OWNER"
+ echo "su - $OWNER -c $ADMIN_HOME/bin/python $ADMIN_HOME/bin/pasport_admin.py $COMMAND"
+ su - $OWNER -c "$ADMIN_HOME/bin/python $ADMIN_HOME/bin/pasport_admin.py $COMMAND"
+ deactivate
+fi
+
+mkdir -p $HOME/var/projects
+mkdir -p $HOME/opt
+mkdir -p $HOME/var/VENV
+sudo apt-get install python-setuptools
+sudo apt-get install python-virtualenv
+sudo easy_install pip
+sudo pip install virtualenvwrapper
+
+
View
40 bh/user.py
@@ -0,0 +1,40 @@
+from fabric.api import *
+from fabfile import _upload_template
+from fabfile import setup_env_for_user
+
+@task
+def init_home_env(base_port):
+ """ initalize remote admin home directory
+ """
+ setup_env_for_user()
+ env.http_port = base_port
+ run('mkdir -p ~/{bin,etc,var/run,var/www/media,var/www/static,logs/pasport,tmp,/etc/httpd/conf}')
+
+ _upload_template("bashrc", "%(base)s/.bashrc")
+ _upload_template("bash_profile", "%(base)s/.bash_profile")
+ _upload_template("django_bash_completion", "%(base)s/.django_bash_completion")
+ _upload_template("httpd.conf", "%(base)s/etc/httpd/conf/httpd.conf")
+ bin_utils(env.http_port)
+
+
+#@task
+#def reset_home_env():
+# setup_env_for_user()
+# old_port = run('echo $HTTP_LISTEN_PORT')
+# run('rm -fr ~/*')
+# init_home_env(old_port)
+
+
+@task(alias='bin')
+def bin_utils(port=None):
+ """copy user utilities to $HOME/bin directory"""
+
+ if port is None:
+ setup_env_for_user()
+ env.http_port = run('echo $HTTP_LISTEN_PORT')
+ _upload_template("bin/activate", "%(base)s/bin/activate")
+
+ run('chmod +x %(base)s/bin/*.*' % env)
+
+
+
View
64 bh/utils.py
@@ -0,0 +1,64 @@
+import json
+from fabric.api import *
+import os
+from fabric.contrib.files import exists, upload_template
+get_home_dir = lambda username: os.path.join(env.PREFIX, username)
+
+def load_password(filename='~/.credentials.json'):
+ try:
+ env.passwords = json.load(open(os.path.expanduser(filename), 'r'))
+ except IOError:
+ pass
+
+def init():
+ env.packages_cache = "%s/packages_cache" % env.PREFIX
+ env.pip_cache = "%s/pip_download_cache" % env.PREFIX
+
+def usudo(command, shell=True, pty=True, combine_stderr=None, user=None):
+ user = user or env.admin
+ return sudo(command, shell, pty, combine_stderr, user)
+
+
+def _bool(value, default):
+ if value in (None, ''):
+ return default
+ if value in ('0', 'false', 'False', 'F', 'no', False, 0):
+ return False
+ elif value in ('1', 'true', 'True', 'T', 'yes', True, 1):
+ return True
+ else:
+ return bool(value)
+
+def _upload_template( name, dest, **kwargs ):
+ upload_template(name % env, dest % env, env, use_jinja=True, template_dir=env.template_dir, **kwargs)
+
+
+def setup_env_for_user(admin=None):
+ """ setup enviroment for the selected admin.
+ Must be called before each task.
+ """
+ admin = admin or env.user
+ assert admin != 'root', "Cannot use root for this task"
+ env.admin = admin
+ env.admin_home_dir = get_home_dir(env.admin)
+ env.base = env.admin_home_dir
+ env.build = os.path.join(env.base, '~build')
+
+@task
+def help():
+ """
+ Steps to work with PASport console.
+
+ PASport console is a set of scripts to install/update and manage multiple pasport installation.
+
+ How to install in a new fresh system.
+
+ $ fab -H root@targetsystem root.init_host root.create_user:admin,password
+ $ fab -H admin@targetsystem user.init_home_env
+ $ fab -H admin@targetsystem system.install
+ $ fab -H admin@targetsystem pasport.configure:profile
+ $ fab -H admin@targetsystem pasport.install:version
+
+ """
+ print help.__doc__
+
View
56 setup.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+from distutils.core import setup
+from distutils.command.install import INSTALL_SCHEMES
+import os
+import bh as app
+
+VERSION = RELEASE = app.get_version()
+NAME = app.NAME
+
+
+for scheme in INSTALL_SCHEMES.values():
+ scheme['data'] = scheme['purelib']
+
+def fullsplit(path, result=None):
+ """
+ Split a pathname into components (the opposite of os.path.join) in a
+ platform-neutral way.
+ """
+ if result is None:
+ result = []
+ head, tail = os.path.split(path)
+ if head == '':
+ return [tail] + result
+ if head == path:
+ return result
+ return fullsplit(head, [tail] + result)
+
+
+def scan_dir( target, _packages=None, _data_files=None):
+ packages = _packages or []
+ data_files = _data_files or []
+ for dir_path, dir_names, file_names in os.walk(target):
+ # Ignore dir_names that start with '.'
+ for i, dir_name in enumerate(dir_names):
+ if dir_name.startswith('.'): del dir_names[i]
+ if '__init__.py' in file_names:
+ packages.append('.'.join(fullsplit(dir_path)))
+ elif file_names:
+ data_files.append([dir_path, [os.path.join(dir_path, f) for f in file_names]])
+ return packages, data_files
+
+packages, data_files = scan_dir('bh')
+
+setup(
+ name=NAME,
+ version=RELEASE,
+ url='https://github.com/saxix/django-buildhost',
+ author='sax',
+ author_email='sax@os4d.org',
+ license='BSD',
+ packages=packages,
+ data_files=data_files,
+ platforms=['any'],
+ classifiers=[],
+ long_description=open('README').read()
+)
Please sign in to comment.
Something went wrong with that request. Please try again.