<commit_before>#!/usr/bin/env python3

#
# Copyright 2013 <NAME>
#
# 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.
#

__author__ = '<NAME>'

import os
import re
import sys
import argparse

COMPLETION_VERSION = "1.1"

class CompletionGenerator(object):
    RE_INVALID = re.compile(r"[^\w]")
    def __init__(self,
                    parser,
                    name=None,
                    output_stream=None,
                    skip_keys=None,
                    complete_function_name=None,
                    complete_add_arguments_name=None,
                    activate_complete_function=None,
                    progname=None):
        self.parser = parser
        if name is None:
            name = os.path.basename(sys.argv[0])
        self.name = self._convert(name)
        if output_stream is None:
            output_stream = sys.stdout
        if skip_keys is None:
            skip_keys = []
        self._skip_keys = []
        for skip_re in skip_keys:
            if isinstance(skip_re, str):
                skip_re = re.compile(skip_re)
            self._skip_keys.append(skip_re)
        self.output_stream = output_stream
        if complete_function_name is None:
            complete_function_name = 'complete_function'
        self.complete_function_name = complete_function_name
        if complete_add_arguments_name is None:
            complete_add_arguments_name = 'complete_add_arguments'
        self.complete_add_arguments_name = complete_add_arguments_name
        if activate_complete_function is None:
            activate_complete_function = ''
        self.activate_complete_function = activate_complete_function
        if progname is None:
            progname = sys.argv[0]
        self.progname = progname
        self._generated_functions = set()
        self.complete(self.parser, [self.name])
        function = self.get_function_name([self.name])
        self.output_stream.write("""\
complete -F {function} -o filenames {name}
""".format(function=function, name=name))

    @classmethod
    def write_version_file(cls, stream):
        stream.write("""\
ZAPPER_CURRENT_COMPLETION_VERSION={}
""".format(COMPLETION_VERSION))

    def _convert(self, key):
        return self.RE_INVALID.sub('X', key)

    def get_function_name(self, stack):
        return '_' + '_'.join(self._convert(key) for key in stack)

    def generate_function(self, parser, stack, keys):
        #print(">>> {} : {}".format('.'.join(stack), keys))
        function_name = self.get_function_name(stack)
        current_keys = ' '.join(keys)
        current_stack = ' '.join(stack)
        complete_function_code = ''
        complete_function = parser.get_default(self.complete_function_name)<commit_msg>Bug fixing: filenames not needed in completion<commit_after>#!/usr/bin/env python3

#
# Copyright 2013 <NAME>
#
# 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.
#

__author__ = '<NAME>'

import os
import re
import sys
import argparse

COMPLETION_VERSION = "1.2"

class CompletionGenerator(object):
    RE_INVALID = re.compile(r"[^\w]")
    def __init__(self,
                    parser,
                    name=None,
                    output_stream=None,
                    skip_keys=None,
                    complete_function_name=None,
                    complete_add_arguments_name=None,
                    activate_complete_function=None,
                    progname=None):
        self.parser = parser
        if name is None:
            name = os.path.basename(sys.argv[0])
        self.name = self._convert(name)
        if output_stream is None:
            output_stream = sys.stdout
        if skip_keys is None:
            skip_keys = []
        self._skip_keys = []
        for skip_re in skip_keys:
            if isinstance(skip_re, str):
                skip_re = re.compile(skip_re)
            self._skip_keys.append(skip_re)
        self.output_stream = output_stream
        if complete_function_name is None:
            complete_function_name = 'complete_function'
        self.complete_function_name = complete_function_name
        if complete_add_arguments_name is None:
            complete_add_arguments_name = 'complete_add_arguments'
        self.complete_add_arguments_name = complete_add_arguments_name
        if activate_complete_function is None:
            activate_complete_function = ''
        self.activate_complete_function = activate_complete_function
        if progname is None:
            progname = sys.argv[0]
        self.progname = progname
        self._generated_functions = set()
        self.complete(self.parser, [self.name])
        function = self.get_function_name([self.name])
        self.output_stream.write("""\
complete -F {function} {name}
""".format(function=function, name=name))

    @classmethod
    def write_version_file(cls, stream):
        stream.write("""\
ZAPPER_CURRENT_COMPLETION_VERSION={}
""".format(COMPLETION_VERSION))

    def _convert(self, key):
        return self.RE_INVALID.sub('X', key)

    def get_function_name(self, stack):
        return '_' + '_'.join(self._convert(key) for key in stack)

    def generate_function(self, parser, stack, keys):
        #print(">>> {} : {}".format('.'.join(stack), keys))
        function_name = self.get_function_name(stack)
        current_keys = ' '.join(keys)
        current_stack = ' '.join(stack)
        complete_function_code = ''
        complete_function = parser.get_default(self.complete_function_name)
{'fraction_non_alphanumeric': 0.09211746522411128, 'fraction_numerical': 0.00401854714064915, 'mean_word_length': 2.5989988876529475, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '6978482', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1785, 'n_words': 459}