<commit_before># -*- coding: utf-8 -*-
"""
    continuity.cli.commons
    ~~~~~~~~~~~~~~~~~~~~~~

    Continuity command line commons.

    :copyright: 2015 by <NAME>.
    :license: BSD, see LICENSE for more details.
"""

from .utils import confirm, prompt, puts, render, to_ascii
from argparse import REMAINDER, SUPPRESS
from clint.textui import colored, indent, puts_err
from continuity.services.commons import ServiceException
from continuity.services.git import GitException, GitService
from continuity.services.github import (GitHubException,
        GitHubRequestException, GitHubService)
from continuity.services.jira import JiraService
from continuity.services.pt import PivotalTrackerService
from continuity.services.utils import cached_property
from os import chmod, rename
from os.path import exists
from requests.exceptions import ConnectionError
from sys import exit


MESSAGES = {
    "continuity_integration_branch": "Integration branch",
    "continuity_tracker": "Configure for (G)itHub Issues, (J)ira, or (P)ivotal Tracker?",  # NOQA
    "git_branch": "Enter branch name",
    "github_2fa_code": "GitHub two-factor authentication code",
    "github_exclusive": "Exclude issues not assigned to you?",
    "github_oauth_token": "GitHub OAuth token",
    "github_password": "<PASSWORD>",
    "github_user": "GitHub user",
    "jira_password": "<PASSWORD>",
    "jira_project_key": "JIRA project key",
    "jira_transition_review": "Transition workflow on review?",
    "jira_transition_finish": "Transition workflow on finish?",
    "jira_url": "JIRA base url",
    "jira_user": "JIRA username",
    "pivotal_api_token": "Pivotal Tracker API token",
    "pivotal_email": "Pivotal Tracker email",
    "pivotal_exclusive": "Exclude stories which you do not own?",
    "pivotal_password": "<PASSWORD>",
    "pivotal_project_id": "Pivotal Tracker project ID"
}
MESSAGES["jira_exclusive"] = MESSAGES["github_exclusive"]


class BaseCommand(object):
    """Base command.

    :param parser: Command-line argument parser.
    :param namespace: Command-line argument namespace.
    """

    def __init__(self, parser, namespace):
        self.namespace = namespace

    @classmethod
    def _help(cls):
        """Get help text for this command.
        """
        try:
            ret_val = getattr(cls, "help")
        except AttributeError:
            ret_val = cls.__doc__.split('\n', 1)[0][:-1]

        return ret_val


class GitCommand(BaseCommand):
    """Base Git command.
    """

    def __call__(self):
        """Call this command.
        """
        self.branch = self.git.branch

        try:
            try:
                self.execute()
            except (ConnectionError, ServiceException):
                puts("fatal: unable to access remote.")
                self.exit()
            except (KeyboardInterrupt, EOFError):
                raise
        except KeyboardInterrupt:
            puts()
            self.exit()

        self.finalize()

    def execute(self):
        """Execute this command.
        """
        raise NotImplementedError

    def exit(self):
        """Handle command exit.
        """
        exit()

    def finalize(self):
        """Finalize this command.
        """
        pass

    def get_section(self, name):
        """Get a git configuration section.
<commit_msg>[#41] Raise specifice KeyboardInterrupt exception<commit_after># -*- coding: utf-8 -*-
"""
    continuity.cli.commons
    ~~~~~~~~~~~~~~~~~~~~~~

    Continuity command line commons.

    :copyright: 2015 by <NAME>.
    :license: BSD, see LICENSE for more details.
"""

from .utils import confirm, prompt, puts, render, to_ascii
from argparse import REMAINDER, SUPPRESS
from clint.textui import colored, indent, puts_err
from continuity.services.commons import ServiceException
from continuity.services.git import GitException, GitService
from continuity.services.github import (GitHubException,
        GitHubRequestException, GitHubService)
from continuity.services.jira import JiraService
from continuity.services.pt import PivotalTrackerService
from continuity.services.utils import cached_property
from os import chmod, rename
from os.path import exists
from requests.exceptions import ConnectionError
from sys import exit


MESSAGES = {
    "continuity_integration_branch": "Integration branch",
    "continuity_tracker": "Configure for (G)itHub Issues, (J)ira, or (P)ivotal Tracker?",  # NOQA
    "git_branch": "Enter branch name",
    "github_2fa_code": "GitHub two-factor authentication code",
    "github_exclusive": "Exclude issues not assigned to you?",
    "github_oauth_token": "GitHub OAuth token",
    "github_password": "<PASSWORD>",
    "github_user": "GitHub user",
    "jira_password": "<PASSWORD>",
    "jira_project_key": "JIRA project key",
    "jira_transition_review": "Transition workflow on review?",
    "jira_transition_finish": "Transition workflow on finish?",
    "jira_url": "JIRA base url",
    "jira_user": "JIRA username",
    "pivotal_api_token": "Pivotal Tracker API token",
    "pivotal_email": "Pivotal Tracker email",
    "pivotal_exclusive": "Exclude stories which you do not own?",
    "pivotal_password": "<PASSWORD>",
    "pivotal_project_id": "Pivotal Tracker project ID"
}
MESSAGES["jira_exclusive"] = MESSAGES["github_exclusive"]


class BaseCommand(object):
    """Base command.

    :param parser: Command-line argument parser.
    :param namespace: Command-line argument namespace.
    """

    def __init__(self, parser, namespace):
        self.namespace = namespace

    @classmethod
    def _help(cls):
        """Get help text for this command.
        """
        try:
            ret_val = getattr(cls, "help")
        except AttributeError:
            ret_val = cls.__doc__.split('\n', 1)[0][:-1]

        return ret_val


class GitCommand(BaseCommand):
    """Base Git command.
    """

    def __call__(self):
        """Call this command.
        """
        self.branch = self.git.branch

        try:
            try:
                self.execute()
            except (ConnectionError, ServiceException):
                puts("fatal: unable to access remote.")
                self.exit()
            except (KeyboardInterrupt, EOFError):
                raise KeyboardInterrupt
        except KeyboardInterrupt:
            puts()
            self.exit()

        self.finalize()

    def execute(self):
        """Execute this command.
        """
        raise NotImplementedError

    def exit(self):
        """Handle command exit.
        """
        exit()

    def finalize(self):
        """Finalize this command.
        """
        pass

    def get_section(self, name):
        """Get a git configuration section.

{'fraction_non_alphanumeric': 0.11370392390011891, 'fraction_numerical': 0.002972651605231867, 'mean_word_length': 2.95358401880141, 'pattern_counts': {'":': 38, '<': 11, '<?xml version=': 0, '>': 11, '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': '2100218', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1873, 'n_words': 545}