<commit_before>#!/usr/bin/env python3
# vim: set ts=4 sw=4 et sts=4 ai:

"""
Functions needed by hdmi2usb-mode-switch implemented using lsusb and other
Linux command line tools.

This will only run on Linux.
"""

import logging
import os
import re
import subprocess

from .base import *

# Try and find unbind-helper


def find_unbind_helper():
    callpaths = [
        os.path.join(os.path.dirname(__file__), "..",
                     "..", "bin", "unbind-helper"),
        "unbind-helper",
    ]

    for path in callpaths:
        pathret = subprocess.call(
            path,
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        if pathret == 255:
            return path

    logging.warning("unbind-helper not found, will have to run as root!")
    return None

unbind_helper = find_unbind_helper()


SYS_ROOT = '/sys/bus/usb/devices'


def get_path_from_sysdir(dirpath):
    buspath = os.path.join(dirpath, 'busnum')
    devpath = os.path.join(dirpath, 'devnum')
    if not os.path.exists(buspath):
        logging.info("Skipping %s (no busnum)", dirname)
        return None
    if not os.path.exists(devpath):
        logging.info("Skipping %s (no devnum)", dirname)
        return None

    busnum = int(open(buspath, 'r').read().strip())
    devnum = int(open(devpath, 'r').read().strip())

    return Path(bus=busnum, address=devnum)

<commit_msg>Fixing two names.<commit_after>#!/usr/bin/env python3
# vim: set ts=4 sw=4 et sts=4 ai:

"""
Functions needed by hdmi2usb-mode-switch implemented using lsusb and other
Linux command line tools.

This will only run on Linux.
"""

import logging
import os
import re
import subprocess

from .base import *

# Try and find unbind-helper


def find_unbind_helper():
    callpaths = [
        os.path.join(os.path.dirname(__file__), "..",
                     "..", "bin", "unbind-helper"),
        "unbind-helper",
    ]

    for path in callpaths:
        pathret = subprocess.call(
            path,
            shell=True,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL)
        if pathret == 255:
            return path

    logging.warning("unbind-helper not found, will have to run as root!")
    return None

unbind_helper = find_unbind_helper()


SYS_ROOT = '/sys/bus/usb/devices'


def get_path_from_sysdir(dirpath):
    buspath = os.path.join(dirpath, 'busnum')
    devpath = os.path.join(dirpath, 'devnum')
    if not os.path.exists(buspath):
        logging.info("Skipping %s (no busnum)", buspath)
        return None
    if not os.path.exists(devpath):
        logging.info("Skipping %s (no devnum)", devpath)
        return None

    busnum = int(open(buspath, 'r').read().strip())
    devnum = int(open(devpath, 'r').read().strip())

    return Path(bus=busnum, address=devnum)


{'fraction_non_alphanumeric': 0.12579281183932348, 'fraction_numerical': 0.005637773079633545, 'mean_word_length': 2.6491002570694087, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2946923', 'n_tokens_mistral': 950, 'n_tokens_neox': 916, 'n_words': 236}