Major cleanup, added all old files (python2) to 'old_v0.1' folder

This commit is contained in:
2017-02-08 20:03:36 +01:00
parent 94e5389e44
commit c17ab40f6a
1507 changed files with 0 additions and 9841 deletions

35
status/cpuTemp.py Executable file
View File

@@ -0,0 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import psutil
def getCpuTemp():
# Check if sensors_temperatures exists
try:
# Define cpu as function of sensors_temperatures
cpu = psutil.sensors_temperatures()
except AttributeError:
error = "'sensors_temperatures' is not supported in this verison of psutil or your OS."
print(error)
return None
# Array for temps for each core.
curCpuTemps = []
# Itterate through all cores of coretemps
for temp in cpu['coretemp']:
curCpuTemps.append(temp[1]) # Append to list
print(temp[0]+': '+str(temp[1])) # Print output
# Check if len of curCpuTemps is something so not to
# calculate on a empty list
if len(curCpuTemps) > 0:
# Compute avg of curCpuTemps
avgCpuTemps = sum(curCpuTemps)/len(curCpuTemps)
return avgCpuTemps
print("Avg: " + str(avgCpuTemps))
else:
print("Couldn't get cpu temp. (division by zero)")
return None
if __name__ == "__main__":
print(getCpuTemp())

43
status/diskusage.py Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: KevinMidboe
# @Date: 2017-01-28 10:54:06
# @Last Modified by: KevinMidboe
# @Last Modified time: 2017-01-31 22:29:43
# f_avail = free blocks avail to non sudo
# frsize = fundamental file sys byte size
# f_blocks = total number of blocks in the filesystem
from os import statvfs
from re import sub
def sizeof(num, suffix='B'):
for unit in ['','K','M','G','T','P','E','Z']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Y', suffix)
# diskUsage uses statvfs to calculate disk size and availability for given disk
def diskUsage(optionalPath=None):
path = '/'
if optionalPath != None:
path += sub('\+', '/', optionalPath)
try:
s = statvfs(path)
byteLeft = s.f_bavail * s.f_frsize
byteTotal = s.f_blocks * s.f_frsize
byteUsed = byteTotal-byteLeft
return { 'left':sizeof(byteLeft), 'used':sizeof(byteUsed), 'total':sizeof(byteTotal) }
except FileNotFoundError:
return None
except TypeError:
return None
if __name__=="__main__":
n = diskUsage('/media/hdd1')
print(n)

48
status/linuxcpureader.py Normal file
View File

@@ -0,0 +1,48 @@
from functools import partial
from os import path
class LinuxCpuTemperatureReader():
files = [
'/sys/devices/LNXSYSTM:00/LNXTHERM:00/LNXTHERM:01/thermal_zone/temp',
'/sys/bus/acpi/devices/LNXTHERM:00/thermal_zone/temp',
'/proc/acpi/thermal_zone/THM0/temperature',
'/proc/acpi/thermal_zone/THRM/temperature',
'/proc/acpi/thermal_zone/THR1/temperature'
]
@classmethod
def get_reader(cls):
readers = {
cls.files[0]: cls.reader1,
cls.files[1]: cls.reader1,
cls.files[2]: cls.reader2,
cls.files[3]: cls.reader2,
cls.files[4]: cls.reader2
}
for file in cls.files:
if path.exists(file):
reader = readers.get(file)
if reader:
print(reader(file))
return reader(file)
@classmethod
def reader1(cls, file):
def reader(file):
temperature = open(file).read().strip()
temperature = int(temperature) // 1000
return temperature
return partial(reader, file)
@classmethod
def reader2(cls, file):
def reader(file):
temperature = open(file).read().strip()
temperature = temperature.lstrip('temperature :').rstrip(' C')
return int(temperature)
return partial(reader, file)
__all__ = ['LinuxCpuTemperatureReader']

43
status/uptime.py Executable file
View File

@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: KevinMidboe
# @Date: 2017-01-27 19:48:42
# @Last Modified by: KevinMidboe
# @Last Modified time: 2017-02-03 12:33:51
# TODO add better error handling to return statements
from psutil import boot_time
from time import time
def secToDay(seconds):
days = int(seconds/86400)
if days is 1:
return str(days)+' day'
else:
return str(days)+' days'
def secToHour(seconds):
hours = (seconds)//3600
minutes = (seconds - hours*3600)//60
hourMinutes = '%02d' % hours +':'+ '%02d' % minutes
return hourMinutes
def timeSinceBoot():
bootTime = boot_time() # Use psutil 'boot_time' to get seconds since start
currTime = time() # Use 'time()' to get seconds currently
deltaSeconds = int(currTime-bootTime)
# Return in day format
if deltaSeconds >= 86400:
return secToDay(deltaSeconds)
# Return in hour format
elif deltaSeconds < 86400 and deltaSeconds >= 0:
return secToHour(deltaSeconds)
else:
# TODO Throw error
return None
if __name__=="__main__":
print(timeSinceBoot())