Пример #1
0
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 _find_root():
    try:
        p = subprocess.run(['git', 'rev-parse', '--show-toplevel'],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE,
                           timeout=10)
    except subprocess.SubprocessError as e:
        print(c_RED(f"Error running git (is this a git tree?): {e}"))
        print("This test is only useful in a git working tree")
        sys.exit(1)

    root = p.stdout.decode().strip()

    should_be_roots = (
        os.path.abspath(os.path.join(os.path.dirname(__file__),
                                     "../../..")),
        os.path.abspath(os.path.join(os.path.dirname(__file__),
                                     "../../../..")),
    )
    if root not in should_be_roots:
        print(c_RED("It looks like we have found the wrong git tree!"))
        sys.exit(1)
    return root
Пример #4
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]"))
Пример #5
0
def get_git_files():
    try:
        p = subprocess.run(['git',
                            '-C', ROOT,
                            'ls-files',
                            '-z'],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE,
                           timeout=10)
    except subprocess.SubprocessError as e:
        print(c_RED(f"Error running git (is this a git tree?): {e}"))
        print("This test is only useful in a git working tree")
        return []

    filenames = p.stdout.split(b'\x00')
    return [x.decode() for x in filenames[:-1]]