<commit_before>import time
from fabric.api import env
from fabric.colors import *

class Provider(object):
    def create_instance(self):
        raise NotImplementedError('create_instance')

class ec2(Provider):
    def create_instance(self):
        """Creates an EC2 Instance"""
        import boto

        print(yellow("Creating EC2 instance"))

        conn = boto.connect_ec2(env.ec2_key, env.ec2_secret)
        reservation = conn.run_instances(env.ec2_ami, 
                                         key_name=env.ec2_keypair, 
                                         instance_type=env.ec2_instancetype,
                                         security_groups=env.ec2_secgroups.split(','))
        
        instance = reservation.instances[0]
        time.sleep(3)

        try:
            conn.create_tags([instance.id], {"Name": env.ec2_tag})
        except AttributeError:
            pass
        
        while instance.state == u'pending':
            print(yellow("Instance state: %s" % instance.state))
            time.sleep(10)
            instance.update()

        print(green("Instance state: %s" % instance.state))
        print(green("Public dns: %s" % instance.public_dns_name))
        
        return instance.public_dns_name

class rackspace(Provider):
    def create_instance(self):
        from cloudservers import CloudServers
        from cloudservers.exceptions import NotFound

        cs = CloudServers(env.rackspace_username, env.rackspace_apikey)
        image = cs.images.find(id=int(env.rackspace_image))
        flavor = cs.flavors.find(id=int(env.rackspace_flavor))
        server = cs.servers.create(env.rackspace_servername, image=image, flavor=flavor)
        server_id = server.id

        while True:
            while True:
                try:
                    server = cs.servers.find(id=server_id)
                    break;
                except NotFound:
                    print(yellow('Server not found yet'))
                    time.sleep(10)
                    pass

            if server.status != 'ACTIVE':
                print(yellow("Server status: %s" % server.status))
                time.sleep(20)
                continue
            break

        server.update(password=env.password)
        public_ip = server.addresses['public'][0]

        print server.addresses
        print(green("Instance state: %s" % server.status))
        print(green("Public IP: %s" % public_ip))

        return public_ip<commit_msg>Friendlier import handling<commit_after>import time
from fabric.api import env
from fabric.colors import *

class Provider(object):
    def create_instance(self):
        raise NotImplementedError('create_instance')

class ec2(Provider):
    def create_instance(self):
        """Creates an EC2 Instance"""
        try:
            import boto
        except ImportError:
            raise Exception("Could not import boto module. "
                            "Try installing by running: pip install boto")

        print(yellow("Creating EC2 instance"))

        conn = boto.connect_ec2(env.ec2_key, env.ec2_secret)
        reservation = conn.run_instances(env.ec2_ami, 
                                         key_name=env.ec2_keypair, 
                                         instance_type=env.ec2_instancetype,
                                         security_groups=env.ec2_secgroups.split(','))
        
        instance = reservation.instances[0]
        time.sleep(3)

        try:
            conn.create_tags([instance.id], {"Name": env.ec2_tag})
        except AttributeError:
            pass
        
        while instance.state == u'pending':
            print(yellow("Instance state: %s" % instance.state))
            time.sleep(10)
            instance.update()

        print(green("Instance state: %s" % instance.state))
        print(green("Public dns: %s" % instance.public_dns_name))
        
        return instance.public_dns_name

class rackspace(Provider):
    def create_instance(self):
        try:
            from cloudservers import CloudServers
            from cloudservers.exceptions import NotFound
        except ImportError:
            raise Exception("Could not import cloudservers module. "
                            "Try installing by running: pip install python-cloudservers")

        cs = CloudServers(env.rackspace_username, env.rackspace_apikey)
        image = cs.images.find(id=int(env.rackspace_image))
        flavor = cs.flavors.find(id=int(env.rackspace_flavor))
        server = cs.servers.create(env.rackspace_servername, image=image, flavor=flavor)
        server_id = server.id

        while True:
            while True:
                try:
                    server = cs.servers.find(id=server_id)
                    break;
                except NotFound:
                    print(yellow('Server not found yet'))
                    time.sleep(10)
                    pass

            if server.status != 'ACTIVE':
                print(yellow("Server status: %s" % server.status))
                time.sleep(20)
                continue
            break

        server.update(password=<PASSWORD>)
        public_ip = server.addresses['public'][0]

        print(green("Instance state: %s" % server.status))
        print(green("Public IP: %s" % public_ip))

        return public_ip
{'fraction_non_alphanumeric': 0.0941066417212348, 'fraction_numerical': 0.007483629560336763, 'mean_word_length': 1.8166491043203372, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6918674', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1401, 'n_words': 293}