Beispiel #1
0
    def __init__(self, base, cli):
        super().__init__(base, cli)
        self.base = base
        self.cli = cli
        self.time_metrics = {}

        # Install the MetricsFilter logger. Hook our handler to all of the
        # relevant loggers which emit metrics and perf messages.
        #
        # See: https://dnf.readthedocs.io/en/latest/api_common.html
        metrics_handler = logging.StreamHandler(sys.stderr)
        metrics_handler.setLevel(dnf.logging.DDEBUG)
        metrics_handler.addFilter(MetricsFilter(self.time_metrics))
        LOGGER.addHandler(metrics_handler)

        # Starts a timer for capturing the full command duration.
        self.full_command_start_time = time.time()

        # Store the process tree and command-line arguments. The process tree
        # includes the parents of the DNF process all the way to init. It can
        # be used to detect whether DNF was launched by a host agent, or just
        # run manually from a user session.
        proc = Process()
        self.time_metrics["process_tree"] = list(
            reversed([proc.name()] + [p.name() for p in proc.parents()]))
        self.time_metrics["command_args"] = sys.argv

        # Set defaults for config variables. We default to saving the
        # perfmetrics reports to `/var/log/yum` since that is where our Chef
        # handler expects to collect them.
        self.metrics_dir = DEFAULT_METRICS_DIR
        self.retention_hours = DEFAULT_RETENTION_HOURS
# determine if we can connect to ipc and get status
try:
    i3 = Connection()
# we won't get a status over ssh, via local console or not running i3/Sway
except Exception:
    exit()

# verify if running Sway
if "sway" not in i3.socket_path:
    exit()

p = Process()
# I am sure there is a better way to loop through all the parent processes
# names and make sure they aren't a multiplexer
for parent in p.parents():
    if parent.name() in multiplexers:
        exit()

# get terminal pid
terminal_pid = p.parents()[-2].pid

# get Sway's information on terminal
container = i3.get_tree().find_by_pid(terminal_pid)[0]

if not container.focused:
    # the application name is handled differently for wayland and xwayland
    # wayland
    if container.app_id:
        termial = container.app_id
    # xwayland