Exemplo n.º 1
0
def install_mods():
	"""install needed python modules using pip"""

	require('host', provided_by=('staging', 'production'))
	require('home', provided_by=('staging', 'production'))
	require('project_name', provided_by=('develpment', 'staging', 'production'))

	virtual_env_bin = _get_venv_bin(env)
	pip = os.path.join(virtual_env_bin, 'pip')
	pip_cmd = None

	with cd(env.home):
		# Check if we need to install any modules
		if os.path.exists('etc/pip.conf'):
			# Setup the pip build command
			pip_cmd = '%s install -q -r %s --log=%s' % (
				pip,
				os.path.join(env.home, env.project_name, 'etc/pip.conf'),
				os.path.join(env.home, 'logs', 'pip.log')
			)

		if os.path.exists('requirements.txt'):
			pip_cmd = '%s install -q -r %s --log=%s' % (
				pip,
				os.path.join(env.home, env.project_name, 'requirements.txt'),
				os.path.join(env.home, 'logs', 'pip.log')
			)

	if pip_cmd is not None:
		# Install the required modules
		sudo(pip_cmd, user=env.project_user)
		print green('PIP install ran.')
	else:
		print yellow('Could not run pip!')
Exemplo n.º 2
0
def manage(cmd, *args, **kwargs):
	"""run a management command"""

	require('home', provided_by=('development', 'staging', 'production'))
	require('project_name', provided_by=('development', 'staging', 'production'))
	require('project_user', provided_by=('development', 'staging', 'production'))

	virtual_env_bin = _get_venv_bin(env)
	py = os.path.join(virtual_env_bin, 'python')

	with cd(env.home):
		manage_cmd = '%s %s %s' % (
			py,
			os.path.join(env.home, env.project_name, 'manage.py'),
			cmd
		)

		if args:
			manage_cmd += ' %s' % ' '.join(args)

		if kwargs:
			manage_cmd += ' %s' % ' '.join(['--%s=%s' % (k, v) for k, v in kwargs.items()])

		sudo(manage_cmd, user=env.project_user)

	print green('Manage command ran.')
Exemplo n.º 3
0
def bootstrap(repo_pull_protocol='ssh'):
	"""bootstrap the project"""

	require('home', provided_by=('development', 'staging', 'production'))
	require('project_name', provided_by=('development', 'staging', 'production'))
	require('project_repo', provided_by=('development', 'staging', 'production'))
	require('project_url', provided_by=('development', 'staging', 'production'))
	require('project_user', provided_by=('development', 'staging', 'production'))

	virtual_env_bin = _get_venv_bin(env)
	pip = os.path.join(virtual_env_bin, 'pip')

	with cd(env.home):
		# Pull the repo

		# Default to HG if a protocol isn't specified, otherwise try to match protocol
		if env.project_repo.startswith('hg://') or env.project_repo.startswith('ssh://'):
			real_repo_path = env.project_repo.replace('hg://', '%s://' % repo_pull_protocol)
			sudo('hg clone %s %s' % (real_repo_path, env.project_name), user=env.project_user)

		elif env.project_repo.startswith('git://'):
			real_repo_path = env.project_repo.replace('git://', '')
			sudo('git clone %s %s' % (real_repo_path, env.project_name), user=env.project_user)

		else:
			print red('Unknown repository protocol!')
			return

		pip_cmd = None

		# Check if we need to install any modules
		if os.path.exists('etc/pip.conf'):
			# Setup the pip build command
			pip_cmd = '%s install -q -r %s --log=%s' % (
				pip,
				os.path.join(env.home, env.project_name, 'etc/pip.conf'),
				os.path.join(env.home, 'logs', 'pip.log')
			)

		if os.path.exists('requirements.txt'):
			pip_cmd = '%s install -q -r %s --log=%s' % (
				pip,
				os.path.join(env.home, env.project_name, 'requirements.txt'),
				os.path.join(env.home, 'logs', 'pip.log')
			)

		if pip_cmd is not None:
			# Install the required modules
			sudo(pip_cmd, user=env.project_user)

		else:
			print yellow('No pip installation!')

		if os.path.exists('etc/nginx.conf'):
			# Link the configs
			sudo('ln -s %s /etc/nginx/sites-enabled/%s' % (
				os.path.join(env.home, env.project_name, 'etc/nginx.conf'),
				env.project_url
			))
		else:
			# Link the configs
			sudo('ln -s %s /etc/nginx/sites-enabled/%s' % (
				os.path.join(env.home, env.project_name, 'etc/nginx.%s.conf' % env.environment),
				env.project_url
			))

		if os.path.exists('etc/upstart.conf'):
			sudo('cp %s /etc/init/%s.conf' % (
				os.path.join(env.home, env.project_name, 'etc/upstart.conf'),
				env.project_name
			))
		else:
			if os.path.exists('etc/upstart.%s.conf' % env.environment):
				sudo('cp %s /etc/init/%s.conf' % (
					os.path.join(env.home, env.project_name, 'etc/upstart.%s.conf' % env.environment),
					env.project_name
				))
			else:
				print yellow('No Upstart file added!')

	print green('Environment is setup.')