Initial commit of files
This commit is contained in:
22
classes/utils/audio.py
Normal file
22
classes/utils/audio.py
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Jan 8 10:26:56 2021
|
||||
|
||||
@author: neal
|
||||
"""
|
||||
|
||||
import os
|
||||
from sys import platform as _platform
|
||||
|
||||
sound_args = ""
|
||||
|
||||
def play_sound(file):
|
||||
if _platform == "win32" or _platform == "win64" or _platform == "cygwin":
|
||||
cmd = "wmplayer " + '"' + file + '"'
|
||||
else:
|
||||
cmd = "aplay -N " + sound_args + " " + file + " &"
|
||||
# print(cmd)
|
||||
os.system(cmd)
|
||||
|
||||
#play_sound("../misc/boat-horn.wav")
|
||||
81
classes/utils/logging.py
Normal file
81
classes/utils/logging.py
Normal file
@ -0,0 +1,81 @@
|
||||
import sys
|
||||
from time import strftime, time
|
||||
import csv
|
||||
import json
|
||||
|
||||
#
|
||||
# Text logging
|
||||
#
|
||||
class LOGlog():
|
||||
def __init__(self):
|
||||
self.filename = ""
|
||||
self.handle = 0
|
||||
self.lineno = 0
|
||||
|
||||
def genname(dire="logs", basename="log-", ext="log"):
|
||||
return dire + '/' + basename + strftime("%Y%m%d-%H%M.") + ext
|
||||
|
||||
def create(self, dire="logs", basename="log-", ext="log"):
|
||||
self.lineno = 0
|
||||
self.handle = open(dire + "/" + basename + strftime("%Y%m%d-%H%M.") + ext, 'a')
|
||||
|
||||
def open(self, filename):
|
||||
self.filename = filename
|
||||
self.handle = open(filename, 'r')
|
||||
|
||||
def write(self, str):
|
||||
self.lineno = self.lineno + 1
|
||||
self.handle.write(str + "\n")
|
||||
|
||||
def read(self):
|
||||
self.lineno = self.lineno + 1
|
||||
return self.handle.read()
|
||||
|
||||
def close(self):
|
||||
self.handle.close()
|
||||
|
||||
def lines(self):
|
||||
return self.lineno
|
||||
|
||||
#
|
||||
# CSV logging
|
||||
#
|
||||
class CSVlog(LOGlog):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.header = ""
|
||||
|
||||
def create(self, dire="logs", basename="log-"):
|
||||
super().create(dire, basename, "csv")
|
||||
|
||||
def open(self, filename):
|
||||
self.reader = csv.reader(super().filename)
|
||||
super().open(filename)
|
||||
|
||||
def read(self):
|
||||
return self.reader.next(super().handle)
|
||||
|
||||
def readall(self, csvfile):
|
||||
data = csv.reader(csvfile)
|
||||
csv.close()
|
||||
return list(data)
|
||||
|
||||
#
|
||||
# JSON logging
|
||||
#
|
||||
class JSONlog(LOGlog):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def create(self, dire="logs", basename="log-"):
|
||||
super().create(dire, basename, "json")
|
||||
|
||||
def open(self, filename):
|
||||
super().open(filename)
|
||||
|
||||
def write(self, data):
|
||||
data['timestamp'] = time()
|
||||
super().write(json.dumps(data))
|
||||
|
||||
def read(self, ):
|
||||
return json.loads(super().read())
|
||||
Reference in New Issue
Block a user