Merge pull request #1464 from niphlod/fix/1309
fixes #1309 (and sessions2trash.py, too)
This commit is contained in:
@@ -1,17 +1,20 @@
|
|||||||
EXPIRATION_MINUTES=60
|
|
||||||
DIGITS=('0','1','2','3','4','5','6','7','8','9')
|
import os, time, stat, logging
|
||||||
import os, time, stat, cPickle, logging
|
from gluon._compat import pickle
|
||||||
path = os.path.join(request.folder,'sessions')
|
|
||||||
|
EXPIRATION_MINUTES = 60
|
||||||
|
|
||||||
|
path = os.path.join(request.folder, 'sessions')
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for filename in os.listdir(path):
|
for path, dirs, files in os.walk(path, topdown=False):
|
||||||
fullpath=os.path.join(path,filename)
|
for x in files:
|
||||||
if os.path.isfile(fullpath) and filename.startswith(DIGITS):
|
fullpath = os.path.join(path, x)
|
||||||
try:
|
try:
|
||||||
filetime = os.stat(fullpath)[stat.ST_MTIME] # get it before our io
|
filetime = os.stat(fullpath)[stat.ST_MTIME] # get it before our io
|
||||||
try:
|
try:
|
||||||
session_data = cPickle.load(open(fullpath, 'rb+'))
|
session_data = pickle.load(open(fullpath, 'rb+'))
|
||||||
expiration = session_data['auth']['expiration']
|
expiration = session_data['auth']['expiration']
|
||||||
except:
|
except:
|
||||||
expiration = EXPIRATION_MINUTES * 60
|
expiration = EXPIRATION_MINUTES * 60
|
||||||
@@ -19,3 +22,7 @@ for filename in os.listdir(path):
|
|||||||
os.unlink(fullpath)
|
os.unlink(fullpath)
|
||||||
except:
|
except:
|
||||||
logging.exception('failure to check %s' % fullpath)
|
logging.exception('failure to check %s' % fullpath)
|
||||||
|
for d in dirs:
|
||||||
|
dd = os.path.join(path, d)
|
||||||
|
if not os.listdir(dd):
|
||||||
|
os.rmdir(dd)
|
||||||
|
|||||||
+11
-15
@@ -30,18 +30,14 @@ Typical usage:
|
|||||||
|
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
sys.path.append(os.path.join(*__file__.split(os.sep)[:-2] or ['.']))
|
|
||||||
|
|
||||||
from gluon import current
|
from gluon import current
|
||||||
from gluon.storage import Storage
|
from gluon.storage import Storage
|
||||||
|
from gluon._compat import pickle
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import cPickle
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
import stat
|
import stat
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
EXPIRATION_MINUTES = 60
|
EXPIRATION_MINUTES = 60
|
||||||
SLEEP_MINUTES = 5
|
SLEEP_MINUTES = 5
|
||||||
@@ -86,12 +82,12 @@ class SessionSet(object):
|
|||||||
status = 'trashed'
|
status = 'trashed'
|
||||||
|
|
||||||
if self.verbose > 1:
|
if self.verbose > 1:
|
||||||
print 'key: %s' % str(item)
|
print('key: %s' % str(item))
|
||||||
print 'expiration: %s seconds' % self.expiration
|
print('expiration: %s seconds' % self.expiration)
|
||||||
print 'last visit: %s' % str(last_visit)
|
print('last visit: %s' % str(last_visit))
|
||||||
print 'age: %s seconds' % age
|
print('age: %s seconds' % age)
|
||||||
print 'status: %s' % status
|
print('status: %s' % status)
|
||||||
print ''
|
print('')
|
||||||
elif self.verbose > 0:
|
elif self.verbose > 0:
|
||||||
print('%s %s' % (str(item), status))
|
print('%s %s' % (str(item), status))
|
||||||
|
|
||||||
@@ -145,7 +141,7 @@ class SessionDb(object):
|
|||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
session = Storage()
|
session = Storage()
|
||||||
session.update(cPickle.loads(self.row.session_data))
|
session.update(pickle.loads(self.row.session_data))
|
||||||
return session
|
return session
|
||||||
|
|
||||||
def last_visit_default(self):
|
def last_visit_default(self):
|
||||||
@@ -155,7 +151,7 @@ class SessionDb(object):
|
|||||||
try:
|
try:
|
||||||
return datetime.datetime.strptime(self.row.modified_datetime, '%Y-%m-%d %H:%M:%S.%f')
|
return datetime.datetime.strptime(self.row.modified_datetime, '%Y-%m-%d %H:%M:%S.%f')
|
||||||
except:
|
except:
|
||||||
print 'failed to retrieve last modified time (value: %s)' % self.row.modified_datetime
|
print('failed to retrieve last modified time (value: %s)' % self.row.modified_datetime)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.row.unique_key
|
return self.row.unique_key
|
||||||
@@ -248,7 +244,7 @@ def main():
|
|||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print 'Sleeping %s seconds' % (options.sleep)
|
print('Sleeping %s seconds' % (options.sleep))
|
||||||
time.sleep(options.sleep)
|
time.sleep(options.sleep)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user