コード例 #1
0
ファイル: ldap_spn.py プロジェクト: szaydel/samba
def colour_text(x, state=None):
    if not COLOUR_TEXT:
        return x
    if state == 'error':
        return c_RED(x)
    if state == 'pass':
        return c_GREEN(x)

    return c_DARK_YELLOW(x)
コード例 #2
0
def check_file_text():
    """If called directly as a script, count the found characters."""
    counts = Counter()
    for name in iter_source_files():
        fullname = os.path.join(ROOT, name)
        try:
            with open(fullname) as f:
                s = f.read()
        except UnicodeDecodeError as e:
            if is_latin1_file(name):
                if is_bad_latin1_file(fullname):
                    print(c_RED(f"latin-1 file {name} has long sequences "
                                "of high bytes"))
                else:
                    print(c_GREEN(f"latin-1 file {name} is fine"))
            else:
                print(c_RED(f"can't read {name}: {e}"))

        counts.update(s)
        chars = set(s)
        for c in chars:
            if u.category(c) == 'Cf':
                print(c_GREEN(f"{name} has {u.name(c)}"))

    print(len(counts))
    controls = []
    formats = []
    others = []
    for x in counts:
        c = u.category(x)
        if c == 'Cc':
            controls.append(x)
        elif c == 'Cf':
            formats.append(x)
        elif c[0] == 'C':
            others.append(x)

    print("normal control characters {controls}")
    print("format characters {formats}")
    print("other control characters {others}")
コード例 #3
0
    def summary_output_handler(self, typeof_output):
        """Print a short message if every seems fine, but print details of any
        links that seem broken."""
        failing_repsto = []
        failing_repsfrom = []

        local_data = self.get_local_repl_data()

        if typeof_output != "pull_summary":
            for rep in local_data['repsTo']:
                if rep['is deleted']:
                    continue
                if rep["consecutive failures"] != 0 or rep["last success"] == 0:
                    failing_repsto.append(rep)

        if typeof_output != "notify_summary":
            for rep in local_data['repsFrom']:
                if rep['is deleted']:
                    continue
                if rep["consecutive failures"] != 0 or rep["last success"] == 0:
                    failing_repsto.append(rep)

        if failing_repsto or failing_repsfrom:
            self.message(colour.c_RED("There are failing connections"))
            if failing_repsto:
                self.message(colour.c_RED("Failing outbound connections:"))
                for rep in failing_repsto:
                    self.print_neighbour(rep)
            if failing_repsfrom:
                self.message(colour.c_RED("Failing inbound connection:"))
                for rep in failing_repsfrom:
                    self.print_neighbour(rep)

            return 1

        self.message(colour.c_GREEN("[ALL GOOD]"))