<commit_before># Copyright 2012 OpenStack LLC.
# All Rights Reserved
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4

"""
Command-line interface to the Quantum APIs
"""
import argparse
import gettext
import logging
import os
import sys

from cliff.app import App
from cliff.commandmanager import CommandManager

from quantumclient.common import clientmanager
from quantumclient.common import exceptions as exc
from quantumclient.common import utils


gettext.install('quantum', unicode=1)
VERSION = '2.0'
QUANTUM_API_VERSION = '2.0'


def env(*_vars, **kwargs):
    """Search for the first defined of possibly many env vars

    Returns the first environment variable defined in vars, or
    returns the default defined in kwargs.

    """
    for v in _vars:
        value = os.environ.get(v, None)
        if value:
            return value
    return kwargs.get('default', '')


COMMAND_V2 = {
    'net-list': utils.import_class(
        'quantumclient.quantum.v2_0.network.ListNetwork'),
    'net-external-list': utils.import_class(
        'quantumclient.quantum.v2_0.network.ListExternalNetwork'),
    'net-show': utils.import_class(
        'quantumclient.quantum.v2_0.network.ShowNetwork'),
    'net-create': utils.import_class(
        'quantumclient.quantum.v2_0.network.CreateNetwork'),
    'net-delete': utils.import_class(
        'quantumclient.quantum.v2_0.network.DeleteNetwork'),
    'net-update': utils.import_class(
        'quantumclient.quantum.v2_0.network.UpdateNetwork'),
    'subnet-list': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.ListSubnet'),
    'subnet-show': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.ShowSubnet'),
    'subnet-create': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.CreateSubnet'),
    'subnet-delete': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.DeleteSubnet'),
    'subnet-update': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.UpdateSubnet'),
    'port-list': utils.import_class(
        'quantumclient.quantum.v2_0.port.ListPort'),
    'port-show': utils.import_class(
        'quantumclient.quantum.v2_0.port.ShowPort'),
    'port-create': utils.import_class(
        'quantumclient.quantum.v2_0.port.CreatePort'),
    'port-delete': utils.import_class(
        'quantumclient.quantum.v2_0.port.DeletePort'),
    'port-update': utils.import_class(
        'quantumclient.quantum.v2_0.port.UpdatePort'),
    'quota-list': utils.import_class(
        'quantumclient.quantum.v2_0.quota.ListQuota'),
    'quota-show': utils.import_class(
        'quantumclient.quantum.v2_0.quota.ShowQuota'),
    'quota-delete': utils.import_class(
        'quantumclient.quantum.v2_0.quota.DeleteQuota'),
    'quota-update': utils.import_class(
        'quantumclient.quantum.v2_0.quota.UpdateQuota'),
    'ext-list': utils.import_class(
        'quantumclient.quantum.v2_0.extension.ListExt'),
    'ext-show': utils.import_class(
        'quantumclient.quantum.v2_0.extension.ShowExt'),
    'router-list': utils.import_class(
        'quantumclient.quantum.v2_0.router.ListRouter'),
    'router-port-list': utils.import_class(
        'quantumclient.quantum.v2_0.port.ListRouterPort'),
    'router-show': utils.import_class(
        'quantumclient.quantum.v2_0.router.ShowRouter'),
    'router-create': utils.import_class(
        'quantumclient.quantum.v2_0.router.CreateRouter'),
    'router-delete': utils.import_class(
        'quantumclient.quantum.v2_0.router.DeleteRouter'),
    'router-update': utils.import_class(
        'quantumclient.quantum.v2_0.router.UpdateRouter'),
    'router-interface-add': utils.import_class(
        'quantumclient.quantum.v2_0.router.AddInterfaceRouter'),
    'router-interface-delete': utils.import_class(
        'quantumclient.quantum.v2_0.router.RemoveInterfaceRouter'),
    'router-gateway-set': utils.import_class(
        'quantumclient.quantum.v2_0.router.SetGatewayRouter'),
    'router-gateway-clear': utils.import_class(
        'quantumclient.quantum.v2_0.router.RemoveGatewayRouter'),
    'floatingip-list': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.ListFloatingIP'),
    'floatingip-show': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.ShowFloatingIP'),
    'floatingip-create': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.CreateFloatingIP'),
    'floatingip-delete': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.DeleteFloatingIP'),
    'floatingip-associate': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.AssociateFloatingIP'),
    'floatingip-disassociate': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.DisassociateFloatingIP'),
    'security-group-list': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroup'),
    'security-group-show': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ShowSecurityGroup'),
    'security-group-create': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroup'),
    'security-group-delete': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroup'),
    'security-group-rule-list': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroupRule'),
    'security-group-rule-show': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ShowSecurityGroupRule'),
    'security-group-rule-create': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroupRule'),
    'security-group-rule-delete': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroupRule'),
}

COMMANDS = {'2.0': COMMAND_V2}


class HelpAction(argparse.Action):
    """Provide a custom action so the -h and --help options
    to the main app will print a list of the commands.

    The commands are determined by checking the CommandManager
    instance, passed in as the "default" value for the action.
    """
    def __call__(self, parser, namespace, values, option_string=None):
        app = self.default
        parser.print_help(app.stdout)
        app.stdout.write('\nCommands for API v%s:\n' % app.api_version)
        command_manager = app.command_manager
        for name, ep in sorted(command_manager):
            factory = ep.load()
            cmd = factory(self, None)
            one_liner = cmd.get_description().split('\n')[0]
            app.stdout.write('  %-25s  %s\n' % (name, one_liner))
        sys.exit(0)

<commit_msg>Ensures that help alignment is not hard coded<commit_after># Copyright 2012 OpenStack LLC.
# All Rights Reserved
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
#
# vim: tabstop=4 shiftwidth=4 softtabstop=4

"""
Command-line interface to the Quantum APIs
"""
import argparse
import gettext
import logging
import os
import sys

from cliff.app import App
from cliff.commandmanager import CommandManager

from quantumclient.common import clientmanager
from quantumclient.common import exceptions as exc
from quantumclient.common import utils


gettext.install('quantum', unicode=1)
VERSION = '2.0'
QUANTUM_API_VERSION = '2.0'


def env(*_vars, **kwargs):
    """Search for the first defined of possibly many env vars

    Returns the first environment variable defined in vars, or
    returns the default defined in kwargs.

    """
    for v in _vars:
        value = os.environ.get(v, None)
        if value:
            return value
    return kwargs.get('default', '')


COMMAND_V2 = {
    'net-list': utils.import_class(
        'quantumclient.quantum.v2_0.network.ListNetwork'),
    'net-external-list': utils.import_class(
        'quantumclient.quantum.v2_0.network.ListExternalNetwork'),
    'net-show': utils.import_class(
        'quantumclient.quantum.v2_0.network.ShowNetwork'),
    'net-create': utils.import_class(
        'quantumclient.quantum.v2_0.network.CreateNetwork'),
    'net-delete': utils.import_class(
        'quantumclient.quantum.v2_0.network.DeleteNetwork'),
    'net-update': utils.import_class(
        'quantumclient.quantum.v2_0.network.UpdateNetwork'),
    'subnet-list': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.ListSubnet'),
    'subnet-show': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.ShowSubnet'),
    'subnet-create': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.CreateSubnet'),
    'subnet-delete': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.DeleteSubnet'),
    'subnet-update': utils.import_class(
        'quantumclient.quantum.v2_0.subnet.UpdateSubnet'),
    'port-list': utils.import_class(
        'quantumclient.quantum.v2_0.port.ListPort'),
    'port-show': utils.import_class(
        'quantumclient.quantum.v2_0.port.ShowPort'),
    'port-create': utils.import_class(
        'quantumclient.quantum.v2_0.port.CreatePort'),
    'port-delete': utils.import_class(
        'quantumclient.quantum.v2_0.port.DeletePort'),
    'port-update': utils.import_class(
        'quantumclient.quantum.v2_0.port.UpdatePort'),
    'quota-list': utils.import_class(
        'quantumclient.quantum.v2_0.quota.ListQuota'),
    'quota-show': utils.import_class(
        'quantumclient.quantum.v2_0.quota.ShowQuota'),
    'quota-delete': utils.import_class(
        'quantumclient.quantum.v2_0.quota.DeleteQuota'),
    'quota-update': utils.import_class(
        'quantumclient.quantum.v2_0.quota.UpdateQuota'),
    'ext-list': utils.import_class(
        'quantumclient.quantum.v2_0.extension.ListExt'),
    'ext-show': utils.import_class(
        'quantumclient.quantum.v2_0.extension.ShowExt'),
    'router-list': utils.import_class(
        'quantumclient.quantum.v2_0.router.ListRouter'),
    'router-port-list': utils.import_class(
        'quantumclient.quantum.v2_0.port.ListRouterPort'),
    'router-show': utils.import_class(
        'quantumclient.quantum.v2_0.router.ShowRouter'),
    'router-create': utils.import_class(
        'quantumclient.quantum.v2_0.router.CreateRouter'),
    'router-delete': utils.import_class(
        'quantumclient.quantum.v2_0.router.DeleteRouter'),
    'router-update': utils.import_class(
        'quantumclient.quantum.v2_0.router.UpdateRouter'),
    'router-interface-add': utils.import_class(
        'quantumclient.quantum.v2_0.router.AddInterfaceRouter'),
    'router-interface-delete': utils.import_class(
        'quantumclient.quantum.v2_0.router.RemoveInterfaceRouter'),
    'router-gateway-set': utils.import_class(
        'quantumclient.quantum.v2_0.router.SetGatewayRouter'),
    'router-gateway-clear': utils.import_class(
        'quantumclient.quantum.v2_0.router.RemoveGatewayRouter'),
    'floatingip-list': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.ListFloatingIP'),
    'floatingip-show': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.ShowFloatingIP'),
    'floatingip-create': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.CreateFloatingIP'),
    'floatingip-delete': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.DeleteFloatingIP'),
    'floatingip-associate': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.AssociateFloatingIP'),
    'floatingip-disassociate': utils.import_class(
        'quantumclient.quantum.v2_0.floatingip.DisassociateFloatingIP'),
    'security-group-list': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroup'),
    'security-group-show': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ShowSecurityGroup'),
    'security-group-create': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroup'),
    'security-group-delete': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroup'),
    'security-group-rule-list': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ListSecurityGroupRule'),
    'security-group-rule-show': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.ShowSecurityGroupRule'),
    'security-group-rule-create': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.CreateSecurityGroupRule'),
    'security-group-rule-delete': utils.import_class(
        'quantumclient.quantum.v2_0.securitygroup.DeleteSecurityGroupRule'),
}

COMMANDS = {'2.0': COMMAND_V2}


class HelpAction(argparse.Action):
    """Provide a custom action so the -h and --help options
    to the main app will print a list of the commands.

    The commands are determined by checking the CommandManager
    instance, passed in as the "default" value for the action.
    """
    def __call__(self, parser, namespace, values, option_string=None):
        outputs = []
        max_len = 0
        app = self.default
        parser.print_help(app.stdout)
        app.stdout.write('\nCommands for API v%s:\n' % app.api_version)
        command_manager = app.command_manager
        for name, ep in sorted(command_manager):
            factory = ep.load()
            cmd = factory(self, None)
            one_liner = cmd.get_description().split('\n')[0]
            outputs.append((name, one_liner))
            max_len = max(len(name), max_len)
        for (name, one_liner) in outputs:
            app.stdout.write('  %s  %s\n' % (name.ljust(max_len), one_liner))
        sys.exit(0)


{'fraction_non_alphanumeric': 0.12033793529775397, 'fraction_numerical': 0.015866474345765505, 'mean_word_length': 3.601769911504425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6400721', 'n_tokens_mistral': 4729, 'n_tokens_neox': 4605, 'n_words': 804}