class TestLogs(unittest.TestCase): NEEDLE = "foobar\n" POSITIONS = [10000, 8000, 6000, 4000, 2000, 500] def setUp(self): fd, filename = tempfile.mkstemp() self.filename = filename self.fp = os.fdopen(fd, "w+") for pos in self.POSITIONS: self.fp.seek(pos) self.fp.write(self.NEEDLE) self.fp.close() self.logs = Logs() self.logs.add_available(filename) def tearDown(self): os.remove(self.filename) self.logs.clear_available() def test_searching(self): log = self.logs.get(self.filename) log.searcher.reset() positions = [log.search(self.NEEDLE)[0] for _ in xrange(len(self.POSITIONS))] self.assertEqual(self.POSITIONS, positions) def test_searching_other_buffer_size(self): log = LogReader(self.filename, LogReader.BUFFER_SIZE / 2) log.searcher.reset() positions = [log.search(self.NEEDLE)[0] for _ in xrange(len(self.POSITIONS))] self.assertEqual(self.POSITIONS, positions)
def setUp(self): fd, filename = tempfile.mkstemp() self.filename = filename self.fp = os.fdopen(fd, "w+") for pos in self.POSITIONS: self.fp.seek(pos) self.fp.write(self.NEEDLE) self.fp.close() self.logs = Logs() self.logs.add_available(filename)
def __init__(self, model, id=None): super(Audit, self).__init__(model, id) self.conf = Conf(model) self.graphs = Graphs(model) self.logs = Logs(model) self.reports = Reports(model) self.rules = Rules(model) self.syscall = Syscall(model) self.uri_fmt = '/audit/%s' self.load_rules = self.generate_action_handler('load_rules', ['auditrule_file']) self.log_map = AUDIT_REQUESTS
os.makedirs(log_folder, exist_ok=True) log_filename = log_folder + "/test_log.txt" logs = [DisplayLog(), FileLog(log_filename)] shutil.copy(parameters_filename, log_folder + "/cartpole_agent_parameters.json") shutil.copy("./cartpole/models.py", log_folder + "/models.py") else: logs = [ DisplayLog(), ] log = Logs(logs) #training and test cumulative_step = 0 State = training_environments.reset() for epoch in range(0, max_epochs + 1): #test if epoch % test_interval == 0: cumulative_rewards = [] steps = [] test_memory.clear() for episode in range(episodes_to_test): state = test_environment.reset() cumulative_reward = 0
from log import Logs (a,b) = (5,0) try: c = a/b except Exception, e: error_log = Logs() err_logs = error_log.insert_error(str(e))
import psutil import platform import socket import os from datetime import datetime import time import threading import uuid import locale from log import Logs from net import NetIOCounters, get_interface_addresses from client import Client logs = Logs() net_io_counters = NetIOCounters() logger = logging.getLogger("psdash.web") def socket_constants(prefix): return dict((getattr(socket, n), n) for n in dir(socket) if n.startswith(prefix)) socket_families = socket_constants('AF_') socket_types = socket_constants('SOCK_') with open("slaves", "r") as fr: slaves = fr.read().splitlines() hostnames = [ [slave, 5050] for slave in slaves ]