本文整理汇总了Python中uds.models.Util.getSqlDatetime函数的典型用法代码示例。如果您正苦于以下问题:Python getSqlDatetime函数的具体用法?Python getSqlDatetime怎么用?Python getSqlDatetime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getSqlDatetime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: store
def store(uuid, data, validator=None, validity=DEFAULT_VALIDITY):
if validator is not None:
validator = pickle.dumps(validator)
try:
t = TicketStore.objects.get(uuid=uuid)
t.data = pickle.dumps(data)
t.stamp = getSqlDatetime()
t.validity = validity
t.save()
except TicketStore.DoesNotExist:
t = TicketStore.objects.create(uuid=uuid, stamp=getSqlDatetime(), data=pickle.dumps(data), validator=validator, validity=validity)
开发者ID:aiminickwong,项目名称:openuds,代码行数:11,代码来源:TicketStore.py
示例2: addPermission
def addPermission(**kwargs):
"""
Adds a permission to an object and an user or group
"""
user = kwargs.get('user', None)
group = kwargs.get('group', None)
if user is not None and group is not None:
raise Exception('Use only user or group, but not both')
if user is None and group is None:
raise Exception('Must at least indicate user or group')
object_type = kwargs.get('object_type', None)
if object_type is None:
raise Exception('At least an object type is required')
object_id = kwargs.get('object_id', None)
permission = kwargs.get('permission', Permissions.PERMISSION_NONE)
if user is not None:
q = Q(user=user)
else:
q = Q(group=group)
try:
existing = Permissions.objects.filter(q, object_type=object_type, object_id=object_id)[0]
existing.permission = permission
existing.save()
return existing
except Exception: # Does not exists
return Permissions.objects.create(created=getSqlDatetime(), ends=None, user=user, group=group,
object_type=object_type, object_id=object_id, permission=permission)
开发者ID:dkmstr,项目名称:openuds,代码行数:35,代码来源:Permissions.py
示例3: nextEvent
def nextEvent(self, checkFrom=None, startEvent=True, offset=None):
"""
Returns next event for this interval
Returns a list of two elements. First is datetime of event begining, second is timedelta of duration
"""
logger.debug('Obtaining nextEvent')
if checkFrom is None:
checkFrom = getSqlDatetime()
if offset is None:
offset = datetime.timedelta(minutes=0)
cacheKey = six.text_type(hash(self.calendar.modified)) + self.calendar.uuid + six.text_type(
offset.seconds) + six.text_type(int(time.mktime(checkFrom.timetuple()))) + 'event' + (
'x' if startEvent is True else '_')
next_event = CalendarChecker.cache.get(cacheKey, None)
if next_event is None:
logger.debug('Regenerating cached nextEvent')
next_event = self._updateEvents(checkFrom + offset,
startEvent) # We substract on checkin, so we can take into account for next execution the "offset" on start & end (just the inverse of current, so we substract it)
if next_event is not None:
next_event += offset
CalendarChecker.cache.put(cacheKey, next_event, 3600)
else:
logger.debug('nextEvent cache hit')
CalendarChecker.hits += 1
return next_event
开发者ID:dkmstr,项目名称:openuds,代码行数:28,代码来源:__init__.py
示例4: get
def get(uuid, invalidate=True, owner=None, secure=False):
try:
t = TicketStore.objects.get(uuid=uuid, owner=owner)
validity = datetime.timedelta(seconds=t.validity)
now = getSqlDatetime()
logger.debug('Ticket validity: {} {}'.format(t.stamp + validity, now))
if t.stamp + validity < now:
raise TicketStore.InvalidTicket('Not valid anymore')
if secure is True:
data = pickle.loads(cryptoManager().decrypt(t.data))
else:
data = pickle.loads(t.data)
# If has validator, execute it
if t.validator is not None:
validator = pickle.loads(t.validator)
if validator(data) is False:
raise TicketStore.InvalidTicket('Validation failed')
if invalidate is True:
t.stamp = now - validity - datetime.timedelta(seconds=1)
t.save()
return data
except TicketStore.DoesNotExist:
raise TicketStore.InvalidTicket('Does not exists')
开发者ID:joaoguariglia,项目名称:openuds,代码行数:29,代码来源:TicketStore.py
示例5: markOldUserServicesAsRemovables
def markOldUserServicesAsRemovables(self, activePub):
'''
Used when a new publication is finished.
Marks all user deployed services that belongs to this deployed service, that do not belongs
to "activePub" and are not in use as removable.
Also cancels all preparing user services
Better see the code, it's easier to understand :-)
Args:
activePub: Active publication used as "current" publication to make checks
'''
logger.debug('Marking old user services as removable...')
now = getSqlDatetime()
if activePub is None:
logger.error('No active publication, don\'t know what to erase!!! (ds = {0})'.format(self))
return
for ap in self.publications.exclude(id=activePub.id):
for u in ap.userServices.filter(state=states.userService.PREPARING):
u.cancel()
with transaction.atomic():
ap.userServices.exclude(cache_level=0).filter(state=states.userService.USABLE).update(state=states.userService.REMOVABLE, state_date=now)
ap.userServices.filter(cache_level=0, state=states.userService.USABLE, in_use=False).update(state=states.userService.REMOVABLE, state_date=now)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:25,代码来源:ServicesPool.py
示例6: get_stats
def get_stats(owner_type, event_type, **kwargs):
'''
Returns the average stats grouped by interval for owner_type and owner_id (optional)
Note: if someone cant get this more optimized, please, contribute it!
'''
if isinstance(event_type, (list, tuple)):
fltr = StatsEvents.objects.filter(event_type__in=event_type)
else:
fltr = StatsEvents.objects.filter(event_type=event_type)
if type(owner_type) in (list, tuple):
fltr = fltr.filter(owner_type__in=owner_type)
else:
fltr = fltr.filter(owner_type=owner_type)
if kwargs.get('owner_id', None) is not None:
oid = kwargs.get('owner_id')
if isinstance(oid, (list, tuple)):
fltr = fltr.filter(owner_id__in=oid)
else:
fltr = fltr.filter(owner_id=oid)
since = kwargs.get('since', None)
to = kwargs.get('to', None)
since = since and int(since) or NEVER_UNIX
to = to and int(to) or getSqlDatetime(True)
fltr = fltr.filter(stamp__gte=since, stamp__lt=to)
# We use result as an iterator
return fltr
开发者ID:joaoguariglia,项目名称:openuds,代码行数:33,代码来源:StatsEvents.py
示例7: execute
def execute(self, save=True):
logger.debug('Executing action')
self.last_execution = getSqlDatetime()
params = json.loads(self.params)
saveServicePool = save
if CALENDAR_ACTION_CACHE_L1['id'] == self.action:
self.service_pool.cache_l1_srvs = int(params['size'])
elif CALENDAR_ACTION_CACHE_L2['id'] == self.action:
self.service_pool.cache_l1_srvs = int(params['size'])
elif CALENDAR_ACTION_INITIAL['id'] == self.action:
self.service_pool.initial_srvs = int(params['size'])
elif CALENDAR_ACTION_MAX['id'] == self.action:
self.service_pool.max_srvs = int(params['size'])
elif CALENDAR_ACTION_PUBLISH['id'] == self.action:
self.service_pool.publish(changeLog='Scheduled publication action')
saveServicePool = False
# On save, will regenerate nextExecution
if save:
self.save()
if saveServicePool:
self.service_pool.save()
开发者ID:glyptodon,项目名称:openuds,代码行数:25,代码来源:CalendarAction.py
示例8: __unicode__
def __unicode__(self):
expired = getSqlDatetime() > self.created + timedelta(seconds=self.validity)
if expired:
expired = "Expired"
else:
expired = "Active"
return u"{0} {1} = {2} ({3})".format(self.owner, self.key, self.value, expired)
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:7,代码来源:Cache.py
示例9: check
def check(self, dtime=None):
"""
Checks if the given time is a valid event on calendar
@param dtime: Datetime object to check
TODO: We can improve performance of this by getting from a cache first if we can
"""
if dtime is None:
dtime = getSqlDatetime()
# First, try to get data from cache if it is valid
cacheKey = six.text_type(hash(self.calendar.modified)) + six.text_type(
dtime.date().toordinal()) + self.calendar.uuid + 'checker'
cached = CalendarChecker.cache.get(cacheKey, None)
if cached is not None:
data = bitarray.bitarray() # Empty bitarray
data.frombytes(cached)
CalendarChecker.cache_hit += 1
else:
data = self._updateData(dtime)
# Now data can be accessed as an array of booleans.
# Store data on persistent cache
CalendarChecker.cache.put(cacheKey, data.tobytes(), 3600 * 24)
return data[dtime.hour * 60 + dtime.minute]
开发者ID:dkmstr,项目名称:openuds,代码行数:26,代码来源:__init__.py
示例10: get
def get(uuid, invalidate=True):
try:
t = TicketStore.objects.get(uuid=uuid)
validity = datetime.timedelta(seconds=t.validity)
now = getSqlDatetime()
logger.debug("Ticket validity: {} {}".format(t.stamp + validity, now))
if t.stamp + validity < now:
raise TicketStore.InvalidTicket("Not valid anymore")
data = pickle.loads(t.data)
# If has validator, execute it
if t.validator is not None:
validator = pickle.loads(t.validator)
if validator(data) is False:
raise TicketStore.InvalidTicket("Validation failed")
if invalidate is True:
t.stamp = now - validity - datetime.timedelta(seconds=1)
t.save()
return data
except TicketStore.DoesNotExist:
raise TicketStore.InvalidTicket("Does not exists")
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:26,代码来源:TicketStore.py
示例11: get
def get(uuid, invalidate=True):
try:
t = TicketStore.objects.get(uuid=uuid)
validity = datetime.timedelta(seconds=t.validity)
now = getSqlDatetime()
if t.stamp + validity < now:
raise Exception('Not valid anymore')
data = pickle.loads(t.data)
# If has validator, execute it
if t.validator is not None:
validator = pickle.loads(t.validator)
if validator(data) is False:
raise Exception('Validation failed')
if invalidate is True:
t.stamp = now - validity - datetime.timedelta(seconds=1)
t.save()
return data
except TicketStore.DoesNotExist:
raise Exception('Does not exists')
开发者ID:aiminickwong,项目名称:openuds,代码行数:25,代码来源:TicketStore.py
示例12: get
def get(self, skey, defValue=None):
now = getSqlDatetime()
logger.debug('Requesting key "{}" for cache "{}"'.format(skey, self._owner))
try:
key = self.__getKey(skey)
logger.debug('Key: {}'.format(key))
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
expired = now > c.created + timedelta(seconds=c.validity)
if expired:
return defValue
try:
logger.debug('value: {}'.format(c.value))
val = pickle.loads(encoders.decode(c.value, 'base64'))
except Exception: # If invalid, simple do no tuse it
logger.exception('Invalid pickle from cache')
c.delete()
return defValue
Cache.hits += 1
return val
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
Cache.misses += 1
logger.debug('key not found: {}'.format(skey))
return defValue
except Exception as e:
Cache.misses += 1
logger.debug('Cache inaccesible: {}:{}'.format(skey, e))
return defValue
开发者ID:glyptodon,项目名称:openuds,代码行数:27,代码来源:Cache.py
示例13: getDeadline
def getDeadline(self, chkDateTime=None):
'''
Gets the deadline for an access on chkDateTime
'''
if chkDateTime is None:
chkDateTime = getSqlDatetime()
if self.isAccessAllowed(chkDateTime) is False:
return -1
deadLine = None
for ac in self.calendaraccess_set.all():
if ac.access == states.action.ALLOW and self.fallbackAccess == states.action.DENY:
nextE = CalendarChecker(ac.calendar).nextEvent(chkDateTime, False)
if deadLine is None or deadLine > nextE:
deadLine = nextE
elif ac.access == states.action.DENY: # DENY
nextE = CalendarChecker(ac.calendar).nextEvent(chkDateTime, True)
if deadLine is None or deadLine > nextE:
deadLine = nextE
if deadLine is None:
if self.fallbackAccess == states.action.ALLOW:
return None
else:
return -1
return int((deadLine - chkDateTime).total_seconds())
开发者ID:glyptodon,项目名称:openuds,代码行数:29,代码来源:ServicesPool.py
示例14: stopUsageAccounting
def stopUsageAccounting(self, service):
if hasattr(service, 'accounting') is False:
return
tmp = service.accounting
tmp.user_service = None
tmp.end = getSqlDatetime()
tmp.save()
开发者ID:joaoguariglia,项目名称:openuds,代码行数:8,代码来源:Account.py
示例15: revalidate
def revalidate(uuid, validity=None):
try:
t = TicketStore.objects.get(uuid=uuid)
t.stamp = getSqlDatetime()
if validity is not None:
t.validity = validity
t.save()
except TicketStore.DoesNotExist:
raise Exception('Does not exists')
开发者ID:aiminickwong,项目名称:openuds,代码行数:9,代码来源:TicketStore.py
示例16: assignToUser
def assignToUser(self, user):
'''
Assigns this user deployed service to an user.
Args:
user: User to assing to (db record)
'''
self.cache_level = 0
self.state_date = getSqlDatetime()
self.user = user
开发者ID:glyptodon,项目名称:openuds,代码行数:10,代码来源:UserService.py
示例17: refresh
def refresh(self, skey):
# logger.debug('Refreshing key "%s" for cache "%s"' % (skey, self._owner,))
try:
key = self.__getKey(skey)
c = uds.models.Cache.objects.get(pk=key) # @UndefinedVariable
c.created = getSqlDatetime()
c.save()
except uds.models.Cache.DoesNotExist: # @UndefinedVariable
logger.debug('Can\'t refresh cache key %s because it doesn\'t exists' % skey)
return
开发者ID:glyptodon,项目名称:openuds,代码行数:10,代码来源:Cache.py
示例18: cleanUp
def cleanUp():
'''
Purges the cache items that are no longer vaild.
'''
from django.db import transaction
now = getSqlDatetime()
with transaction.atomic():
for v in Cache.objects.all():
if now > v.created + timedelta(seconds=v.validity):
v.delete()
开发者ID:AlexeyBychkov,项目名称:openuds,代码行数:10,代码来源:Cache.py
示例19: store
def store(uuid, data, validator=None, validity=DEFAULT_VALIDITY, owner=owner, secure=False):
'''
Stores an ticketstore. If one with this uuid already exists, replaces it. Else, creates a new one
validity is in seconds
'''
if validator is not None:
validator = pickle.dumps(validator)
data = pickle.dumps(data)
if secure:
data = cryptoManager().encrypt()
try:
t = TicketStore.objects.get(uuid=uuid, owner=owner)
t.data = data
t.stamp = getSqlDatetime()
t.validity = validity
t.save()
except TicketStore.DoesNotExist:
t = TicketStore.objects.create(uuid=uuid, stamp=getSqlDatetime(), data=data, validator=validator, validity=validity, owner=owner)
开发者ID:joaoguariglia,项目名称:openuds,代码行数:20,代码来源:TicketStore.py
示例20: create
def create(data, validator=None, validity=DEFAULT_VALIDITY, owner=None, secure=False):
'''
validity is in seconds
'''
if validator is not None:
validator = pickle.dumps(validator)
data = pickle.dumps(data)
if secure:
data = cryptoManager().encrypt(data)
return TicketStore.objects.create(stamp=getSqlDatetime(), data=data, validator=validator, validity=validity, owner=owner).uuid
开发者ID:joaoguariglia,项目名称:openuds,代码行数:11,代码来源:TicketStore.py
注:本文中的uds.models.Util.getSqlDatetime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论