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

import os
import sys

import subprocess
import re
from subprocess import call

"""
mousefix tool
this tries to automatically do the equivalent of the following:
xinput --list
xinput --list-props DEVICE_ID
xinput set-prop DEVICE_ID "Device Accel Profile" -1
"""

def getidfromxinputstring(theline):
    """returns None if it cant find matches in the given line"""

    m = re.search("id=[0-9]+", theline)
    if m is None:
        return None # incorrect parameters. forget it.

    m = re.search("[0-9]+", m.group(0))
    if m is None:
        return None
    else:
        return m.group(0)

def getidfromdapstring(theline):
    """returns None if it cant find matches in the given line"""

    m = re.search("Device Accel Profile \([0-9]+\)", theline, re.IGNORECASE)
    if m is None:
        return None # incorrect parameters. forget it.

    m = re.search("[0-9]+", m.group(0))
    if m is None:
        return None
    else:
        return m.group(0)

def hascandidateinxinputstring(theline, candidate):
    """returns boolean"""

    if theline.lower().find(candidate.lower()) > 0:
        return True
    else:
        return False

def getdeviceaccelprofilefromid(mid):
    """returns None if cant find DAP"""
    xinput_listprops_ret = os.popen("xinput --list-props %s" % mid).read().strip()
    xlp_list = xinput_listprops_ret.split('\n')
    for pc in xlp_list: # pc = props candidate
        if hascandidateinxinputstring(pc, "Device Accel Profile"):
            dap = getidfromdapstring(pc)
            return dap
    return None

# mid = mouse id, dap = device accel profile
def applymousefix(mid, dap):
    call(["xinput", "set-prop", mid, dap, "-1"])

def detect_and_apply():
    mouse_detection = ["mouse", "touchpad"]

    call(["xset", "m", "0", "0"])

    xinput_ret = os.popen("xinput --list").read().strip()
    xr_list = xinput_ret.split('\n')
    for mc in xr_list: # mc = mouse candidate
        for md in mouse_detection: # md = mouse detection
            if hascandidateinxinputstring(mc, md):
                mouse_id = getidfromxinputstring(mc)
                dap = getdeviceaccelprofilefromid(mouse_id)
                if dap is not None:
                    applymousefix(mouse_id, dap)
                else:
                    print("%s: WARNING: detected mouse, but could not detect Device Accel Profile!" % os.path.basename(__file__))<commit_msg>patched mousefix so it returns true/false, so that it can be integrated into env-setup scripts<commit_after>#!/usr/bin/env python

import os
import sys

import subprocess
import re
from subprocess import call

"""
mousefix tool
this tries to automatically do the equivalent of the following:
xinput --list
xinput --list-props DEVICE_ID
xinput set-prop DEVICE_ID "Device Accel Profile" -1
"""

def getidfromxinputstring(theline):
    """returns None if it cant find matches in the given line"""

    m = re.search("id=[0-9]+", theline)
    if m is None:
        return None # incorrect parameters. forget it.

    m = re.search("[0-9]+", m.group(0))
    if m is None:
        return None
    else:
        return m.group(0)

def getidfromdapstring(theline):
    """returns None if it cant find matches in the given line"""

    m = re.search("Device Accel Profile \([0-9]+\)", theline, re.IGNORECASE)
    if m is None:
        return None # incorrect parameters. forget it.

    m = re.search("[0-9]+", m.group(0))
    if m is None:
        return None
    else:
        return m.group(0)

def hascandidateinxinputstring(theline, candidate):
    """returns boolean"""

    if theline.lower().find(candidate.lower()) > 0:
        return True
    else:
        return False

def getdeviceaccelprofilefromid(mid):
    """returns None if cant find DAP"""
    xinput_listprops_ret = os.popen("xinput --list-props %s" % mid).read().strip()
    xlp_list = xinput_listprops_ret.split('\n')
    for pc in xlp_list: # pc = props candidate
        if hascandidateinxinputstring(pc, "Device Accel Profile"):
            dap = getidfromdapstring(pc)
            return dap
    return None

# mid = mouse id, dap = device accel profile
def applymousefix(mid, dap):
    call(["xinput", "set-prop", mid, dap, "-1"])

def detect_and_apply():
    mouse_detection = ["mouse", "touchpad"]

    call(["xset", "m", "0", "0"])

    xinput_ret = os.popen("xinput --list").read().strip()
    xr_list = xinput_ret.split('\n')
    for mc in xr_list: # mc = mouse candidate
        for md in mouse_detection: # md = mouse detection
            if hascandidateinxinputstring(mc, md):
                mouse_id = getidfromxinputstring(mc)
                dap = getdeviceaccelprofilefromid(mouse_id)
                if dap is not None:
                    applymousefix(mouse_id, dap)
                else:
                    print("%s: WARNING: detected mouse, but could not detect Device Accel Profile!" % os.path.basename(__file__))
                    return False

    return True
{'fraction_non_alphanumeric': 0.1171859296482412, 'fraction_numerical': 0.006834170854271356, 'mean_word_length': 2.685925925925926, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1741618', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1551, 'n_words': 485}