mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-22 22:03:54 +03:00
more fixes an refactoring for 3.7
This commit is contained in:
parent
e836a142fe
commit
d5ac86cfba
@ -36,7 +36,7 @@ import typing
|
||||
|
||||
from uds.core.util.Config import GlobalConfig
|
||||
from uds.models import StatsCounters
|
||||
from uds.models import getSqlDatetime
|
||||
from uds.models import getSqlDatetime, getSqlDatetimeAsUnix
|
||||
from uds.models import StatsEvents
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -155,7 +155,7 @@ class StatsManager:
|
||||
logger.debug('Adding event stat')
|
||||
stamp = kwargs.get('stamp')
|
||||
if stamp is None:
|
||||
stamp = getSqlDatetime(unix=True)
|
||||
stamp = getSqlDatetimeAsUnix()
|
||||
else:
|
||||
# To Unix epoch
|
||||
stamp = int(time.mktime(stamp.timetuple())) # pylint: disable=maybe-no-member
|
||||
|
@ -39,7 +39,7 @@ from django.db.utils import IntegrityError
|
||||
from django.db.models.query import QuerySet
|
||||
|
||||
from uds.models.unique_id import UniqueId
|
||||
from uds.models.util import getSqlDatetime
|
||||
from uds.models.util import getSqlDatetimeAsUnix
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -73,7 +73,7 @@ class UniqueIDGenerator:
|
||||
is global to "unique ids' database
|
||||
"""
|
||||
# First look for a name in the range defined
|
||||
stamp = getSqlDatetime(True)
|
||||
stamp = getSqlDatetimeAsUnix()
|
||||
seq = rangeStart
|
||||
# logger.debug(UniqueId)
|
||||
counter = 0
|
||||
@ -130,7 +130,7 @@ class UniqueIDGenerator:
|
||||
).filter(
|
||||
owner=self._owner, seq=seq
|
||||
).update(
|
||||
owner=toUidGen._owner, basename=toUidGen._baseName, stamp=getSqlDatetime(True) # pylint: disable=protected-access
|
||||
owner=toUidGen._owner, basename=toUidGen._baseName, stamp=getSqlDatetimeAsUnix() # pylint: disable=protected-access
|
||||
)
|
||||
return True
|
||||
|
||||
@ -142,7 +142,7 @@ class UniqueIDGenerator:
|
||||
).filter(
|
||||
owner=self._owner, seq=seq
|
||||
).update(
|
||||
owner='', assigned=False, stamp=getSqlDatetime(True)
|
||||
owner='', assigned=False, stamp=getSqlDatetimeAsUnix()
|
||||
)
|
||||
if flt > 0:
|
||||
self.__purge()
|
||||
@ -160,10 +160,10 @@ class UniqueIDGenerator:
|
||||
self.__filter(seq).delete() # Clean ups all unassigned after last assigned in this range
|
||||
|
||||
def release(self) -> None:
|
||||
UniqueId.objects.select_for_update().filter(owner=self._owner).update(assigned=False, owner='', stamp=getSqlDatetime(True)) # @UndefinedVariable
|
||||
UniqueId.objects.select_for_update().filter(owner=self._owner).update(assigned=False, owner='', stamp=getSqlDatetimeAsUnix()) # @UndefinedVariable
|
||||
self.__purge()
|
||||
|
||||
def releaseOlderThan(self, stamp=None) -> None:
|
||||
stamp = getSqlDatetime(True) if stamp is None else stamp
|
||||
stamp = getSqlDatetimeAsUnix() if stamp is None else stamp
|
||||
UniqueId.objects.select_for_update().filter(owner=self._owner, stamp__lt=stamp).update(assigned=False, owner='', stamp=stamp) # @UndefinedVariable
|
||||
self.__purge()
|
||||
|
@ -36,9 +36,12 @@ import logging
|
||||
from .permissions import Permissions
|
||||
|
||||
# Utility
|
||||
from .util import getSqlDatetime
|
||||
from .util import NEVER
|
||||
from .util import NEVER_UNIX
|
||||
from .util import (
|
||||
getSqlDatetime,
|
||||
getSqlDatetimeAsUnix,
|
||||
NEVER,
|
||||
NEVER_UNIX
|
||||
)
|
||||
|
||||
# Services
|
||||
from .provider import Provider
|
||||
|
@ -37,7 +37,7 @@ import logging
|
||||
from django.db import models
|
||||
|
||||
from .util import NEVER_UNIX
|
||||
from .util import getSqlDatetime
|
||||
from .util import getSqlDatetimeAsUnix
|
||||
from .util import getSqlFnc
|
||||
|
||||
|
||||
@ -90,7 +90,7 @@ class StatsCounters(models.Model):
|
||||
to = kwargs.get('to', None)
|
||||
|
||||
since = int(since) if since else NEVER_UNIX
|
||||
to = int(to) if to else getSqlDatetime(True)
|
||||
to = int(to) if to else getSqlDatetimeAsUnix()
|
||||
|
||||
interval = 600 # By default, group items in ten minutes interval (600 seconds)
|
||||
|
||||
|
@ -37,7 +37,7 @@ import types
|
||||
from django.db import models
|
||||
|
||||
from .util import NEVER_UNIX
|
||||
from .util import getSqlDatetime
|
||||
from .util import getSqlDatetimeAsUnix
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -94,7 +94,7 @@ class StatsEvents(models.Model):
|
||||
to = kwargs.get('to', None)
|
||||
|
||||
since = int(since) if since else NEVER_UNIX
|
||||
to = int(to) if to else getSqlDatetime(True)
|
||||
to = int(to) if to else getSqlDatetimeAsUnix()
|
||||
|
||||
fltr = fltr.filter(stamp__gte=since, stamp__lt=to)
|
||||
|
||||
|
@ -32,7 +32,6 @@
|
||||
"""
|
||||
import logging
|
||||
from time import mktime
|
||||
import typing
|
||||
|
||||
from datetime import datetime
|
||||
from django.db import models
|
||||
@ -56,7 +55,7 @@ class UnsavedForeignKey(models.ForeignKey):
|
||||
allow_unsaved_instance_assignment = True
|
||||
|
||||
|
||||
def getSqlDatetime(unix: bool = False) -> typing.Union[int, datetime]:
|
||||
def getSqlDatetime() -> datetime:
|
||||
"""
|
||||
Returns the current date/time of the database server.
|
||||
|
||||
@ -74,11 +73,10 @@ def getSqlDatetime(unix: bool = False) -> typing.Union[int, datetime]:
|
||||
else:
|
||||
date = datetime.now() # If not know how to get database datetime, returns local datetime (this is fine for sqlite, which is local)
|
||||
|
||||
if unix:
|
||||
return int(mktime(date.timetuple()))
|
||||
else:
|
||||
return date
|
||||
return date
|
||||
|
||||
def getSqlDatetimeAsUnix() -> int:
|
||||
return int(mktime(getSqlDatetime().timetuple()))
|
||||
|
||||
def getSqlFnc(fncName):
|
||||
"""
|
||||
|
@ -30,18 +30,16 @@
|
||||
"""
|
||||
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
|
||||
"""
|
||||
from __future__ import unicode_literals
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
|
||||
from uds.core.services import UserDeployment
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util import log
|
||||
from uds.models.util import getSqlDatetime
|
||||
from uds.models.util import getSqlDatetimeAsUnix
|
||||
|
||||
from . import og
|
||||
import six
|
||||
|
||||
import pickle
|
||||
import logging
|
||||
|
||||
__updated__ = '2019-02-07'
|
||||
|
||||
@ -62,7 +60,7 @@ class OGDeployment(UserDeployment):
|
||||
|
||||
"""
|
||||
|
||||
# : Recheck every six seconds by default (for task methods)
|
||||
# : Recheck every N seconds by default (for task methods)
|
||||
suggestedTime = 20
|
||||
|
||||
def initialize(self):
|
||||
@ -249,7 +247,7 @@ class OGDeployment(UserDeployment):
|
||||
self._name = r['name']
|
||||
self._mac = r['mac']
|
||||
self._ip = r['ip']
|
||||
self._stamp = getSqlDatetime(unix=True)
|
||||
self._stamp = getSqlDatetimeAsUnix()
|
||||
|
||||
# Store actor version & Known ip
|
||||
self.dbservice().setProperty('actor_version', '1.0-OpenGnsys')
|
||||
|
Loading…
x
Reference in New Issue
Block a user