Example #1
0
def packages(pkg_list, pip_cmd='pip', python_cmd='python',
             allow_external=None, allow_unverified=None, **kwargs):
    """
    Require several Python packages.

    Package names are case insensitive.

    Starting with version 1.5, pip no longer scrapes insecure external
    urls by default and no longer installs externally hosted files by
    default. Use ``allow_external=['foo', 'bar']`` or
    ``allow_unverified=['bar', 'baz']`` to change these behaviours
    for specific packages.
    """
    if allow_external is None:
        allow_external = []

    if allow_unverified is None:
        allow_unverified = []

    pip(MIN_PIP_VERSION, python_cmd=python_cmd)

    pkg_list = [pkg for pkg in pkg_list if not is_installed(pkg, pip_cmd=pip_cmd)]
    if pkg_list:
        install(pkg_list,
                pip_cmd=pip_cmd,
                allow_external=allow_external,
                allow_unverified=allow_unverified,
                **kwargs)
Example #2
0
def packages(pkg_list,
             pip_cmd='pip',
             python_cmd='python',
             allow_external=None,
             allow_unverified=None,
             **kwargs):
    """
    Require several Python packages.

    Package names are case insensitive.

    Starting with version 1.5, pip no longer scrapes insecure external
    urls by default and no longer installs externally hosted files by
    default. Use ``allow_external=['foo', 'bar']`` or
    ``allow_unverified=['bar', 'baz']`` to change these behaviours
    for specific packages.
    """
    if allow_external is None:
        allow_external = []

    if allow_unverified is None:
        allow_unverified = []

    pip(MIN_PIP_VERSION, python_cmd=python_cmd)

    pkg_list = [
        pkg for pkg in pkg_list if not is_installed(pkg, pip_cmd=pip_cmd)
    ]
    if pkg_list:
        install(pkg_list,
                pip_cmd=pip_cmd,
                allow_external=allow_external,
                allow_unverified=allow_unverified,
                **kwargs)
Example #3
0
def package(pkg_name, url=None, pip_cmd='pip', python_cmd='python', **kwargs):
    """
    Require a Python package.

    If the package is not installed, it will be installed
    using the `pip installer`_.

    Package names are case insensitive.

    ::

        from fabtools.python import virtualenv
        from fabtools import require

        # Install package system-wide
        require.python.package('foo', use_sudo=True)

        # Install package in an existing virtual environment
        with virtualenv('/path/to/venv'):
            require.python.package('bar')

    .. _pip installer: http://www.pip-installer.org/
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    if not is_installed(pkg_name, pip_cmd=pip_cmd):
        install(url or pkg_name, pip_cmd=pip_cmd, **kwargs)
Example #4
0
def package(pkg_name, url=None, pip_cmd='pip', python_cmd='python', **kwargs):
    """
    Require a Python package.

    If the package is not installed, it will be installed
    using the `pip installer`_.

    Package names are case insensitive.

    ::

        from fabtools.python import virtualenv
        from fabtools import require

        # Install package system-wide
        require.python.package('foo', use_sudo=True)

        # Install package in an existing virtual environment
        with virtualenv('/path/to/venv'):
            require.python.package('bar')

    .. _pip installer: http://www.pip-installer.org/
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    if not is_installed(pkg_name, pip_cmd=pip_cmd):
        install(url or pkg_name, pip_cmd=pip_cmd, **kwargs)
Example #5
0
def packages(pkg_list, **kwargs):
    """
    Require several Python packages.
    """
    pip(DEFAULT_PIP_VERSION)
    pkg_list = [pkg for pkg in pkg_list if not is_installed(pkg)]
    if pkg_list:
        install(pkg_list, **kwargs)
Example #6
0
def packages(pkg_list, **kwargs):
    """
    Require several Python packages.
    """
    pip(DEFAULT_PIP_VERSION)
    pkg_list = [pkg for pkg in pkg_list if not is_installed(pkg)]
    if pkg_list:
        install(pkg_list, **kwargs)
Example #7
0
def packages(pkg_list, pip_cmd='pip', python_cmd='python', **kwargs):
    """
    Require several Python packages.

    Package names are case insensitive.
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    pkg_list = [pkg for pkg in pkg_list if not is_installed(pkg, pip_cmd=pip_cmd)]
    if pkg_list:
        install(pkg_list, pip_cmd=pip_cmd, **kwargs)
Example #8
0
def packages(pkg_list, pip_cmd='pip', python_cmd='python', **kwargs):
    """
    Require several Python packages.

    Package names are case insensitive.
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    pkg_list = [
        pkg for pkg in pkg_list if not is_installed(pkg, pip_cmd=pip_cmd)
    ]
    if pkg_list:
        install(pkg_list, pip_cmd=pip_cmd, **kwargs)
Example #9
0
def install_useful_packages():
    pip_pkg_list = '''
        Sphinx mercurial virtualenv virtualenvwrapper pytest nose
        monitoring see ipython bpython
    '''.split()
    require.python.packages(pip_pkg_list, use_sudo=True)

    distribute_pkg_list = '''
    '''.split()
    distribute_pkg_list = [pkg for pkg in distribute_pkg_list
                           if not python.is_installed(pkg)]
    if distribute_pkg_list:
        python_distribute.install(distribute_pkg_list, use_sudo=True)
Example #10
0
def setup(existing_server=False, database_password=None, https=False):
	env.database_password = database_password or generate_password()

	with cd(env.project_root):
		if not files.exists(env.code_root):
			run('git clone %s %s' % (env.source_repo, env.project_name))

		with cd(env.code_root):
			if not existing_server: install_system_deps()

			if not existing_server:
				run('wget --no-check-certificate https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz', quiet=True)
				run('tar zxvf Python-2.7.6.tgz', quiet=True)
				with cd('Python-2.7.6'):
					run('CFLAGS=-fPIC ./configure --enable-shared && make -j2', quiet=True)
					sudo('make altinstall', quiet=True)

			if not python.is_installed('virtualenv'):
				sudo('pip install virtualenv')
			run('virtualenv -p python2.7 %s' % env.virtualenv_path)

			with prefix(env.virtualenv):
				with shell_env(PATH='$PATH:/usr/pgsql-9.2/bin/'):
					run('pip install -r requirements.txt')

				if existing_server:
					if env.database_password != database_password: # need to change the password
						sudo('psql -U postgres -c "alter user kandu with password \'%s\';"' % env.database_password)
				else:
					run('psql -U postgres -c "CREATE ROLE kandu WITH PASSWORD \'%s\' NOSUPERUSER CREATEDB NOCREATEROLE LOGIN;"' % database_password)
					run('psql -U postgres -c "CREATE DATABASE %s WITH OWNER=kandu TEMPLATE=template0 ENCODING=\'utf-8\';"' % env.project_name)
					run('psql %s -U postgres -c "CREATE EXTENSION postgis;"' % env.project_name)
					run('psql %s -U postgres -c "CREATE EXTENSION postgis_topology;"' % env.project_name)

				files.upload_template('.env.dist', '.env', {'env': env}, use_jinja=True)

				run('python manage.py syncdb --migrate --noinput')
				run('python manage.py collectstatic --noinput')

				if not existing_server:
					run('echo "from django.contrib.auth.models import User; User.objects.create_superuser(\'%s\', \'[email protected]\', \'%s\')" | python manage.py shell' % (env.user, database_password))

			run('chmod 0755 -R %s' % env.project_root, warn_only=True)
			run('mkdir -p %s/%s-media' % (env.project_root, env.project_name))

			configure_apache(existing_server, https)
			sudo('service httpd restart')

			if not existing_server:
				print 'Deployment to %s is done.\nDjango superuser has\n\tusername: %s\n\tpassword: %s' % (env.host, env.user, database_password)
Example #11
0
def sphinx():
    # they are not available in older releases
    require_deb_packages(
        '''
                    python-blockdiag
                    python-seqdiag
                    python-sphinxcontrib.blockdiag
                    python-sphinxcontrib.seqdiag
                    python-tablib
                    ''', error_if_not_exists=False
    )

    require_deb_packages(
        '''
gtkwave
mercurial
python-sphinx
scrot
texlive-fonts-recommended
texlive-latex-extra
                    '''
    )

    require_python_packages(
        '''
PyVirtualDisplay
pyscreenshot

sphinxcontrib-programoutput
sphinxcontrib-programscreenshot
sphinxcontrib-gtkwave
sphinxcontrib-eagle
eagexp
discogui
PyMouse
                    ''')

    # sphinx-contrib
    if not is_installed('autorun'):
        if is_dir('/tmp/sphinx-contrib'):
            run('rm -rf /tmp/sphinx-contrib')
        with cd('/tmp'):
            run('hg clone https://bitbucket.org/birkenfeld/sphinx-contrib')
        install('/tmp/sphinx-contrib/autorun', use_sudo=True)
Example #12
0
def package(pkg_name,
            url=None,
            pip_cmd='pip',
            python_cmd='python',
            allow_external=False,
            allow_unverified=False,
            **kwargs):
    """
    Require a Python package.

    If the package is not installed, it will be installed
    using the `pip installer`_.

    Package names are case insensitive.

    Starting with version 1.5, pip no longer scrapes insecure external
    urls by default and no longer installs externally hosted files by
    default. Use ``allow_external=True`` or ``allow_unverified=True``
    to change these behaviours.

    ::

        from fabtools.python import virtualenv
        from fabtools import require

        # Install package system-wide (not recommended)
        require.python.package('foo', use_sudo=True)

        # Install package in an existing virtual environment
        with virtualenv('/path/to/venv'):
            require.python.package('bar')

    .. _pip installer: http://www.pip-installer.org/
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    if not is_installed(pkg_name, python_cmd=python_cmd, pip_cmd=pip_cmd):
        install(url or pkg_name,
                python_cmd=python_cmd,
                pip_cmd=pip_cmd,
                allow_external=[url or pkg_name] if allow_external else [],
                allow_unverified=[url or pkg_name] if allow_unverified else [],
                **kwargs)
Example #13
0
def setupsupervisor():
    """
    Setup supervisor on remote host.
    """
    if not is_installed("supervisor"):
        puts(green("Installing supervisor."))
        sudo("pip install supervisor")
    if not exists("supervisor"):
        puts(green("Creating supervisor user"))
        create("supervisor", comment="supervisord user", system=True)
    supervisor_context = {"logpath": "/var/log/supervisord.log"}
    puts(green("Uploading supervisord.conf"))
    upload_template("templates/supervisord.conf", "/etc/supervisord.conf", \
    context=supervisor_context, mode=0700, use_sudo=True)
    texts = ["[include]", "files=/etc/supervisor.d/*.conf"]
    for text in texts:
        if not contains("/etc/supervisord.conf", text, use_sudo=True):
            append("/etc/supervisord.conf", text, use_sudo=True)
    with cd("/etc"):
        if not is_dir("supervisor.d"):
            puts(green("Making supervisor.d configuration directory"))
            sudo("mkdir supervisor.d")
        sudo("chown supervisor:root -R supervisor.d")
        sudo("chown supervisor:root supervisord.conf")
        with cd("init.d"):
            if not is_file("supervisord"):
                puts(green("Uploading supervisord startup script"))
                put(local_path="files/supervisord", remote_path="/etc/init.d/supervisord", \
                mode=0700, use_sudo=True)
            sudo("chown supervisor:root supervisord")
        puts(green("Starting supervisord service"))
        sudo("chkconfig --add supervisord")
        sudo("chkconfig --level 3 supervisord on")
        sudo("service supervisord start")
    with cd("/var/log"):
        if not is_file("supervisord.log"):
            puts(green("Creating supervisor log file"))
            sudo(
                "touch supervisord.log && chown supervisor:root supervisord.log"
            )
Example #14
0
def package(pkg_name, url=None, pip_cmd='pip', python_cmd='python',
            allow_external=False, allow_unverified=False, trusted_hosts=None,
            **kwargs):
    """
    Require a Python package.

    If the package is not installed, it will be installed
    using the `pip installer`_.

    Package names are case insensitive.

    Starting with version 1.5, pip no longer scrapes insecure external
    urls by default and no longer installs externally hosted files by
    default. Use ``allow_external=True`` or ``allow_unverified=True``
    to change these behaviours.

    ::

        from fabtools.python import virtualenv
        from fabtools import require

        # Install package system-wide (not recommended)
        require.python.package('foo', use_sudo=True)

        # Install package in an existing virtual environment
        with virtualenv('/path/to/venv'):
            require.python.package('bar')

    .. _pip installer: http://www.pip-installer.org/
    """
    pip(MIN_PIP_VERSION, python_cmd=python_cmd)
    if not is_installed(pkg_name, pip_cmd=pip_cmd):
        install(url or pkg_name,
                pip_cmd=pip_cmd,
                allow_external=[url or pkg_name] if allow_external else [],
                allow_unverified=[url or pkg_name] if allow_unverified else [],
                trusted_hosts=trusted_hosts,
                **kwargs)