aboutsummaryrefslogtreecommitdiff
path: root/ayatanasettings/psutil.py
blob: acdbe672d21116417111e8a3c1e49a724a592de4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import psutil
import os
from .appdata import APPNAME

def isRunning():

    for pProc in psutil.process_iter():

        sName = pProc.name

        if not isinstance(sName, str):

           sName = pProc.name()

        if sName == 'python3' or sName == 'python':

            lCmdLine = pProc.cmdline

            if not isinstance(lCmdLine, list):

               lCmdLine = pProc.cmdline()

            for sCmd in lCmdLine:

                if sCmd.endswith(APPNAME) and pProc.pid != os.getpid():

                    return True

        elif sName.endswith(APPNAME) and pProc.pid != os.getpid():

            return True

    return False

def isSystemd():

    for pProc in psutil.process_iter():

        sName = pProc.name

        if not isinstance(sName, str):

           sName = pProc.name()

        if sName == 'systemd':

            lCmdLine = pProc.cmdline

            if not isinstance(lCmdLine, list):

               lCmdLine = pProc.cmdline()

            for sCmd in lCmdLine:

                if sCmd == '--user':

                    return True

    return False