<commit_before># -*- coding: utf-8 -*-
from . import Command as _Command
from .. import io

from ...vendor.terraform import TFVarsConfig
from ...vendor.git_extensions import extensions as git_ext


class Status(_Command):
    def validate_and_configure(self):
        super(self.__class__, self).validate_and_configure()

        self.tf = TFVarsConfig(self.tfvars_path)

    def _format_row(self, artifact):
        image_tag = artifact['image'].split(':')[-1]
        desired_count = int(artifact.get('desired_count', 0))
        if desired_count == 0:
            desired_count = io.add_color('zero', 'red')

        cpu = artifact.get('cpu', io.add_color('n/a', 'red'))
        memory = artifact.get('memory', io.add_color('n/a', 'red'))
        return [image_tag, desired_count, cpu, memory]

    def run(self):
        git_ext.sync_updates(self.deployment_repo)
        self.tf.load()  # sync_updates may have changed tfvars

        services = self.tf.get_services()

        docker_org = self.config['DOCKER_ORG']
        table_data = [
            ['id', 'name', 'image tag (%s)' % docker_org, 'desired count', 'cpu units', 'memory (mb)'],
        ]
        for i, service_name in enumerate(sorted(services.iterkeys()), 1):
            artifact = services[service_name]
            table_data.append([i, service_name] + self._format_row(artifact))

        io.info('displaying "%s" active&inactive services on %s' % (docker_org, self.env))
        io.print_table(table_data, 'current %s artifacts' % self.env)
        io.warn('only dockerized services are shown here (i.e. no lambda)')
<commit_msg>feat+fix(status): status now works with new TFVarsConfig<commit_after># -*- coding: utf-8 -*-
from . import Command as _Command
from .. import io

from ...vendor.git_extensions import extensions as git_ext


class Status(_Command):
    def _format_row(self, artifact):
        image_tag = artifact['image'].split(':')[-1]
        desired_count = int(artifact.get('desired_count', 0))
        if desired_count == 0:
            desired_count = io.add_color('zero', 'red')

        cpu = artifact.get('cpu', io.add_color('n/a', 'red'))
        memory = artifact.get('memory', io.add_color('n/a', 'red'))
        return [image_tag, desired_count, cpu, memory]

    def _build_status_table(self, deployment_repo):
        services = deployment_repo['tfvars'].get_services()
        docker_org = self.config.get('dockerhub')['organization']
        table_data = [
            ['id', 'name', 'image tag (%s)' % docker_org, 'desired count', 'cpu units', 'memory (mb)'],
        ]
        for i, service_name in enumerate(sorted(services.iterkeys()), 1):
            artifact = services[service_name]
            table_data.append([i, service_name] + self._format_row(artifact))
        return table_data

    def run(self):
        io.info('performing git sync across all specified repositories...')
        for deployment_repo in self.config.get('terraformRepositories'):
            git_ext.sync_updates(deployment_repo['git'])
            deployment_repo['tfvars'].load()  # sync_updates may have changed tfvars.

            table_data = self._build_status_table(deployment_repo)
            env = self.kwargs['env'] or deployment_repo['defaultEnvironment']
            docker_org = self.config.get('dockerhub')['organization']
            io.info('displaying "%s" active&inactive services on "%s"' % (docker_org, env))
            io.print_table(table_data, 'current %s artifacts' % env)
        io.warn('only dockerized services are shown here (i.e. no lambda)')

{'fraction_non_alphanumeric': 0.13841412160268982, 'fraction_numerical': 0.002801905295601009, 'mean_word_length': 3.0706955530216646, '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': '5301455', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1062, 'n_words': 250}