16
ˆ
ƒµÂÁà Ú
Index of /FSS-BCZ/root/sys/bus/acpi/devices/LNXCPU:03/physical_node/node0/memory46/subsystem
Index of /FSS-BCZ/root/sys/bus/acpi/devices/LNXCPU:03/physical_node/node0/memory46/subsystem
ˆÀ¿
ƒh¹¾Áà 0
:
ˆl–Ãa¾”êj"Tâ€zàpN©‹FÿÀ
ƒl,³¿a–ß=¿JJj"Tâ‚À3q—TÅ£Å
import inspect
import logging
import os
import time
from peewee import (
BlobField,
CharField,
DateField,
ForeignKeyField,
IntegerField,
PeeweeException,
)
from defence360agent.model import instance, Model
#: seconds in a POSIX day
POSIX_DAY = 24 * 60 * 60
logger = logging.getLogger(__name__)
class FilenameField(BlobField):
"""
Class to store file names in database
"""
def db_value(self, value):
return os.fsencode(value)
def python_value(self, value):
return os.fsdecode(value)
class ScanPathField(CharField):
REALTIME_SCAN_PATH_STUB = "list_of_files"
def db_value(self, value):
if isinstance(value, list):
return self.REALTIME_SCAN_PATH_STUB
return value
class ModelError(PeeweeException):
"""
Model exception. Please use this one from other modules instead
PeeweeException directly
"""
pass
async def run_in_executor(loop, cb, *args):
"""
Fake run_in_executor() test (DEF-4541)
"""
return cb(*args)
def remove_old_and_truncate(
table: Model, num_days: int, max_count: int
) -> int:
"""
Removes records that is older that *num_days* days and
all others that are out of range *max_count* from *table*.
Returns count of rows deleted.
"""
has_timestamp = getattr(table, "timestamp", False)
if not has_timestamp:
raise ValueError("No 'timestamp' column in table {!r}".format(table))
# keep no more than *max_count* rows that are newer than *num_days*
end_save_time = time.time() - num_days * POSIX_DAY
to_keep = (
table.select(table.timestamp)
.order_by(table.timestamp.desc())
.limit(max_count)
.where(table.timestamp > end_save_time)
)
deleted_count = (
table.delete().where(table.timestamp.not_in(to_keep)).execute()
)
return deleted_count
class Eula(Model):
"""Keeps track of updates and acceptions of end user license agreement.
Admins will be asked to accept EULA if the latest version is not accepted
yet.
"""
class Meta:
database = instance.db
db_table = "eula"
#: Date when EULA was updat