<commit_before>__author__ = 'ohaz'

import os
import util
import shutil
import subprocess
from distutils import file_util, dir_util
from util import copy_repo_to_specific, add_to_requirements
from cloud_specific_files.aws import config

OWN_FOLDER = os.path.join(util.OWN_PATH, 'cloud_specific_files', 'aws')
#OWN_PATH = os.path.dirname(os.path.realpath(__file__))

#List with extra pip install packages
add_to_reqs = ['boto']




# Implement this function
def deploy():
    try:
        prepare_deployment()
    except StandardError, e:
        print('Canceling AWS')
        return
    copy_config_to_repo()
    copy_ebextensions_to_repo()
    copy_elasticbeanstalk_to_repo()
    deploy_app_to_aws()

def prepare_deployment():
    copy_repo_to_specific('aws')
    add_to_requirements('aws', add_to_reqs)

def run_subprocess(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=1, shell=True)
    for line in iter(p.stdout.readline, b''):
        print(line)
    p.stdout.close()
    p.wait()


def deploy_app_to_aws():
    arglist = OWN_FOLDER+' '+os.path.join(OWN_FOLDER, 'repo')+' '+config.AWS_EB_ACCESS_KEY+' '+config.AWS_EB_SECRET_KEY
    bashCommand = "/bin/bash "+os.path.join(OWN_FOLDER, 'deploy_to_aws.sh')+ ' ' + arglist 
    os.system(bashCommand)

def copy_config_to_repo():
    target = os.path.join(OWN_FOLDER, 'repo', 'config.py')
    if os.path.exists(target):
        print(' > AWS Deploy > Removing file '+target)
        os.remove(target)
    print(' > AWS Deploy > copying config.py to aws/repo/')
    file_util.copy_file(os.path.join(OWN_FOLDER, 'config.py'), target)
    print(' > AWS Deploy > Done copying.')

def copy_ebextensions_to_repo():
    target = os.path.join(OWN_FOLDER, 'repo', '.ebextensions')
    if os.path.exists(target):
        print(' > AWS Deploy > Removing dir '+target)
        shutil.rmtree(target)
    print(' > AWS Deploy > copying .ebextensions to aws/repo/')
    shutil.copytree(os.path.join(OWN_FOLDER, '.ebextensions'), target)<commit_msg>changed aws.py for bug fix<commit_after>__author__ = 'ohaz'

import os
import util
import shutil
import subprocess
from distutils import file_util, dir_util
from util import copy_repo_to_specific, add_to_requirements
from cloud_specific_files.aws import config

OWN_FOLDER = os.path.join(util.OWN_PATH, 'cloud_specific_files', 'aws')
#OWN_PATH = os.path.dirname(os.path.realpath(__file__))

#List with extra pip install packages
add_to_reqs = ['boto']




# Implement this function
def deploy():
    try:
        prepare_deployment()
    except StandardError, e:
        print('Canceling AWS')
        return
    copy_config_to_repo()
    copy_ebextensions_to_repo()
    copy_elasticbeanstalk_to_repo()
    deploy_app_to_aws()

def prepare_deployment():
    copy_repo_to_specific('aws')
    add_to_requirements('aws', add_to_reqs)

def run_subprocess(cmd):
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, bufsize=1, shell=True)
    for line in iter(p.stdout.readline, b''):
        print(line)
    p.stdout.close()
    p.wait()

def deploy_app_to_aws():
    arglist = OWN_FOLDER+' '+os.path.join(OWN_FOLDER, 'repo')+' '+config.AWS_EB_ACCESS_KEY+' '+config.AWS_EB_SECRET_KEY
    bashCommand = "/bin/bash "+os.path.join(OWN_FOLDER, 'deploy_to_aws.sh')+ ' ' + arglist 
    os.system(bashCommand)

def copy_config_to_repo():
    target = os.path.join(OWN_FOLDER, 'repo', 'config.py')
    if os.path.exists(target):
        print(' > AWS Deploy > Removing file '+target)
        os.remove(target)
    print(' > AWS Deploy > copying config.py to aws/repo/')
    file_util.copy_file(os.path.join(OWN_FOLDER, 'config.py'), target)
    print(' > AWS Deploy > Done copying.')

def copy_ebextensions_to_repo():
    target = os.path.join(OWN_FOLDER, 'repo', '.ebextensions')
    if os.path.exists(target):
        print(' > AWS Deploy > Removing dir '+target)
        shutil.rmtree(target)
    print(' > AWS Deploy > copying .ebextensions to aws/repo/')
    shutil.copytree(os.path.join(OWN_FOLDER, '.ebextensions'), target)
{'fraction_non_alphanumeric': 0.1275184275184275, 'fraction_numerical': 0.0004914004914004914, 'mean_word_length': 4.133669609079445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6192015', 'n_tokens_mistral': 1502, 'n_tokens_neox': 1460, 'n_words': 293}