<commit_before>#!/usr/bin/env python3
import sys
import argparse
import boto3

# --------------------------------------------------------------------------------
# arg parse
# --------------------------------------------------------------------------------

parser = argparse.ArgumentParser(description='ec2 utils')
parser.set_defaults(target='')

sub_parsers =  parser.add_subparsers(title='sub commands')

# --------------------------------------------------------------------------------
# other functions 
# --------------------------------------------------------------------------------

def getInstanceName(instance):
    for tag in instance.tags:
        if tag['Key'] == 'Name':
            return tag['Value']
    return None

def printIfMatchOrEmpty(ins, cond, out):
    if cond == None or ins == cond:
        print(out)

# --------------------------------------------------------------------------------
# sub commands
# --------------------------------------------------------------------------------
def ids(ns):
    ec2 = boto3.resource('ec2')
    for instance in ec2.instances.all():
        printIfMatchOrEmpty(getInstanceName(instance), ns.name, instance.instance_id)

sub_parser = sub_parsers.add_parser('ids')
sub_parser.set_defaults(target='ids')
sub_parser.set_defaults(func=ids)
sub_parser.add_argument('--name')

def names(ns):
    ec2 = boto3.resource('ec2')
    for instance in ec2.instances.all():<commit_msg>fix no name tag instance status display<commit_after>#!/usr/bin/env python3
import sys
import argparse
import boto3

# --------------------------------------------------------------------------------
# arg parse
# --------------------------------------------------------------------------------

parser = argparse.ArgumentParser(description='ec2 utils')
parser.set_defaults(target='')

sub_parsers =  parser.add_subparsers(title='sub commands')

# --------------------------------------------------------------------------------
# other functions 
# --------------------------------------------------------------------------------

def getInstanceName(instance):
    for tag in instance.tags or []:
        if tag['Key'] == 'Name':
            return tag['Value']
    return None

def printIfMatchOrEmpty(ins, cond, out):
    if cond == None or ins == cond:
        print(out)

# --------------------------------------------------------------------------------
# sub commands
# --------------------------------------------------------------------------------
def ids(ns):
    ec2 = boto3.resource('ec2')
    for instance in ec2.instances.all():
        printIfMatchOrEmpty(getInstanceName(instance), ns.name, instance.instance_id)

sub_parser = sub_parsers.add_parser('ids')
sub_parser.set_defaults(target='ids')
sub_parser.set_defaults(func=ids)
sub_parser.add_argument('--name')

def names(ns):
    ec2 = boto3.resource('ec2')
    for instance in ec2.instances.all():
{'fraction_non_alphanumeric': 0.41775636613902273, 'fraction_numerical': 0.007570543702684102, 'mean_word_length': 1.1645569620253164, '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': '6911509', 'n_tokens_mistral': 665, 'n_tokens_neox': 664, 'n_words': 144}