<commit_before>import os
import subprocess
import sys
from datetime import datetime
from time import sleep
from uuid import uuid4

import digitalocean
import pytz

from readconfig import read_config, read_environemnt, read_startup

USAGE = ('USAGE: featuredeploy deploy [$branch [$commit]] | ls | rm $id | '
         'rmbranch $branch | rmall | ttl $ip $hours | logs $ip)')
NAME_PREFIX = 'resmioapp--'


dir_path = os.path.dirname(os.path.realpath(__file__))
startup_script = os.path.join(dir_path, 'deploy.sh')
config = read_config()


def get_manager():
    return digitalocean.Manager(token=config['DIGITAL_OCEAN_TOKEN'])


def expand_config_vars(stri, extra):
    for key, value in config.items() + extra.items():
        if key.isupper():
            stri = stri.replace('{{' + key + '}}', value)
    return stri


def create_droplet(branch, githash):
    user_data = open(startup_script).read()

    # use all keys registered at digitalocean
    keys = get_manager().get_all_sshkeys()

    setenvs = []
    for var, value in read_environemnt().items():
        assert var.replace('_', '').isalnum()
        export = '{var}=$(cat <<-{eof}\n{value}\n{eof}\n)'.format(
            value=value,
            var=var,
            eof=uuid4().hex)
        setenvs.append(export)

    user_data = expand_config_vars(
        user_data,
        {'GITHASH': githash,
         'BRANCH': branch,
         'SETENVS': ' '.join(setenvs),
         'STARTUP': read_startup()})

    droplet = digitalocean.Droplet(token=config['DIGITAL_OCEAN_TOKEN'],
                                   name='{}{}--{}'.format(
                                       NAME_PREFIX, githash, branch),
                                   region='ams3',
                                   image='docker',
                                   size_slug='2gb',<commit_msg>Update featuredeploy.py<commit_after>import os
import subprocess
import sys
from datetime import datetime
from time import sleep
from uuid import uuid4

import digitalocean
import pytz

from readconfig import read_config, read_environemnt, read_startup

USAGE = ('USAGE: featuredeploy deploy [$branch [$commit]] | ls | rm $id | '
         'rmbranch $branch | rmall | ttl $ip $hours | logs $ip)')
NAME_PREFIX = 'resmioapp--'


dir_path = os.path.dirname(os.path.realpath(__file__))
startup_script = os.path.join(dir_path, 'deploy.sh')
config = read_config()


def get_manager():
    return digitalocean.Manager(token=config['DIGITAL_OCEAN_TOKEN'])


def expand_config_vars(stri, extra):
    for key, value in config.items() + extra.items():
        if key.isupper():
            stri = stri.replace('{{' + key + '}}', value)
    return stri


def create_droplet(branch, githash):
    user_data = open(startup_script).read()

    # use all keys registered at digitalocean
    keys = get_manager().get_all_sshkeys()

    setenvs = []
    for var, value in read_environemnt().items():
        assert var.replace('_', '').isalnum()
        export = '{var}=$(cat <<-{eof}\n{value}\n{eof}\n)'.format(
            value=value,
            var=var,
            eof=uuid4().hex)
        setenvs.append(export)

    user_data = expand_config_vars(
        user_data,
        {'GITHASH': githash,
         'BRANCH': branch,
         'SETENVS': ' '.join(setenvs),
         'STARTUP': read_startup()})

    droplet = digitalocean.Droplet(token=config['DIGITAL_OCEAN_TOKEN'],
                                   name='{}{}--{}'.format(
                                       NAME_PREFIX, githash, branch),
                                   region='ams3',
                                   image='docker-18-04',
                                   size_slug='2gb',
{'fraction_non_alphanumeric': 0.13070652173913044, 'fraction_numerical': 0.003260869565217391, 'mean_word_length': 2.355515041020966, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5604608', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1135, 'n_words': 248}