some features blocked because of dependency management problems

This commit is contained in:
Volkan Şahin 2016-06-08 14:52:37 +03:00
parent 9e2fbac6a5
commit 944498af3d
2 changed files with 136 additions and 65 deletions

View File

@ -105,8 +105,8 @@ class Registration():
'os.distributionVersion': System.Os.distribution_version(),
'os.architecture': System.Os.architecture(),
'hardware.cpu.architecture': System.Hardware.Cpu.architecture(),
'hardware.cpu.logicalCoreCount': System.Hardware.Cpu.logical_core_count(),
'hardware.cpu.physicalCoreCount': System.Hardware.Cpu.physical_core_count(),
# 'hardware.cpu.logicalCoreCount': System.Hardware.Cpu.logical_core_count(),
# 'hardware.cpu.physicalCoreCount': System.Hardware.Cpu.physical_core_count(),
'hardware.disk.total': System.Hardware.Disk.total(),
'hardware.disk.used': System.Hardware.Disk.used(),
'hardware.disk.free': System.Hardware.Disk.free(),

View File

@ -4,11 +4,17 @@
import platform
import psutil
import cpuinfo
# import cpuinfo
import re
import os
import configparser
import socket
import fcntl
import struct
from uuid import getnode as get_mac
"""
some functions closed because of dependency management
"""
class System:
class Ahenk(object):
@ -58,18 +64,14 @@ class System:
@staticmethod
def is_running():
try:
if System.Ahenk.get_pid_number() is not None:
if psutil.Process(int(System.Ahenk.get_pid_number())).is_running() is True:
return True
return psutil.pid_exists(int(System.Ahenk.get_pid_number()))
else:
return False
except Exception as e:
return False
@staticmethod
def config_path():
return '/etc/ahenk/ahenk.conf'
@ -80,6 +82,11 @@ class System:
class Process(object):
@staticmethod
def process_by_pid(pid):
return psutil.Process(pid)
"""
@staticmethod
def pids():
return psutil.pids()
@ -90,11 +97,7 @@ class System:
if psutil.Process(id).name() == p_name:
return id
return None
@staticmethod
def process_by_pid(pid):
return psutil.Process(pid)
"""
@staticmethod
def kill_by_pid(pid):
@ -108,9 +111,11 @@ class System:
def path(pid):
return psutil.Process(pid).exe()
"""
@staticmethod
def working_directory(pid):
return psutil.Process(pid).cwd()
"""
@staticmethod
def command_line(pid):
@ -128,6 +133,8 @@ class System:
def create_time(pid):
return psutil.Process(pid).create_time()
"""
@staticmethod
def cpu_times(pid):
return psutil.Process(pid).cpu_times()
@ -151,14 +158,17 @@ class System:
@staticmethod
def threads(pid):
return psutil.Process(pid).threads()
"""
@staticmethod
def nice(pid):
return psutil.Process(pid).nice()
"""
@staticmethod
def environment(pid):
return psutil.Process(pid).environ()
"""
@staticmethod
def details():
@ -166,6 +176,15 @@ class System:
class Sessions(object):
@staticmethod
def user_name():
arr = []
for user in psutil.get_users():
if str(user[0]) is not 'None' and user[0] not in arr:
arr.append(user[0])
return arr
"""
@staticmethod
def user_name():
arr = []
@ -178,6 +197,10 @@ class System:
def user_details():
return psutil.users()
"""
@staticmethod
def last_login_username():
# TODO
@ -185,14 +208,17 @@ class System:
class Os(object):
@staticmethod
def boot_time():
return psutil.boot_time()
@staticmethod
def architecture():
return platform.architecture()[0]
"""
@staticmethod
def boot_time():
return psutil.boot_time()
"""
@staticmethod
def file_format():
return platform.architecture()[1]
@ -277,10 +303,6 @@ class System:
def interface_size():
return len(psutil.net_io_counters(pernic=True))
@staticmethod
def interfaces_details():
return psutil.net_if_addrs()
@staticmethod
def io_counter_detail():
return psutil.net_io_counters(pernic=True)
@ -288,7 +310,7 @@ class System:
@staticmethod
def interfaces():
arr = []
for iface in psutil.net_if_addrs():
for iface in psutil.net_io_counters(pernic=True):
arr.append(str(iface))
return arr
@ -296,38 +318,71 @@ class System:
def ip_addresses():
arr = []
for iface in psutil.net_io_counters(pernic=True):
ip = psutil.net_if_addrs()[str(iface)][0][1]
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$', ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
f = os.popen('ifconfig {} | grep "inet\ addr" | cut -d: -f2 | cut -d" " -f1'.format(iface))
ip = str(f.read()).replace('\n', '')
if ip != '127.0.0.1':
arr.append(ip)
return arr
"""
@staticmethod
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
@staticmethod
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15]))
return ''.join(['%02x:' % ord(char) for char in info[18:24]])[:-1]
@staticmethod
def mac_addresses():
mac = get_mac()
':'.join(("%012X" % mac)[i:i+2] for i in range(0, 12, 2)
arr = []
for iface in psutil.net_io_counters(pernic=True):
try:
addr_list = psutil.net_if_addrs()
mac = addr_list[str(iface)][2][1]
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()) and str(mac) != '00:00:00:00:00:00':
arr.append(mac.lower())
except Exception as e:
pass
# return arr
"""
@staticmethod
def mac_addresses():
arr = []
arr=[]
for iface in psutil.net_io_counters(pernic=True):
try:
addr_list=psutil.net_if_addrs()
mac = addr_list[str(iface)][2][1]
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", mac.lower()) and str(mac) != '00:00:00:00:00:00':
arr.append(mac.lower())
except Exception as e:
pass
mac = open('/sys/class/net/' + iface + '/address').readline()
if str(mac[0:17]) != "00:00:00:00:00:00":
arr.append(mac[0:17])
return arr
"""
@staticmethod
def interfaces_details():
return psutil.net_if_addrs()
@staticmethod
def ip_addresses():
arr = []
for iface in psutil.net_io_counters(pernic=True):
ip = psutil.net_if_addrs()[str(iface)][0][1]
if re.match(r'^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])$', ip) and str(ip) != 'localhost' and str(ip) != '127.0.0.1':
arr.append(ip)
return arr
"""
class Cpu(object):
@staticmethod
def physical_core_count():
return psutil.cpu_count(logical=False)
@staticmethod
def logical_core_count():
return psutil.cpu_count(logical=True)
@staticmethod
def stats():
return psutil.cpu_stats()
@staticmethod
def times():
return psutil.cpu_times()
@ -336,31 +391,47 @@ class System:
def architecture():
return platform.processor()
@staticmethod
def vendor():
return cpuinfo.get_cpu_info()['vendor_id']
"""
@staticmethod
def physical_core_count():
return psutil.cpu_count(logical=False)
@staticmethod
def brand():
return cpuinfo.get_cpu_info()['brand']
@staticmethod
def logical_core_count():
return psutil.cpu_count(logical=True)
@staticmethod
def hz_advertised():
return cpuinfo.get_cpu_info()['hz_advertised']
@staticmethod
def stats():
return psutil.cpu_stats()
"""
@staticmethod
def hz_actual():
return cpuinfo.get_cpu_info()['hz_actual']
"""
@staticmethod
def vendor():
return cpuinfo.get_cpu_info()['vendor_id']
@staticmethod
def bit():
return cpuinfo.get_cpu_info()['bits']
@staticmethod
def brand():
return cpuinfo.get_cpu_info()['brand']
@staticmethod
def family():
return cpuinfo.get_cpu_info()['family']
@staticmethod
def hz_advertised():
return cpuinfo.get_cpu_info()['hz_advertised']
@staticmethod
def model():
return cpuinfo.get_cpu_info()['model']
@staticmethod
def hz_actual():
return cpuinfo.get_cpu_info()['hz_actual']
@staticmethod
def bit():
return cpuinfo.get_cpu_info()['bits']
@staticmethod
def family():
return cpuinfo.get_cpu_info()['family']
@staticmethod
def model():
return cpuinfo.get_cpu_info()['model']
"""