def _get_latest_source(source_folder): """ Updates files on staging server with current git commit on dev branch. """ if env.exists(source_folder + '/.git'): env.run('cd {source_folder} && git fetch'.format(source_folder=source_folder,)) else: env.run('git clone {github_url} {source_folder}'.format(github_url=REPO_URL, source_folder=source_folder)) current_commit = local('git log -n 1 --format=%H', capture=True)
def _create_directory_structure_if_necessary(folders): """ Ensure basic file structure in project. """ site_folder = folders['site'] if not env.exists(site_folder): # base deployment folder env.run('mkdir -p {site_folder}'.format(site_folder=site_folder,)) # set linux user group. env.run('chown :{group} {site_folder}'.format(group=LINUXGROUP, site_folder=site_folder)) # set folder priveleges - 6*** means group and user sticky bits are set, and subfolders and files. # will inherit parent folder's group and user. # 770 means read, write and execute for folder is enabled for owner and group. env.run('chmod 6770 {site_folder}'.format(site_folder=site_folder,)) # Make folders for static files, virtual environment and so on. # -p flag means that folder is only created if it doesn't exist, # and parent directories are also created if needed. env.run('mkdir -p {folder_paths}'.format(folder_paths=' '.join(folders.values())))
def _create_virtualenv(venv_folder, global_venv_folder): """ Create python virtual environment. """ if not env.exists(venv_folder + '/bin/pip'): env.run('{python_venv_version} {venv_folder}'.format(python_venv_version=PYVENV, venv_folder=venv_folder,)) # link to global folder to enable virtualenvwrapper 'workon' command. env.run('ln -fs {venv_folder} {venvs}'.format(venv_folder=venv_folder, venvs=global_venv_folder))