<commit_before>---
# Installs and configures a uWSGI python app in a virtualenv

# Make sure that pip and virtualenv are installed.
- apt: name=python-pip state=present update_cache=yes cache_valid_time=3600

# Make sure that virtualenv is installed
- pip: name=virtualenv state=present

# Install system packages
- apt: name={{item}} state=present
  with_items: system_packages

# Make sure that the www directory exists
- file: path=/www/ state=directory mode=750 owner=www-data group=www-data

# Create the user (if necessary)
- user: name={{ appuser }} shell=/bin/bash createhome=yes group=www-data
  when: appuser == "www-data"

# Create the app user (if necessary)
- user: name={{ app_name }} shell=/bin/bash createhome=yes group=www-data

# Make sure that the source directory exists
- file: path={{ source_dir }} state=directory mode=770 owner={{ appuser }} group=www-data

# Set the authorized_keys
- authorized_key: user={{ appuser }} key="{{ item }}"
  with_items: authorized_keys

- name: make sure .ssh folder exists for app
  file: path=/home/{{ app_name }}/.ssh mode=700 state=directory owner={{ app_name }}

- authorized_key: user={{ app_name }} key="{{ item }}"
  with_items: authorized_keys

# Make sure that the virtual env directory exists
- file: path={{ virtualenv_dir }} state=directory owner={{ appuser }} group=www-data

# Make sure that the virtualenv is created
- command: virtualenv {{ virtualenv_dir }} creates={{ virtualenv_dir }}/bin/activate
  sudo_user: "{{ appuser }}"

- name: adding venv source to .profile 
  lineinfile: dest=/home/{{ app_name }}/.profile mode=700 owner={{ app_name }} regexp='source .*/bin/activate' line='cd {{ source_dir }} && source /var/venvs/{{ app_name }}/bin/activate'

- name: adding DJANGO_SETTINGS_MODULE to .profile
  lineinfile: dest=/home/{{ app_name }}/.profile mode=700 owner={{ app_name }} regexp='DJANGO_SETTINGS_MODULE=*' line='export {{ env_vars[0] }}'

# Install python packages
- pip: name={{ item }} state=present virtualenv={{ virtualenv_dir }} chdir={{ source_dir }}
  with_items: python_packages
  when: python_requirements == None

# Install python packages
- pip: requirements="{{python_requirements}}" state=present virtualenv={{ virtualenv_dir }} chdir={{ source_dir }}
  when: python_requirements != None

# Create virtualenv directory
- file: path={{ virtualenv_dir }} state=directory owner={{ appuser }} group=www-data recurse=yes

# Create a uwsgi configuration file
- template: src=uwsgi.ini.j2 dest=/etc/uwsgi-emperor/vassals/{{ app_name }}.ini owner={{ appuser }} group=www-data
  when: app_enabled

# Make sure that uWSGI is started
- service: name=uwsgi-emperor state=started<commit_msg>su magic<commit_after>---
# Installs and configures a uWSGI python app in a virtualenv

# Make sure that pip and virtualenv are installed.
- apt: name=python-pip state=present update_cache=yes cache_valid_time=3600

# Make sure that virtualenv is installed
- pip: name=virtualenv state=present

# Install system packages
- apt: name={{item}} state=present
  with_items: system_packages

# Make sure that the www directory exists
- file: path=/www/ state=directory mode=750 owner=www-data group=www-data

# Create the user (if necessary)
- user: name={{ appuser }} shell=/bin/bash createhome=yes group=www-data
  when: appuser == "www-data"

# Create the app user (if necessary)
- user: name={{ app_name }} shell=/bin/bash createhome=yes group=www-data

# Make sure that the source directory exists
- file: path={{ source_dir }} state=directory mode=770 owner={{ appuser }} group=www-data

# Set the authorized_keys
- authorized_key: user={{ appuser }} key="{{ item }}"
  with_items: authorized_keys

- name: make sure .ssh folder exists for app
  file: path=/home/{{ app_name }}/.ssh mode=700 state=directory owner={{ app_name }}

- authorized_key: user={{ app_name }} key="{{ item }}"
  with_items: authorized_keys

- name: Make sure that the virtual env directory exists
  file: path={{ virtualenv_dir }} state=directory owner={{ appuser }} group=www-data

- name: Make sure that the virtualenv is created
  command: su {{ appuser }} -c "virtualenv {{ virtualenv_dir }}" creates={{ virtualenv_dir }}/bin/activate

- name: adding venv source to .profile 
  lineinfile: dest=/home/{{ app_name }}/.profile mode=700 owner={{ app_name }} regexp='source .*/bin/activate' line='cd {{ source_dir }} && source /var/venvs/{{ app_name }}/bin/activate'

- name: adding DJANGO_SETTINGS_MODULE to .profile
  lineinfile: dest=/home/{{ app_name }}/.profile mode=700 owner={{ app_name }} regexp='DJANGO_SETTINGS_MODULE=*' line='export {{ env_vars[0] }}'

# Install python packages
- pip: name={{ item }} state=present virtualenv={{ virtualenv_dir }} chdir={{ source_dir }}
  with_items: python_packages
  when: python_requirements == None

# Install python packages
- pip: requirements="{{python_requirements}}" state=present virtualenv={{ virtualenv_dir }} chdir={{ source_dir }}
  when: python_requirements != None

# Create virtualenv directory
- file: path={{ virtualenv_dir }} state=directory owner={{ appuser }} group=www-data recurse=yes

# Create a uwsgi configuration file
- template: src=uwsgi.ini.j2 dest=/etc/uwsgi-emperor/vassals/{{ app_name }}.ini owner={{ appuser }} group=www-data
  when: app_enabled

# Make sure that uWSGI is started
- service: name=uwsgi-emperor state=started
{'fraction_non_alphanumeric': 0.1335820895522388, 'fraction_numerical': 0.007835820895522387, 'mean_word_length': 5.023595505617978, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 22, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4205479', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1660, 'n_words': 519}