<commit_before>#!/usr/bin/env python

import argparse
import subprocess
import os
import sys

from instance_utils import format_instance, AwsInstance

# Ithemal runs on Python 2 mostly
try:
    input = raw_input
except NameError:
    pass

class InstanceConnector(AwsInstance):
    def __init__(self, identity, host, root):
        super(InstanceConnector, self).__init__(identity, require_pem=True)
        self.host = host
        self.root = root

    def connect_to_instance(self, instance):
        ssh_address = 'ec2-user@{}'.format(instance['PublicDnsName'])
        ssh_args = ['ssh', '-i', self.pem_key, '-t', ssh_address]

        if self.host:
            ssh_args.append('bash -l')
        elif self.root:
            ssh_args.append('sudo docker exec -u root -it ithemal bash -l')
        else:
            ssh_args.append('sudo docker exec -u ithemal -it ithemal bash -l')

        os.execvp('ssh', ssh_args)
        sys.exit(1)

def interactively_connect_to_instance(aws_instances):
    while True:
        instances = aws_instances.get_running_instances()
        if not instances:
            print('No instances to connect to!')
            return
        elif len(instances) == 1:
            aws_instances.connect_to_instance(instances[0])
            return

        print('Active instances:')
        for i, instance in enumerate(instances):
            print('{}) {}'.format(i + 1, format_instance(instance)))

        try:
            res = input('Enter a number to connect to that instance, or "q" to exit: ')
        except KeyboardInterrupt:
            return
        except EOFError:
            return
<commit_msg>connect with tmux rather than just bash to keep sessions running<commit_after>#!/usr/bin/env python

import argparse
import subprocess
import os
import sys

from instance_utils import format_instance, AwsInstance

# Ithemal runs on Python 2 mostly
try:
    input = raw_input
except NameError:
    pass

class InstanceConnector(AwsInstance):
    def __init__(self, identity, host, root):
        super(InstanceConnector, self).__init__(identity, require_pem=True)
        self.host = host
        self.root = root

    def connect_to_instance(self, instance):
        ssh_address = 'ec2-user@{}'.format(instance['PublicDnsName'])
        ssh_args = ['ssh', '-i', self.pem_key, '-t', ssh_address]

        conn_com = "bash -lc '~/ithemal/aws/tmux_attach.sh'"

        if self.host:
            ssh_args.append(conn_com)
        elif self.root:
            ssh_args.append('sudo docker exec -u root -it ithemal {}'.format(conn_com))
        else:
            ssh_args.append('sudo docker exec -u ithemal -it ithemal {}'.format(conn_com))

        os.execvp('ssh', ssh_args)
        sys.exit(1)

def interactively_connect_to_instance(aws_instances):
    while True:
        instances = aws_instances.get_running_instances()
        if not instances:
            print('No instances to connect to!')
            return
        elif len(instances) == 1:
            aws_instances.connect_to_instance(instances[0])
            return

        print('Active instances:')
        for i, instance in enumerate(instances):
            print('{}) {}'.format(i + 1, format_instance(instance)))

        try:
            res = input('Enter a number to connect to that instance, or "q" to exit: ')
        except KeyboardInterrupt:
            return
        except EOFError:
            return

{'fraction_non_alphanumeric': 0.10105140186915888, 'fraction_numerical': 0.0035046728971962616, 'mean_word_length': 2.502044989775051, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '625147', 'n_tokens_mistral': 1033, 'n_tokens_neox': 998, 'n_words': 273}