<commit_before>#!/usr/bin/python
# devguard.py
#
# Device monitoring
#
# Author: Zex <<EMAIL>>
#
import pyudev
#from pyudev import MonitorObserver
#from gi.overrides import GObject as gobject
import gobject
from pyudev.glib import GUDevMonitorObserver

def on_dev_changed(action, device):

    with open('/tmp/device-changed', 'a') as fd:

        fd.write('<+++++++++++++++++++++++++++++++++++>\n')
        fd.write(str(action)+'\n')
        fd.write('---------------------------\n')


        [fd.write(str(item)+'\n') for item in device.items()]

context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by('block')

observer = GUDevMonitorObserver(monitor)
observer.connect('device-changed', on_dev_changed)
monitor.start()

#monitor.enable_receiving()
gobject.MainLoop().run()

<commit_msg>do cleanup<commit_after>#!/usr/bin/python
# devguard.py
#
# Device monitoring
#
# Author: Zex <<EMAIL>>
#
import pyudev
#from pyudev import MonitorObserver
#from gi.overrides import GObject as gobject
import gobject
from pyudev.glib import GUDevMonitorObserver

def on_dev_changed(action, device):

    with open('/tmp/device-changed', 'a') as fd:

        fd.write(str(action)+'\n')
        [fd.write(str(item)+'\n') for item in device.items()]

context = pyudev.Context()
monitor = pyudev.Monitor.from_netlink(context)
monitor.filter_by('block')

observer = GUDevMonitorObserver(monitor)
observer.connect('device-changed', on_dev_changed)
monitor.start()

gobject.MainLoop().run()


{'fraction_non_alphanumeric': 0.1786896095301125, 'fraction_numerical': 0.0, 'mean_word_length': 4.538461538461538, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '1412399', 'n_tokens_mistral': 510, 'n_tokens_neox': 495, 'n_words': 104}